浏览代码

add close recharge job

Mr.qian 6 天之前
父节点
当前提交
1c2d8fb6f5

+ 5 - 2
cif-service/src/main/java/com/txz/cif/service/RechargeRecordService.java

@@ -1,4 +1,5 @@
 package com.txz.cif.service;
+
 import com.txz.cif.model.RechargeRecord;
 import com.txz.cif.core.Service;
 
@@ -7,8 +8,10 @@ import com.txz.cif.core.Service;
  * Created by CodeGenerator on 2025/07/15.
  */
 public interface RechargeRecordService extends Service<RechargeRecord> {
-
+    
     void success(RechargeRecord record);
-
+    
     void fail(RechargeRecord record);
+    
+    void closeRecharge();
 }

+ 40 - 13
cif-service/src/main/java/com/txz/cif/service/impl/RechargeRecordServiceImpl.java

@@ -1,17 +1,22 @@
 package com.txz.cif.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
+import com.txz.cif.core.AbstractService;
 import com.txz.cif.dao.RechargeRecordMapper;
 import com.txz.cif.model.RechargeRecord;
 import com.txz.cif.param.RechargeParam;
 import com.txz.cif.service.AccountService;
 import com.txz.cif.service.FlowService;
 import com.txz.cif.service.RechargeRecordService;
-import com.txz.cif.core.AbstractService;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import tk.mybatis.mapper.entity.Condition;
+import tk.mybatis.mapper.entity.Example;
 
 import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
 
 
 /**
@@ -22,12 +27,13 @@ import javax.annotation.Resource;
 public class RechargeRecordServiceImpl extends AbstractService<RechargeRecord> implements RechargeRecordService {
     @Resource
     private RechargeRecordMapper cRechargeRecordMapper;
-
+    
     @Resource
     private FlowService flowService;
-
+    
     @Resource
     private AccountService accountService;
+    
     @Override
     public void success(RechargeRecord record) {
         update(RechargeRecord.builder()
@@ -35,20 +41,41 @@ public class RechargeRecordServiceImpl extends AbstractService<RechargeRecord> i
                 .successTime(DateUtil.date())
                 .status(2)
                 .build());
-//        accountService.
+        //        accountService.
         flowService.recharge(RechargeParam.builder()
-                        .amount(record.getRealAmount())
-                        .bizNo(record.getOrderNo())
-                        .bizId(record.getId()+"")
-                        .userId(record.getUserId())
-                        .bizType(1001)
-                        .discount(record.getDiscount())
-                        .transTime(record.getTransTime())
+                .amount(record.getRealAmount())
+                .bizNo(record.getOrderNo())
+                .bizId(record.getId() + "")
+                .userId(record.getUserId())
+                .bizType(1001)
+                .discount(record.getDiscount())
+                .transTime(record.getTransTime())
                 .build());
     }
-
+    
     @Override
     public void fail(RechargeRecord record) {
-        update(RechargeRecord.builder() .id(record.getId()) .status(3).build());
+        update(RechargeRecord.builder().id(record.getId()).status(3).build());
+    }
+    
+    @Override
+    public void closeRecharge() {
+        Date thirtyMinutesAgo = DateUtil.offsetMinute(new Date(), -30);
+        Condition condition = new Condition(RechargeRecord.class);
+        Example.Criteria criteria = condition.createCriteria();
+        criteria.andEqualTo("status", 1);
+        criteria.andLessThan("createTime", thirtyMinutesAgo);
+        
+        List<RechargeRecord> processingRecords = this.findByCondition(condition);
+        if (CollectionUtil.isEmpty(processingRecords)) {
+            return;
+        }
+        for (RechargeRecord record : processingRecords) {
+            update(RechargeRecord.builder()
+                    .id(record.getId())
+                    .status(4)
+                    .updateTime(new Date())
+                    .build());
+        }
     }
 }

+ 70 - 59
cif-service/src/main/java/com/txz/cif/task/GeneralJob.java

@@ -2,15 +2,12 @@ package com.txz.cif.task;
 
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
-import cn.hutool.http.HttpUtil;
-import cn.hutool.json.JSONObject;
-import cn.hutool.json.JSONUtil;
+import com.txz.cif.configurer.Parameters;
 import com.txz.cif.dubbo.client.OrderDubboServiceClient;
 import com.txz.cif.service.DayCutService;
-import com.txz.cif.configurer.Parameters;
+import com.txz.cif.service.RechargeRecordService;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
-import org.apache.commons.codec.binary.Hex;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -21,7 +18,7 @@ import java.util.Map;
 
 /**
  * 常规job
- *
+ * <p>
  * 开发步骤:
  * 1、在Spring Bean实例中,开发Job方法,方式格式要求为 "public ReturnT<String> execute(String param)"
  * 2、为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")",注解value值对应的是调度中心新建任务的JobHandler属性的值。
@@ -32,17 +29,20 @@ import java.util.Map;
 @Component
 public class GeneralJob {
     private static Logger logger = LoggerFactory.getLogger(GeneralJob.class);
-
+    
     @Resource
     private DayCutService dayCutService;
-
-
+    
+    
     @Resource
     private OrderDubboServiceClient orderDubboServiceClient;
-
+    
     @Resource
     private Parameters parameters;
-
+    
+    @Resource
+    private RechargeRecordService rechargeRecordService;
+    
     /**
      * 日切
      */
