Просмотр исходного кода

app端结算接口增加结算比例展示、app端结算详情接口

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

+ 21 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/controller/app/AppKwpSettlementTradeController.java

@@ -7,6 +7,8 @@ import com.sckw.payment.model.vo.req.SettlementTradeReq;
 import com.sckw.payment.service.KwpSettlementTradeService;
 import jakarta.annotation.Resource;
 import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotBlank;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 /**
@@ -14,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
  *
  * @author xucaiqin
  */
+@Validated
 @RestController
 @RequestMapping("/appKwpSettlementTrade")
 public class AppKwpSettlementTradeController {
@@ -52,7 +55,15 @@ public class AppKwpSettlementTradeController {
         return HttpResult.ok(kwpSettlementTradeService.getCount(settlementReq));
     }
 
-
+    /**
+     * 销售方查询结算单详情
+     * @param id
+     * @return
+     */
+    @GetMapping( "sellDetail")
+    public HttpResult sellDetail(@NotBlank(message = "结算单id不能为空")@RequestParam("id") String id) {
+        return HttpResult.ok(kwpSettlementTradeService.queryDetail(Long.parseLong(id),TradeUnitType.PURCHASE));
+    }
     //   ========= 付款 采购 =========
 
     /**
@@ -83,5 +94,14 @@ public class AppKwpSettlementTradeController {
         settlementReq.setEntId(LoginUserHolder.getEntId());
         return HttpResult.ok(kwpSettlementTradeService.getCount(settlementReq));
     }
+    /**
+     * 采购方查询结算单详情
+     * @param id 结算单id
+     * @return
+     */
+    @GetMapping( "purchaseDetail")
+    public HttpResult purchaseDetail(@NotBlank(message = "结算单id不能为空")@RequestParam("id") String id) {
+        return HttpResult.ok(kwpSettlementTradeService.queryDetail(Long.parseLong(id),TradeUnitType.SELL));
+    }
 
 }

+ 2 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/dao/KwpSettlementTradeMapper.java

@@ -30,4 +30,6 @@ public interface KwpSettlementTradeMapper extends BaseMapper<KwpSettlementTrade>
     SettlementTradeDto getById(@Param("id") Long id, @Param("unitType") Integer unitType);
 
     List<LedgerUnitDto> getListById(@Param("id") Long id);
+
+    SettlementTradeDto selectDetail(@Param("id") Long id, @Param("unitTYpe") Integer unitType);
 }

+ 13 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/constant/TradingEnum.java

@@ -1,6 +1,7 @@
 package com.sckw.payment.model.constant;
 
 import com.sckw.payment.api.model.constant.ChannelEnum;
+import org.apache.commons.lang3.StringUtils;
 
 import java.util.Objects;
 
@@ -43,6 +44,18 @@ public enum TradingEnum {
         return "";
     }
 
+    //根据支付方式获取交易方式前缀
+    public static Integer getPrefix(String trading) {
+        if (StringUtils.isNotBlank(trading)) {
+            for (TradingEnum value : values()) {
+                if (StringUtils.equals(value.getValue(), trading.substring(0, 1))) {
+                    return value.getStatus();
+                }
+            }
+        }
+        return null;
+    }
+
     public int getStatus() {
         return status;
     }

+ 13 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/dto/ISettlement.java

@@ -1,6 +1,7 @@
 package com.sckw.payment.model.dto;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.DecimalFormat;
 import java.util.Objects;
 
@@ -33,4 +34,16 @@ public interface ISettlement {
         }
         return df().format(price);
     }
+
+    default String changePercentage(BigDecimal pay, BigDecimal total) {
+        if (Objects.isNull(pay)) {
+            pay = new BigDecimal("0.0");
+        }
+        //分母为0的情况,直接返回百分比0.00%
+        if (Objects.isNull(total)) {
+            pay = new BigDecimal("0.0");
+            total = new BigDecimal("1");
+        }
+        return df().format(pay.divide(total, 2, RoundingMode.HALF_UP)) + "%";
+    }
 }

+ 25 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/dto/SettlementDetailDto.java

@@ -0,0 +1,25 @@
+package com.sckw.payment.model.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * 结算详情
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class SettlementDetailDto<T,K> {
+    /**
+     * 物流、贸易结算单信息
+     */
+    private T settlement;
+    /**
+     * 钱包结算记录
+     */
+    private List<K> walletList;
+
+}

+ 2 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/dto/SettlementPurchaseDto.java

@@ -86,5 +86,7 @@ public class SettlementPurchaseDto implements ISettlement {
     private String firmName;
     private Long updateBy;
     private String updateByLabel;
+    //百分比
+    private String percentage;
 
 }

+ 2 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/dto/SettlementSellDto.java

