package com.boying.job; import com.boying.entity.Statistic; import com.boying.entity.TicketBlack; import com.boying.service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.io.IOException; import java.time.LocalDateTime; import java.util.Date; import java.util.List; //大屏页面统计 @Component public class DaPingScheduled { @Autowired private StatisticService statisticService; @Autowired private OutParkService outParkService; @Autowired private EnterParkService enterParkService; @Autowired private TicketService ticketService; @Autowired private ParkService parkService; @Autowired private TicketBlackService ticketBlackService; //@Scheduled(cron = "0 0/40 * * * ?") public void execute() throws IOException { System.out.println("开始定时任务-------》"); // List list = ticketBlackService.updateType(); // if(list.size() > 0){ // for(TicketBlack t:list){ // t.setBlackType(1); // ticketBlackService.saveOrUpdate(t); // } // } Statistic statistic = null; List all = statisticService.list(); if(all.size()>0){ statistic = all.get(0); }else { System.out.println("创建statistic"); statistic = new Statistic(); } statistic.setCreateTime(LocalDateTime.now()); statistic.setData1(outParkService.count1()); statistic.setData2(outParkService.count2()); statistic.setData3(outParkService.sumByPrice()); statistic.setData4(enterParkService.count1()); statistic.setData5(outParkService.count5()); statistic.setData6(ticketService.count2()); statistic.setData7(ticketService.count1()); statistic.setData8(ticketService.sumByPrice()); statistic.setData9(outParkService.count3()); statistic.setData10(outParkService.sumByPrice2()); statistic.setData11(ticketService.count3()); statistic.setData12(ticketService.sumByPrice2()); int i = parkService.count1(); if(i > 0){ statistic.setData13((enterParkService.count1()*100)/parkService.count1()); }else { statistic.setData13(100); } statistic.setData14(ticketService.count4()); statistic.setData15(ticketService.count5(1)); statistic.setData16(ticketService.count5(2)); statistic.setData17(ticketService.count6()); statistic.setData18(ticketService.sumByPrice3()); statistic.setData19(ticketBlackService.count1()); statistic.setData20(ticketBlackService.count2()); statisticService.saveOrUpdate(statistic); System.out.println("结束定时任务-------》"); } }