18782137998 1 سال پیش
والد
کامیت
1d7c63a888
31فایلهای تغییر یافته به همراه543 افزوده شده و 47 حذف شده
  1. 20 0
      src/main/java/com/sckw/freight/controller/LedgerController.java
  2. 5 5
      src/main/java/com/sckw/freight/entity/freight/KwpSettlementLogistics.java
  3. 43 0
      src/main/java/com/sckw/freight/job/FreightTask.java
  4. 24 0
      src/main/java/com/sckw/freight/job/TaskScheduler.java
  5. 4 1
      src/main/java/com/sckw/freight/mapper/freight/KwpLedgerLogisticsMapper.java
  6. 2 1
      src/main/java/com/sckw/freight/mapper/freight/KwpLedgerLogisticsOrderMapper.java
  7. 2 1
      src/main/java/com/sckw/freight/mapper/freight/KwpLedgerLogisticsTrackMapper.java
  8. 2 1
      src/main/java/com/sckw/freight/mapper/freight/KwpLedgerLogisticsUnitMapper.java
  9. 2 1
      src/main/java/com/sckw/freight/mapper/freight/KwpSettlementLogisticsMapper.java
  10. 2 1
      src/main/java/com/sckw/freight/mapper/freight/KwpSettlementLogisticsTrackMapper.java
  11. 2 1
      src/main/java/com/sckw/freight/mapper/freight/KwpSettlementRecordMapper.java
  12. 2 1
      src/main/java/com/sckw/freight/mapper/freight/KwpWalletRelationMapper.java
  13. 2 1
      src/main/java/com/sckw/freight/mapper/kll/KllOrderMapper.java
  14. 2 1
      src/main/java/com/sckw/freight/mapper/kll/KllOrderProductMapper.java
  15. 2 1
      src/main/java/com/sckw/freight/mapper/kll/KllOrderTaskMapper.java
  16. 2 1
      src/main/java/com/sckw/freight/mapper/kll/KllOrderTruckMapper.java
  17. 5 0
      src/main/java/com/sckw/freight/model/dto/PayIndex.java
  18. 49 0
      src/main/java/com/sckw/freight/model/dto/PayOrderDetail.java
  19. 2 3
      src/main/java/com/sckw/freight/model/enums/KwpSettlementLogisticsStatusEnum.java
  20. 1 0
      src/main/java/com/sckw/freight/model/enums/PayCenterEnum.java
  21. 24 0
      src/main/java/com/sckw/freight/model/po/LedgerLogisticsAndBuySellInfo.java
  22. 134 0
      src/main/java/com/sckw/freight/service/JobService.java
  23. 15 17
      src/main/java/com/sckw/freight/service/PayCenterService.java
  24. 11 0
      src/main/java/com/sckw/freight/service/freight/IKwpLedgerLogisticsService.java
  25. 9 1
      src/main/java/com/sckw/freight/service/freight/IKwpSettlementLogisticsService.java
  26. 77 5
      src/main/java/com/sckw/freight/service/freight/impl/KwpLedgerLogisticsServiceImpl.java
  27. 23 3
      src/main/java/com/sckw/freight/service/freight/impl/KwpSettlementLogisticsServiceImpl.java
  28. 41 0
      src/main/java/com/sckw/freight/util/MoneyChange.java
  29. 9 1
      src/main/resources/application-dev.yml
  30. 8 0
      src/main/resources/application-test.yml
  31. 17 0
      src/main/resources/com/sckw/freight/mapper/freight/KwpLedgerLogisticsMapper.xml

+ 20 - 0
src/main/java/com/sckw/freight/controller/LedgerController.java

@@ -1,5 +1,6 @@
 package com.sckw.freight.controller;
 
+import com.sckw.freight.model.dto.PayIndex;
 import com.sckw.freight.model.vo.request.RequestLedgerLogisticsPageInfo;
 import com.sckw.freight.model.vo.request.RequestSaveLedgerLogisticsInfo;
 import com.sckw.freight.model.vo.response.ResponseKllOrderTask;
@@ -82,4 +83,23 @@ public class LedgerController {
     public R<ResponseLedgerLogisticsStatistics> queryLedgerLogisticsStatistics(@RequestParam(value = "entId", required = true) Long entId) {
         return iKwpLedgerLogisticsService.queryLedgerLogisticsStatistics(entId);
     }
+
+    /**
+     * @description: 申请收款
+     * @author: xj
+     * @date: 2025/1/14 星期二 10:47
+     * @param:
+     * @return: null
+     **/
+    @GetMapping("/applyPayment")
+    @Operation(summary = "物流对账单-申请收款")
+    @Parameters(value = {
+            @Parameter(name = "ledgerLogisticsId", description = "对账单id"),
+            @Parameter(name = "entId", description = "企业id")
+    })
+    public R<PayIndex> applyPayment(
+            @RequestParam(value = "ledgerLogisticsId", required = true) Long ledgerLogisticsId,
+            @RequestParam(value = "entId", required = true) Long entId) {
+        return iKwpLedgerLogisticsService.applyPayment(ledgerLogisticsId, entId);
+    }
 }

+ 5 - 5
src/main/java/com/sckw/freight/entity/freight/KwpSettlementLogistics.java