@@ -86,5 +86,7 @@ public class SettlementSellDto implements ISettlement {
     private String firmName;
     private Long updateBy;
     private String updateByLabel;
+    //百分比
+    private String percentage;
 
 }

+ 1 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/dto/SettlementTradeDto.java

@@ -31,6 +31,7 @@ public class SettlementTradeDto implements ISettlement {
     /**
      * 交易订单对账id
      */
+    @JsonProperty("tLedgerId")
     private Long tLedgerId;
 
     /**

+ 2 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpLedgerLogisticsService.java

@@ -374,7 +374,6 @@ public class KwpLedgerLogisticsService extends AbsLedger {
         deleteCheck(kwpLedgerLogistics.getStatus());
         kwpLedgerLogistics.setDelFlag(Global.DELETED);
         logisticsMapper.updateById(kwpLedgerLogistics);
-        logisticsTrackService.saveTrack(id, Global.EMPTY_STRING, LedgerTrackEnum.DELETE);
         List<KwpLedgerLogisticsOrder> kwpLedgerLogisticsOrders = logisticsOrderService.queryList(id);
         //更新物流订单状态为已解绑
         AccountCheckingBindDTO accountCheckingBindDTO = new AccountCheckingBindDTO();
@@ -386,6 +385,8 @@ public class KwpLedgerLogisticsService extends AbsLedger {
         if (httpResult.getCode() != 60200) {
             throw new BusinessException(httpResult.getMsg());
         }
+        logisticsOrderService.remove(id);
+        logisticsTrackService.saveTrack(id, Global.EMPTY_STRING, LedgerTrackEnum.DELETE);
         return "删除成功";
     }
 

+ 7 - 3
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpLedgerTradeService.java

@@ -380,6 +380,7 @@ public class KwpLedgerTradeService extends AbsLedger {
         kwpLedgerTrade.setUpdateBy(LoginUserHolder.getUserId());
         kwpLedgerTrade.setUpdateTime(LocalDateTime.now());
         tradeMapper.updateById(kwpLedgerTrade);
+        tradeOrderService.remove(id);
         //更新贸易订单状态为未绑定对账单
         for (KwpLedgerTradeOrder kwpLedgerTradeOrder : kwpLedgerTradeOrders) {
             UpdateAssociateStatementParam updateAssociateStatementParam = new UpdateAssociateStatementParam();
@@ -640,12 +641,15 @@ public class KwpLedgerTradeService extends AbsLedger {
         List<UnitInfoDetailRes> unitInfo = orderDetailRes.getUnitInfo();
         if (!CollectionUtils.isEmpty(unitInfo)) {
             for (UnitInfoDetailRes unitInfoDetailRes : unitInfo) {
-                if (StringUtils.equals(unitInfoDetailRes.getUnitType(), "1")) {
+                //2-销售
+                if (StringUtils.equals(unitInfoDetailRes.getUnitType(), "2")) {
                     orderDto.setSupplyEntId(unitInfoDetailRes.getEntId());
                     orderDto.setSupplyFirmName(unitInfoDetailRes.getFirmName());
                 }
-                if (StringUtils.equals(unitInfoDetailRes.getUnitType(), "2")) {
+                //1-采购
+                if (StringUtils.equals(unitInfoDetailRes.getUnitType(), "1")) {
                     orderDto.setProcureEntId(unitInfoDetailRes.getEntId());
+                    //采购企业名称
                     orderDto.setProcureFirmName(unitInfoDetailRes.getFirmName());
                 }
             }
@@ -745,6 +749,6 @@ public class KwpLedgerTradeService extends AbsLedger {
             return new ArrayList<>();
         }
         List<KwpLedgerTrade> kwpLedgerTrades = tradeMapper.selectBatchIds(longs);
-        return kwpLedgerTrades.stream().filter(a->!Objects.equals(a.getStatus(),LedgerEnum.SUCCESS.getStatus())).map(KwpLedgerTrade::getTLedgerNo).distinct().toList();
+        return kwpLedgerTrades.stream().filter(a -> !Objects.equals(a.getStatus(), LedgerEnum.SUCCESS.getStatus())).map(KwpLedgerTrade::getTLedgerNo).distinct().toList();
     }
 }

+ 39 - 5
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementTradeService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.sckw.core.common.enums.enums.DictTypeEnum;
+import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.model.vo.TableTop;
@@ -13,13 +14,16 @@ import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.payment.dao.KwpSettlementTradeMapper;
 import com.sckw.payment.model.KwpSettlementTrade;
 import com.sckw.payment.model.constant.SettlementEnum;
+import com.sckw.payment.model.constant.SettlementOrderTypeEnum;
 import com.sckw.payment.model.constant.TradeUnitType;
+import com.sckw.payment.model.constant.TradingEnum;
 import com.sckw.payment.model.dto.*;
 import com.sckw.payment.model.vo.req.SettlementTradeReq;
 import com.sckw.payment.model.vo.res.SettlementSumVo;
 import com.sckw.system.api.RemoteSystemService;
 import com.sckw.system.api.model.dto.res.SysDictResDto;
 import com.sckw.system.api.model.dto.res.UserCacheResDto;
+import jakarta.annotation.Resource;
 import lombok.RequiredArgsConstructor;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.stereotype.Service;
@@ -31,16 +35,22 @@ import java.util.Objects;
 import java.util.stream.Collectors;
 
 /**
+ * 贸易结算
  * @author xucaiqin
  * @date 2023-07-10 16:38:36
  */
 @Service
 @RequiredArgsConstructor
 public class KwpSettlementTradeService {
-    private final KwpSettlementTradeMapper settlementTradeMapper;
     @DubboReference(version = "1.0.0", group = "design", check = false)
     private RemoteSystemService remoteSystemService;
+
+    private final KwpSettlementTradeMapper settlementTradeMapper;
     private final KwpLedgerTradeUnitService tradeUnitService;
+    @Resource
+    private KwpSettlementWalletService walletService;
+    @Resource
+    private KwpSettlementOfflineService offlineService;
 
     /**
      * 查询结算单详情
@@ -113,7 +123,8 @@ public class KwpSettlementTradeService {
                     settlementSellDto.setTotalPrice(settlementSellDto.changePrice(settlementTradeDto.getTotalPrice()));
                     settlementSellDto.setWaitPrice(settlementSellDto.changePrice(settlementTradeDto.getWaitPrice()));
                     UserCacheResDto userCacheResDto = remoteSystemService.queryUserCacheById(settlementTradeDto.getUpdateBy());
-                    settlementSellDto.setUpdateByLabel(Objects.nonNull(userCacheResDto)?userCacheResDto.getName():"");
+                    settlementSellDto.setUpdateByLabel(Objects.nonNull(userCacheResDto) ? userCacheResDto.getName() : "");
+                    settlementSellDto.setPercentage(settlementSellDto.changePercentage(settlementTradeDto.getActualPrice(), settlementTradeDto.getTotalPrice()));
                     res.add(settlementSellDto);
                 }
                 changeDict(res);
@@ -130,14 +141,15 @@ public class KwpSettlementTradeService {
                     settlementSellDto.setTotalPrice(settlementSellDto.changePrice(settlementTradeDto.getTotalPrice()));
                     settlementSellDto.setWaitPrice(settlementSellDto.changePrice(settlementTradeDto.getWaitPrice()));
                     UserCacheResDto userCacheResDto = remoteSystemService.queryUserCacheById(settlementTradeDto.getUpdateBy());
-                    settlementSellDto.setUpdateByLabel(Objects.nonNull(userCacheResDto)?userCacheResDto.getName():"");
+                    settlementSellDto.setUpdateByLabel(Objects.nonNull(userCacheResDto) ? userCacheResDto.getName() : "");
+                    settlementSellDto.setPercentage(settlementSellDto.changePercentage(settlementTradeDto.getActualPrice(), settlementTradeDto.getTotalPrice()));
                     res.add(settlementSellDto);
                 }
                 changeDict(res);
                 return new PageRes<>(settlementPageInfo, res);
             }
         }
-        return new PageRes<>();
+        return new PageRes<>(settlementPageInfo);
     }
 
     /**
@@ -212,7 +224,6 @@ public class KwpSettlementTradeService {
     }
 
 
-
     /**
      * 更新对账单
      *
@@ -237,4 +248,27 @@ public class KwpSettlementTradeService {
                 .filter(a -> !Objects.equals(a.getStatus(), SettlementEnum.ALL_PAYMENT.getStatus()))
                 .map(KwpSettlementTrade::getStOrderNo).distinct().collect(Collectors.toList());
     }
+
+    /**
+     * 查询贸易结算详情
+     *
+     * @param id       结算单id
+     * @param unitType 企业类型
+     * @return
+     */
+    public SettlementDetailDto<SettlementTradeDto, SettlementWalletDto> queryDetail(Long id, Integer unitType) {
+        SettlementTradeDto settlementTradeDto = settlementTradeMapper.selectDetail(id, unitType);
+        if (Objects.isNull(settlementTradeDto)) {
+            throw new BusinessException("结算单不存在");
+        }
+        Map<String, SysDictResDto> dictResDtoMap = remoteSystemService.queryDictMapByType(DictTypeEnum.TRADE_TYPE.getType());
+        String trading = settlementTradeDto.getTrading();
+        SysDictResDto sysDictResDto = dictResDtoMap.get(trading);
+        if (Objects.nonNull(sysDictResDto)) {
+            settlementTradeDto.setTradingLabel(sysDictResDto.getLabel());
+        }
+        settlementTradeDto.setStatusLabel(SettlementEnum.getStatusDesc(settlementTradeDto.getStatus()));
+        List<SettlementWalletDto> settlementWallet = walletService.queryList(id, SettlementOrderTypeEnum.TRADE.getStatus(), TradingEnum.getPrefix(trading));
+        return new SettlementDetailDto<>(settlementTradeDto, settlementWallet);
+    }
 }

+ 17 - 2
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementWalletService.java

@@ -20,7 +20,10 @@ import com.sckw.payment.dao.KwpSettlementLogisticsTrackMapper;
 import com.sckw.payment.dao.KwpSettlementWalletMapper;
 import com.sckw.payment.model.*;
 import com.sckw.payment.model.constant.*;
-import com.sckw.payment.model.dto.*;
+import com.sckw.payment.model.dto.LedgerUnitDto;
+import com.sckw.payment.model.dto.SettlementLogisticsDto;
+import com.sckw.payment.model.dto.SettlementTradeDto;
+import com.sckw.payment.model.dto.SettlementWalletDto;
 import com.sckw.payment.model.vo.req.OfflinePaymentReq;
 import com.sckw.payment.model.vo.req.SettlementWalletReq;
 import com.sckw.payment.model.vo.req.WalletPayReq;
@@ -626,6 +629,18 @@ public class KwpSettlementWalletService {
         return BigDecimal.valueOf(data.get(NumberConstant.ZERO).getMoney() / 100.0);
     }
 
-
+    /**
+     * 查询结算记录
+     * @param id 结算单id
+     * @param status 订单类型 1-物流 2-贸易
+     * @param payType 支付方式 1-预付款、2-货到付款
+     */
+    public List<SettlementWalletDto> queryList(Long id, int status,Integer payType) {
+        SettlementWalletReq settlementWalletReq = new SettlementWalletReq();
+        settlementWalletReq.setPayType(payType);
+        settlementWalletReq.setOrderType(status);
+        settlementWalletReq.setId(String.valueOf(id));
+        return settlementWalletMapper.pageList(settlementWalletReq);
+    }
 }
 

