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

新增钱包接口相关参数实体

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

+ 18 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/model/page/PageRes.java

@@ -89,6 +89,24 @@ public class PageRes<T> {
         return tPageRes;
     }
 
+    /**
+     * 手动对list进行分页数据处理
+     *
+     * @param page     当前页
+     * @param pageSize 每页大小
+     * @param list     总数据
+     * @return
+     */
+    public static <T> PageRes<T> handPage(int page, int pageSize, List<T> list) {
+        PageRes<T> tPageRes = new PageRes<>();
+        tPageRes.setPage(page);
+        tPageRes.setPageSize(pageSize);
+        tPageRes.setSize(list.size());
+        tPageRes.setPages(list.size() / pageSize);
+        tPageRes.setList(list.stream().skip((long) (page - 1) * pageSize).limit(pageSize).toList());
+        return tPageRes;
+    }
+
     public void setPage(int page) {
         this.page = page;
     }

+ 1 - 2
sckw-common/sckw-common-core/src/main/java/com/sckw/core/model/vo/BasePara.java

@@ -1,6 +1,5 @@
 package com.sckw.core.model.vo;
 
-import com.sckw.core.model.base.IdsList;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -13,7 +12,7 @@ import java.io.Serializable;
  */
 @Getter
 @Setter
-public class BasePara implements IdsList, Serializable {
+public class BasePara implements Serializable {
     @Serial
     private static final long serialVersionUID = 1881051859375157819L;
     /**

+ 4 - 0
sckw-common/sckw-common-redis/src/main/java/com/sckw/redis/constant/RedisConstant.java

@@ -70,5 +70,9 @@ public class RedisConstant {
      * 结算单锁
      */
     public static final String SETTLEMENT_KEY = "sckw:kst:%s";
+    /**
+     * 钱包企业关联关系
+     */
+    public static final String WALLET = "wallet:uid";
 
 }

+ 29 - 0
sckw-modules-api/sckw-payment-api/src/main/java/com/sckw/payment/api/model/constant/ChannelEnum.java

@@ -31,4 +31,33 @@ public enum ChannelEnum {
         return null;
     }
 
+    /**
+     * 通过渠道获取描述
+     *
+     * @param channel 渠道
+     * @return 渠道名称
+     */
+    public static String getDesc(String channel) {
+        for (ChannelEnum channelEnum : ChannelEnum.values()) {
+            if (channelEnum.getChannel().equals(channel)) {
+                return channelEnum.getDesc();
+            }
+        }
+        return "";
+    }
+
+    /**
+     * 通过字典值获取
+     *
+     * @param value
+     * @return
+     */
+    public static ChannelEnum getByValue(String value) {
+        for (ChannelEnum channelEnum : ChannelEnum.values()) {
+            if (channelEnum.getValue().equals(value)) {
+                return channelEnum;
+            }
+        }
+        return null;
+    }
 }

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

@@ -35,6 +35,7 @@ public class WalletDto implements Serializable {
     private String filter;
     /**
      * 冻结金额(分)
+     * note:冻结金额为预付金额
      */
     private Long freeze;
     /**

+ 4 - 3
sckw-modules-api/sckw-payment-api/src/main/java/com/sckw/payment/api/model/dto/WalletInfo.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.annotation.JSONField;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 
 /**
  * 钱包清单
@@ -31,14 +32,14 @@ public class WalletInfo implements Serializable {
      * 预付金额(分)
      */
     @JSONField(name = "ap_money")
-    private Long apMoney;
+    private BigDecimal apMoney;
     /**
      * 提现余额
      */
     @JSONField(name = "wd_money")
-    private Long wdMoney;
+    private BigDecimal wdMoney;
     /**
      * 可用余额
      */
-    private Long money;
+    private BigDecimal money;
 }

+ 1 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/KwpSettlementTrade.java