@@ -58,36 +58,34 @@ public class GeneralJob {
         }
         return ReturnT.SUCCESS;
     }
-
+    
     @XxlJob("checkin")
     public ReturnT<String> checkin(String param) throws Exception {
-        Map<String,Object> map = new HashMap<>();
-        map.put("email","351550660@qq.com");
-        map.put("passwd","Lin123456");
+        Map<String, Object> map = new HashMap<>();
+        map.put("email", "351550660@qq.com");
+        map.put("passwd", "Lin123456");
         HttpResponse resp = HttpRequest.post("https://chynet01.azureedge.net/auth/login").form(map).timeout(-1).execute();
         String key = resp.getCookie("key").toString();
         String expire_in = resp.getCookie("expire_in").toString();
-        String cookie = "cookie:PHPSESSID=fun75tna6st563e78799552e69; cnxad_lunbo=yes; crisp-client%2Fsession%2F7850791f-bbe4-4874-9f05-c9dea3c63595=session_8a49d3eb-e9c7-43f8-9fe9-12d1560a4122; crisp-client%2Fsession%2F7850791f-bbe4-4874-9f05-c9dea3c63595%2Fc89170bf-a23d-3152-9ad4-fda9810011f7=session_8a49d3eb-e9c7-43f8-9fe9-12d1560a4122; uid=14105; email=351550660%40qq.com; ip=5f0f60145ce69c8054af6bb0a24e9c1a;"+key+"; "+expire_in;
+        String cookie = "cookie:PHPSESSID=fun75tna6st563e78799552e69; cnxad_lunbo=yes; crisp-client%2Fsession%2F7850791f-bbe4-4874-9f05-c9dea3c63595=session_8a49d3eb-e9c7-43f8-9fe9-12d1560a4122; crisp-client%2Fsession%2F7850791f-bbe4-4874-9f05-c9dea3c63595%2Fc89170bf-a23d-3152-9ad4-fda9810011f7=session_8a49d3eb-e9c7-43f8-9fe9-12d1560a4122; uid=14105; email=351550660%40qq.com; ip=5f0f60145ce69c8054af6bb0a24e9c1a;" + key + "; " + expire_in;
         String ret = HttpRequest.post("https://chynet01.azureedge.net/user/checkin").cookie(cookie).timeout(-1).execute().body();
-        logger.error("[checkin]:"+ret);
-
-
-
-//        JSONObject json = new JSONObject();
-//        json.put("username","linxinkai");
-//        json.put("password","Lin123456");
-//        String ret2 = HttpUtil.post("https://c4.a0.chat/v1/user/login/",json.toString());
-//        String token = JSONUtil.parseObj(ret2).getJSONObject("data").getStr("token");
-//        json = new JSONObject();
-//        json.put("action","sign_today");
-//        ret = HttpRequest.post("https://c4.a0.chat/v1/user/info/").body(json.toString()).header("Authorization",token).timeout(-1).execute().body();
-//        logger.error("[checkin]:"+ret);
-
+        logger.error("[checkin]:" + ret);
+        
+        
+        //        JSONObject json = new JSONObject();
+        //        json.put("username","linxinkai");
+        //        json.put("password","Lin123456");
+        //        String ret2 = HttpUtil.post("https://c4.a0.chat/v1/user/login/",json.toString());
+        //        String token = JSONUtil.parseObj(ret2).getJSONObject("data").getStr("token");
+        //        json = new JSONObject();
+        //        json.put("action","sign_today");
+        //        ret = HttpRequest.post("https://c4.a0.chat/v1/user/info/").body(json.toString()).header("Authorization",token).timeout(-1).execute().body();
+        //        logger.error("[checkin]:"+ret);
+        
         return ReturnT.SUCCESS;
     }
