ariesy 加分布式锁

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

@ -668,126 +668,128 @@ 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("当前已有线程获取到锁");
DynamicContextHolder.push(db + DbConstant.BUSINESS_READ); }else {
TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao.findInvoiceByUUid(invoiceSelectInfo.getUuid()); // 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新
if (entity != null) { DynamicContextHolder.push(db + DbConstant.BUSINESS_READ);
boolean flag = false; TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao.findInvoiceByUUid(invoiceSelectInfo.getUuid());
if (StringUtils.isBlank(entity.getCheckCode()) if (entity != null) {
&& StringUtils.isNotBlank(invoiceSelectInfo.getCheckCode())) { boolean flag = false;
entity.setCheckCode(invoiceSelectInfo.getCheckCode()); if (StringUtils.isBlank(entity.getCheckCode())
entity.setCheckDate(new Date()); && StringUtils.isNotBlank(invoiceSelectInfo.getCheckCode())) {
flag = true; entity.setCheckCode(invoiceSelectInfo.getCheckCode());
} entity.setCheckDate(new Date());
if (!entity.getInvoiceStatus().equals(invoiceSelectInfo.getInvoiceStatus())) { flag = true;
entity.setInvoiceStatus(invoiceSelectInfo.getInvoiceStatus()); }
entity.setStatusUpdateDate(new Date()); if (!entity.getInvoiceStatus().equals(invoiceSelectInfo.getInvoiceStatus())) {
flag = true; entity.setInvoiceStatus(invoiceSelectInfo.getInvoiceStatus());
} entity.setStatusUpdateDate(new Date());
if ("0".equals(entity.getRzhYesorno()) flag = true;
&& !entity.getRzhYesorno().equals(invoiceSelectInfo.getLegalizeState())) { }
if ("1".equals(invoiceSelectInfo.getRzlx())) { if ("0".equals(entity.getRzhYesorno())
entity.setRzhYesorno(invoiceSelectInfo.getLegalizeState()); && !entity.getRzhYesorno().equals(invoiceSelectInfo.getLegalizeState())) {
entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate()); if ("1".equals(invoiceSelectInfo.getRzlx())) {
entity.setRzlx(invoiceSelectInfo.getRzlx()); entity.setRzhYesorno(invoiceSelectInfo.getLegalizeState());
entity.setRzhType(invoiceSelectInfo.getLegalizeType()); entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate());
entity.setSfygx("1"); entity.setRzlx(invoiceSelectInfo.getRzlx());
if (StringUtils.isNotBlank(invoiceSelectInfo.getLegalizeDate())) { entity.setRzhType(invoiceSelectInfo.getLegalizeType());
SimpleDateFormat sim = new SimpleDateFormat("yyyyMMdd"); entity.setSfygx("1");
entity.setRzhDate(sim.parse(invoiceSelectInfo.getLegalizeDate())); if (StringUtils.isNotBlank(invoiceSelectInfo.getLegalizeDate())) {
} SimpleDateFormat sim = new SimpleDateFormat("yyyyMMdd");
if ("1".equals(invoiceSelectInfo.getLegalizeState())) { entity.setRzhDate(sim.parse(invoiceSelectInfo.getLegalizeDate()));
entity.setAuthStatus("4"); }
} else { if ("1".equals(invoiceSelectInfo.getLegalizeState())) {
entity.setAuthStatus("0"); entity.setAuthStatus("4");
} } else {
entity.setBdkStatus("1"); entity.setAuthStatus("0");
} else if ("4".equals(invoiceSelectInfo.getRzlx())) { }
entity.setRzhYesorno("2"); entity.setBdkStatus("1");
entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate()); } else if ("4".equals(invoiceSelectInfo.getRzlx())) {
entity.setRzlx(invoiceSelectInfo.getRzlx()); entity.setRzhYesorno("2");
entity.setRzhType(invoiceSelectInfo.getLegalizeType()); entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate());
entity.setSfygx("1"); entity.setRzlx(invoiceSelectInfo.getRzlx());
if (StringUtils.isNotBlank(invoiceSelectInfo.getLegalizeDate())) { entity.setRzhType(invoiceSelectInfo.getLegalizeType());
SimpleDateFormat sim = new SimpleDateFormat("yyyyMMdd"); entity.setSfygx("1");
entity.setRzhDate(sim.parse(invoiceSelectInfo.getLegalizeDate())); 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");
} }
if ("1".equals(invoiceSelectInfo.getLegalizeState())) { flag = true;
entity.setAuthStatus("4");
} else { } else if (!"0".equals(entity.getRzhYesorno())
entity.setAuthStatus("0"); && !"1".equals(invoiceSelectInfo.getLegalizeState())) {
entity.setRzhYesorno("0");
entity.setRzhBelongDate(null);
entity.setRzlx("0");
entity.setRzhType(null);
entity.setRzhDate(null);
entity.setAuthStatus("0");
entity.setBdkStatus("0");
entity.setSfygx("0");
flag = true;
}
//TODO 这块业务不理解??
if ("1".equals(entity.getSourceSystem()) && "0".equals(entity.getCollectStatus())) {
entity.setCollectStatus("1");
entity.setCollectFrom("0");
entity.setCollectDate(new Date());
entity.setPoolStatus("1");
entity.setInPoolReason("数据重复");
flag = true;
}
if (flag) {
DynamicContextHolder.push(db + DbConstant.BUSINESS_WRITE);
if (StringUtils.isBlank(entity.getInvoiceCode())) {
entity.setInvoiceCode("");
} }
entity.setBdkStatus("2"); tDxRecordInvoiceJobDao.updateInvoice(entity, taxno);
} }
flag = true; // 艺龙推送数据
if (yLcompany.equals(company)) {
} else if (!"0".equals(entity.getRzhYesorno()) DynamicContextHolder.push(db + DbConstant.BUSINESS_READ);
&& !"1".equals(invoiceSelectInfo.getLegalizeState())) { InvoiceScanEntity selectSign = tDxRecordInvoiceJobDao
entity.setRzhYesorno("0"); .selectByScan(entity.getInvoiceCode() + entity.getInvoiceNo(), dxhyAdmin);
entity.setRzhBelongDate(null); if (selectSign != null && "1".equals(selectSign.getQsStatus())) {
entity.setRzlx("0"); String record = JSON.toJSONString(entity);
entity.setRzhType(null); sender.sendToStatus(Base64.encode(record));
entity.setRzhDate(null); }
entity.setAuthStatus("0");
entity.setBdkStatus("0");
entity.setSfygx("0");
flag = true;
}
//TODO 这块业务不理解??
if ("1".equals(entity.getSourceSystem()) && "0".equals(entity.getCollectStatus())) {
entity.setCollectStatus("1");
entity.setCollectFrom("0");
entity.setCollectDate(new Date());
entity.setPoolStatus("1");
entity.setInPoolReason("数据重复");
flag = true;
}
if (flag) {
DynamicContextHolder.push(db + DbConstant.BUSINESS_WRITE);
if (StringUtils.isBlank(entity.getInvoiceCode())) {
entity.setInvoiceCode("");
} }
tDxRecordInvoiceJobDao.updateInvoice(entity, taxno); } else {
} if (StringUtils.isBlank(invoiceSelectInfo.getLegalizeDate())) {
// 艺龙推送数据 invoiceSelectInfo.setLegalizeDate(null);
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));
} }
TDxRecordInvoiceJobEntity record = exchangePo2Entity(invoiceSelectInfo);
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);
} }
} else { InvoiceLog invoiceLog = new InvoiceLog();
if (StringUtils.isBlank(invoiceSelectInfo.getLegalizeDate())) { invoiceLog.setInvoiceCode(invoiceSelectInfo.getInvoiceCode());
invoiceSelectInfo.setLegalizeDate(null); invoiceLog.setInvoiceNo(invoiceSelectInfo.getInvoiceNo());
} invoiceLog.setType("1");
TDxRecordInvoiceJobEntity record = exchangePo2Entity(invoiceSelectInfo); invoiceLog.setInputStatus("0");
record.setCompany(company); invoiceLog.setCreateDate(new Date());
record.setCollectStatus("1"); invoiceLog.setInputName("系统自动");
record.setCollectFrom("0"); logList.add(invoiceLog);
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);
}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