@@ -52,7 +52,7 @@ public class KwpSettlementTrade {
     private String name;
 
     /**
-     * 总应收/元
+     * 对账金额(对账单表的实际结算金额字段settle_price)
      */
     @TableField(value = "total_price")
     private BigDecimal totalPrice;

+ 1 - 3
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/model/KwpWalletRelation.java

@@ -9,12 +9,10 @@ import lombok.Data;
 import java.util.Date;
 
 /**
+ * 企业与中台用户关系表
 * @date 2023-07-24 10:47:47
 * @author xucaiqin
 */
-/**
-    * 企业与中台用户关系表
-    */
 @Data
 @TableName(value = "kwp_wallet_relation")
 public class KwpWalletRelation {

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

@@ -48,7 +48,7 @@ public class KwpSettlementTradeService {
     private RemoteSystemService remoteSystemService;
     private final KwpLedgerTradeUnitService tradeUnitService;
     @Resource
-    private KwpSettlementWalletService walletService;
+    private KwpSettlementWalletService settlementWalletService;
 
 
     /**
@@ -267,7 +267,7 @@ public class KwpSettlementTradeService {
             settlementTradeDto.setTradingLabel(sysDictResDto.getLabel());
         }
         settlementTradeDto.setStatusLabel(SettlementEnum.getStatusDesc(settlementTradeDto.getStatus()));
-        List<SettlementWalletDto> settlementWallet = walletService.queryList(id, SettlementOrderTypeEnum.TRADE.getStatus(), TradingEnum.getPrefix(trading));
+        List<SettlementWalletDto> settlementWallet = settlementWalletService.queryList(id, SettlementOrderTypeEnum.TRADE.getStatus(), TradingEnum.getPrefix(trading));
         return new SettlementDetailDto<>(settlementTradeDto, settlementWallet);
     }
 }

+ 41 - 6
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpWalletRelationService.java

@@ -1,12 +1,20 @@
 package com.sckw.payment.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.sckw.core.common.enums.NumberConstant;
+import com.sckw.core.utils.IdWorker;
+import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.payment.dao.KwpWalletRelationMapper;
 import com.sckw.payment.model.KwpWalletRelation;
-import jakarta.annotation.Resource;
+import com.sckw.payment.model.dto.WalletRelationDto;
+import com.sckw.redis.constant.RedisConstant;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
 import java.util.Objects;
 
 /**
@@ -15,9 +23,10 @@ import java.util.Objects;
  */
 @Service
 @Slf4j
+@RequiredArgsConstructor
 public class KwpWalletRelationService {
-    @Resource
-    private KwpWalletRelationMapper relationMapper;
+    private final KwpWalletRelationMapper relationMapper;
+    private final RedisTemplate<String, Object> redisTemplate;
 
     /**
      * 根据企业id查询中台用户
@@ -29,12 +38,38 @@ public class KwpWalletRelationService {
         if (Objects.isNull(entId)) {
             return null;
         }
-
-        KwpWalletRelation kwpWalletRelation = relationMapper.selectOne(new LambdaQueryWrapper<KwpWalletRelation>().eq(KwpWalletRelation::getEntId, entId).eq(KwpWalletRelation::getDelFlag, 0).last("limit 1"));
+        String uid = (String) redisTemplate.opsForHash().get(RedisConstant.WALLET, String.valueOf(entId));
+        if (StringUtils.isNotBlank(uid)) {
+            return uid;
+        }
+        KwpWalletRelation kwpWalletRelation = relationMapper.selectOne(new LambdaQueryWrapper<KwpWalletRelation>()
+                .eq(KwpWalletRelation::getEntId, entId)
+                .eq(KwpWalletRelation::getDelFlag, 0).last("limit 1"));
         if (Objects.isNull(kwpWalletRelation)) {
             return null;
         }
-        return kwpWalletRelation.getUid();
+        uid = kwpWalletRelation.getUid();
+        redisTemplate.opsForHash().put(RedisConstant.WALLET, String.valueOf(entId), uid);
+        return uid;
+    }
+
+    /**
+     * 保存关联信息
+     *
+     * @param walletRelationDto 企业关联钱包信息
+     */
+    public void save(WalletRelationDto walletRelationDto) {
+        KwpWalletRelation kwpWalletRelation = new KwpWalletRelation();
+        kwpWalletRelation.setId(new IdWorker(NumberConstant.ONE).nextId());
+        kwpWalletRelation.setEntId(walletRelationDto.entId());
+        kwpWalletRelation.setUid(walletRelationDto.uid());
+        kwpWalletRelation.setStatus(0);
+        kwpWalletRelation.setCreateBy(LoginUserHolder.getUserId());
+        kwpWalletRelation.setCreateTime(new Date());
+        kwpWalletRelation.setUpdateBy(LoginUserHolder.getUserId());
+        kwpWalletRelation.setUpdateTime(new Date());
+        kwpWalletRelation.setDelFlag(0);
+        relationMapper.insert(kwpWalletRelation);
     }
 
 

+ 8 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/PayCenterService.java

@@ -173,7 +173,7 @@ public class PayCenterService {
         }
         String sync = getHttp(PayCenterEnum.MEMBER_WALLET, new HashMap<>() {{
             put("uid", uid);
-            put("channel", channel);
+            put("channel", Objects.isNull(channel) ? "" : channel);
             put("filter", filter);
         }});
         return parseArray(sync, WalletDto.class);
@@ -443,6 +443,8 @@ public class PayCenterService {
 
     /**
      * 余额转出
+     * 中台逻辑:
+     * 从uid的money到filter的money,通过清分接口实现。
      *
      * @param uid
      * @param channel
@@ -596,6 +598,9 @@ public class PayCenterService {
 
     /**
      * 冻结资金
+     * 中台逻辑:
+     * 先判断预付金额是否足够,足够就冻结预付金额。
+     * 不够则进行追加预付操作,在进行冻结
      *
      * @param uid        付款方uid
      * @param channel    支付通道
@@ -632,6 +637,8 @@ public class PayCenterService {
 
     /**
      * 清分
+     * 中台逻辑:
+     * 先从预付金额中进行扣除,然后金额不够的情况下在调用三方接口进行清分,然后进行记账
      *
      * @param buyUid
      * @param sellUid