Forráskód Böngészése

钱包退款定时任务

xucaiqin 2 éve
szülő
commit
9b5c3c8e76

+ 0 - 3
sckw-common/sckw-common-log/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@@ -1,3 +0,0 @@
-com.sckw.log.aspect.LogInfoAspect
-com.sckw.log.interceptor.LogInterceptor
-com.sckw.log.config.WebConfig

+ 33 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/job/AsyncPool.java

@@ -0,0 +1,33 @@
+package com.sckw.payment.job;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author xucaiqin
+ * @date 2023-09-05 20:13:57
+ */
+public class AsyncPool {
+
+    private AsyncPool() {
+    }
+
+    /**
+     * 提交任务
+     *
+     * @param runnable
+     */
+    public static void addTask(Runnable runnable) {
+        ThreadPool.threadPoolExecutor.execute(runnable);
+    }
+
+    private static class ThreadPool {
+        public static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1,
+                1,
+                1,
+                TimeUnit.MINUTES,
+                new LinkedBlockingQueue<>(12));
+
+    }
+}

+ 67 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/task/RefundTask.java

@@ -0,0 +1,67 @@
+package com.sckw.payment.task;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.sckw.payment.model.dto.wallet.PatchPay;
+import com.sckw.payment.dao.KwpWalletRefundMapper;
+import com.sckw.payment.model.KwpWalletRefund;
+import com.sckw.payment.model.constant.RefundEnum;
+import com.sckw.payment.service.PayCenterService;
+import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author xucaiqin
+ * @date 2023-09-05 19:37:00
+ */
+@Slf4j
+@Component
+@EnableScheduling
+public class RefundTask {
+    @Resource
+    private PayCenterService payCenterService;
+    @Resource
+    private KwpWalletRefundMapper kwpWalletRefundMapper;
+
+
+    @Scheduled(cron = "0 0/1 * * * ? ")
+    public void task() {
+        LambdaQueryWrapper<KwpWalletRefund> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(KwpWalletRefund::getStatus, RefundEnum.REFUNDING.getStatus());
+        List<KwpWalletRefund> kwpWalletRefunds = kwpWalletRefundMapper.selectList(wrapper);
+        if (CollectionUtils.isEmpty(kwpWalletRefunds)) {
+            log.warn("无数据");
+            return;
+        }
+        List<PatchPay> list;
+        try {
+            for (KwpWalletRefund kwpWalletRefund : kwpWalletRefunds) {
+                list = new ArrayList<>();
+                PatchPay patchPay = new PatchPay();
+                patchPay.setUid(kwpWalletRefund.getFilter());
+                patchPay.setMoney(bigMoney(kwpWalletRefund.getActualMoney()));
+                patchPay.setRemark(kwpWalletRefund.getRemark());
+                list.add(patchPay);
+                //查询清分状态,修改退款单状态 todo-xcq
+            }
+        } catch (Exception ex) {
+            log.error("定时任务异常:{}", ex, ex);
+        }
+    }
+
+    private Long bigMoney(BigDecimal big) {
+        if (Objects.isNull(big)) {
+            return 0L;
+        }
+        BigDecimal divide = big.multiply(new BigDecimal("100"));
+        return divide.longValueExact();
+    }
+}