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 tDrivers = driverService.selectList(new EntityWrapper().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 list = orderPrivateCarService.selectList(new EntityWrapper().isNotNull("voiceTime").gt("voiceTime", date)); List tOrderTaxis = orderTaxiService.selectList(new EntityWrapper().isNotNull("voiceTime").gt("voiceTime", date)); List tOrderCrossCities = orderCrossCityService.selectList(new EntityWrapper().isNotNull("voiceTime").gt("voiceTime", date)); ArrayList 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 autoPlanList = lineCompanyService.selectList( new EntityWrapper().eq("autoPlan", 1) ); if (autoPlanList == null || autoPlanList.size() <= 0) { return; } Set 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 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 fileNames) { try { for (String fileName : fileNames) { // 删除文件 ossClient.deleteObject(bucketName, "img/"+fileName); } // 关闭OSSClient ossClient.shutdown(); return true; } catch (Exception e) { e.printStackTrace(); return false; } } }