From c3e63f6e17a99b769ae2e8950f7b4a4f6fab1c1c Mon Sep 17 00:00:00 2001 From: yefei Date: Sun, 8 Oct 2023 10:30:33 +0800 Subject: [PATCH] =?UTF-8?q?ariesy=20=20=E9=87=87=E9=9B=86=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E6=95=B0=E6=8D=AE=E9=87=8D=E5=A4=8D-=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E5=B8=83=E5=BC=8F=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/InvoiceInterfaceServiceImpl.java | 232 +++++++++--------- 1 file changed, 118 insertions(+), 114 deletions(-) diff --git a/dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java b/dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java index 45dfde96..d54ef101 100644 --- a/dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java +++ b/dxhy-core/src/main/java/com/dxhy/core/job/service/impl/InvoiceInterfaceServiceImpl.java @@ -81,7 +81,7 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService { @Resource 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; @@ -657,6 +657,9 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService { String company = tDxRecordInvoiceJobDao.findCompany(taxno); List logList = new ArrayList<>(); for (InvoiceSelectInfo invoiceSelectInfo : invoicesList) { + //加分布式锁 + 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 认证失败 @@ -664,126 +667,127 @@ public class InvoiceInterfaceServiceImpl implements InvoiceInterfaceService { } else { invoiceSelectInfo.setAuthStatus("0"); } - - //加分布式锁 - String lockKey = invoiceSelectInfo.getUuid(); - - RLock lock = redisson.getLock(lockKey); - lock.lock(); - stringRedisTemplate.opsForValue().set(REDIS_KEY, String.valueOf(0)); - - // 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新 - DynamicContextHolder.push(db + DbConstant.BUSINESS_READ); - TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao.findInvoiceByUUid(invoiceSelectInfo.getUuid()); - if (entity != null) { - boolean flag = false; - if (StringUtils.isBlank(entity.getCheckCode()) - && StringUtils.isNotBlank(invoiceSelectInfo.getCheckCode())) { - entity.setCheckCode(invoiceSelectInfo.getCheckCode()); - entity.setCheckDate(new Date()); - flag = true; - } - if (!entity.getInvoiceStatus().equals(invoiceSelectInfo.getInvoiceStatus())) { - entity.setInvoiceStatus(invoiceSelectInfo.getInvoiceStatus()); - entity.setStatusUpdateDate(new Date()); - flag = true; - } - if ("0".equals(entity.getRzhYesorno()) - && !entity.getRzhYesorno().equals(invoiceSelectInfo.getLegalizeState())) { - if ("1".equals(invoiceSelectInfo.getRzlx())) { - entity.setRzhYesorno(invoiceSelectInfo.getLegalizeState()); - entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate()); - entity.setRzlx(invoiceSelectInfo.getRzlx()); - entity.setRzhType(invoiceSelectInfo.getLegalizeType()); - entity.setSfygx("1"); - 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("1"); - } else if ("4".equals(invoiceSelectInfo.getRzlx())) { - entity.setRzhYesorno("2"); - entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate()); - entity.setRzlx(invoiceSelectInfo.getRzlx()); - entity.setRzhType(invoiceSelectInfo.getLegalizeType()); - entity.setSfygx("1"); - if (StringUtils.isNotBlank(invoiceSelectInfo.getLegalizeDate())) { - SimpleDateFormat sim = new SimpleDateFormat("yyyyMMdd"); - entity.setRzhDate(sim.parse(invoiceSelectInfo.getLegalizeDate())); + try { + lock.lock(); + stringRedisTemplate.opsForValue().set(lockKey, String.valueOf(0)); + + // 判断库里是否已经存在,存在则只更新发票状态,状态更新时间,认证状态以及相关字段更新 + DynamicContextHolder.push(db + DbConstant.BUSINESS_READ); + TDxRecordInvoiceJobEntity entity = tDxRecordInvoiceJobDao.findInvoiceByUUid(invoiceSelectInfo.getUuid()); + if (entity != null) { + boolean flag = false; + if (StringUtils.isBlank(entity.getCheckCode()) + && StringUtils.isNotBlank(invoiceSelectInfo.getCheckCode())) { + entity.setCheckCode(invoiceSelectInfo.getCheckCode()); + entity.setCheckDate(new Date()); + flag = true; + } + if (!entity.getInvoiceStatus().equals(invoiceSelectInfo.getInvoiceStatus())) { + entity.setInvoiceStatus(invoiceSelectInfo.getInvoiceStatus()); + entity.setStatusUpdateDate(new Date()); + flag = true; + } + if ("0".equals(entity.getRzhYesorno()) + && !entity.getRzhYesorno().equals(invoiceSelectInfo.getLegalizeState())) { + if ("1".equals(invoiceSelectInfo.getRzlx())) { + entity.setRzhYesorno(invoiceSelectInfo.getLegalizeState()); + entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate()); + entity.setRzlx(invoiceSelectInfo.getRzlx()); + entity.setRzhType(invoiceSelectInfo.getLegalizeType()); + entity.setSfygx("1"); + 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("1"); + } else if ("4".equals(invoiceSelectInfo.getRzlx())) { + entity.setRzhYesorno("2"); + entity.setRzhBelongDate(invoiceSelectInfo.getLegalizeBlongDate()); + entity.setRzlx(invoiceSelectInfo.getRzlx()); + entity.setRzhType(invoiceSelectInfo.getLegalizeType()); + entity.setSfygx("1"); + 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())) { - entity.setAuthStatus("4"); - } else { - entity.setAuthStatus("0"); + flag = true; + + } else if (!"0".equals(entity.getRzhYesorno()) + && !"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; - - } else if (!"0".equals(entity.getRzhYesorno()) - && !"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(""); + // 艺龙推送数据 + 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)); + } } - tDxRecordInvoiceJobDao.updateInvoice(entity, taxno); - } - // 艺龙推送数据 - 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)); + } else { + if (StringUtils.isBlank(invoiceSelectInfo.getLegalizeDate())) { + invoiceSelectInfo.setLegalizeDate(null); } + 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 { - if (StringUtils.isBlank(invoiceSelectInfo.getLegalizeDate())) { - invoiceSelectInfo.setLegalizeDate(null); - } - 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); + 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) { + e.printStackTrace(); + } finally { + lock.unlock(); } - 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); } httpLog.setStatus("1"); httpLog.setTotal(total);