xucaiqin 2 лет назад
Родитель
Сommit
fd55081045

+ 13 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/exception/GlobalSystemExceptionHandler.java

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
 
 import java.util.List;
+import java.util.Objects;
 import java.util.Set;
 
 @Slf4j
@@ -116,6 +117,18 @@ public class GlobalSystemExceptionHandler {
     @ExceptionHandler(Exception.class)
     public HttpResult defaultExceptionHandler(Exception ex) {
         log.error("系统异常", ex);
+        Throwable cause = ex.getCause();
+        int i = 5;
+        do {
+            i--;
+            if (Objects.isNull(cause)) {
+                break;
+            }
+            cause = cause.getCause();
+            if (cause instanceof BusinessException be) {
+                return HttpResult.error(be.getMsg());
+            }
+        } while (cause != null || i > 0);
         return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, HttpStatus.GLOBAL_EXCEPTION_MESSAGE);
     }
 

+ 8 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/KwpSettlementTradeController.java

@@ -41,6 +41,7 @@ public class KwpSettlementTradeController {
     @PostMapping(name = "收款-销售结算单列表", path = "pageSellList")
     public HttpResult pageListCollection(@RequestBody @Valid SettlementTradeReq settlementReq) {
         settlementReq.setUnitType(TradeUnitType.PURCHASE);
+        settlementReq.check();
         return HttpResult.ok(kwpSettlementTradeService.pageListCollection(settlementReq));
     }
 
@@ -53,6 +54,7 @@ public class KwpSettlementTradeController {
     @PostMapping(name = "收款-表头统计数量", path = "getSellCount")
     public HttpResult getCount(@RequestBody @Valid SettlementTradeReq settlementReq) {
         settlementReq.setUnitType(TradeUnitType.PURCHASE);
+        settlementReq.check();
         return HttpResult.ok(kwpSettlementTradeService.getCount(settlementReq));
     }
 
@@ -64,12 +66,14 @@ public class KwpSettlementTradeController {
      */
     @PostMapping(name = "收款-表尾金额结算数据", path = "getSellSum")
     public HttpResult getSellSum(@RequestBody @Valid SettlementTradeReq settlementReq) {
+        settlementReq.check();
         settlementReq.setUnitType(TradeUnitType.PURCHASE);
         return HttpResult.ok(kwpSettlementTradeService.getCountListCollection(settlementReq));
     }
 
     @PostMapping(name = "收款-根据ids导出销售结算单列表", path = "exportCollection")
     public HttpResult exportCollection(HttpServletResponse response, @RequestBody @Valid SettlementTradeReq settlementReq) {
+        settlementReq.check();
         List<ISettlement> list;
         settlementReq.setUnitType(TradeUnitType.PURCHASE);
         if (CollectionUtils.isEmpty(settlementReq.getIdList())) {
@@ -97,6 +101,7 @@ public class KwpSettlementTradeController {
      */
     @PostMapping(name = "付款-采购结算单列表", path = "pagePurchaseList")
     public HttpResult pageListPayment(@RequestBody @Valid SettlementTradeReq settlementReq) {
+        settlementReq.check();
         settlementReq.setUnitType(TradeUnitType.SELL);
         return HttpResult.ok(kwpSettlementTradeService.pageListCollection(settlementReq));
     }
@@ -109,6 +114,7 @@ public class KwpSettlementTradeController {
      */
     @PostMapping(name = "收款-表头统计数量", path = "getPurchaseCount")
     public HttpResult getPurchaseCount(@RequestBody @Valid SettlementTradeReq settlementReq) {
+        settlementReq.check();
         settlementReq.setUnitType(TradeUnitType.SELL);
         return HttpResult.ok(kwpSettlementTradeService.getCount(settlementReq));
     }
@@ -121,12 +127,14 @@ public class KwpSettlementTradeController {
      */
     @PostMapping(name = "收款-物流结算订单列表头部汇总数量", path = "getPurchaseSum")
     public HttpResult getCountListPayment(@RequestBody @Valid SettlementTradeReq settlementReq) {
+        settlementReq.check();
         settlementReq.setUnitType(TradeUnitType.SELL);
         return HttpResult.ok(kwpSettlementTradeService.getCountListCollection(settlementReq));
     }
 
     @PostMapping(name = "付款-根据ids导出采购结算单列表", path = "exportPayment")
     public HttpResult exportPayment(HttpServletResponse response, @RequestBody @Valid SettlementTradeReq settlementReq) {
+        settlementReq.check();
         List<ISettlement> list;
         settlementReq.setUnitType(TradeUnitType.SELL);
         if (CollectionUtils.isEmpty(settlementReq.getIdList())) {

+ 1 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/KwpSettlementWalletController.java

@@ -83,7 +83,7 @@ public class KwpSettlementWalletController {
      * 采购-货到付款
      */
     @PostMapping(name = "销售-付款确认-(新增电子钱包记录-采购货到付款)", path = "confirmReceive")
-    public HttpResult confirmTradePayment(@RequestBody WalletPayReq payReq) {
+    public HttpResult confirmTradePayment(@RequestBody @Valid WalletPayReq payReq) {
         return HttpResult.ok(kwpSettlementWalletService.confirmTradePayment(payReq));
     }
 

+ 5 - 7
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/vo/req/SettlementOfflinePayReq.java

@@ -1,12 +1,13 @@
 package com.sckw.payment.model.vo.req;
 
-import com.sckw.core.model.vo.BasePara;
+import com.sckw.core.model.base.IdsList;
 import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import lombok.Getter;
 import lombok.Setter;
 
 import java.io.Serial;
+import java.io.Serializable;
 import java.math.BigDecimal;
 
 /**
@@ -17,19 +18,16 @@ import java.math.BigDecimal;
  */
 @Getter
 @Setter
-public class SettlementOfflinePayReq extends BasePara {
+public class SettlementOfflinePayReq implements IdsList, Serializable {
     @Serial
-    private static final long serialVersionUID = 6537008434516489423L;
+    private static final long serialVersionUID = -4521836357698982285L;
     private Integer orderType;
 
     @NotBlank(message = "结算单id不能为空")
-    private String settlementId;
+    private String id;
     @NotNull(message = "结算单金额不能为空")
     private BigDecimal payPrice;
     @NotBlank(message = "相关附近不能为空")
     private String url;
 
-    public Long getSettlementIdLong(){
-        return changeId(settlementId);
-    }
 }

+ 1 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/vo/req/SettlementOfflineReq.java

@@ -16,7 +16,7 @@ public class SettlementOfflineReq extends BasePara {
      * 结算单id
      */
     @NotBlank(message = "结算单id不能为空")
-    private String settlementId;
+    private String id;
 
     /**
      * 订单类型 1-物流 2-贸易

+ 7 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/vo/req/SettlementTradeReq.java

@@ -95,4 +95,11 @@ public class SettlementTradeReq extends BasePara implements TimeBase {
     public void setIds(String ids) {
         this.ids = ids;
     }
+
+    public void check() {
+        getStartCreateTime();
+        getEndCreateTime();
+        getStartReceiptTime();
+        getEndReceiptTime();
+    }
 }

+ 83 - 60
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementOfflineService.java

@@ -9,7 +9,9 @@ import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.payment.dao.KwpSettlementOfflineMapper;
 import com.sckw.payment.model.KwpSettlementOffline;
 import com.sckw.payment.model.KwpSettlementTrade;
+import com.sckw.payment.model.KwpSettlementTradeTrack;
 import com.sckw.payment.model.constant.SettlementEnum;
+import com.sckw.payment.model.constant.SettlementTrackEnum;
 import com.sckw.payment.model.constant.TradeUnitType;
 import com.sckw.payment.model.constant.TradingEnum;
 import com.sckw.payment.model.dto.SettlementOfflineDto;
@@ -17,6 +19,8 @@ import com.sckw.payment.model.dto.SettlementTradeDto;
 import com.sckw.payment.model.vo.req.SettlementOfflinePayReq;
 import com.sckw.payment.model.vo.req.SettlementOfflineReq;
 import com.sckw.payment.model.vo.res.SettlementOfflineVo;
+import com.sckw.redis.config.RedisLockUtil;
+import com.sckw.redis.constant.RedisConstant;
 import com.sckw.system.api.RemoteSystemService;
 import com.sckw.system.api.model.dto.res.UserCacheResDto;
 import jakarta.annotation.Resource;
@@ -47,8 +51,12 @@ public class KwpSettlementOfflineService {
     private KwpSettlementOfflineMapper settlementOfflineMapper;
     @Resource
     private KwpSettlementTradeService settlementTradeService;
+    @Resource
+    private KwpSettlementTradeTrackService settlementTradeTrackService;
     @DubboReference(version = "2.0.0", group = "design", check = false)
     private RemoteSystemService remoteSystemService;
+    @Resource
+    private RedisLockUtil redisLockUtil;
 
     /**
      * 物流-线下付款(运费收款)记录-列表
@@ -161,68 +169,83 @@ public class KwpSettlementOfflineService {
         return new PageRes<>(new PageInfo<>(collect));
     }
 
+    /**
+     * 线下付款
+     *
+     * @param payReq
+     * @return
+     */
     @Transactional(rollbackFor = Exception.class)
     public String confirmTradeCollection(SettlementOfflinePayReq payReq) {
-        SettlementTradeDto byId = settlementTradeService.getById(payReq.getSettlementIdLong(), TradeUnitType.PURCHASE);
-        if (Objects.isNull(byId)) {
-            throw new BusinessException("结算单不存在");
-        }
-        if (StringUtils.equals(TradingEnum.OFFLINE_PAY.getValue(), byId.getTrading())) {
-            throw new BusinessException("只支持线下付款交易方法进行线下结算");
-        }
-        BigDecimal totalPrice = byId.getTotalPrice();
-        BigDecimal actualPrice = byId.getActualPrice();
-        if (Objects.isNull(totalPrice)) {
-            throw new BusinessException("总应收异常");
-        }
-        if (Objects.isNull(actualPrice)) {
-            throw new BusinessException("已收款金额异常");
-        }
-        //总应收-已收款=剩余待付款
-        BigDecimal subtract = totalPrice.subtract(actualPrice);
-        //本次付款金额
-        BigDecimal payPrice = payReq.getPayPrice();
-        //剩余待付款-本次付款=下次剩余待付款
-        BigDecimal subtract1 = subtract.subtract(payPrice);
-        if (subtract1.compareTo(new BigDecimal("0.0")) < 0) {
-            throw new BusinessException("实际付款金额大于剩余待付款金额");
-        }
-        KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
-        kwpSettlementTrade.setId(byId.getId());
-        kwpSettlementTrade.setActualPrice(actualPrice.add(payPrice));//已收款加本次收款
-        int status = 0;
-        if (subtract1.compareTo(new BigDecimal("0.0")) == 0) {
-            status = SettlementEnum.ALL_PAYMENT.getStatus();
-        } else if (subtract1.compareTo(new BigDecimal("0.0")) > 0) {
-            status = SettlementEnum.PARTIAL_PAYMENT.getStatus();
+        String key = String.format(RedisConstant.SETTLEMENT_KEY, payReq.getId());
+        if (redisLockUtil.tryLock(key)) {
+            try {
+                SettlementTradeDto byId = settlementTradeService.getById(payReq.getIdLong(), TradeUnitType.PURCHASE);
+                if (Objects.isNull(byId)) {
+                    throw new BusinessException("结算单不存在");
+                }
+                if (!StringUtils.equals(TradingEnum.OFFLINE_PAY.getValue(), byId.getTrading())) {
+                    throw new BusinessException("只支持线下付款交易方法进行线下结算");
+                }
+                BigDecimal totalPrice = byId.getTotalPrice();
+                BigDecimal actualPrice = byId.getActualPrice();
+                if (Objects.isNull(totalPrice)) {
+                    throw new BusinessException("总应收异常");
+                }
+                if (Objects.isNull(actualPrice)) {
+                    throw new BusinessException("已收款金额异常");
+                }
+                //总应收-已收款=剩余待付款
+                BigDecimal subtract = totalPrice.subtract(actualPrice);
+                //本次付款金额
+                BigDecimal payPrice = payReq.getPayPrice();
+                //剩余待付款-本次付款=下次剩余待付款
+                BigDecimal subtract1 = subtract.subtract(payPrice);
+                if (subtract1.compareTo(new BigDecimal("0.0")) < 0) {
+                    throw new BusinessException("实际付款金额大于剩余待付款金额");
+                }
+                KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
+                kwpSettlementTrade.setId(byId.getId());
+                kwpSettlementTrade.setActualPrice(actualPrice.add(payPrice));//已收款加本次收款
+                int status = 0;
+                if (subtract1.compareTo(new BigDecimal("0.0")) == 0) {
+                    status = SettlementEnum.ALL_PAYMENT.getStatus();
+                } else if (subtract1.compareTo(new BigDecimal("0.0")) > 0) {
+                    status = SettlementEnum.PARTIAL_PAYMENT.getStatus();
+                }
+                kwpSettlementTrade.setStatus(status);
+                kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
+                kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
+                settlementTradeService.updateById(kwpSettlementTrade);
+
+                KwpSettlementOffline kwpSettlementOffline = new KwpSettlementOffline();
+                kwpSettlementOffline.setId(new IdWorker(1).nextId());
+                kwpSettlementOffline.setEntId(LoginUserHolder.getEntId());
+                kwpSettlementOffline.setSettlementId(byId.getId());
+                kwpSettlementOffline.setOrderType(payReq.getOrderType());
+                kwpSettlementOffline.setPayTime(LocalDateTime.now());
+                kwpSettlementOffline.setPayPrice(payReq.getPayPrice());
+                kwpSettlementOffline.setTopayPrice(subtract1);
+                kwpSettlementOffline.setUrl(payReq.getUrl());
+                kwpSettlementOffline.setRemark("");
+                kwpSettlementOffline.setStatus(0);
+                kwpSettlementOffline.setCreateBy(LoginUserHolder.getUserId());
+                kwpSettlementOffline.setCreateTime(LocalDateTime.now());
+                kwpSettlementOffline.setUpdateBy(LoginUserHolder.getUserId());
+                kwpSettlementOffline.setUpdateTime(LocalDateTime.now());
+                kwpSettlementOffline.setDelFlag(0);
+
+                settlementOfflineMapper.insert(kwpSettlementOffline);
+
+                //记录表记录数据
+                settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.OFFLINE_PAY.getStatus()));
+
+                //中台接口 todo-xcq
+                return "确认回款成功";
+            } finally {
+                redisLockUtil.unlock(key);
+            }
         }
-        kwpSettlementTrade.setStatus(status);
-        kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
-        kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
-        settlementTradeService.updateById(kwpSettlementTrade);
-
-        KwpSettlementOffline kwpSettlementOffline = new KwpSettlementOffline();
-        kwpSettlementOffline.setId(new IdWorker(1).nextId());
-        kwpSettlementOffline.setEntId(LoginUserHolder.getEntId());
-        kwpSettlementOffline.setSettlementId(byId.getId());
-        kwpSettlementOffline.setOrderType(payReq.getOrderType());
-        kwpSettlementOffline.setPayTime(LocalDateTime.now());
-        kwpSettlementOffline.setPayPrice(payReq.getPayPrice());
-        kwpSettlementOffline.setTopayPrice(subtract1);
-        kwpSettlementOffline.setUrl(payReq.getUrl());
-        kwpSettlementOffline.setRemark("");
-        kwpSettlementOffline.setStatus(0);
-        kwpSettlementOffline.setCreateBy(LoginUserHolder.getUserId());
-        kwpSettlementOffline.setCreateTime(LocalDateTime.now());
-        kwpSettlementOffline.setUpdateBy(LoginUserHolder.getUserId());
-        kwpSettlementOffline.setUpdateTime(LocalDateTime.now());
-        kwpSettlementOffline.setDelFlag(0);
-
-        settlementOfflineMapper.insert(kwpSettlementOffline);
-
-        //记录表记录数据 todo-xcq
-
-        //中台接口 todo-xcq
-        return "";
+        return "请勿重复提交";
     }
 }

+ 128 - 106
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementWalletService.java

@@ -23,6 +23,8 @@ import com.sckw.payment.model.dto.SettlementWalletDto;
 import com.sckw.payment.model.vo.req.SettlementWalletReq;
 import com.sckw.payment.model.vo.req.WalletPayReq;
 import com.sckw.payment.model.vo.res.SettlementWalletVo;
+import com.sckw.redis.config.RedisLockUtil;
+import com.sckw.redis.constant.RedisConstant;
 import com.sckw.system.api.RemoteSystemService;
 import com.sckw.system.api.model.dto.res.UserCacheResDto;
 import jakarta.annotation.Resource;
@@ -62,6 +64,8 @@ public class KwpSettlementWalletService {
     @Resource
     private KwpWalletRelationService walletRelationService;
     @Resource
+    private RedisLockUtil redisLockUtil;
+    @Resource
     private KwpSettlementTradeTrackService settlementTradeTrackService;
     @DubboReference(version = "2.0.0", group = "design", check = false)
     private RemoteSystemService remoteSystemService;
@@ -227,37 +231,40 @@ public class KwpSettlementWalletService {
      */
     @Transactional(rollbackFor = Exception.class)
     public String confirmTradePayment(WalletPayReq walletPayReq) {
-        SettlementTradeDto byId = kwpSettlementTradeService.getById(walletPayReq.getIdLong(), TradeUnitType.SELL);
-        if (Objects.isNull(byId)) {
-            throw new BusinessException("结算单不存在");
-        }
-        if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.RECEIVE_PAY.getValue())) {
-            throw new BusinessException("只支持货货到付款方式订单进行当前操作");
-        }
-        List<LedgerUnitDto> listById = kwpSettlementTradeService.getListById(walletPayReq.getIdLong());
-        if (CollectionUtils.isEmpty(listById) || listById.size() != 2) {
-            throw new BusinessException("对账单交易企业双方不存在或缺少");
-        }
-        Long uid = null;
-        Long filter = null;
-        for (LedgerUnitDto ledgerUnitDto : listById) {
-            Integer unitType = ledgerUnitDto.getUnitType();
-            if (TradeUnitType.PURCHASE.equals(unitType)) {
-                uid = ledgerUnitDto.getTopEntId();
-                continue;
-            }
-            if (TradeUnitType.SELL.equals(unitType)) {
-                filter = ledgerUnitDto.getTopEntId();
-            }
-        }
-        String relation = walletRelationService.getRelation(uid);
-        String filterUser = walletRelationService.getRelation(filter);
-        if (StringUtils.isBlank(relation) || StringUtils.isBlank(filterUser)) {
-            throw new BusinessException("顶级企业未开通电子钱包");
-        }
-        //付款金额
-        BigDecimal price = walletPayReq.getPrice();
-        //todo-xcq-完善
+        String key = String.format(RedisConstant.SETTLEMENT_KEY, walletPayReq.getId());
+        if (redisLockUtil.tryLock(key)) {
+            try {
+                SettlementTradeDto byId = kwpSettlementTradeService.getById(walletPayReq.getIdLong(), TradeUnitType.SELL);
+                if (Objects.isNull(byId)) {
+                    throw new BusinessException("结算单不存在");
+                }
+                if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.RECEIVE_PAY.getValue())) {
+                    throw new BusinessException("只支持货货到付款方式订单进行当前操作");
+                }
+                List<LedgerUnitDto> listById = kwpSettlementTradeService.getListById(walletPayReq.getIdLong());
+                if (CollectionUtils.isEmpty(listById) || listById.size() != 2) {
+                    throw new BusinessException("对账单交易企业双方不存在或缺少");
+                }
+                Long uid = null;
+                Long filter = null;
+                for (LedgerUnitDto ledgerUnitDto : listById) {
+                    Integer unitType = ledgerUnitDto.getUnitType();
+                    if (TradeUnitType.PURCHASE.equals(unitType)) {
+                        uid = ledgerUnitDto.getTopEntId();
+                        continue;
+                    }
+                    if (TradeUnitType.SELL.equals(unitType)) {
+                        filter = ledgerUnitDto.getTopEntId();
+                    }
+                }
+                String relation = walletRelationService.getRelation(uid);
+                String filterUser = walletRelationService.getRelation(filter);
+                if (StringUtils.isBlank(relation) || StringUtils.isBlank(filterUser)) {
+                    throw new BusinessException("顶级企业未开通电子钱包");
+                }
+                //付款金额
+                BigDecimal price = walletPayReq.getPrice();
+                //todo-xcq-完善
 
 //        R<List<WalletDto>> wallet = payCenterService.wallet(relation, ChannelEnum.getByCode(byId.getTrading()), filterUser);
 //        if (CollectionUtils.isEmpty(wallet.getData())) {
@@ -269,45 +276,50 @@ public class KwpSettlementWalletService {
 //        if (bigDecimal.compareTo(price) < 0) {
 //            throw new BusinessException("钱包可用余额不足");
 //        }
-        //待付款金额-本次付款金额= 剩余待付款金额
-        BigDecimal subtract = byId.getWaitPrice().subtract(walletPayReq.getPrice());
-        if (subtract.compareTo(new BigDecimal("0.0")) < 0) {
-            throw new BusinessException("付款金额不能大于待付款金额");
+                //待付款金额-本次付款金额= 剩余待付款金额
+                BigDecimal subtract = byId.getWaitPrice().subtract(walletPayReq.getPrice());
+                if (subtract.compareTo(new BigDecimal("0.0")) < 0) {
+                    throw new BusinessException("付款金额不能大于待付款金额");
+                }
+                //新增电子钱包结算记录
+                KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
+                kwpSettlementWallet.setId(new IdWorker(1).nextId());
+                kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
+                kwpSettlementWallet.setSettlementId(walletPayReq.getIdLong());
+                kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
+                kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
+                kwpSettlementWallet.setPayTime(LocalDateTime.now());
+                kwpSettlementWallet.setPayPrice(walletPayReq.getPrice());
+                kwpSettlementWallet.setTopayPrice(subtract);
+                kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
+                kwpSettlementWallet.setRemark("");
+                kwpSettlementWallet.setStatus(0);
+                kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
+                kwpSettlementWallet.setCreateTime(LocalDateTime.now());
+                kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
+                kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
+                kwpSettlementWallet.setDelFlag(0);
+                settlementWalletMapper.insert(kwpSettlementWallet);
+
+                //更新交易结算单状态和金额
+                KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
+                kwpSettlementTrade.setId(byId.getId());
+                kwpSettlementTrade.setActualPrice(byId.getActualPrice().add(price));
+                kwpSettlementTrade.setStatus(subtract.compareTo(new BigDecimal("0.0")) == 0 ? SettlementEnum.ALL_PAYMENT.getStatus()
+                        : SettlementEnum.PARTIAL_PAYMENT.getStatus());
+                kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
+                kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
+                kwpSettlementTradeService.updateById(kwpSettlementTrade);
+
+                settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.RECEIVE_PAY.getStatus()));
+                //todo-xcq 调用中台接口
+
+                return "付款确认成功";
+            } finally {
+                redisLockUtil.unlock(key);
+            }
         }
-        //新增电子钱包结算记录
-        KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
-        kwpSettlementWallet.setId(new IdWorker(1).nextId());
-        kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
-        kwpSettlementWallet.setSettlementId(walletPayReq.getIdLong());
-        kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
-        kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
-        kwpSettlementWallet.setPayTime(LocalDateTime.now());
-        kwpSettlementWallet.setPayPrice(walletPayReq.getPrice());
-        kwpSettlementWallet.setTopayPrice(subtract);
-        kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
-        kwpSettlementWallet.setRemark("");
-        kwpSettlementWallet.setStatus(0);
-        kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
-        kwpSettlementWallet.setCreateTime(LocalDateTime.now());
-        kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
-        kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
-        kwpSettlementWallet.setDelFlag(0);
-        settlementWalletMapper.insert(kwpSettlementWallet);
-
-        //更新交易结算单状态和金额
-        KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
-        kwpSettlementTrade.setId(byId.getId());
-        kwpSettlementTrade.setActualPrice(byId.getActualPrice().add(price));
-        kwpSettlementTrade.setStatus(subtract.compareTo(new BigDecimal("0.0")) == 0 ? SettlementEnum.ALL_PAYMENT.getStatus()
-                : SettlementEnum.PARTIAL_PAYMENT.getStatus());
-        kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
-        kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
-        kwpSettlementTradeService.updateById(kwpSettlementTrade);
-
-        settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.RECEIVE_PAY.getStatus()));
-        //todo-xcq 调用中台接口
-
-        return "付款确认成功";
+        return "请勿重复提交!";
     }
 
     /**
@@ -388,44 +400,54 @@ public class KwpSettlementWalletService {
      * @return
      */
     public String confirmTradeCollection(Long id) {
-        SettlementTradeDto byId = kwpSettlementTradeService.getById(id, TradeUnitType.PURCHASE);
-        if (Objects.isNull(byId)) {
-            throw new BusinessException("结算单不存在");
-        }
-        if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.PRE_PAY.getValue())) {
-            throw new BusinessException("只支持预付款交易方法进行预付款确认操作");
+        String key = String.format(RedisConstant.SETTLEMENT_KEY, id);
+
+        if (redisLockUtil.tryLock(key)) {
+            try {
+                SettlementTradeDto byId = kwpSettlementTradeService.getById(id, TradeUnitType.PURCHASE);
+                if (Objects.isNull(byId)) {
+                    throw new BusinessException("结算单不存在");
+                }
+                if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.PRE_PAY.getValue())) {
+                    throw new BusinessException("只支持预付款交易方式进行预付款确认操作");
+                }
+                //更新交易结算单状态和金额
+                KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
+                kwpSettlementTrade.setId(byId.getId());
+                kwpSettlementTrade.setActualPrice(byId.getTotalPrice());
+                kwpSettlementTrade.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
+                kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
+                kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
+                kwpSettlementTradeService.updateById(kwpSettlementTrade);
+                //新增电子钱包结算记录
+                KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
+                kwpSettlementWallet.setId(new IdWorker(1).nextId());
+                kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
+                kwpSettlementWallet.setSettlementId(byId.getId());
+                kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
+                kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
+                kwpSettlementWallet.setPayTime(LocalDateTime.now());
+                kwpSettlementWallet.setPayPrice(byId.getTotalPrice());
+                kwpSettlementWallet.setTopayPrice(new BigDecimal("0.0"));
+                kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.ADVANCE_PAYMENT.getStatus());
+                kwpSettlementWallet.setRemark("");
+                kwpSettlementWallet.setStatus(0);
+                kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
+                kwpSettlementWallet.setCreateTime(LocalDateTime.now());
+                kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
+                kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
+                kwpSettlementWallet.setDelFlag(0);
+                settlementWalletMapper.insert(kwpSettlementWallet);
+                settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.PRE_PAY.getStatus()));
+                //todo-xcq 调用中台接口
+                //todo-xcq 调用订单接口,更新订单状态
+                return "确认回款成功";
+            } finally {
+                redisLockUtil.unlock(key);
+            }
         }
-        //更新交易结算单状态和金额
-        KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
-        kwpSettlementTrade.setId(byId.getId());
-        kwpSettlementTrade.setActualPrice(byId.getTotalPrice());
-        kwpSettlementTrade.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
-        kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
-        kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
-        kwpSettlementTradeService.updateById(kwpSettlementTrade);
-        //新增电子钱包结算记录
-        KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
-        kwpSettlementWallet.setId(new IdWorker(1).nextId());
-        kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
-        kwpSettlementWallet.setSettlementId(byId.getId());
-        kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
-        kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
-        kwpSettlementWallet.setPayTime(LocalDateTime.now());
-        kwpSettlementWallet.setPayPrice(byId.getTotalPrice());
-        kwpSettlementWallet.setTopayPrice(new BigDecimal("0.0"));
-        kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.ADVANCE_PAYMENT.getStatus());
-        kwpSettlementWallet.setRemark("");
-        kwpSettlementWallet.setStatus(0);
-        kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
-        kwpSettlementWallet.setCreateTime(LocalDateTime.now());
-        kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
-        kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
-        kwpSettlementWallet.setDelFlag(0);
-        settlementWalletMapper.insert(kwpSettlementWallet);
-        settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.PRE_PAY.getStatus()));
-        //todo-xcq 调用中台接口
-        //todo-xcq 调用订单接口,更新订单状态
-        return "确认回款成功";
+        return "请勿重复提交!";
+
     }
 
     /**

+ 2 - 2
sckw-modules/sckw-payment/src/main/resources/mapper/KwpSettlementOfflineMapper.xml

@@ -57,8 +57,8 @@
             <if test="offlineReq.orderType != null">
                 and order_type = #{offlineReq.orderType,jdbcType=INTEGER}
             </if>
-            <if test="offlineReq.settlementId != null">
-                and settlement_id = #{offlineReq.settlementId,jdbcType=INTEGER}
+            <if test="offlineReq.id != null and offlineReq.id != ''">
+                and settlement_id = #{offlineReq.id,jdbcType=INTEGER}
             </if>
         </where>
     </select>