ariesy 加分布式锁

release
yefei 2 years ago
parent fc604ad5d7
commit 355a3c4d22
  1. 8
      dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java

@ -668,9 +668,11 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
invoiceSelectInfo.setAuthStatus("0");
}
try {
lock.lock();
stringRedisTemplate.opsForValue().set(lockKey, String.valueOf(0));
boolean isLock = lock.tryLock();
if(!isLock){
log.info("当前已有线程获取到锁");
}else {
// 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新
DynamicContextHolder.push(db + DbConstant.BUSINESS_READ);
TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao.findInvoiceByUUid(invoiceSelectInfo.getUuid());
@ -783,11 +785,11 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService {
invoiceLog.setCreateDate(new Date());
invoiceLog.setInputName("系统自动");
logList.add(invoiceLog);
}
}catch (Exception e) {
e.printStackTrace();
} finally {
//关锁
stringRedisTemplate.opsForValue().set(lockKey, String.valueOf(1));
lock.unlock();
}
}

Loading…
Cancel
Save