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"); invoiceSelectInfo.setAuthStatus("0");
} }
try { try {
lock.lock(); boolean isLock = lock.tryLock();
stringRedisTemplate.opsForValue().set(lockKey, String.valueOf(0));
if(!isLock){
log.info("当前已有线程获取到锁");
}else {
// 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新 // 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新
DynamicContextHolder.push(db + DbConstant.BUSINESS_READ); DynamicContextHolder.push(db + DbConstant.BUSINESS_READ);
TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao.findInvoiceByUUid(invoiceSelectInfo.getUuid()); TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao.findInvoiceByUUid(invoiceSelectInfo.getUuid());
@ -783,11 +785,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) { }catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
//关锁 //关锁
stringRedisTemplate.opsForValue().set(lockKey, String.valueOf(1));
lock.unlock(); lock.unlock();
} }
} }

Loading…
Cancel
Save