+ 37 - 0
sckw-modules/sckw-payment/src/main/resources/mapper/KwpSettlementTradeMapper.xml

@@ -83,6 +83,8 @@
                kst.success_user,
                kst.success_phone,
                kst.create_time,
+               kst.t_ledger_id,
+               klt.id                                             ledgerId,
                klt.name,
                klt.trading,
                kltu.firm_name                                     firmName,
@@ -207,6 +209,8 @@
                kst.success_user,
                kst.success_phone,
                kst.create_time,
+               kst.t_ledger_id,
+               klt.id                                             ledgerId,
                klt.name,
                klt.trading,
                kltu.firm_name
@@ -235,6 +239,7 @@
                kst.success_user,
                kst.success_phone,
                kst.create_time,
+               kst.t_ledger_id,
                klt.id                                             ledgerId,
                klt.name,
                klt.trading,
@@ -261,4 +266,36 @@
               and kst.id = #{id,jdbcType=BIGINT}
         </where>
     </select>
+
+    <select id="selectDetail" resultType="com.sckw.payment.model.dto.SettlementTradeDto">
+        select kst.id,
+               kst.status,
+               kst.st_order_no,
+               klt.t_ledger_no                                    tLedgerNo,
+               klt.id                                             tLedgerId,
+               kst.create_time,
+               kst.receipt_time,
+               cast(kst.actual_price as char)                     actualPrice,
+               cast(kst.total_price as char)                      totalPrice,
+               cast((kst.total_price - kst.actual_price) as char) waitPrice,
+               kst.audit_user,
+               kst.audit_phone,
+               kst.success_user,
+               kst.success_phone,
+               kst.create_time,
+               kst.t_ledger_id,
+               klt.id                                             ledgerId,
+               klt.name,
+               klt.trading,
+               kltu.firm_name                                     firmName,
+               kst.update_by                                      updateBy
+        from kwp_settlement_trade kst
+                 inner join kwp_ledger_trade klt on kst.t_ledger_id = klt.id and klt.del_flag = 0
+                 inner join kwp_ledger_trade_unit kltu on klt.id = kltu.t_ledger_id and kltu.del_flag = 0 and
+                                                          kltu.unit_type = #{unitTYpe,jdbcType=INTEGER}
+        <where>
+            kst.del_flag = 0
+              and kst.id = #{id,jdbcType=BIGINT}
+        </where>
+    </select>
 </mapper>