ariesy 采集入库数据重复-加分布式锁

release
yefei 2 years ago
parent 87ccf9689e
commit c3e63f6e17
  1. 18
      dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java

@ -81,7 +81,7 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
@Resource @Resource
private RedissonClient redisson; private RedissonClient redisson;
private static final String REDIS_KEY = "redis_oa_01"; private static final String REDIS_KEY = "collect_invoice_";
private static final int MAX_SIZE = 1000; private static final int MAX_SIZE = 1000;
@ -657,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 认证失败
@ -664,13 +667,9 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
} else { } else {
invoiceSelectInfo.setAuthStatus("0"); invoiceSelectInfo.setAuthStatus("0");
} }
try {
//加分布式锁
String lockKey = invoiceSelectInfo.getUuid();
RLock lock = redisson.getLock(lockKey);
lock.lock(); lock.lock();
stringRedisTemplate.opsForValue().set(REDIS_KEY, String.valueOf(0)); stringRedisTemplate.opsForValue().set(lockKey, String.valueOf(0));
// 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新 // 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新
DynamicContextHolder.push(db + DbConstant.BUSINESS_READ); DynamicContextHolder.push(db + DbConstant.BUSINESS_READ);
@ -784,6 +783,11 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
invoiceLog.setCreateDate(new Date()); invoiceLog.setCreateDate(new Date());
invoiceLog.setInputName("系统自动"); invoiceLog.setInputName("系统自动");
logList.add(invoiceLog); logList.add(invoiceLog);
}catch (Exception e) {
e.printStackTrace();
} finally {
lock.unlock();
}
} }
httpLog.setStatus("1"); httpLog.setStatus("1");
httpLog.setTotal(total); httpLog.setTotal(total);

Loading…
Cancel
Save