Browse Source

清分逻辑

18782137998 11 months ago
parent
commit
c539bc4bb1

+ 40 - 0
src/main/java/com/sckw/freight/entity/payment/PayBatchAgentPay.java

@@ -0,0 +1,40 @@
+package com.sckw.freight.entity.payment;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author xj
+ * @since 2025-02-11
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("pay_batch_agent_pay")
+public class PayBatchAgentPay implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    private String businessNo;
+
+    private String json;
+
+    private LocalDateTime createTime;
+
+    private Integer status;
+
+
+}

+ 19 - 0
src/main/java/com/sckw/freight/mapper/payment/PayBatchAgentPayMapper.java

@@ -0,0 +1,19 @@
+package com.sckw.freight.mapper.payment;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
+import com.sckw.freight.entity.payment.PayBatchAgentPay;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author xj
+ * @since 2025-02-11
+ */
+@DS(DataSourceNames.PAYMENT)
+public interface PayBatchAgentPayMapper extends BaseMapper<PayBatchAgentPay> {
+
+}

+ 20 - 27
src/main/java/com/sckw/freight/service/JobService.java

@@ -2,16 +2,10 @@ package com.sckw.freight.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.sckw.freight.entity.freight.KwpSettlementLogistics;
-import com.sckw.freight.entity.payment.PayMemberWalletAp;
-import com.sckw.freight.entity.payment.PayOrder;
-import com.sckw.freight.entity.payment.PayOrderSub;
-import com.sckw.freight.entity.payment.PayWalletWithdrawOrder;
+import com.sckw.freight.entity.payment.*;
 import com.sckw.freight.mapper.freight.KwpLedgerLogisticsMapper;
 import com.sckw.freight.mapper.freight.KwpSettlementLogisticsMapper;
-import com.sckw.freight.mapper.payment.PayMemberWalletApMapper;
-import com.sckw.freight.mapper.payment.PayOrderMapper;
-import com.sckw.freight.mapper.payment.PayOrderSubMapper;
-import com.sckw.freight.mapper.payment.PayWalletWithdrawOrderMapper;
+import com.sckw.freight.mapper.payment.*;
 import com.sckw.freight.model.dto.BusinessNo;
 import com.sckw.freight.model.dto.Order;
 import com.sckw.freight.model.dto.PatchPay;
