Merge remote-tracking branch 'origin/1008-采集入库数据重复' into release

release
wangrangrang 2 years ago
commit 7b5616200c
  1. 4
      dxhy-core/pom.xml
  2. 33
      dxhy-core/src/main/java/com/dxhy/core/config/RedissionConfig.java
  3. 238
      dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java

@ -164,6 +164,10 @@
<artifactId>itext-asian</artifactId> <artifactId>itext-asian</artifactId>
<version>5.2.0</version> <version>5.2.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba.cloud</groupId> <groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>

@ -0,0 +1,33 @@
package com.dxhy.core.config;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RedissionConfig {
@Value("${spring.redis.host}")
private String host;
@Value("${spring.redis.port}")
private String port;
@Value("${spring.redis.password}")
private String redisPassword;
@Bean
public RedissonClient getRedisson(){
Config config = new Config();
//单机模式 依次设置redis地址和密码
config.useSingleServer()
.setAddress("redis://" + host + ":" + port)
.setPassword(redisPassword);
return Redisson.create(config);
}
}

@ -14,7 +14,10 @@ import javax.crypto.spec.SecretKeySpec;
import com.dxhy.core.job.thread.InvoiceParseHandle; import com.dxhy.core.job.thread.InvoiceParseHandle;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
@ -72,6 +75,16 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
@Resource @Resource
private Sender sender; private Sender sender;
@Resource
private StringRedisTemplate stringRedisTemplate;
@Resource
private RedissonClient redisson;
private static final String REDIS_KEY = "collect_invoice_";
private static final int MAX_SIZE = 1000;
@Value("${jxjk.collectUrl}") @Value("${jxjk.collectUrl}")
private String collectUrl; private String collectUrl;
@Value("${jxjk.invoiceGet}") @Value("${jxjk.invoiceGet}")
@ -644,6 +657,9 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
String company = tDxRecordInvoiceJobDao.findCompany(taxno); String company = tDxRecordInvoiceJobDao.findCompany(taxno);
List<InvoiceLog> logList = new ArrayList<>(); List<InvoiceLog> logList = new ArrayList<>();
for (InvoiceSelectInfo invoiceSelectInfo : invoicesList) { for (InvoiceSelectInfo invoiceSelectInfo : invoicesList) {
//加分布式锁
String lockKey = REDIS_KEY + invoiceSelectInfo.getUuid();
RLock lock = redisson.getLock(lockKey);
invoiceSelectInfo.setUuid(invoiceSelectInfo.getInvoiceCode() + invoiceSelectInfo.getInvoiceNo()); invoiceSelectInfo.setUuid(invoiceSelectInfo.getInvoiceCode() + invoiceSelectInfo.getInvoiceNo());
if ("1".equals(invoiceSelectInfo.getLegalizeState())) { if ("1".equals(invoiceSelectInfo.getLegalizeState())) {
//认证处理状态 0-未认证 1-已勾选未确认,2已确认 3 已发送认证 4 认证成功 5 认证失败 //认证处理状态 0-未认证 1-已勾选未确认,2已确认 3 已发送认证 4 认证成功 5 认证失败
@ -651,119 +667,131 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
} else { } else {
invoiceSelectInfo.setAuthStatus("0"); invoiceSelectInfo.setAuthStatus("0");
} }
// 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新 try {
DynamicContextHolder.push(db + DbConstant.BUSINESS_READ); boolean isLock = lock.tryLock();
TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao
.findInvoiceByUUid(invoiceSelectInfo.getUuid()); if(!isLock){
if (entity != null) { log.info("当前已有线程获取到锁");
boolean flag = false; }else {
if (StringUtils.isBlank(entity.getCheckCode()) // 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新
&& StringUtils.isNotBlank(invoiceSelectInfo.getCheckCode())) { DynamicContextHolder.push(db + DbConstant.BUSINESS_READ);
entity.setCheckCode(invoiceSelectInfo.getCheckCode()); TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao.findInvoiceByUUid(invoiceSelectInfo.getUuid());
entity.setCheckDate(new Date()); if (entity != null) {
flag = true; boolean flag = false;
} if (StringUtils.isBlank(entity.getCheckCode())
if (!entity.getInvoiceStatus().equals(invoiceSelectInfo.getInvoiceStatus())) { && StringUtils.isNotBlank(invoiceSelectInfo.getCheckCode())) {
entity.setInvoiceStatus(invoiceSelectInfo.getInvoiceStatus()); entity.setCheckCode(invoiceSelectInfo.getCheckCode());
entity.setStatusUpdateDate(new Date()); entity.setCheckDate(new Date());
flag = true; flag = true;
} }
if ("0".equals(entity.getRzhYesorno()) if (!entity.getInvoiceStatus().equals(invoiceSelectInfo.getInvoiceStatus())) {
&& !entity.getRzhYesorno().equals(invoiceSelectInfo.getLegalizeState())) { entity.setInvoiceStatus(invoiceSelectInfo.getInvoiceStatus());
if ("1".equals(invoiceSelectInfo.getRzlx())) { entity.setStatusUpdateDate(new Date());
entity.setRzhYesorno(invoiceSelectInfo.getLegalizeState()); flag = true;
entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate());
entity.setRzlx(invoiceSelectInfo.getRzlx());
entity.setRzhType(invoiceSelectInfo.getLegalizeType());
entity.setSfygx("1");
if (StringUtils.isNotBlank(invoiceSelectInfo.getLegalizeDate())) {
SimpleDateFormat sim = new SimpleDateFormat("yyyyMMdd");
entity.setRzhDate(sim.parse(invoiceSelectInfo.getLegalizeDate()));
} }
if ("1".equals(invoiceSelectInfo.getLegalizeState())) { if ("0".equals(entity.getRzhYesorno())
entity.setAuthStatus("4"); && !entity.getRzhYesorno().equals(invoiceSelectInfo.getLegalizeState())) {
} else { if ("1".equals(invoiceSelectInfo.getRzlx())) {
entity.setRzhYesorno(invoiceSelectInfo.getLegalizeState());
entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate());
entity.setRzlx(invoiceSelectInfo.getRzlx());
entity.setRzhType(invoiceSelectInfo.getLegalizeType());
entity.setSfygx("1");
if (StringUtils.isNotBlank(invoiceSelectInfo.getLegalizeDate())) {
SimpleDateFormat sim = new SimpleDateFormat("yyyyMMdd");
entity.setRzhDate(sim.parse(invoiceSelectInfo.getLegalizeDate()));
}
if ("1".equals(invoiceSelectInfo.getLegalizeState())) {
entity.setAuthStatus("4");
} else {
entity.setAuthStatus("0");
}
entity.setBdkStatus("1");
} else if ("4".equals(invoiceSelectInfo.getRzlx())) {
entity.setRzhYesorno("2");
entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate());
entity.setRzlx(invoiceSelectInfo.getRzlx());
entity.setRzhType(invoiceSelectInfo.getLegalizeType());
entity.setSfygx("1");
if (StringUtils.isNotBlank(invoiceSelectInfo.getLegalizeDate())) {
SimpleDateFormat sim = new SimpleDateFormat("yyyyMMdd");
entity.setRzhDate(sim.parse(invoiceSelectInfo.getLegalizeDate()));
}
if ("1".equals(invoiceSelectInfo.getLegalizeState())) {
entity.setAuthStatus("4");
} else {
entity.setAuthStatus("0");
}
entity.setBdkStatus("2");
}
flag = true;
} else if (!"0".equals(entity.getRzhYesorno())
&& !"1".equals(invoiceSelectInfo.getLegalizeState())) {
entity.setRzhYesorno("0");
entity.setRzhBelongDate(null);
entity.setRzlx("0");
entity.setRzhType(null);
entity.setRzhDate(null);
entity.setAuthStatus("0"); entity.setAuthStatus("0");
entity.setBdkStatus("0");
entity.setSfygx("0");
flag = true;
} }
entity.setBdkStatus("1"); //TODO 这块业务不理解??
} else if ("4".equals(invoiceSelectInfo.getRzlx())) { if ("1".equals(entity.getSourceSystem()) && "0".equals(entity.getCollectStatus())) {
entity.setRzhYesorno("2"); entity.setCollectStatus("1");
entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate()); entity.setCollectFrom("0");
entity.setRzlx(invoiceSelectInfo.getRzlx()); entity.setCollectDate(new Date());
entity.setRzhType(invoiceSelectInfo.getLegalizeType()); entity.setPoolStatus("1");
entity.setSfygx("1"); entity.setInPoolReason("数据重复");
if (StringUtils.isNotBlank(invoiceSelectInfo.getLegalizeDate())) { flag = true;
SimpleDateFormat sim = new SimpleDateFormat("yyyyMMdd");
entity.setRzhDate(sim.parse(invoiceSelectInfo.getLegalizeDate()));
} }
if ("1".equals(invoiceSelectInfo.getLegalizeState())) { if (flag) {
entity.setAuthStatus("4"); DynamicContextHolder.push(db + DbConstant.BUSINESS_WRITE);
} else { if (StringUtils.isBlank(entity.getInvoiceCode())) {
entity.setAuthStatus("0"); entity.setInvoiceCode("");
}
tDxRecordInvoiceJobDao.updateInvoice(entity, taxno);
} }
entity.setBdkStatus("2"); // 艺龙推送数据
} if (yLcompany.equals(company)) {
flag = true; DynamicContextHolder.push(db + DbConstant.BUSINESS_READ);
InvoiceScanEntity selectSign = tDxRecordInvoiceJobDao
} else if (!"0".equals(entity.getRzhYesorno()) .selectByScan(entity.getInvoiceCode() + entity.getInvoiceNo(), dxhyAdmin);
&& !"1".equals(invoiceSelectInfo.getLegalizeState())) { if (selectSign != null && "1".equals(selectSign.getQsStatus())) {
entity.setRzhYesorno("0"); String record = JSON.toJSONString(entity);
entity.setRzhBelongDate(null); sender.sendToStatus(Base64.encode(record));
entity.setRzlx("0"); }
entity.setRzhType(null); }
entity.setRzhDate(null); } else {
entity.setAuthStatus("0"); if (StringUtils.isBlank(invoiceSelectInfo.getLegalizeDate())) {
entity.setBdkStatus("0"); invoiceSelectInfo.setLegalizeDate(null);
entity.setSfygx("0"); }
flag = true; TDxRecordInvoiceJobEntity record = exchangePo2Entity(invoiceSelectInfo);
} record.setCompany(company);
//TODO 这块业务不理解?? record.setCollectStatus("1");
if ("1".equals(entity.getSourceSystem()) && "0".equals(entity.getCollectStatus())) { record.setCollectFrom("0");
entity.setCollectStatus("1"); record.setCollectDate(new Date());
entity.setCollectFrom("0"); record.setPoolStatus("0");
entity.setCollectDate(new Date()); DynamicContextHolder.push(db + DbConstant.BUSINESS_WRITE);
entity.setPoolStatus("1"); tDxRecordInvoiceJobDao.insert(record);
entity.setInPoolReason("数据重复");
flag = true;
}
if (flag) {
DynamicContextHolder.push(db + DbConstant.BUSINESS_WRITE);
if (StringUtils.isBlank(entity.getInvoiceCode())) {
entity.setInvoiceCode("");
}
tDxRecordInvoiceJobDao.updateInvoice(entity, taxno);
}
// 艺龙推送数据
if (yLcompany.equals(company)) {
DynamicContextHolder.push(db + DbConstant.BUSINESS_READ);
InvoiceScanEntity selectSign = tDxRecordInvoiceJobDao
.selectByScan(entity.getInvoiceCode() + entity.getInvoiceNo(), dxhyAdmin);
if (selectSign != null && "1".equals(selectSign.getQsStatus())) {
String record = JSON.toJSONString(entity);
sender.sendToStatus(Base64.encode(record));
} }
InvoiceLog invoiceLog = new InvoiceLog();
invoiceLog.setInvoiceCode(invoiceSelectInfo.getInvoiceCode());
invoiceLog.setInvoiceNo(invoiceSelectInfo.getInvoiceNo());
invoiceLog.setType("1");
invoiceLog.setInputStatus("0");
invoiceLog.setCreateDate(new Date());
invoiceLog.setInputName("系统自动");
logList.add(invoiceLog);
} }
} else { }catch (Exception e) {
if (StringUtils.isBlank(invoiceSelectInfo.getLegalizeDate())) { e.printStackTrace();
invoiceSelectInfo.setLegalizeDate(null); } finally {
} //关锁
TDxRecordInvoiceJobEntity record = exchangePo2Entity(invoiceSelectInfo); lock.unlock();
record.setCompany(company);
record.setCollectStatus("1");
record.setCollectFrom("0");
record.setCollectDate(new Date());
record.setPoolStatus("0");
DynamicContextHolder.push(db + DbConstant.BUSINESS_WRITE);
tDxRecordInvoiceJobDao.insert(record);
} }
InvoiceLog invoiceLog = new InvoiceLog();
invoiceLog.setInvoiceCode(invoiceSelectInfo.getInvoiceCode());
invoiceLog.setInvoiceNo(invoiceSelectInfo.getInvoiceNo());
invoiceLog.setType("1");
invoiceLog.setInputStatus("0");
invoiceLog.setCreateDate(new Date());
invoiceLog.setInputName("系统自动");
logList.add(invoiceLog);
} }
httpLog.setStatus("1"); httpLog.setStatus("1");
httpLog.setTotal(total); httpLog.setTotal(total);

Loading…
Cancel
Save