zhibing.pu
2024-04-19 2e366b939271b6ea338641f8a72d1bcd2182dbe7
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
package com.stylefeng.guns.modular.system.util.quartz.jobs;
 
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
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.util.PushUtil;
import com.stylefeng.guns.modular.system.util.quartz.QuartzUtil;
import com.stylefeng.guns.modular.system.util.quartz.model.QuartzJob;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobKey;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 * 订单司机超时提醒任务
 * @author zhibing.pu
 * @Date 2024/4/18 15:19
 */
@Slf4j
@Component
public class OrderTimeOutJob extends QuartzJob {
    
    @Resource
    private PushUtil pushUtil;
    @Resource
    private IOrderPrivateCarService orderPrivateCarService;
    @Resource
    private IOrderLogisticsService orderLogisticsService;
    
    
    
    @Override
    public QuartzJob buildQuartzJob() {
        return super.buildQuartzJob();
    }
    
    @Override
    public QuartzJob buildQuartzJob(String name) {
        return super.buildQuartzJob(name);
    }
    
    @Override
    public QuartzJob buildQuartzJob(String name, String group) {
        return super.buildQuartzJob(name, group);
    }
    
    @Override
    public QuartzJob buildQuartzJob(String name, String group, JobDataMap jobDataMap) {
        return super.buildQuartzJob(name, group, jobDataMap);
    }
    
    /**
     * 执行的业务逻辑
     * @param jobExecutionContext 定时任务上下文对象
     */
    @Override
    public void run(JobExecutionContext jobExecutionContext) {
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        Integer driverId = jobDataMap.getIntegerFromString("driverId");
        Integer orderId = jobDataMap.getIntegerFromString("orderId");
        Integer orderType = jobDataMap.getIntegerFromString("orderType");
        String describe = jobDataMap.getString("describe");
        if(1 == orderType){
            OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId);
            if(2 != orderPrivateCar.getState()){
                JobKey key = jobExecutionContext.getJobDetail().getKey();
                boolean b = QuartzUtil.deleteQuartzTask(key);
                if(!b){
                    log.error("定时任务关闭失败:" + key.toString());
                }
                return;
            }
        }
        if(4 == orderType){
            OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId);
            if(2 != orderLogistics.getState()){
                JobKey key = jobExecutionContext.getJobDetail().getKey();
                boolean b = QuartzUtil.deleteQuartzTask(key);
                if(!b){
                    log.error("定时任务关闭失败:" + key.toString());
                }
                return;
            }
        }
        pushUtil.pushOrderTimeOut(2, driverId, orderId, orderType, describe);
    }
    
    
    /**
     * 初始化任务对象
     * @return
     */
    public static QuartzJob init(){
        return new OrderTimeOutJob().buildQuartzJob();
    }
    
    /**
     * 初始化任务对象
     * @param name
     * @return
     */
    public static QuartzJob init(String name){
        return new OrderTimeOutJob().buildQuartzJob(name);
    }
    
    
    
    /**
     * 初始化任务对象
     * @param name
     * @param group
     * @return
     */
    public static QuartzJob init(String name, String group){
        return new OrderTimeOutJob().buildQuartzJob(name, group);
    }
    
    
    
    /**
     * 初始化任务对象
     * @param name
     * @param group
     * @return
     */
    public static QuartzJob init(String name, String group, JobDataMap jobDataMap){
        return new OrderTimeOutJob().buildQuartzJob(name, group, jobDataMap);
    }
}