@@ -61,7 +55,8 @@ public class JobService {
     PayWalletWithdrawOrderMapper payWalletWithdrawOrderMapper;
     @Autowired
     PayMemberWalletApMapper payMemberWalletApMapper;
-
+    @Autowired
+    PayBatchAgentPayMapper payBatchAgentPayMapper;
     /**
      * 【轮循程序】
      * 1:根据未完成的单子组合查询信息(收款方uid、付款方uid、未付金额)到支付中台【充值记录清单】接口 /v2/wallet/recharge/orders(收款方uid、付款方uid,时间)
@@ -131,7 +126,7 @@ public class JobService {
                             }
 
                             //检查清分
-                            CheckResult checkAgentPay = checkAgentPay(_qf, _yp, settlementLogisticsInfo, logisticsAndBuySellInfo, money);
+                            CheckResult checkAgentPay = checkAgentPay(_qf, settlementLogisticsInfo, logisticsAndBuySellInfo, money);
                             _qf = checkAgentPay.getBusinessNo();
                             if (!checkAgentPay.isStatus()) {
                                 continue;
@@ -377,10 +372,10 @@ public class JobService {
         try {
             if (StringUtils.isBlank(_yp)) {
                 // 发起预付
-                R<Order> orderR = payCenterService.advancePayApply(logisticsAndBuySellInfo.getBuyUid(), ChannelEnum.XW,
-                        logisticsAndBuySellInfo.getSellUid(), MoneyChange.bigMoney(money));
+                R<Order> orderR = payCenterService.advancePayApply(logisticsAndBuySellInfo.getSellUid (), ChannelEnum.XW,
+                        logisticsAndBuySellInfo.getBuyUid(), MoneyChange.bigMoney(money));
                 if (orderR == null || !orderR.getStatus() || orderR.getData() == null) {
-                    setCheckResult(checkResult, false, null, null);
+                    setCheckResult(checkResult, false, " ", null);
                     return checkResult;
                 }
                 _yp = orderR.getData().getOrderNo();
@@ -403,24 +398,19 @@ public class JobService {
      * @author: xj
      * @date: 2025/2/10 星期一 14:28
      */
-    private CheckResult<PayOrderSub> checkAgentPay(String _qf, String _yp, KwpSettlementLogistics settlementLogisticsInfo, LedgerLogisticsAndBuySellInfo logisticsAndBuySellInfo, BigDecimal money) {
-        CheckResult<PayOrderSub> checkResult = new CheckResult<>();
+    private CheckResult<PayBatchAgentPay> checkAgentPay(String _qf,   KwpSettlementLogistics settlementLogisticsInfo, LedgerLogisticsAndBuySellInfo logisticsAndBuySellInfo, BigDecimal money) {
+        CheckResult<PayBatchAgentPay> checkResult = new CheckResult<>();
 
         try {
-            // 根据预付单号查询清分单子
-            LambdaQueryWrapper<PayOrderSub> wrapper = new LambdaQueryWrapper<>();
-            wrapper.eq(PayOrderSub::getBusinessNo, _yp);
-            PayOrderSub orderSub = payOrderSubMapper.selectOne(wrapper);
-
-            if (orderSub == null) { // 没有清分单子,发起清分请求
+            if (StringUtils.isBlank(_qf)) { // 没有清分单子,发起清分请求
                 List<PatchPay> list = new ArrayList<>();
                 PatchPay patchPay = new PatchPay();
-                patchPay.setUid(logisticsAndBuySellInfo.getSellUid());
+                patchPay.setUid(logisticsAndBuySellInfo.getBuyUid());
                 patchPay.setMoney(MoneyChange.bigMoney(money));
                 patchPay.setRemark("对账单结算");
                 list.add(patchPay);
 
-                R<BusinessNo> businessNoR = payCenterService.payAgentPayV2(logisticsAndBuySellInfo.getBuyUid(), logisticsAndBuySellInfo.getSellUid(), ChannelEnum.XW,
+                R<BusinessNo> businessNoR = payCenterService.payAgentPayV2(logisticsAndBuySellInfo.getBuyUid  (), logisticsAndBuySellInfo.getSellUid(), ChannelEnum.XW,
                         MoneyChange.bigMoney(money), list, settlementLogisticsInfo.getSlOrderNo(), "1");
                 log.info("发起清分结果->{}", businessNoR);
                 if (businessNoR == null || !businessNoR.getStatus() || businessNoR.getData() == null) {
@@ -428,11 +418,14 @@ public class JobService {
                     return checkResult;
                 }
                 _qf = businessNoR.getData().getBusinessNo();
-                setCheckResult(checkResult, true, _qf, null);
-                return checkResult;
             }
 
-            setCheckResult(checkResult, orderSub.getStatus().equals(1), orderSub.getApNo(), orderSub);
+            // 根据预付单号查询清分单子
+            LambdaQueryWrapper<PayBatchAgentPay> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(PayBatchAgentPay::getBusinessNo, _qf);
+            PayBatchAgentPay orderSub = payBatchAgentPayMapper.selectOne(wrapper);
+
+            setCheckResult(checkResult, orderSub.getStatus().equals(1), orderSub.getBusinessNo(), orderSub);
         } catch (Exception e) {
             log.error("检查清分异常, settlementLogisticsInfo: {}, logisticsAndBuySellInfo: {}, money: {}", settlementLogisticsInfo, logisticsAndBuySellInfo, money, e);
             setCheckResult(checkResult, false, null, null);
@@ -476,7 +469,7 @@ public class JobService {
     // 辅助方法:设置 CheckResult 的状态、业务编号和数据
     private <T> void setCheckResult(CheckResult<T> checkResult, boolean status, String businessNo, T data) {
         checkResult.setStatus(status);
-        checkResult.setBusinessNo(businessNo);
+        checkResult.setBusinessNo(StringUtils.isBlank(businessNo)? " " : businessNo);
         checkResult.setData(data);
     }
 }

+ 5 - 2
src/main/java/com/sckw/freight/service/PayCenterService.java

@@ -422,8 +422,11 @@ public class PayCenterService {
         jsonObject.put("business_no", businessNo);
         jsonObject.put("pay_type", payType);
         String sync = jsonHttp(PayCenterEnum.PAY_AGENT_PAY_V2, jsonObject);
-        return JSONObject.parseObject(sync, new TypeReference<>() {
-        });
+//        return JSONObject.parseObject(sync, new TypeReference<>() {
+//        });
+
+        TypeReference<R<BusinessNo>> typeRef = new TypeReference<R<BusinessNo>>() {};
+        return JSONObject.parseObject(sync, typeRef);
     }
 
     /**

+ 16 - 0
src/main/java/com/sckw/freight/service/payment/IPayBatchAgentPayService.java

@@ -0,0 +1,16 @@
+package com.sckw.freight.service.payment;
+
+import com.sckw.freight.entity.payment.PayBatchAgentPay;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author xj
+ * @since 2025-02-11
+ */
+public interface IPayBatchAgentPayService extends IService<PayBatchAgentPay> {
+
+}

+ 20 - 0
src/main/java/com/sckw/freight/service/payment/impl/PayBatchAgentPayServiceImpl.java

@@ -0,0 +1,20 @@
+package com.sckw.freight.service.payment.impl;
+
+import com.sckw.freight.entity.payment.PayBatchAgentPay;
+import com.sckw.freight.mapper.payment.PayBatchAgentPayMapper;
+import com.sckw.freight.service.payment.IPayBatchAgentPayService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author xj
+ * @since 2025-02-11
+ */
+@Service
+public class PayBatchAgentPayServiceImpl extends ServiceImpl<PayBatchAgentPayMapper, PayBatchAgentPay> implements IPayBatchAgentPayService {
+
+}

+ 5 - 0
src/main/resources/com/sckw/freight/mapper/payment/PayBatchAgentPayMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sckw.freight.mapper.payment.PayBatchAgentPayMapper">
+
+</mapper>