ScheduledService.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.szwl.controller;
  2. import com.szwl.service.TDepartmentService;
  3. import com.szwl.service.TOrderTaskService;
  4. import com.szwl.service.TShandeMchService;
  5. import com.szwl.service.es.EsTCoinOrderService;
  6. import com.szwl.service.es.EsTOrderService;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.context.annotation.Configuration;
  9. import org.springframework.scheduling.annotation.EnableScheduling;
  10. import org.springframework.scheduling.annotation.Scheduled;
  11. import org.springframework.stereotype.Component;
  12. import java.net.InetAddress;
  13. import java.net.UnknownHostException;
  14. import java.text.ParseException;
  15. import java.util.Calendar;
  16. @Configuration //1.主要用于标记配置类,兼备Component的效果。
  17. @Component
  18. @EnableScheduling // 2.开启定时任务
  19. public class ScheduledService {
  20. @Autowired
  21. private TShandeMchService tShandeMchService;
  22. @Autowired
  23. private TOrderTaskService orderTaskService;
  24. @Autowired
  25. EsTCoinOrderService esTCoinOrderService;
  26. @Autowired
  27. EsTOrderService esTOrderService;
  28. //8点到22点,每隔30秒去重发订单
  29. @Scheduled(cron = "0/30 * 8-22 * * ?")
  30. public void checkOrder() throws ParseException {
  31. // orderTaskService.checkOrder();
  32. int i = 0;
  33. try {
  34. String hostAddress = InetAddress.getLocalHost().getHostAddress();
  35. if(hostAddress.equals("10.0.0.153")){
  36. orderTaskService.checkOrder();
  37. i++;
  38. }
  39. // if(hostAddress.equals("10.0.0.152")){
  40. // i++;
  41. // }
  42. } catch (UnknownHostException e) {
  43. e.printStackTrace();
  44. }
  45. }
  46. //每天凌晨删除订单定时发送表
  47. @Scheduled(cron = "30 05 1 * * ?")
  48. public void removeOrder(){
  49. int i = 0;
  50. try {
  51. String hostAddress = InetAddress.getLocalHost().getHostAddress();
  52. if(hostAddress.equals("10.0.0.153")){
  53. orderTaskService.removeOrder();
  54. i++;
  55. }
  56. // if(hostAddress.equals("10.0.0.152")){
  57. // i++;
  58. // }
  59. } catch (UnknownHostException e) {
  60. e.printStackTrace();
  61. }
  62. }
  63. // 在每小时的26分执行一次 es同步数据
  64. @Scheduled(cron = "0 26 * * * ?")
  65. public void tongbuEs() throws ParseException {
  66. // esTOrderService.tongbuByHour();
  67. // esTCoinOrderService.tongbuByHour();
  68. int i = 0;
  69. try {
  70. String hostAddress = InetAddress.getLocalHost().getHostAddress();
  71. if(hostAddress.equals("10.0.0.153")){
  72. esTOrderService.tongbuByHour();
  73. esTCoinOrderService.tongbuByHour();
  74. i++;
  75. }
  76. // if(hostAddress.equals("10.0.0.152")){
  77. // i++;
  78. // }
  79. } catch (UnknownHostException e) {
  80. e.printStackTrace();
  81. }
  82. }
  83. //凌晨同步过去一天数据 es同步数据
  84. @Scheduled(cron = "30 10 0 * * ?")
  85. public void tongbuDayEs() throws ParseException {
  86. // esTOrderService.tongbuByHour();
  87. // esTCoinOrderService.tongbuByHour();
  88. int i = 0;
  89. try {
  90. String hostAddress = InetAddress.getLocalHost().getHostAddress();
  91. if(hostAddress.equals("10.0.0.153")){
  92. esTOrderService.tongbuByDay();
  93. esTCoinOrderService.tongbuByDay();
  94. i++;
  95. }
  96. // if(hostAddress.equals("10.0.0.152")){
  97. // i++;
  98. // }
  99. } catch (UnknownHostException e) {
  100. e.printStackTrace();
  101. }
  102. }
  103. // //每天凌晨统计/核对杉德支付的金额表
  104. // @Scheduled(cron = "30 05 0 * * ?")
  105. // public void shandejiesuan(){
  106. // tShandeMchService.jiesuan();
  107. // }
  108. //
  109. }