guyue
2025-08-01 0f79643e35af90cb63a4b3c67ee72abfe0e37770
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.stylefeng.guns.modular.system.util;
 
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.account.controller.AppOrderController;
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.IUserCouponRecordService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.service.IUserMerchantCouponService;
import com.stylefeng.guns.modular.system.util.qianyuntong.OrderUtil;
import com.stylefeng.guns.modular.system.util.qianyuntong.SMSUtil;
import com.stylefeng.guns.modular.system.util.qianyuntong.model.*;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
/**
 * 定时任务工具类
 */
@Slf4j
@Component
public class TaskUtil {
    
    @Autowired
    private IUserCouponRecordService userCouponRecordService;
    
    @Autowired
    private IUserMerchantCouponService userMerchantCouponService;
    
    @Autowired
    private AppOrderController appOrderController;
    
    @Autowired
    private IOrderPrivateCarService orderPrivateCarService;
    
    
    @Autowired
    private IOrderCrossCityService orderCrossCityService;
    
    @Autowired
    private IOrderLogisticsService orderLogisticsService;
    
    @Autowired
    private IOrderTaxiService orderTaxiService;
    
    @Autowired
    private ChinaMobileUtil chinaMobileUtil;
    
    @Autowired
    private IUserInfoService userInfoService;
    
    
    /**
     * 每隔一分钟去处理的定时任务
     */
    @Scheduled(fixedRate = 1000 * 60)
    public void taskMinute() {
        try {
            //修改过期的优惠券
            userCouponRecordService.updateTimeOut();
            //修改过期的商家优惠券
            userMerchantCouponService.updateExpired();
            //处理超时未支付的订单
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
    /**
     * 每天的凌晨执行的任务
     */
    @Scheduled(fixedRate = 1000 * 60)
    public void taskDay() {
    }
    
    
    /**
     * 每天中午12点发送提醒短信
     */
    @Scheduled(cron = "0 0 12 * * ?")
    public void taskMonth() {
        try {
            List<OrderPrivateCar> orderPrivateCars = orderPrivateCarService.selectList(new EntityWrapper<OrderPrivateCar>().eq("isDelete", 1)
                    .eq("state", 7).eq("abnormal", 1)
                    .last(" and now() > DATE_ADD(endServiceTime, INTERVAL 24 HOUR)"));
            for (OrderPrivateCar orderPrivateCar : orderPrivateCars) {
                UserInfo userInfo = userInfoService.selectById(orderPrivateCar.getUserId());
                SendSmsRequest request = new SendSmsRequest();
                request.setDestAddress(userInfo.getPhone());
                request.setTemplateId("TPL202507300002");
                Map<String, String> templateParams = new HashMap<>();
                request.setTemplateParams(templateParams);
                request.setSpId("Y86asr7J");
                SMSUtil.sendSms(request);
            }
            List<OrderTaxi> orderTaxis = orderTaxiService.selectList(new EntityWrapper<OrderTaxi>().eq("isDelete", 1)
                    .eq("state", 7).eq("abnormal", 1)
                    .last(" and now() > DATE_ADD(endServiceTime, INTERVAL 24 HOUR)"));
            for (OrderTaxi orderTaxi : orderTaxis) {
                UserInfo userInfo = userInfoService.selectById(orderTaxi.getUserId());
                SendSmsRequest request = new SendSmsRequest();
                request.setDestAddress(userInfo.getPhone());
                request.setTemplateId("TPL202507300002");
                Map<String, String> templateParams = new HashMap<>();
                request.setTemplateParams(templateParams);
                request.setSpId("Y86asr7J");
                SMSUtil.sendSms(request);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
    /**
     * 大于24小时未支付的订单
     */
    public void timoutNoPayment() {
        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarService.selectList(new EntityWrapper<OrderPrivateCar>().eq("state", 7)
                .eq("isDelete", 1).eq("recoveryOrder", 0).last(" and now() >= DATE_ADD(insertTime, INTERVAL 24 HOUR)"));
        for (OrderPrivateCar orderPrivateCar : orderPrivateCars) {
            //使用备付金进行支付订单
            TradePayOffData tradePayOffData = new TradePayOffData();
            tradePayOffData.setPartnerPayId("PR" + orderPrivateCar.getId());
            tradePayOffData.setTotalFee(Double.valueOf(orderPrivateCar.getOrderMoney() * 100).intValue() + "");
            tradePayOffData.setOrderDesc("完成订单");
            PayInfo payInfo = OrderUtil.tradePayOff(tradePayOffData);
            String retCode = payInfo.getRetCode();
            if(!"000000".equals(retCode)){
                log.error("备付金支付失败:{}", payInfo.getRetMsg());
                continue;
            }
            PayInfoData data = payInfo.getData();
            String status = data.getStatus();
            if("3".equals(status)){
                log.error("备付金支付失败:{}", payInfo.getRetMsg());
                continue;
            }
            //copy原始订单后生成追缴单
            OrderPrivateCar orderPrivateCar1 = new OrderPrivateCar();
            BeanUtils.copyProperties(orderPrivateCar, orderPrivateCar1);
            orderPrivateCar1.setId(null);
            orderPrivateCar1.setRecoveryOrder(1);
            
            //修改原始订单为支付状态
            orderPrivateCar.setState(8);
            orderPrivateCar.setPayType(5);
            orderPrivateCar.setPayMoney(orderPrivateCar.getOrderMoney());
            orderPrivateCarService.updateById(orderPrivateCar);
            orderPrivateCarService.insert(orderPrivateCar1);
        }
    }
}