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

转账中金额,定时任务维护

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

+ 13 - 3
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/dao/KwpWalletTransferMapper.java

@@ -3,16 +3,26 @@ package com.sckw.payment.dao;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sckw.payment.model.KwpWalletTransfer;
 import com.sckw.payment.model.vo.req.page.MoneyPage;
+import com.sckw.payment.model.vo.res.FundVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
-* @date 2023-09-06 16:42:08
-* @author xucaiqin
-*/
+ * @author xucaiqin
+ * @date 2023-09-06 16:42:08
+ */
 @Mapper
 public interface KwpWalletTransferMapper extends BaseMapper<KwpWalletTransfer> {
     List<KwpWalletTransfer> pageList(@Param("moneyPage") MoneyPage moneyPage);
+
+    /**
+     * 统计转账中金额
+     *
+     * @param fundVo
+     * @return
+     */
+    BigDecimal sumMoney(@Param("fundVo")FundVo fundVo);
 }

+ 6 - 9
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/WalletService.java

@@ -1,7 +1,6 @@
 package com.sckw.payment.service;
 
 import com.alibaba.fastjson2.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.sckw.core.common.enums.NumberConstant;
@@ -237,16 +236,14 @@ public class WalletService {
         }
     }
 
+    /**
+     * 计算转账中金额
+     * @param fundVo
+     */
     private void transferMoney(FundVo fundVo) {
         DecimalFormat df = new DecimalFormat("0.00");
-        LambdaQueryWrapper<KwpWalletTransfer> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(KwpWalletTransfer::getUid, fundVo.getUid()).eq(KwpWalletTransfer::getFilter, fundVo.getFilter()).eq(KwpWalletTransfer::getChannel, fundVo.getChannel()).eq(KwpWalletTransfer::getStatus, TransferEnum.TRANSFERRING.getStatus()).last("limit 1");
-        KwpWalletTransfer kwpWalletTransfer = kwpWalletTransferMapper.selectOne(wrapper);
-        if (Objects.nonNull(kwpWalletTransfer)) {
-            fundVo.setTransferMoney(df.format(kwpWalletTransfer.getMoney()));
-        } else {
-            fundVo.setTransferMoney("0.00");
-        }
+        BigDecimal bigDecimal = kwpWalletTransferMapper.sumMoney(fundVo);
+        fundVo.setTransferMoney(df.format(bigDecimal));
     }
 
     /**

+ 35 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/task/RefundTask.java

@@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.sckw.payment.api.model.constant.ChannelEnum;
 import com.sckw.payment.api.model.dto.common.R;
 import com.sckw.payment.dao.KwpWalletRefundMapper;
+import com.sckw.payment.dao.KwpWalletTransferMapper;
 import com.sckw.payment.model.KwpWalletRefund;
+import com.sckw.payment.model.KwpWalletTransfer;
 import com.sckw.payment.model.constant.RefundEnum;
+import com.sckw.payment.model.constant.TransferEnum;
 import com.sckw.payment.model.dto.wallet.SplitDto;
 import com.sckw.payment.service.PayCenterService;
 import jakarta.annotation.Resource;
@@ -30,6 +33,8 @@ public class RefundTask {
     private PayCenterService payCenterService;
     @Resource
     private KwpWalletRefundMapper kwpWalletRefundMapper;
+    @Resource
+    private KwpWalletTransferMapper kwpWalletTransferMapper;
 
     @Scheduled(cron = "0 0/1 * * * ? ")
     public void task() {
@@ -37,7 +42,7 @@ public class RefundTask {
         wrapper.eq(KwpWalletRefund::getStatus, RefundEnum.REFUNDING.getStatus());
         List<KwpWalletRefund> kwpWalletRefunds = kwpWalletRefundMapper.selectList(wrapper);
         if (CollectionUtils.isEmpty(kwpWalletRefunds)) {
-//            log.warn("无数据");
+            log.warn("退款定时任务无数据");
             return;
         }
         try {
@@ -59,4 +64,33 @@ public class RefundTask {
             log.error("定时任务异常:{}", ex, ex);
         }
     }
+
+    @Scheduled(cron = "0 0/1 * * * ? ")
+    public void transferTask() {
+        LambdaQueryWrapper<KwpWalletTransfer> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(KwpWalletTransfer::getStatus, TransferEnum.TRANSFERRING.getStatus());
+        List<KwpWalletTransfer> kwpWalletTransferList = kwpWalletTransferMapper.selectList(wrapper);
+        if (CollectionUtils.isEmpty(kwpWalletTransferList)) {
+            log.warn("转账定时任务无数据");
+            return;
+        }
+        try {
+            for (KwpWalletTransfer kwpWalletTransfer : kwpWalletTransferList) {
+                //查询清分状态,修改退款单状态
+                R<List<SplitDto>> listR = payCenterService.agentPayQuery(kwpWalletTransfer.getUid(), ChannelEnum.getByChannel(kwpWalletTransfer.getChannel()), kwpWalletTransfer.getOrderNo());
+                if (listR.getStatus()) {
+                    List<SplitDto> data = listR.getData();
+                    if (!CollectionUtils.isEmpty(data)) {
+                        if (data.stream().allMatch(a -> a.getStatus() == 1)) {
+                            kwpWalletTransfer.setUpdateTime(LocalDateTime.now());
+                            kwpWalletTransfer.setStatus(TransferEnum.SUCCESS.getStatus());
+                            kwpWalletTransferMapper.updateById(kwpWalletTransfer);
+                        }
+                    }
+                }
+            }
+        } catch (Exception ex) {
+            log.error("转账定时任务异常:{}", ex, ex);
+        }
+    }
 }

+ 17 - 0
sckw-modules/sckw-payment/src/main/resources/mapper/KwpWalletTransferMapper.xml

@@ -55,4 +55,21 @@
             </if>
         </where>
     </select>
+    <select id="sumMoney" resultType="java.math.BigDecimal">
+        select sum(kwt.money)
+        from kwp_wallet_transfer kwt
+        <where>
+            kwt.del_flag = 0
+              and kwt.status = 2
+            <if test="fundVo.channel != null and fundVo.channel != ''">
+                and kwt.channel = #{fundVo.channel,jdbcType=VARCHAR}
+            </if>
+            <if test="fundVo.uid != null and fundVo.uid != ''">
+                and kwt.uid = #{fundVo.uid,jdbcType=VARCHAR}
+            </if>
+            <if test="fundVo.filter != null and fundVo.filter != ''">
+                and kwt.filter = #{fundVo.filter,jdbcType=VARCHAR}
+            </if>
+        </where>
+    </select>
 </mapper>