package com.zcloud.util; import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import com.zcloud.entity.PageData; import com.zcloud.service.bus.ListManagerService; import com.zcloud.service.bus.ListStatisticsService; @Component public class ListScheduled { @Autowired private ListManagerService listManagerService; @Autowired private ListStatisticsService listStatisticsService; //@Scheduled(cron ="0 5 0 * * ?")//每天12点05 @Scheduled(cron ="0 30 0 * * ?")//每天12点30 //@Scheduled(cron ="0 0/3 * * * ?")//测试 public void scheduled(){ try { System.out.println("============定时查询清单排查数量=========="); PageData list = new PageData(); List varlist = listManagerService.listExaminedNum(list); for (PageData pd : varlist) { pd.put("LISTSTATISTICS_ID", this.get32UUID()); //主键 if(pd.get("PERIOD") != null && Tools.notEmpty(pd.get("PERIOD").toString())) { String period = pd.get("PERIOD").toString(); switch (period) { case "checkPeriod0001"://每日 pd.put("STARTTIME", DateUtil.getDay()+" 00:00:00"); pd.put("ENDTIME", DateUtil.getDay()+" 23:59:59"); break; case "checkPeriod0002"://每周 pd.put("STARTTIME", DateUtil.getWeekStart()); pd.put("ENDTIME", DateUtil.getWeekEnd()); break; case "checkPeriod0003"://每旬 String year = DateUtil.getYear().toString(); String month = DateUtil.getMonth().toString(); Integer day = Integer.parseInt(DateUtil.getOnlyDay().toString()); String startTime = year + "-" + month + "-"; String endTime = year + "-" + month + "-"; if(day <= 10) { startTime = startTime+"01 00:00:00"; endTime = endTime+"10 23:59:59"; } else if(day > 10 && day <= 20) { startTime = startTime+"11 00:00:00"; endTime = endTime+"20 23:59:59"; } else { startTime = startTime+"21 00:00:00"; endTime = DateUtil.getMonthEndDay()+" 23:59:59"; } pd.put("STARTTIME", startTime); pd.put("ENDTIME", endTime); break; case "checkPeriod0004"://每月 pd.put("STARTTIME", DateUtil.getMonthFirstDay()+" 00:00:00"); pd.put("ENDTIME", DateUtil.getMonthEndDay()+" 23:59:59"); break; case "checkPeriod0005"://每季 pd.put("STARTTIME", DateUtil.quarterStart()+" 00:00:00"); pd.put("ENDTIME", DateUtil.quarterEnd()+" 23:59:59"); break; case "checkPeriod0006"://每年 pd.put("STARTTIME", DateUtil.getCurrYearFirst()+" 00:00:00"); pd.put("ENDTIME", DateUtil.getCurrYearLast()+" 23:59:59"); break; case "checkPeriod0007"://半年 String byear = DateUtil.getYear().toString(); Integer bmonth = Integer.parseInt(DateUtil.getMonth().toString()); if(bmonth <= 6) { pd.put("STARTTIME", byear+"-01-01 00:00:00"); pd.put("ENDTIME", byear+"-06-30 23:59:59"); } else if(bmonth > 6) { pd.put("STARTTIME", byear+"-07-01 00:00:00"); pd.put("ENDTIME", byear+"-12-31 23:59:59"); } break; default: break; } } PageData statistics = listStatisticsService.findByCondition(pd); if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) { statistics.put("NOTEXAMINEDNUM", pd.get("NOTEXAMINEDNUM")); statistics.put("CREATTIME", DateUtil.date2Str(new Date())); //创建时间 statistics.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 listStatisticsService.edit(statistics); } else { pd.put("CREATTIME", DateUtil.date2Str(new Date())); //创建时间 pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 listStatisticsService.save(pd); } } List varJjrList = listManagerService.listExaminedNumJjr(list); if(varJjrList != null && varJjrList.size() > 0) { for(PageData jjr:varJjrList) { jjr.put("LISTSTATISTICS_ID", this.get32UUID()); //主键 jjr.put("STARTTIME", jjr.get("START_DATE").toString()+" 00:00:00"); jjr.put("ENDTIME", jjr.get("END_DATE").toString()+" 23:59:59"); PageData statistics = listStatisticsService.findByCondition(jjr); if(statistics != null && statistics.get("LISTSTATISTICS_ID") != null) { statistics.put("NOTEXAMINEDNUM", jjr.get("NOTEXAMINEDNUM")); statistics.put("CREATTIME", DateUtil.date2Str(new Date())); //创建时间 statistics.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 listStatisticsService.edit(statistics); } else { jjr.put("CREATTIME", DateUtil.date2Str(new Date())); //创建时间 jjr.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 listStatisticsService.save(jjr); } } } } catch (Exception e) { e.printStackTrace(); } } /**得到32位的uuid * @return */ public String get32UUID(){ return UuidUtil.get32UUID(); } }