@@ -1,15 +1,16 @@
 package com.sckw.freight.entity.freight;
 
-import java.math.BigDecimal;
-import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.IdType;
-import java.time.LocalDateTime;
 import com.baomidou.mybatisplus.annotation.TableId;
-import java.io.Serializable;
+import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
 /**
  * <p>
  * 结算-物流订单
@@ -125,5 +126,4 @@ public class KwpSettlementLogistics implements Serializable {
      */
     private Integer delFlag;
 
-
 }

+ 43 - 0
src/main/java/com/sckw/freight/job/FreightTask.java

@@ -0,0 +1,43 @@
+package com.sckw.freight.job;
+
+import com.sckw.freight.service.JobService;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+/**
+ * @BelongsProject: Freight-Settlement-Backend
+ * @BelongsPackage: com.sckw.freight.job
+ * @Author: xj
+ * @CreateTime: 2025-01-14  15:33
+ * @Description: TODO
+ * @Version: 1.0
+ */
+@Component
+@Data
+@Slf4j
+public class FreightTask implements Runnable {
+
+    @Value("${job.sleep}")
+    private Integer sleep;
+    @Autowired
+    private JobService jobService;
+
+    @Override
+    public void run() {
+        new Thread(() -> {
+            while (true) {
+                try {
+                    log.info("轮循任务执行中...");
+                    jobService.executeJob();
+                    Thread.sleep(sleep * 1000l);
+                    log.info("轮循任务执行完成");
+                } catch (InterruptedException e) {
+                    log.error("轮循任务执行失败", e);
+                }
+            }
+        }).start();
+    }
+}

+ 24 - 0
src/main/java/com/sckw/freight/job/TaskScheduler.java

@@ -0,0 +1,24 @@
+package com.sckw.freight.job;
+
+import jakarta.annotation.PostConstruct;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @BelongsProject: Freight-Settlement-Backend
+ * @BelongsPackage: com.sckw.freight.job
+ * @Author: xj
+ * @CreateTime: 2025-01-14  15:40
+ * @Description: TODO
+ * @Version: 1.0
+ */
+@Component
+public class TaskScheduler {
+    @Autowired
+    FreightTask freightTask;
+
+    @PostConstruct
+    public void init() {
+        freightTask.run();
+    }
+}

+ 4 - 1
src/main/java/com/sckw/freight/mapper/freight/KwpLedgerLogisticsMapper.java

@@ -2,7 +2,9 @@ package com.sckw.freight.mapper.freight;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.freight.KwpLedgerLogistics;
+import com.sckw.freight.model.po.LedgerLogisticsAndBuySellInfo;
 import com.sckw.freight.model.po.LedgerLogisticsStatistics;
 
 import java.util.List;
@@ -15,7 +17,8 @@ import java.util.List;
  * @author xj
  * @since 2025-01-09
  */