-
-
-
+    
+    
     @XxlJob("scheduledTaskStorePinkSummaryClose")
     public ReturnT<String> scheduledTaskStorePinkSummaryClose(String param) throws Exception {
         try {
@@ -100,8 +98,8 @@ public class GeneralJob {
         }
         return ReturnT.SUCCESS;
     }
-
-
+    
+    
     @XxlJob("scheduledTaskBatchSigning")
     public ReturnT<String> scheduledTaskBatchSigning(String param) throws Exception {
         try {
@@ -114,7 +112,7 @@ public class GeneralJob {
         }
         return ReturnT.SUCCESS;
     }
-
+    
     @XxlJob("orderTimeoutAutomaticCancel")
     public ReturnT<String> orderTimeoutAutomaticCancel(String param) throws Exception {
         try {
@@ -127,33 +125,46 @@ public class GeneralJob {
         }
         return ReturnT.SUCCESS;
     }
-
+    
+    @XxlJob("closeRecharge")
+    public ReturnT<String> closeRecharge() throws Exception {
+        try {
+            logger.info("【关闭支付订单】开始");
+            rechargeRecordService.closeRecharge();
+            logger.info("【关闭支付订单】完成");
+        } catch (Exception e) {
+            logger.error("【关闭支付订单】异常:e{}", e);
+            return ReturnT.FAIL;
+        }
+        return ReturnT.SUCCESS;
+    }
+    
     public static void main(String[] args) {
-//        int quhao = 154;
-//        int weihao = 9642;
-//        String a = Hex.encodeHexString( new byte[] {(byte)((quhao>>8)&0x00FF),(byte)(quhao&0x00FF),(byte)((weihao>>8)&0x00FF),(byte)(weihao&0x00FF)});
-//        System.out.println(a);
-//
-//        String b = Hex.encodeHexString( new byte[] {(byte)((quhao>>8)&0x00FF),(byte)(quhao&0x00FF)});
-//        System.out.println(b);
-//        String hex = "009a25aa";
-//        int decimal = Integer.parseInt(hex, 16);
-//        System.out.println(decimal); // 输出:2571
-//        String str = String.format("%09d", decimal);
-//        System.out.println(str); // 输出:2571
-//        System.out.println(str.substring(0,6)); // 输出:2571
-//        System.out.println(str.substring(6)); // 输出:2571
-
-        Map<String,Object> map = new HashMap<>();
-        map.put("email","351550660@qq.com");
-        map.put("passwd","Lin123456");
+        //        int quhao = 154;
+        //        int weihao = 9642;
+        //        String a = Hex.encodeHexString( new byte[] {(byte)((quhao>>8)&0x00FF),(byte)(quhao&0x00FF),(byte)((weihao>>8)&0x00FF),(byte)(weihao&0x00FF)});
+        //        System.out.println(a);
+        //
+        //        String b = Hex.encodeHexString( new byte[] {(byte)((quhao>>8)&0x00FF),(byte)(quhao&0x00FF)});
+        //        System.out.println(b);
+        //        String hex = "009a25aa";
+        //        int decimal = Integer.parseInt(hex, 16);
+        //        System.out.println(decimal); // 输出:2571
+        //        String str = String.format("%09d", decimal);
+        //        System.out.println(str); // 输出:2571
+        //        System.out.println(str.substring(0,6)); // 输出:2571
+        //        System.out.println(str.substring(6)); // 输出:2571
+        
+        Map<String, Object> map = new HashMap<>();
+        map.put("email", "351550660@qq.com");
+        map.put("passwd", "Lin123456");
         HttpResponse resp = HttpRequest.post("https://chynet01.azureedge.net/auth/login").form(map).timeout(-1).execute();
         String key = resp.getCookie("key").toString();
         String expire_in = resp.getCookie("expire_in").toString();
-        String cookie = "cookie:PHPSESSID=fun75tna6st563e78799552e69; cnxad_lunbo=yes; crisp-client%2Fsession%2F7850791f-bbe4-4874-9f05-c9dea3c63595=session_8a49d3eb-e9c7-43f8-9fe9-12d1560a4122; crisp-client%2Fsession%2F7850791f-bbe4-4874-9f05-c9dea3c63595%2Fc89170bf-a23d-3152-9ad4-fda9810011f7=session_8a49d3eb-e9c7-43f8-9fe9-12d1560a4122; uid=14105; email=351550660%40qq.com; ip=5f0f60145ce69c8054af6bb0a24e9c1a;"+key+"; "+expire_in;
+        String cookie = "cookie:PHPSESSID=fun75tna6st563e78799552e69; cnxad_lunbo=yes; crisp-client%2Fsession%2F7850791f-bbe4-4874-9f05-c9dea3c63595=session_8a49d3eb-e9c7-43f8-9fe9-12d1560a4122; crisp-client%2Fsession%2F7850791f-bbe4-4874-9f05-c9dea3c63595%2Fc89170bf-a23d-3152-9ad4-fda9810011f7=session_8a49d3eb-e9c7-43f8-9fe9-12d1560a4122; uid=14105; email=351550660%40qq.com; ip=5f0f60145ce69c8054af6bb0a24e9c1a;" + key + "; " + expire_in;
         String ret = HttpRequest.post("https://chynet01.azureedge.net/user/checkin").cookie(cookie).timeout(-1).execute().body();
-        logger.error("[checkin]:"+ret);
+        logger.error("[checkin]:" + ret);
     }
-
-
+    
+    
 }