package com.adc.da.scheduled; import com.adc.da.scheduled.dao.SarStandardInfoDao; import com.adc.da.scheduled.dao.SarStandardItemDao; import com.adc.da.scheduled.dao.SarStandardWarningDao; import com.adc.da.scheduled.entity.DataDTO; import com.adc.da.scheduled.entity.WarningEO; import com.adc.da.util.UUIDUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.time.LocalDate; import java.util.LinkedList; import java.util.List; @EnableScheduling @Component @Slf4j public class ScheduledJob { /** * 根据配置文件设置是否开启定时器 */ @Value("${isNotScheduled}") private boolean isNotScheduled; //是否开启定时器 // // @Scheduled(cron="*/5 * * * * ?") // @Async // public void StandScheduledJob(){ // System.out.println("hello"); //// if(isNotScheduled){ //// System.out.println(Thread.currentThread().getName() + " cron=0 0 1 1 * ? --- " + new Date()+"---START-01"); //// System.out.println(Thread.currentThread().getName() + " cron=0 0 1 1 * ? --- " + new Date()+"---End-01"); //// try{ //// Thread.sleep(2000); //// }catch(Exception e){ //// } //// } // } @Autowired private SarStandardWarningDao sarStandardWarningDao; @Autowired private SarStandardItemDao sarStandardItemDao; @Autowired private SarStandardInfoDao sarStandardInfoDao; // @Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行 @Scheduled(cron="*/5 * * * * ?") @Async public void schedulingTasks() { /** * 1.查询标准属性字段表(sar_stand_attr_info) XCXSSEQ ZCCSSRQ ZRGCS * 联接标准信息表sar_standards_info表的STAND_NAME * 2.查询分解单(条款表) * 3.查询预警表 * 4.去掉预警表中已存在的的数据 * 5.插入预警表 */ /** mark:标识预警的种类 3:新车标准预警 4:在产车标准预警 1:新车条款预警 2:在产车条款预警 */ System.out.println("开始执行预警!!!"); //预警期限 DataDTO dataDTO = new DataDTO(); dataDTO.setStartDate(LocalDate.now().plusDays(1)) //系统日期的下一天 .setEndDate(LocalDate.now().plusMonths(3).plusDays(1));//系统日期3个月后 LinkedList warningList = new LinkedList<>(); //分解单(条款) 新车型 mark=1 List itemForXCXSSRQ = sarStandardItemDao.select(dataDTO, "XCXSSRQ"); for (WarningEO warningEO : itemForXCXSSRQ) { warningEO.setId(UUIDUtils.randomUUID20()) .setPower("1") .setMark("1") .setPutTime(warningEO.getXCXSSRQ()); } warningList.addAll(itemForXCXSSRQ); //分解单(条款) 在产车型 mark=2 List itemForZCCSSRQ = sarStandardItemDao.select(dataDTO, "ZCCSSRQ"); for (WarningEO warningEO : itemForZCCSSRQ) { warningEO.setId(UUIDUtils.randomUUID20()) .setPower("1") .setMark("2") .setPutTime(warningEO.getZCCSSRQ()); } warningList.addAll(itemForZCCSSRQ); //标准 新车型 预警 mark=3 List standInfoXCXSSRQ = sarStandardInfoDao.select(dataDTO, "XCXSSRQ"); for (WarningEO warningEO : standInfoXCXSSRQ) { warningEO.setId(UUIDUtils.randomUUID20()) .setPower("1") .setMark("3") .setPutTime(warningEO.getXCXSSRQ()); } warningList.addAll(standInfoXCXSSRQ); //标准 在产车型 mark=4 List standInfoZCCSSRQ = sarStandardInfoDao.select(dataDTO, "ZCCSSRQ"); for (WarningEO warningEO : standInfoZCCSSRQ) { warningEO.setId(UUIDUtils.randomUUID20()) .setPower("1") .setMark("4") .setPutTime(warningEO.getZCCSSRQ()); } warningList.addAll(standInfoZCCSSRQ); //持久化至预警表 忽略标准id和标志位都一样的数据 if (warningList.size()!=0){ int count = sarStandardWarningDao.ignoreInsert(warningList); System.out.println("已预警 " + count + " 条标准或条款!!"); } } }