fix
longz
2026-04-30 83ff381c5c0e62c98cb9e3dd8e1d82771b1dc23f
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package com.stylefeng.guns.modular.system.util;
 
 
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.system.dao.LineShiftDriverMapper;
import com.stylefeng.guns.modular.system.model.LineShiftDriver;
import com.stylefeng.guns.modular.system.model.TDriver;
import com.stylefeng.guns.modular.system.model.TLineCompany;
import com.stylefeng.guns.modular.system.model.TOrderCrossCity;
import com.stylefeng.guns.modular.system.model.TOrderPrivateCar;
import com.stylefeng.guns.modular.system.model.TOrderTaxi;
import com.stylefeng.guns.modular.system.service.ITDriverService;
import com.stylefeng.guns.modular.system.service.ITLineCompanyService;
import com.stylefeng.guns.modular.system.service.ITOrderCrossCityService;
import com.stylefeng.guns.modular.system.service.ITOrderPrivateCarService;
import com.stylefeng.guns.modular.system.service.ITOrderTaxiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Date;
import java.util.List;
import java.util.Set;
 
 
/**
 * 定时任务工具类
 */
@Component
public class TaskUtil {
 
    @Autowired
    private PushMinistryOfTransportUtil pushMinistryOfTransportUtil;
 
    @Value("${pushMinistryOfTransport}")
    private boolean pushMinistryOfTransport;
 
    @Autowired
    private ITDriverService driverService;
 
    @Autowired
    private ITOrderPrivateCarService orderPrivateCarService;
 
    @Autowired
    private ITOrderTaxiService orderTaxiService;
 
    @Autowired
    private ITOrderCrossCityService orderCrossCityService;
 
    @Autowired
    private ITLineCompanyService lineCompanyService;
 
    @Autowired
    private LineShiftDriverMapper lineShiftDriverMapper;
    
    
    /**
     * 每月第一天的1点执行的任务
     */
    @Scheduled(cron = "0 0 1 1 * *")
    public void taskMonth(){
        try {
            if(pushMinistryOfTransport){
                List<TDriver> tDrivers = driverService.selectList(new EntityWrapper<TDriver>().eq("authState", 2).ne("flag", 3));
                for(TDriver driver : tDrivers){
                    pushMinistryOfTransportUtil.baseInfoDriverStat(driver.getId());
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
 
    /**
     * 每分钟执行
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    public void taskMinute(){
        // 15天后的时间
        long time = System.currentTimeMillis() + 15 * 24 * 60 * 60 * 1000;
        Date date = new Date(time);
        // 查出录音
        List<TOrderPrivateCar> list = orderPrivateCarService.selectList(new EntityWrapper<TOrderPrivateCar>().isNotNull("voiceTime").gt("voiceTime", date));
        List<TOrderTaxi> tOrderTaxis = orderTaxiService.selectList(new EntityWrapper<TOrderTaxi>().isNotNull("voiceTime").gt("voiceTime", date));
        List<TOrderCrossCity> tOrderCrossCities = orderCrossCityService.selectList(new EntityWrapper<TOrderCrossCity>().isNotNull("voiceTime").gt("voiceTime", date));
        ArrayList<String> strings = new ArrayList<>();
        for (TOrderPrivateCar tOrderPrivateCar : list) {
            strings.add(tOrderPrivateCar.getVoice());
        }
        for (TOrderTaxi tOrderTaxi : tOrderTaxis) {
            strings.add(tOrderTaxi.getVoice());
        }
        for (TOrderCrossCity tOrderCrossCity : tOrderCrossCities) {
            strings.add(tOrderCrossCity.getVoice());
        }
        if(strings.size()>0){
            deleteFile(strings);
        }
 
    }
 
    /**
     * 每天凌晨2点执行智能排班复制:
     * 将前一天排班复制到6天后(即前一天+7天)
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void taskLineAutoPlanCopy(){
        try {
            LocalDate today = LocalDate.now();
            String sourceDay = today.minusDays(1).toString();
            String targetDay = today.plusDays(6).toString();
            List<TLineCompany> autoPlanList = lineCompanyService.selectList(
                    new EntityWrapper<TLineCompany>().eq("autoPlan", 1)
            );
            if (autoPlanList == null || autoPlanList.size() <= 0) {
                return;
            }
            Set<Integer> lineIds = new LinkedHashSet<>();
            for (TLineCompany lineCompany : autoPlanList) {
                if (lineCompany != null && lineCompany.getLineId() != null) {
                    lineIds.add(lineCompany.getLineId());
                }
            }
            for (Integer lineId : lineIds) {
                copyLineSchedule(lineId, sourceDay, targetDay);
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }
 
    private void copyLineSchedule(Integer lineId, String sourceDay, String targetDay) {
        if (lineId == null) {
            return;
        }
        List<LineShiftDriver> sourceList = lineShiftDriverMapper.getSchedulesByLineAndDay(lineId, sourceDay);
        if (sourceList == null || sourceList.size() <= 0) {
            return;
        }
        Date targetDate = java.sql.Date.valueOf(targetDay);
        for (LineShiftDriver source : sourceList) {
            if (source == null || source.getLineShiftId() == null || source.getDriverId() == null) {
                continue;
            }
            Integer count = lineShiftDriverMapper.countExistsSchedule(source.getLineShiftId(), source.getDriverId(), targetDay);
            if (count != null && count > 0) {
                continue;
            }
            LineShiftDriver target = new LineShiftDriver();
            target.setLineShiftId(source.getLineShiftId());
            target.setDriverId(source.getDriverId());
            target.setDay(targetDate);
            target.setLaveSeat(source.getLaveSeat());
            target.setLaveSeatNumber(source.getLaveSeatNumber());
            target.setTotalSeat(source.getTotalSeat());
            target.setInserTime(new Date());
            target.setAssignType(source.getAssignType());
            lineShiftDriverMapper.insert(target);
        }
    }
 
    public static String oss_domain = "https://cdxy-jiaotong-20250725.oss-cn-chengdu.aliyuncs.com/";
    public static String accessKeyId = "LTAI5t8obxz88oV8MgFMr4Bd";
    public static String accessKeySecret = "Y17SxRCVYGePCkr82FSCk9jqCBljRP";
    public static String bucketName="cdxy-jiaotong-20250725";
    public static String endpoint = "oss-cn-chengdu.aliyuncs.com";
    public static OSSClient ossClient = new OSSClient(endpoint, accessKeyId,accessKeySecret);
    private static boolean deleteFile(List<String> fileNames) {
        try {
            for (String fileName : fileNames) {
                // 删除文件
                ossClient.deleteObject(bucketName, "img/"+fileName);
            }
            // 关闭OSSClient
            ossClient.shutdown();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
 
}