From 08e33f4e8177a0e123345a83e9a56101c6f52f08 Mon Sep 17 00:00:00 2001 From: yefei Date: Thu, 30 Nov 2023 14:01:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ariesy=20=E5=A2=9E=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E9=AA=8C=E6=8E=A5=E5=8F=A3=E5=B9=82=E7=AD=89=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dxhy-erp/pom.xml | 4 + .../controller/SDNYMainProcessController.java | 376 ++++++++++-------- 2 files changed, 205 insertions(+), 175 deletions(-) diff --git a/dxhy-erp/pom.xml b/dxhy-erp/pom.xml index 1341d782..7f9916cd 100644 --- a/dxhy-erp/pom.xml +++ b/dxhy-erp/pom.xml @@ -156,6 +156,10 @@ spring-cloud-starter-bootstrap 3.0.2 + + org.redisson + redisson-spring-boot-starter + ${project.artifactId} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java b/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java index f5bf6160..6ce25a21 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java @@ -12,7 +12,6 @@ import com.dxhy.common.exception.BaseException; import com.dxhy.common.util.InvoiceUtil; import com.dxhy.common.utils.Base64Encoding; import com.dxhy.common.utils.R; -import com.dxhy.erp.dao.*; import com.dxhy.erp.entity.*; import com.dxhy.erp.entity.sdny.*; import com.dxhy.erp.model.InvoiceDetailInfo; @@ -21,11 +20,14 @@ import com.dxhy.erp.utils.Base64; import com.dxhy.erp.utils.HmacSHA1Util; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Async; +import org.springframework.util.Base64Utils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -86,6 +88,9 @@ public class SDNYMainProcessController extends AbstractController { @Autowired private ImageSubmitService imageSubmitService; + @Resource + private RedissonClient redisson; + /** * 查验发票 */ @@ -489,220 +494,241 @@ public class SDNYMainProcessController extends AbstractController { @SysLog("发票查验") public ResponseEntity singleInvoiceCheck(@RequestBody Map pramsMap) throws Exception { log.info("传入的参数为:{}", pramsMap); - String dbName = "business"; - JSONObject checkInvoiceResult = null; + String param = JSONObject.toJSONString(pramsMap); + //加分布式锁 + String lockKey = Base64Utils.encodeToString(param.getBytes()); + RLock lock = redisson.getLock(lockKey); + try { + boolean isLock = lock.tryLock(); - InvoiceUtil iu = new InvoiceUtil(pramsMap.get("invoiceCode")); - String fplxdm = iu.getFplxdm(); - if (fplxdm != null || "10107".equals(pramsMap.get("invoiceType")) || "10108".equals(pramsMap.get("invoiceType")) || pramsMap.get("invoiceCode").startsWith("50000")) { - //查验类发票,执行查验操作后入库 - log.info("查验类发票,执行查验操作后入库"); - //权限校验 - if (StringUtils.isBlank(pramsMap.get("invoiceNumber"))) { - return ResponseEntity.ok(JSONObject.toJSONString(R.error("发票号码不能为空!"))); - } + if (!isLock) { + log.info("当前已有线程获取到锁"); + } else { - pramsMap.put("invoiceNo", pramsMap.get("invoiceNumber")); + String dbName = "business"; + JSONObject checkInvoiceResult = null; + + InvoiceUtil iu = new InvoiceUtil(pramsMap.get("invoiceCode")); + String fplxdm = iu.getFplxdm(); + if (fplxdm != null || "10107".equals(pramsMap.get("invoiceType")) || "10108".equals(pramsMap.get("invoiceType")) || pramsMap.get("invoiceCode").startsWith("50000")) { + //查验类发票,执行查验操作后入库 + log.info("查验类发票,执行查验操作后入库"); + //权限校验 + if (StringUtils.isBlank(pramsMap.get("invoiceNumber"))) { + return ResponseEntity.ok(JSONObject.toJSONString(R.error("发票号码不能为空!"))); + } - if (StringUtils.isNotBlank(pramsMap.get("billingDate"))) { - String billingDate = pramsMap.get("billingDate").replaceAll("-", ""); - iu.setKprq(pramsMap.get("billingDate")); - pramsMap.put("invoiceDate", billingDate); - pramsMap.put("billingDate", billingDate); - } else { - return ResponseEntity.ok(JSONObject.toJSONString(R.error("开票日期不能为空!"))); - } + pramsMap.put("invoiceNo", pramsMap.get("invoiceNumber")); - if (StringUtils.isBlank(pramsMap.get("invoiceType"))) { - return ResponseEntity.ok(JSONObject.toJSONString(R.error("发票类型不能为空!"))); - } + if (StringUtils.isNotBlank(pramsMap.get("billingDate"))) { + String billingDate = pramsMap.get("billingDate").replaceAll("-", ""); + iu.setKprq(pramsMap.get("billingDate")); + pramsMap.put("invoiceDate", billingDate); + pramsMap.put("billingDate", billingDate); + } else { + return ResponseEntity.ok(JSONObject.toJSONString(R.error("开票日期不能为空!"))); + } - if (SNFplxEnum.ZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) - || SNFplxEnum.JDC.getSnFplxDm().equals(pramsMap.get("invoiceType")) - || SNFplxEnum.DZZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) - || SNFplxEnum.ESC.getSnFplxDm().equals(pramsMap.get("invoiceType")) - || SNFplxEnum.QDZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) - || SNFplxEnum.QDPP.getSnFplxDm().equals(pramsMap.get("invoiceType"))) { - if (StringUtils.isBlank(pramsMap.get("totalAmount"))) { - return ResponseEntity.ok(JSONObject.toJSONString(R.error("金额不能为空!"))); - } - } else { - if (StringUtils.isBlank(pramsMap.get("checkCode"))) { - return ResponseEntity.ok(JSONObject.toJSONString(R.error("校验码不能为空!"))); - } - } + if (StringUtils.isBlank(pramsMap.get("invoiceType"))) { + return ResponseEntity.ok(JSONObject.toJSONString(R.error("发票类型不能为空!"))); + } - if ("10107".equals(pramsMap.get("invoiceType")) || "10108".equals(pramsMap.get("invoiceType"))) { - pramsMap.put("invoiceType", "21"); - } + if (SNFplxEnum.ZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.JDC.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.DZZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.ESC.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.QDZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.QDPP.getSnFplxDm().equals(pramsMap.get("invoiceType"))) { + if (StringUtils.isBlank(pramsMap.get("totalAmount"))) { + return ResponseEntity.ok(JSONObject.toJSONString(R.error("金额不能为空!"))); + } + } else { + if (StringUtils.isBlank(pramsMap.get("checkCode"))) { + return ResponseEntity.ok(JSONObject.toJSONString(R.error("校验码不能为空!"))); + } + } - log.info("发票类型为:{}", pramsMap.get("invoiceType")); + if ("10107".equals(pramsMap.get("invoiceType")) || "10108".equals(pramsMap.get("invoiceType"))) { + pramsMap.put("invoiceType", "21"); + } - String uuid = (StringUtils.isBlank(pramsMap.get("invoiceCode")) ? "" : pramsMap.get("invoiceCode")) + pramsMap.get("invoiceNo"); - log.info("uuid={}", uuid); - String notes = invoiceQueryService.checkingInvoiceInfo("business", uuid, getUserInfo()); - if (notes != null) { - return ResponseEntity.ok(JSONObject.toJSONString(R.error(notes))); - } + log.info("发票类型为:{}", pramsMap.get("invoiceType")); - //非通行费类发票 先判断底账库中是否已存在 - if (!"32000".equals(pramsMap.get("invoiceType"))) { - //查询底账库是否有对应发票,有则直接返回 - QueryWrapper recordWrapper = new QueryWrapper<>(); - recordWrapper.eq("uuid", uuid); - BaseTDxRecordInvoice checkInvoiceByUuid = snPushCheckRecordService.selectRecordByWrapper(recordWrapper); - if (checkInvoiceByUuid != null) { - log.info("进项票池已存在发票.直接返回票池信息"); - R data = new R(1000, "default success"); + String uuid = (StringUtils.isBlank(pramsMap.get("invoiceCode")) ? "" : pramsMap.get("invoiceCode")) + pramsMap.get("invoiceNo"); + log.info("uuid={}", uuid); + String notes = invoiceQueryService.checkingInvoiceInfo("business", uuid, getUserInfo()); + if (notes != null) { + return ResponseEntity.ok(JSONObject.toJSONString(R.error(notes))); + } - //如果购方名称为空,则查验之后补充购销方相关信息 - String gfName = checkInvoiceByUuid.getGfName(); - String gfAddressAndPhone = checkInvoiceByUuid.getGfAddressAndPhone(); - if(StringUtils.isEmpty(gfName) || StringUtils.isEmpty(gfAddressAndPhone)){ - log.info("购方名称为空,查验补充信息"); - checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap, null); + //非通行费类发票 先判断底账库中是否已存在 + if (!"32000".equals(pramsMap.get("invoiceType"))) { + //查询底账库是否有对应发票,有则直接返回 + QueryWrapper recordWrapper = new QueryWrapper<>(); + recordWrapper.eq("uuid", uuid); + BaseTDxRecordInvoice checkInvoiceByUuid = snPushCheckRecordService.selectRecordByWrapper(recordWrapper); + if (checkInvoiceByUuid != null) { + log.info("进项票池已存在发票.直接返回票池信息"); + R data = new R(1000, "default success"); + + //如果购方名称为空,则查验之后补充购销方相关信息 + String gfName = checkInvoiceByUuid.getGfName(); + String gfAddressAndPhone = checkInvoiceByUuid.getGfAddressAndPhone(); + if (StringUtils.isEmpty(gfName) || StringUtils.isEmpty(gfAddressAndPhone)) { + log.info("购方名称为空,查验补充信息"); + checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap, null); + + if (!checkInvoiceResult.containsKey("code")) { + if (!checkInvoiceResult.containsKey("cyjg")) { + snPushCheckRecordService.updateInvoice(dbName, checkInvoiceResult, recordWrapper); + } else if (checkInvoiceResult.containsKey("cyjg") && !"0001".equals(checkInvoiceResult.getString("cyjg"))) { + data = errorInfo(checkInvoiceResult, data); + return ResponseEntity.ok(JSONObject.toJSONString(data)); - if (!checkInvoiceResult.containsKey("code")) { - if (!checkInvoiceResult.containsKey("cyjg")) { - snPushCheckRecordService.updateInvoice(dbName, checkInvoiceResult, recordWrapper); - } else if (checkInvoiceResult.containsKey("cyjg") && !"0001".equals(checkInvoiceResult.getString("cyjg"))) { - data = errorInfo(checkInvoiceResult, data); - return ResponseEntity.ok(JSONObject.toJSONString(data)); + } + } + checkInvoiceByUuid = snPushCheckRecordService.selectRecordByWrapper(recordWrapper); + } + String invoiceNo = checkInvoiceByUuid.getInvoiceNo(); + QueryWrapper detailWrapper = new QueryWrapper<>(); + detailWrapper.eq("uuid", uuid); + + List baseTDxRecordInvoiceDetail = null; + List vehicleList = null; + if ("10104".equals(pramsMap.get("invoiceType")) || "10105".equals(pramsMap.get("invoiceType"))) { + vehicleList = snPushCheckRecordService.vihicleList(uuid); + } else { + baseTDxRecordInvoiceDetail = snPushCheckRecordService.selectRecordDetailListByWrapper(detailWrapper); } - } - checkInvoiceByUuid = snPushCheckRecordService.selectRecordByWrapper(recordWrapper); - } - String invoiceNo = checkInvoiceByUuid.getInvoiceNo(); - QueryWrapper detailWrapper = new QueryWrapper<>(); - detailWrapper.eq("uuid", uuid); + if ((baseTDxRecordInvoiceDetail == null || baseTDxRecordInvoiceDetail.size() == 0) && (vehicleList == null || vehicleList.size() == 0)) { + checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap, null); + + if (!checkInvoiceResult.containsKey("code")) { + if (!checkInvoiceResult.containsKey("cyjg")) { + //先删除原有主数据,再查验更新主数据和明细数据 + snPushCheckRecordService.updateInvoice(dbName, checkInvoiceResult, recordWrapper); + + if ("10104".equals(pramsMap.get("invoiceType")) || "10105".equals(pramsMap.get("invoiceType"))) { + vehicleList = snPushCheckRecordService.vihicleList(uuid); + } else { + baseTDxRecordInvoiceDetail = snPushCheckRecordService.selectRecordDetailListByWrapper(detailWrapper); + } + } else if (checkInvoiceResult.containsKey("cyjg") && !"0001".equals(checkInvoiceResult.getString("cyjg"))) { + data = errorInfo(checkInvoiceResult, data); + return ResponseEntity.ok(JSONObject.toJSONString(data)); + } + } + } + JSONObject checkInvoice = (JSONObject) JSONObject.toJSON(checkInvoiceByUuid); + JSONArray checkInvoiceDetail = (JSONArray) JSONObject.toJSON(baseTDxRecordInvoiceDetail); + JSONObject vehicleDetail = new JSONObject(); + if (vehicleList != null && vehicleList.size() > 0) { + vehicleDetail = (JSONObject) JSONObject.toJSON(vehicleList.get(0)); + } - List baseTDxRecordInvoiceDetail = null; - List vehicleList = null; - if ("10104".equals(pramsMap.get("invoiceType")) || "10105".equals(pramsMap.get("invoiceType"))) { - vehicleList = snPushCheckRecordService.vihicleList(uuid); - } else { - baseTDxRecordInvoiceDetail = snPushCheckRecordService.selectRecordDetailListByWrapper(detailWrapper); - } + convertToResult(checkInvoice, checkInvoiceDetail, vehicleDetail); - if ((baseTDxRecordInvoiceDetail == null || baseTDxRecordInvoiceDetail.size() == 0) && (vehicleList == null || vehicleList.size() == 0)) { - checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap, null); + data.put("data", checkInvoice); + //查验结果保存 + //saveCheckLog(pramsMap, checkInvoice); - if (!checkInvoiceResult.containsKey("code")) { - if (!checkInvoiceResult.containsKey("cyjg")) { - //先删除原有主数据,再查验更新主数据和明细数据 - snPushCheckRecordService.updateInvoice(dbName, checkInvoiceResult, recordWrapper); + return ResponseEntity.ok(JSONObject.toJSONString(data)); + } else { + TdxSaleRecordInvoice tdxSaleRecordInvoice = snPushCheckRecordService.selectSaleByUuid(uuid); + log.info("tdxSaleRecordInvoice={}", tdxSaleRecordInvoice); + if (tdxSaleRecordInvoice != null) { + log.info("销项票池已存在发票.直接返回票池信息"); + R data = new R(1000, "default success"); + + String invoiceNo = tdxSaleRecordInvoice.getInvoiceNo(); + QueryWrapper saleDetailWrapper = new QueryWrapper<>(); + saleDetailWrapper.eq("invoice_no", invoiceNo); + List recordInvoiceSaleDetailModel = snPushCheckRecordService.selectSaleListByWrapper(saleDetailWrapper); + + JSONObject checkInvoice = (JSONObject) JSONObject.toJSON(tdxSaleRecordInvoice); + JSONArray saleDetail = (JSONArray) JSONObject.toJSON(recordInvoiceSaleDetailModel); + convertToResult(checkInvoice, saleDetail); + + data.put("data", checkInvoice); + //查验结果保存 + // saveCheckLog(pramsMap,checkInvoice); - if ("10104".equals(pramsMap.get("invoiceType")) || "10105".equals(pramsMap.get("invoiceType"))) { - vehicleList = snPushCheckRecordService.vihicleList(uuid); - } else { - baseTDxRecordInvoiceDetail = snPushCheckRecordService.selectRecordDetailListByWrapper(detailWrapper); - } - } else if (checkInvoiceResult.containsKey("cyjg") && !"0001".equals(checkInvoiceResult.getString("cyjg"))) { - data = errorInfo(checkInvoiceResult, data); return ResponseEntity.ok(JSONObject.toJSONString(data)); } } } - JSONObject checkInvoice = (JSONObject) JSONObject.toJSON(checkInvoiceByUuid); - JSONArray checkInvoiceDetail = (JSONArray) JSONObject.toJSON(baseTDxRecordInvoiceDetail); - JSONObject vehicleDetail = new JSONObject(); - if(vehicleList != null && vehicleList.size() > 0) { - vehicleDetail = (JSONObject) JSONObject.toJSON(vehicleList.get(0)); + + try { + checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap, "1"); + log.info("查验结果为:{}", checkInvoiceResult); + } catch (Exception e) { + e.printStackTrace(); + log.error("查验失败,errormsg:{}", e.getMessage()); + return ResponseEntity.ok(JSONObject.toJSONString(R.error("查验失败," + e.getMessage()))); } - convertToResult(checkInvoice, checkInvoiceDetail, vehicleDetail); + if (!checkInvoiceResult.containsKey("code")) { - data.put("data", checkInvoice); - //查验结果保存 - //saveCheckLog(pramsMap, checkInvoice); + if (checkInvoiceResult.containsKey("cyjg") && !"0001".equals(checkInvoiceResult.getString("cyjg"))) { + R data = new R(); + data = errorInfo(checkInvoiceResult, data); + return ResponseEntity.ok(JSONObject.toJSONString(data)); + } - return ResponseEntity.ok(JSONObject.toJSONString(data)); - } else { - TdxSaleRecordInvoice tdxSaleRecordInvoice = snPushCheckRecordService.selectSaleByUuid(uuid); - log.info("tdxSaleRecordInvoice={}", tdxSaleRecordInvoice); - if (tdxSaleRecordInvoice != null) { - log.info("销项票池已存在发票.直接返回票池信息"); R data = new R(1000, "default success"); + data.put("message", "success"); - String invoiceNo = tdxSaleRecordInvoice.getInvoiceNo(); - QueryWrapper saleDetailWrapper = new QueryWrapper<>(); - saleDetailWrapper.eq("invoice_no", invoiceNo); - List recordInvoiceSaleDetailModel = snPushCheckRecordService.selectSaleListByWrapper(saleDetailWrapper); - - JSONObject checkInvoice = (JSONObject) JSONObject.toJSON(tdxSaleRecordInvoice); - JSONArray saleDetail = (JSONArray) JSONObject.toJSON(recordInvoiceSaleDetailModel); - convertToResult(checkInvoice, saleDetail); + if (!checkInvoiceResult.containsKey("cyjg")) { + checkInvoiceResult.put("invoiceNo", checkInvoiceResult.getString("invoiceNumber")); + log.info("返回给影像系统的结果为:{}", checkInvoiceResult); + signSaveInvoiceInfoService.saveQueryInvoiceResult(checkInvoiceResult, "", "1", dbName); + } - data.put("data", checkInvoice); - //查验结果保存 - // saveCheckLog(pramsMap,checkInvoice); + Object o = checkInvoiceResult.get("invoiceLineList"); + JSONArray jsonArray = JSONObject.parseArray(JSONObject.toJSONString(o)); + for (Object object : jsonArray) { + Map map = JSONObject.parseObject(JSONObject.toJSONString(object), Map.class); + String taxRate = (String) map.get("taxRate"); + if ("0".equals(taxRate) || "*".equals(taxRate) || "**".equals(taxRate) || "***".equals(taxRate) || "不征税".equals(taxRate) || "免税".equals(taxRate)) { + map.put("taxRate", "0.00"); + } + } + data.put("data", checkInvoiceResult); return ResponseEntity.ok(JSONObject.toJSONString(data)); } - } - } + } else { + //其他类发票,直接入库 + R data = new R(1000, "default success"); + if (checkInvoiceResult != null && !checkInvoiceResult.isEmpty()) { + log.info("其他类发票,不做查验,直接入库"); + data.put("message", "success"); - try { - checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap, "1"); - log.info("查验结果为:{}", checkInvoiceResult); - } catch (Exception e) { - e.printStackTrace(); - log.error("查验失败,errormsg:{}", e.getMessage()); - return ResponseEntity.ok(JSONObject.toJSONString(R.error("查验失败," + e.getMessage()))); - } + checkInvoiceResult.put("invoiceNo", checkInvoiceResult.getString("invoiceNumber")); + checkInvoiceResult.put("message", "入库成功"); + log.info("返回给影像系统的结果为:{}", checkInvoiceResult); - if (!checkInvoiceResult.containsKey("code")) { + data.put("data", checkInvoiceResult); + } else { + data.put("message", "error 其他类发票不支持查验"); + } - if (checkInvoiceResult.containsKey("cyjg") && !"0001".equals(checkInvoiceResult.getString("cyjg"))) { - R data = new R(); - data = errorInfo(checkInvoiceResult, data); return ResponseEntity.ok(JSONObject.toJSONString(data)); } - R data = new R(1000, "default success"); - data.put("message", "success"); - - if (!checkInvoiceResult.containsKey("cyjg")) { - checkInvoiceResult.put("invoiceNo", checkInvoiceResult.getString("invoiceNumber")); - log.info("返回给影像系统的结果为:{}", checkInvoiceResult); - signSaveInvoiceInfoService.saveQueryInvoiceResult(checkInvoiceResult, "", "1", dbName); - } - - Object o = checkInvoiceResult.get("invoiceLineList"); - JSONArray jsonArray = JSONObject.parseArray(JSONObject.toJSONString(o)); - for (Object object : jsonArray) { - Map map = JSONObject.parseObject(JSONObject.toJSONString(object), Map.class); - String taxRate = (String) map.get("taxRate"); - if ("0".equals(taxRate) || "*".equals(taxRate) || "**".equals(taxRate) || "***".equals(taxRate) || "不征税".equals(taxRate) || "免税".equals(taxRate)) { - map.put("taxRate", "0.00"); - } - } - data.put("data", checkInvoiceResult); - - return ResponseEntity.ok(JSONObject.toJSONString(data)); + return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", checkInvoiceResult))); } - } else { - //其他类发票,直接入库 - R data = new R(1000, "default success"); - if (checkInvoiceResult != null && !checkInvoiceResult.isEmpty()) { - log.info("其他类发票,不做查验,直接入库"); - data.put("message", "success"); - - checkInvoiceResult.put("invoiceNo", checkInvoiceResult.getString("invoiceNumber")); - checkInvoiceResult.put("message", "入库成功"); - log.info("返回给影像系统的结果为:{}", checkInvoiceResult); - - data.put("data", checkInvoiceResult); - } else { - data.put("message", "error 其他类发票不支持查验"); - } - - return ResponseEntity.ok(JSONObject.toJSONString(data)); + }catch (Exception e) { + e.printStackTrace(); + return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", ""))); } - - return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", checkInvoiceResult))); + finally { + //关锁 + lock.unlock(); + } + return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", "请求正在处理,不要重复提交"))); } @Async From 3f522409e14b757965eefc4f7f78e6c87a76cece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=AF=E6=98=8E=E6=85=A7?= <1191093413@qq.com> Date: Fri, 1 Dec 2023 16:22:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=B3=E9=94=81?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dxhy/erp/controller/SDNYMainProcessController.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java b/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java index 6ce25a21..a2fd250d 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java @@ -497,9 +497,10 @@ public class SDNYMainProcessController extends AbstractController { String param = JSONObject.toJSONString(pramsMap); //加分布式锁 String lockKey = Base64Utils.encodeToString(param.getBytes()); + boolean isLock = false; RLock lock = redisson.getLock(lockKey); try { - boolean isLock = lock.tryLock(); + isLock = lock.tryLock(); if (!isLock) { log.info("当前已有线程获取到锁"); @@ -726,7 +727,9 @@ public class SDNYMainProcessController extends AbstractController { } finally { //关锁 - lock.unlock(); + if (isLock) { + lock.unlock(); + } } return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", "请求正在处理,不要重复提交"))); }