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

release
wangrangrang 2 years ago
commit f038561c3c
  1. 48
      dxhy-core/src/main/java/com/dxhy/core/config/RedissionConfig.java
  2. 25
      dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java

@ -7,27 +7,27 @@ 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);
}
}
//@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);
// }
//}
//

@ -78,8 +78,8 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
@Resource
private StringRedisTemplate stringRedisTemplate;
@Resource
private RedissonClient redisson;
// @Resource
// private RedissonClient redisson;
private static final String REDIS_KEY = "collect_invoice_";
@ -658,8 +658,8 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
List<InvoiceLog> logList = new ArrayList<>();
for (InvoiceSelectInfo invoiceSelectInfo : invoicesList) {
//加分布式锁
String lockKey = REDIS_KEY + invoiceSelectInfo.getUuid();
RLock lock = redisson.getLock(lockKey);
// String lockKey = REDIS_KEY + invoiceSelectInfo.getUuid();
// RLock lock = redisson.getLock(lockKey);
invoiceSelectInfo.setUuid(invoiceSelectInfo.getInvoiceCode() + invoiceSelectInfo.getInvoiceNo());
if ("1".equals(invoiceSelectInfo.getLegalizeState())) {
//认证处理状态 0-未认证 1-已勾选未确认,2已确认 3 已发送认证 4 认证成功 5 认证失败
@ -668,11 +668,11 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
invoiceSelectInfo.setAuthStatus("0");
}
try {
boolean isLock = lock.tryLock();
// boolean isLock = lock.tryLock();
if(!isLock){
log.info("当前已有线程获取到锁");
}else {
// if(!isLock){
// log.info("当前已有线程获取到锁");
// }else {
// 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新
DynamicContextHolder.push(db + DbConstant.BUSINESS_READ);
TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao.findInvoiceByUUid(invoiceSelectInfo.getUuid());
@ -785,13 +785,14 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
invoiceLog.setCreateDate(new Date());
invoiceLog.setInputName("系统自动");
logList.add(invoiceLog);
}
// }
}catch (Exception e) {
e.printStackTrace();
} finally {
//关锁
lock.unlock();
}
// finally {
// //关锁
// lock.unlock();
// }
}
httpLog.setStatus("1");
httpLog.setTotal(total);

Loading…
Cancel
Save