-@DS("freight")
+@DS(DataSourceNames.FREIGHT)
 public interface KwpLedgerLogisticsMapper extends BaseMapper<KwpLedgerLogistics> {
     List<LedgerLogisticsStatistics> queryLedgerLogisticsStatistics(Long entId);
+    List<LedgerLogisticsAndBuySellInfo> queryLedgerLogisticsAndBuySellInfoNopaid();
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/freight/KwpLedgerLogisticsOrderMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.freight;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.freight.KwpLedgerLogisticsOrder;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-09
  */
-@DS("freight")
+@DS(DataSourceNames.FREIGHT)
 public interface KwpLedgerLogisticsOrderMapper extends BaseMapper<KwpLedgerLogisticsOrder> {
 
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/freight/KwpLedgerLogisticsTrackMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.freight;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.freight.KwpLedgerLogisticsTrack;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-09
  */
-@DS("freight")
+@DS(DataSourceNames.FREIGHT)
 public interface KwpLedgerLogisticsTrackMapper extends BaseMapper<KwpLedgerLogisticsTrack> {
 
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/freight/KwpLedgerLogisticsUnitMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.freight;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.freight.KwpLedgerLogisticsUnit;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-09
  */
-@DS("freight")
+@DS(DataSourceNames.FREIGHT)
 public interface KwpLedgerLogisticsUnitMapper extends BaseMapper<KwpLedgerLogisticsUnit> {
 
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/freight/KwpSettlementLogisticsMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.freight;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.freight.KwpSettlementLogistics;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-09
  */
-@DS("freight")
+@DS(DataSourceNames.FREIGHT)
 public interface KwpSettlementLogisticsMapper extends BaseMapper<KwpSettlementLogistics> {
 
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/freight/KwpSettlementLogisticsTrackMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.freight;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.freight.KwpSettlementLogisticsTrack;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-09
  */
-@DS("freight")
+@DS(DataSourceNames.FREIGHT)
 public interface KwpSettlementLogisticsTrackMapper extends BaseMapper<KwpSettlementLogisticsTrack> {
 
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/freight/KwpSettlementRecordMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.freight;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.freight.KwpSettlementRecord;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-09
  */
-@DS("freight")
+@DS(DataSourceNames.FREIGHT)
 public interface KwpSettlementRecordMapper extends BaseMapper<KwpSettlementRecord> {
 
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/freight/KwpWalletRelationMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.freight;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.freight.KwpWalletRelation;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-14
  */
-@DS("freight")
+@DS(DataSourceNames.FREIGHT)
 public interface KwpWalletRelationMapper extends BaseMapper<KwpWalletRelation> {
 
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/kll/KllOrderMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.kll;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.kll.KllOrder;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-09
  */
-@DS("kll")
+@DS(DataSourceNames.KLL)
 public interface KllOrderMapper extends BaseMapper<KllOrder> {
 
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/kll/KllOrderProductMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.kll;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.kll.KllOrderProduct;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-09
  */
-@DS("kll")
+@DS(DataSourceNames.KLL)
 public interface KllOrderProductMapper extends BaseMapper<KllOrderProduct> {
 
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/kll/KllOrderTaskMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.kll;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.kll.KllOrderTask;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-09
  */
-@DS("kll")
+@DS(DataSourceNames.KLL)
 public interface KllOrderTaskMapper extends BaseMapper<KllOrderTask> {
 
 }

+ 2 - 1
src/main/java/com/sckw/freight/mapper/kll/KllOrderTruckMapper.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.mapper.kll;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.sckw.freight.config.DataSourceNames;
 import com.sckw.freight.entity.kll.KllOrderTruck;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -12,7 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author xj
  * @since 2025-01-09
  */
-@DS("kll")
+@DS(DataSourceNames.KLL)
 public interface KllOrderTruckMapper extends BaseMapper<KllOrderTruck> {
 
 }

+ 5 - 0
src/main/java/com/sckw/freight/model/dto/PayIndex.java

@@ -1,6 +1,7 @@
 package com.sckw.freight.model.dto;
 
 import com.alibaba.fastjson.annotation.JSONField;
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -9,15 +10,19 @@ import java.io.Serializable;
 
 @Getter
 @Setter
+@Schema(description = "充值信息")
 public class PayIndex implements Serializable {
     @Serial
     private static final long serialVersionUID = -114261812502553262L;
     @JSONField(name = "order_no")
+    @Schema(description = "充值单号")
     private String orderNo;
 
     @JSONField(name = "uid")
+    @Schema(description = "用户id")
     private String uid;
 
     @JSONField(name = "pay_url")
+    @Schema(description = "充值地址")
     private String payUrl;
 }

+ 49 - 0
src/main/java/com/sckw/freight/model/dto/PayOrderDetail.java

@@ -0,0 +1,49 @@
+package com.sckw.freight.model.dto;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * @BelongsProject: Freight-Settlement-Backend
+ * @BelongsPackage: com.sckw.freight.model.dto
+ * @Author: xj
+ * @CreateTime: 2025-01-14  16:25
+ * @Description: TODO
+ * @Version: 1.0
+ */
+@Data
+@Schema(description = "充值订单详细信息")
+public class PayOrderDetail implements Serializable {
+    @Serial
+    private static final long serialVersionUID = -114261812502553262L;
+
+    @JSONField(name = "uid")
+    @Schema(description = "充值单号")
+    private String orderNo;
+
+    @JSONField(name = "uid")
+    @Schema(description = "用户id")
+    private String uid;
+
+    @JSONField(name = "uid")
+    @Schema(description = "充值地址")
+    private String payUrl;
+
+    @JSONField(name = "status")
+    @Schema(description = "充值状态")
+    private Integer status;
+
+    @JSONField(name = "payTime")
+    @Schema(description = "充值时间")
+    private LocalDateTime payTime;
+
+    @JSONField(name = "money")
+    @Schema(description = "金额")
+    private BigDecimal money;
+}

+ 2 - 3
src/main/java/com/sckw/freight/model/enums/KwpSettlementLogisticsStatusEnum.java

@@ -18,9 +18,8 @@ import java.util.stream.Collectors;
 @AllArgsConstructor
 public enum KwpSettlementLogisticsStatusEnum {
 
-//    ToSettled(1, "待结算"),
-//    PartialSettlement (2, "部分结算"),
-    FullSettlement (3, "已付款");
+    Nopaid(1, "待支付"),
+    Paid (2, "已支付") ;
     private final Integer code;
     private final String msg;
 

+ 1 - 0
src/main/java/com/sckw/freight/model/enums/PayCenterEnum.java

@@ -53,6 +53,7 @@ public enum PayCenterEnum {
     WITHDRAW_TRANSFER("/v2/wallet/withdraw/transfer", "转出加提现"),
     WALLET_INDEX("/v1/wallet/index", "创建钱包"),
     REFUND_APPLY("/v1/pay/refund_apply", "充值订单退款"),
+    PAY_DETAIL_BY_ORDER_NO("/v1/pay/GET_PAY_DETAIL_BY_ORDER_NO", "充值订单详情"),
     ;
     private final String addr;
     private final String desc;

+ 24 - 0
src/main/java/com/sckw/freight/model/po/LedgerLogisticsAndBuySellInfo.java

@@ -0,0 +1,24 @@
+package com.sckw.freight.model.po;
+
+import com.sckw.freight.entity.freight.KwpLedgerLogistics;
+import lombok.Data;
+
+/**
+ * @BelongsProject: Freight-Settlement-Backend
+ * @BelongsPackage: com.sckw.freight.model.po
+ * @Author: xj
+ * @CreateTime: 2025-01-14  15:58
+ * @Description: TODO
+ * @Version: 1.0
+ */
+@Data
+public class LedgerLogisticsAndBuySellInfo extends KwpLedgerLogistics {
+    /*
+     * 买方id
+     */
+    private String buyUid;
+    /*
+     * 卖方id
+     */
+    private String sellUid;
+}

+ 134 - 0
src/main/java/com/sckw/freight/service/JobService.java

@@ -0,0 +1,134 @@
+package com.sckw.freight.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.sckw.freight.entity.freight.KwpSettlementLogistics;
+import com.sckw.freight.mapper.freight.KwpLedgerLogisticsMapper;
+import com.sckw.freight.mapper.freight.KwpSettlementLogisticsMapper;
+import com.sckw.freight.model.dto.PatchPay;
+import com.sckw.freight.model.dto.PayOrderDetail;
+import com.sckw.freight.model.enums.ChannelEnum;
+import com.sckw.freight.model.enums.KwpSettlementLogisticsStatusEnum;
+import com.sckw.freight.model.po.LedgerLogisticsAndBuySellInfo;
+import com.sckw.freight.service.freight.IKwpLedgerLogisticsService;
+import com.sckw.freight.service.freight.IKwpSettlementLogisticsService;
+import com.sckw.freight.util.MoneyChange;
+import com.sckw.freight.util.R;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @BelongsProject: Freight-Settlement-Backend
+ * @BelongsPackage: com.sckw.freight.service
+ * @Author: xj
+ * @CreateTime: 2025-01-14  15:15
+ * @Description: 轮循任务
+ * @Version: 1.0
+ */
+@Slf4j
+@Service
+public class JobService {
+    @Autowired
+    PayCenterService payCenterService;
+    @Autowired
+    IKwpLedgerLogisticsService iKwpLedgerLogisticsService;
+    @Autowired
+    IKwpSettlementLogisticsService iKwpSettlementLogisticsService;
+    @Autowired
+    KwpLedgerLogisticsMapper kwpLedgerLogisticsMapper;
+    @Autowired
+    KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
+
+    /**
+     * 【轮循程序】
+     * 1:根据未完成的单子组合查询信息(收款方uid、付款方uid、未付金额)到支付中台【充值记录清单】接口 /v2/wallet/recharge/orders(收款方uid、付款方uid,时间)
+     * 2:当查询到新的充值记录时,调用支付中台【预付校验,新增预付】两个接口发起预付
+     * 3:预付成功后调用支付中台【清分】接口/v2/pay/agent_pay
+     * 4:清分接口调用成功后调支付中台【提现】接口 withdrawTake
+     * 5:提现成功创建 收款明细。
+     *
+     * @description:
+     * @author: xj
+     * @date: 2025/1/14 星期二 15:25
+     * @param:
+     * @param: null
+     * @return:
+     * @return: null
+     **/
+    public void executeJob() {
+        try {
+            //获取未支付的 对账单订单信息
+            List<LedgerLogisticsAndBuySellInfo> logisticsAndBuySellInfos = kwpLedgerLogisticsMapper.queryLedgerLogisticsAndBuySellInfoNopaid();
+            if (logisticsAndBuySellInfos == null || logisticsAndBuySellInfos.isEmpty()) {
+                //没有未支付的对账单订单信息 直接退出
+                return;
+            }
+            for (LedgerLogisticsAndBuySellInfo logisticsAndBuySellInfo : logisticsAndBuySellInfos) {
+                try {
+                    //查询该物流对账单 对应所有结算(支付)信息
+                    LambdaQueryWrapper<KwpSettlementLogistics> settlementLogisticsLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                    settlementLogisticsLambdaQueryWrapper.eq(KwpSettlementLogistics::getLLedgerId, logisticsAndBuySellInfo.getId());
+                    settlementLogisticsLambdaQueryWrapper.eq(KwpSettlementLogistics::getStatus, KwpSettlementLogisticsStatusEnum.Nopaid.getCode());
+                    settlementLogisticsLambdaQueryWrapper.select(KwpSettlementLogistics::getSlOrderNo);
+                    List<KwpSettlementLogistics> settlementLogistics = kwpSettlementLogisticsMapper.selectList(settlementLogisticsLambdaQueryWrapper);
+                    if (settlementLogistics == null || settlementLogistics.isEmpty()) {
+                        //没有未支付的结算信息 直接下一条
+                        continue;
+                    }
+                    for (KwpSettlementLogistics settlementLogisticsInfo : settlementLogistics) {
+                        try {
+
+                            R<PayOrderDetail> details = payCenterService.getPayDetailByOrderNo(settlementLogisticsInfo.getSlOrderNo());
+                            if (details == null || details.getCode() != 200 || details.getData() == null || !details.getStatus()) {
+                                continue;
+                            }
+                            //根据充值订单状态 处理结算状态
+                            if (details.getData().getStatus() == 1) {//已支付
+                                //发起预付
+                                payCenterService.advancePayApply(logisticsAndBuySellInfo.getBuyUid().toString(), ChannelEnum.XW,
+                                        logisticsAndBuySellInfo.getSellUid().toString(), MoneyChange.bigMoney(details.getData().getMoney()));
+
+
+                                // 1.记账
+                                List<PatchPay> list = new ArrayList<>();
+                                PatchPay patchPay = new PatchPay();
+                                patchPay.setUid(logisticsAndBuySellInfo.getSellUid().toString());
+                                patchPay.setMoney(MoneyChange.bigMoney(details.getData().getMoney()));
+                                list.add(patchPay);
+                                //清分
+                                payCenterService.payAgentPayV2(logisticsAndBuySellInfo.getBuyUid().toString(), logisticsAndBuySellInfo.getSellUid().toString(), ChannelEnum.XW,
+                                        MoneyChange.bigMoney(details.getData().getMoney()), list, settlementLogisticsInfo.getSlOrderNo(), "1");
+
+                                //提现
+                                payCenterService.withdrawTake(logisticsAndBuySellInfo.getSellUid().toString(), ChannelEnum.XW,
+                                        MoneyChange.bigMoney(details.getData().getMoney()),
+                                        "");
+
+                                //修改结算单状态
+                                iKwpSettlementLogisticsService.updateSettlementLogisticsStatusPaid(settlementLogisticsInfo, details.getData());
+                            }
+                        } catch (Exception e) {
+                            log.error("获取/处理 充值详情异常", e);
+                        }
+                    }
+                } catch (Exception e) {
+                    log.error("【" + logisticsAndBuySellInfo.getId() + "】轮循任务执行失败", e);
+                } finally {
+                    try {
+                        //修改物流对账单状态
+                        iKwpLedgerLogisticsService.updateLedgerLogisticsStatus(logisticsAndBuySellInfo, logisticsAndBuySellInfo.getCreateBy());
+                    } catch (Exception e) {
+                        log.error("【" + logisticsAndBuySellInfo.getId() + "】轮循任务执行失败", e);
+                    }
+                }
+
+            }
+        } catch (Exception e) {
+            log.error("轮循任务执行失败", e);
+        }
+    }
+
+}

+ 15 - 17
src/main/java/com/sckw/freight/service/PayCenterService.java

@@ -155,10 +155,6 @@ public class PayCenterService {
     }
 
 
-
-
-
-
     /**
      * 会员注册信息
      *
@@ -176,11 +172,6 @@ public class PayCenterService {
     }
 
 
-
-
-
-
-
     /**
      * 订单状态
      *
@@ -252,8 +243,6 @@ public class PayCenterService {
     }
 
 
-
-
     /**
      * 操作记录-分类
      *
@@ -266,9 +255,6 @@ public class PayCenterService {
     }
 
 
-
-
-
     /**
      * 发起预付
      *
@@ -344,7 +330,6 @@ public class PayCenterService {
     }
 
 
-
     /**
      * 冻结资金
      * 中台逻辑:
@@ -456,6 +441,19 @@ public class PayCenterService {
         return JSONObject.parseObject(sync, new TypeReference<>() {
         });
     }
-
-
+    /**
+     * @description: 根据单号,获取充值记录详情
+     * @author: xj
+     * @date: 2025/1/14 星期二 16:28
+     * @param:
+     * @return: null
+     **/
+    public R<PayOrderDetail> getPayDetailByOrderNo(String orderNo) {
+
+        String sync = getHttp(PayCenterEnum.PAY_DETAIL_BY_ORDER_NO, new HashMap<>() {{
+            put("order_no", orderNo);
+        }});
+        return JSONObject.parseObject(sync, new TypeReference<>() {
+        });
+    }
 }

+ 11 - 0
src/main/java/com/sckw/freight/service/freight/IKwpLedgerLogisticsService.java

@@ -2,6 +2,7 @@ package com.sckw.freight.service.freight;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.sckw.freight.entity.freight.KwpLedgerLogistics;
+import com.sckw.freight.model.dto.PayIndex;
 import com.sckw.freight.model.vo.request.RequestLedgerLogisticsPageInfo;
 import com.sckw.freight.model.vo.request.RequestSaveLedgerLogisticsInfo;
 import com.sckw.freight.model.vo.response.ResponseKllOrderTask;
@@ -68,4 +69,14 @@ public interface IKwpLedgerLogisticsService extends IService<KwpLedgerLogistics>
      * @return: null
      **/
     R<ResponseLedgerLogisticsStatistics> queryLedgerLogisticsStatistics(Long entId);
+
+
+    /**
+     * @description: 申请收款
+     * @author: xj
+     * @date: 2025/1/14 星期二 10:52
+     * @param:
+     * @return: null
+     **/
+    R<PayIndex> applyPayment(Long ledgerLogisticsId, Long entId);
 }

+ 9 - 1
src/main/java/com/sckw/freight/service/freight/IKwpSettlementLogisticsService.java

@@ -1,7 +1,10 @@
 package com.sckw.freight.service.freight;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.sckw.freight.entity.freight.KwpLedgerLogistics;
 import com.sckw.freight.entity.freight.KwpSettlementLogistics;
+import com.sckw.freight.model.dto.PayOrderDetail;
+import com.sckw.freight.model.enums.KwpSettlementLogisticsStatusEnum;
 import com.sckw.freight.model.vo.request.RequestSettlementLogisticsPageInfo;
 import com.sckw.freight.model.vo.response.ResponsePageData;
 import com.sckw.freight.model.vo.response.ResponseSettlementLogistics;
@@ -20,5 +23,10 @@ import java.time.LocalDateTime;
  */
 public interface IKwpSettlementLogisticsService extends IService<KwpSettlementLogistics> {
     void addSettlementLogistics(Long lLedgerId, BigDecimal price, String slOrderNo, LocalDateTime payTime, Long userid);
-    R<ResponsePageData<ResponseSettlementLogistics>> list( RequestSettlementLogisticsPageInfo requestPageInfo);
+
+    R<ResponsePageData<ResponseSettlementLogistics>> list(RequestSettlementLogisticsPageInfo requestPageInfo);
+
+    void saveSettlementLogistics(KwpLedgerLogistics logistics, BigDecimal price, String slOrderNo, KwpSettlementLogisticsStatusEnum status, LocalDateTime payTime, Long userid);
+
+    void updateSettlementLogisticsStatusPaid(KwpSettlementLogistics kwpSettlementLogistics, PayOrderDetail payOrderDetail);
 }

+ 77 - 5
src/main/java/com/sckw/freight/service/freight/impl/KwpLedgerLogisticsServiceImpl.java

@@ -3,15 +3,14 @@ package com.sckw.freight.service.freight.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.sckw.freight.entity.freight.KwpLedgerLogistics;
-import com.sckw.freight.entity.freight.KwpLedgerLogisticsOrder;
-import com.sckw.freight.entity.freight.KwpLedgerLogisticsTrack;
-import com.sckw.freight.entity.freight.KwpSettlementLogistics;
+import com.sckw.freight.entity.freight.*;
 import com.sckw.freight.entity.kll.KllOrder;
 import com.sckw.freight.entity.kll.KllOrderTask;
 import com.sckw.freight.mapper.freight.KwpLedgerLogisticsMapper;
 import com.sckw.freight.mapper.freight.KwpSettlementLogisticsMapper;
+import com.sckw.freight.mapper.freight.KwpWalletRelationMapper;
 import com.sckw.freight.mapper.kll.KllOrderTaskMapper;
+import com.sckw.freight.model.dto.PayIndex;
 import com.sckw.freight.model.enums.*;
 import com.sckw.freight.model.po.LedgerLogisticsStatistics;
 import com.sckw.freight.model.vo.request.RequestLedgerLogisticsPageInfo;
@@ -20,15 +19,18 @@ import com.sckw.freight.model.vo.response.ResponseKllOrderTask;
 import com.sckw.freight.model.vo.response.ResponseLedgerLogistics;
 import com.sckw.freight.model.vo.response.ResponseLedgerLogisticsStatistics;
 import com.sckw.freight.model.vo.response.ResponsePageData;
+import com.sckw.freight.service.PayCenterService;
 import com.sckw.freight.service.freight.IKwpLedgerLogisticsOrderService;
 import com.sckw.freight.service.freight.IKwpLedgerLogisticsService;
 import com.sckw.freight.service.freight.IKwpLedgerLogisticsTrackService;
+import com.sckw.freight.service.freight.IKwpSettlementLogisticsService;
 import com.sckw.freight.service.kll.IKllOrderService;
 import com.sckw.freight.util.DateTimeUtil;
 import com.sckw.freight.util.R;
 import com.sckw.freight.util.SnowflakeIdUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
@@ -60,6 +62,13 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
     KwpLedgerLogisticsMapper kwpLedgerLogisticsMapper;
     @Autowired
     KllOrderTaskMapper kllOrderTaskMapper;
+    @Autowired
+    KwpWalletRelationMapper kwpWalletRelationMapper;
+    @Autowired
+    PayCenterService payCenterService;
+    @Lazy
+    @Autowired
+    IKwpSettlementLogisticsService iKwpSettlementLogisticsService;
 
     /**
      * @description: 物流对账统计信息
@@ -108,11 +117,12 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
 
         LambdaQueryWrapper<KwpSettlementLogistics> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(KwpSettlementLogistics::getLLedgerId, ledgerLogistics.getId());
-        wrapper.eq(KwpSettlementLogistics::getStatus, KwpSettlementLogisticsStatusEnum.FullSettlement.getCode());
+        wrapper.eq(KwpSettlementLogistics::getStatus, KwpSettlementLogisticsStatusEnum.Paid.getCode());
         List<KwpSettlementLogistics> kwpSettlementLogistics = kwpSettlementLogisticsMapper.selectList(wrapper);
         if (kwpSettlementLogistics == null) kwpSettlementLogistics = new ArrayList<>();
         BigDecimal totalPrice = kwpSettlementLogistics.stream().map(KwpSettlementLogistics::getActualPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
         newLedgerLogistics.setActualPrice(totalPrice);
+        if (totalPrice.compareTo(BigDecimal.ZERO)==0)return;
         KwpLedgerLogisticsStatusEnum status = KwpLedgerLogisticsStatusEnum.Unpaid;
         if (totalPrice.compareTo(ledgerLogistics.getSettlePrice()) < 0) {
             status = KwpLedgerLogisticsStatusEnum.PartialPaid;
@@ -448,4 +458,66 @@ public class KwpLedgerLogisticsServiceImpl extends ServiceImpl<KwpLedgerLogistic
         boolean isUpdate = iKllOrderService.update(newOrder, new LambdaQueryWrapper<KllOrder>().in(KllOrder::getId, orderList.stream().map(KllOrder::getId).collect(Collectors.toList())));
         if (!isUpdate) throw new RuntimeException("更新物流订单状态失败");
     }
+
+    /**
+     * 申请收款
+     * 1:检查信息(状态、所属)
+     * 2:查询收款方、付款方对应的 账户信息
+     * 3:支付中台的 【在线充值】接口
+     * 4:保存 付款单信息
+     * 5:返回前端支付连接
+     *
+     * @description: 申请收款
+     * @author: xj
+     * @date: 2025/1/14 星期二 10:54
+     * @param:
+     * @return: null
+     **/
+    @Override
+    public R<PayIndex> applyPayment(Long ledgerLogisticsId, Long entId) {
+        if (entId == null) return R.failed("企业id不能为空");
+        if (ledgerLogisticsId == null) return R.failed("对账单id不能为空");
+        //查询对账单信息
+        LambdaQueryWrapper<KwpLedgerLogistics> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(KwpLedgerLogistics::getId, ledgerLogisticsId);
+        wrapper.eq(KwpLedgerLogistics::getEntId, entId);
+        KwpLedgerLogistics ledgerLogistics = this.getOne(wrapper);
+
+        if (ledgerLogistics == null) {
+            return R.failed("对账单不存在");
+        }
+        if (KwpLedgerLogisticsStatusEnum.Paid.getCode().equals(ledgerLogistics.getStatus())) {
+            return R.failed("对账单支付");
+        }
+        //计算剩余未付金额=实际结算金额-已付金额
+        BigDecimal money = ledgerLogistics.getSettlePrice().subtract(ledgerLogistics.getActualPrice());
+        if (money.compareTo(BigDecimal.ZERO) <= 0) {
+            return R.failed("对账单已支付");
+        }
+        //查询收款方(卖方)  账户信息
+        LambdaQueryWrapper<KwpWalletRelation> walletRelationWrapperS = new LambdaQueryWrapper<>();
+        walletRelationWrapperS.eq(KwpWalletRelation::getEntId, entId);
+        KwpWalletRelation walletRelationS = kwpWalletRelationMapper.selectOne(walletRelationWrapperS);
+        if (walletRelationS == null) {
+            return R.failed("收款方【"+entId+"】账户不存在");
+        }
+        //查询付款方(买方)  账户信息
+        LambdaQueryWrapper<KwpWalletRelation> walletRelationWrapperP = new LambdaQueryWrapper<>();
+        walletRelationWrapperP.eq(KwpWalletRelation::getEntId, ledgerLogistics.getCompanyId());
+        KwpWalletRelation walletRelationP = kwpWalletRelationMapper.selectOne(walletRelationWrapperP);
+        if (walletRelationP == null) {
+            return R.failed("付款方【"+ledgerLogistics.getCompanyId()+"】账户不存在");
+        }
+        //调用支付中台的【在线充值】接口
+        R<PayIndex> payIndexR = payCenterService.payIndex(walletRelationP.getUid(), walletRelationS.getUid(), ChannelEnum.XW, money.multiply(BigDecimal.valueOf(100)).longValue());
+        if (payIndexR == null || !payIndexR.getStatus() || payIndexR.getCode() != 200) {
+            return R.failed("支付中台的【在线充值】接口失败");
+        }
+        PayIndex payIndex = payIndexR.getData();
+        //保存付款单信息
+        iKwpSettlementLogisticsService.addSettlementLogistics(ledgerLogisticsId, money, payIndex.getOrderNo(), null, ledgerLogistics.getCreateBy());
+        // 返回前端支付连接
+        return R.ok(payIndex);
+    }
+
 }

+ 23 - 3
src/main/java/com/sckw/freight/service/freight/impl/KwpSettlementLogisticsServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.sckw.freight.entity.freight.KwpLedgerLogistics;
 import com.sckw.freight.entity.freight.KwpSettlementLogistics;
 import com.sckw.freight.mapper.freight.KwpSettlementLogisticsMapper;
+import com.sckw.freight.model.dto.PayOrderDetail;
 import com.sckw.freight.model.enums.DelFlagEnum;
 import com.sckw.freight.model.enums.KwpSettlementLogisticsStatusEnum;
 import com.sckw.freight.model.vo.request.RequestSettlementLogisticsPageInfo;
@@ -64,7 +65,7 @@ public class KwpSettlementLogisticsServiceImpl extends ServiceImpl<KwpSettlement
         //先进性数据验证
         KwpLedgerLogistics logistics = verifySettlementLogistics(lLedgerId, price, payTime, userid);
         //插入结算单信息(插入支付记录)
-        saveSettlementLogistics(logistics, price, slOrderNo, payTime, userid);
+        saveSettlementLogistics(logistics, price, slOrderNo,KwpSettlementLogisticsStatusEnum.Paid, payTime, userid);
         //修改物流单对账单状态(如果支付总额已超过对账单)
         iKwpLedgerLogisticsService.updateLedgerLogisticsStatus(logistics, userid);
 
@@ -146,7 +147,8 @@ public class KwpSettlementLogisticsServiceImpl extends ServiceImpl<KwpSettlement
      * @param:
      * @return: null
      **/
-    private void saveSettlementLogistics(KwpLedgerLogistics logistics, BigDecimal price, String slOrderNo, LocalDateTime payTime, Long userid) {
+    @Override
+    public void saveSettlementLogistics(KwpLedgerLogistics logistics, BigDecimal price, String slOrderNo,KwpSettlementLogisticsStatusEnum status, LocalDateTime payTime, Long userid) {
         KwpSettlementLogistics settlementLogistics = new KwpSettlementLogistics();
         settlementLogistics.setId(SnowflakeIdUtil.getInstance().nextId());
         settlementLogistics.setEntId(logistics.getEntId());
@@ -156,7 +158,7 @@ public class KwpSettlementLogisticsServiceImpl extends ServiceImpl<KwpSettlement
         settlementLogistics.setTotalPrice(price);
         settlementLogistics.setActualPrice(price);
         settlementLogistics.setReceiptTime(payTime);
-        settlementLogistics.setStatus(KwpSettlementLogisticsStatusEnum.FullSettlement.getCode());
+        settlementLogistics.setStatus(status.getCode());
         settlementLogistics.setCreateBy(userid);
         settlementLogistics.setUpdateBy(userid);
         settlementLogistics.setCreateTime(LocalDateTime.now());
@@ -167,5 +169,23 @@ public class KwpSettlementLogisticsServiceImpl extends ServiceImpl<KwpSettlement
         if (!save) throw new RuntimeException("保存结算单失败");
 
     }
+    /**
+     * @description: 更新结算单状态为已支付
+     * @author: xj
+     * @date: 2025/1/14 星期二 16:38
+     * @param:
+     * @return: null
+     **/
+    @Override
+    public void updateSettlementLogisticsStatusPaid(KwpSettlementLogistics kwpSettlementLogistics, PayOrderDetail payOrderDetail) {
+        KwpSettlementLogistics newSettlementLogistics = new KwpSettlementLogistics();
+        newSettlementLogistics.setId(kwpSettlementLogistics.getId());
+        newSettlementLogistics.setStatus(KwpSettlementLogisticsStatusEnum.Paid.getCode());
+        newSettlementLogistics.setUpdateTime(payOrderDetail.getPayTime());
+        newSettlementLogistics.setActualPrice(payOrderDetail.getMoney());
+        newSettlementLogistics.setTotalPrice( payOrderDetail.getMoney());
+        boolean update = updateById(newSettlementLogistics);
+        if (!update) throw new RuntimeException("更新结算单状态为已支付失败");
+    }
 
 }

+ 41 - 0
src/main/java/com/sckw/freight/util/MoneyChange.java

@@ -0,0 +1,41 @@
+package com.sckw.freight.util;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Objects;
+
+/**
+ * 金额转换
+ *
+ * @author xucaiqin
+ * @date 2023-08-28 18:06:18
+ */
+public class MoneyChange {
+    /**
+     * 元转分
+     *
+     * @param big
+     * @return
+     */
+    public static Long bigMoney(BigDecimal big) {
+        if (Objects.isNull(big)) {
+            return 0L;
+        }
+        BigDecimal divide = big.multiply(new BigDecimal("100"));
+        return divide.longValueExact();
+    }
+
+    /**
+     * 分转元
+     *
+     * @param big
+     * @return
+     */
+    public static BigDecimal smallMoney(BigDecimal big) {
+        if (Objects.isNull(big)) {
+            return BigDecimal.ZERO.setScale(2, RoundingMode.DOWN);
+        }
+        return big.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
+    }
+
+}

+ 9 - 1
src/main/resources/application-dev.yml

@@ -48,4 +48,12 @@ knife4j:
   enable: true
 #  setting:
 #    language: zh_cn
-    #swagger-model-name: 物流单对账结算-Api
+    #swagger-model-name: 物流单对账结算-Api
+
+# 支付中心 地址
+payCenter:
+  address: http://10.10.10.223:9805
+
+#轮循任务 间隔时长(秒)
+job:
+  sleep: 5

+ 8 - 0
src/main/resources/application-test.yml

@@ -40,3 +40,11 @@ logging:
 mybatis-plus:
   configuration:
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+
+
+# 支付中心 地址
+payCenter:
+  address: http://10.10.10.223:9805
+#轮循任务 间隔时长(秒)
+job:
+  sleep: 5

+ 17 - 0
src/main/resources/com/sckw/freight/mapper/freight/KwpLedgerLogisticsMapper.xml

@@ -9,4 +9,21 @@
         where t.ent_id=#{entId}
         GROUP BY t.`status`
     </select>
+    <select id="queryLedgerLogisticsAndBuySellInfoNopaid"
+            resultType="com.sckw.freight.model.po.LedgerLogisticsAndBuySellInfo">
+        SELECT
+            t.*,
+            rs.uid by_uid,
+            rp.uid sell_uid
+        FROM
+            kwp_ledger_logistics t
+                LEFT JOIN kwp_wallet_relation rs ON rs.ent_id = t.ent_id
+                LEFT JOIN kwp_wallet_relation rp ON rp.ent_id = t.company_id
+        WHERE
+            rp.uid IS NOT NULL
+          AND rs.uid IS NOT NULL
+          and t.del_flag= 0
+          AND t.`status` IN (0,  1)
+
+    </select>
 </mapper>