package com.stylefeng.guns.modular.system.util; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.stylefeng.guns.modular.system.model.TDriver; import com.stylefeng.guns.modular.system.service.IPushEvaluationService; import com.stylefeng.guns.modular.system.service.ITDriverService; import com.stylefeng.guns.modular.system.service.ITLocationService; 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.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; /** * 定时任务工具类 */ @Component public class TaskUtil { @Autowired private ITLocationService locationService; @Autowired private PushMinistryOfTransportUtil pushMinistryOfTransportUtil; @Value("${pushMinistryOfTransport}") private boolean pushMinistryOfTransport; @Autowired private ITDriverService driverService; @Autowired private IPushEvaluationService pushEvaluationService; /** * 每隔一分钟去处理的定时任务 */ @Scheduled(fixedRate = 1000 * 60) public void taskMinute(){ try { } catch (Exception e) { e.printStackTrace(); } } /** * 每天的凌晨执行的任务 */ @Scheduled(cron = "0 0 0 * * *") public void taskDay(){ try { locationService.updateFence();//更新线上电子围栏 }catch (Exception e){ e.printStackTrace(); } } /** * 每月第一天的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(); } } /** * 每周一零晨3点执行任务 * 推送上周订单评价数据 */ @Scheduled(cron = "0 0 3 ? * MON") public void taskPushEvaluation() { try { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime endTimeObj = LocalDateTime.now(); String startTime = endTimeObj.minusWeeks(1).format(formatter); String endTime = endTimeObj.format(formatter); pushEvaluationService.pushEvaluation(startTime, endTime); }catch (Exception e){ e.printStackTrace(); } } }