package com.szwl.controller; import com.szwl.service.TDepartmentService; import com.szwl.service.TOrderTaskService; import com.szwl.service.TShandeMchService; import com.szwl.service.es.EsTCoinOrderService; import com.szwl.service.es.EsTOrderService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.net.InetAddress; import java.net.UnknownHostException; import java.text.ParseException; import java.util.Calendar; @Configuration //1.主要用于标记配置类,兼备Component的效果。 @Component @EnableScheduling // 2.开启定时任务 public class ScheduledService { @Autowired private TShandeMchService tShandeMchService; @Autowired private TOrderTaskService orderTaskService; @Autowired EsTCoinOrderService esTCoinOrderService; @Autowired EsTOrderService esTOrderService; //8点到22点,每隔30秒去重发订单 @Scheduled(cron = "0/30 * 8-22 * * ?") public void checkOrder() throws ParseException { // orderTaskService.checkOrder(); int i = 0; try { String hostAddress = InetAddress.getLocalHost().getHostAddress(); if(hostAddress.equals("10.0.0.153")){ orderTaskService.checkOrder(); i++; } // if(hostAddress.equals("10.0.0.152")){ // i++; // } } catch (UnknownHostException e) { e.printStackTrace(); } } //每天凌晨删除订单定时发送表 @Scheduled(cron = "30 05 1 * * ?") public void removeOrder(){ int i = 0; try { String hostAddress = InetAddress.getLocalHost().getHostAddress(); if(hostAddress.equals("10.0.0.153")){ orderTaskService.removeOrder(); i++; } // if(hostAddress.equals("10.0.0.152")){ // i++; // } } catch (UnknownHostException e) { e.printStackTrace(); } } // 在每小时的26分执行一次 es同步数据 @Scheduled(cron = "0 26 * * * ?") public void tongbuEs() throws ParseException { // esTOrderService.tongbuByHour(); // esTCoinOrderService.tongbuByHour(); int i = 0; try { String hostAddress = InetAddress.getLocalHost().getHostAddress(); if(hostAddress.equals("10.0.0.153")){ esTOrderService.tongbuByHour(); esTCoinOrderService.tongbuByHour(); i++; } // if(hostAddress.equals("10.0.0.152")){ // i++; // } } catch (UnknownHostException e) { e.printStackTrace(); } } //凌晨同步过去一天数据 es同步数据 @Scheduled(cron = "30 10 0 * * ?") public void tongbuDayEs() throws ParseException { // esTOrderService.tongbuByHour(); // esTCoinOrderService.tongbuByHour(); int i = 0; try { String hostAddress = InetAddress.getLocalHost().getHostAddress(); if(hostAddress.equals("10.0.0.153")){ esTOrderService.tongbuByDay(); esTCoinOrderService.tongbuByDay(); i++; } // if(hostAddress.equals("10.0.0.152")){ // i++; // } } catch (UnknownHostException e) { e.printStackTrace(); } } // //每天凌晨统计/核对杉德支付的金额表 // @Scheduled(cron = "30 05 0 * * ?") // public void shandejiesuan(){ // tShandeMchService.jiesuan(); // } // }