O
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.6 KiB

2 years ago
10 months ago
2 years ago
10 months ago
2 years ago
1 year ago
10 months ago
10 months ago
2 years ago
10 months ago
10 months ago
2 years ago
2 years ago
2 years ago
10 months ago
2 years ago
2 years ago
2 years ago
10 months ago
1 year ago
10 months ago
1 year ago
10 months ago
1 year ago
10 months ago
10 months ago
  1. package com.xujie.sys.common.utils;
  2. import com.xujie.sys.modules.pms.service.EamProjectService;
  3. import com.xujie.sys.modules.pms.service.EamService;
  4. import com.xujie.sys.modules.pms.service.Impl.QcServiceImpl;
  5. import com.xujie.sys.modules.reader.service.GetInformationForExcelService;
  6. import com.xujie.sys.modules.reader.service.ModbusCommunicateService;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.beans.factory.annotation.Value;
  9. import org.springframework.context.annotation.Configuration;
  10. import org.springframework.scheduling.annotation.EnableScheduling;
  11. import org.springframework.scheduling.annotation.Scheduled;
  12. import org.springframework.stereotype.Component;
  13. import javax.mail.MessagingException;
  14. import java.io.UnsupportedEncodingException;
  15. @Component
  16. @Configuration
  17. @EnableScheduling
  18. public class TaskUtils {
  19. @Autowired
  20. private EamService eamService;
  21. @Autowired
  22. private QcServiceImpl qcService;
  23. @Autowired
  24. private GetInformationForExcelService getInformationForExcelService;
  25. @Autowired
  26. private EamProjectService eamProjectService;
  27. @Autowired
  28. private ModbusCommunicateService modbusCommunicateService;
  29. // 全局任务开关
  30. @Value("${task.enabled:true}")
  31. private boolean taskEnabled;
  32. /**
  33. * 添加定时任务
  34. */
  35. @Scheduled(cron = "${task.data.eamWorkPlanTime}")
  36. public void doTask() {
  37. if(!taskEnabled){
  38. return;
  39. }
  40. eamService.eamWorkPlanTask();
  41. }
  42. /**
  43. * 读取Excel数据
  44. */
  45. @Scheduled(cron = "${task.data.getExcelInformation}" ) //每五秒执行 读取文件数据
  46. public void getExcel(){
  47. if(!taskEnabled){
  48. return;
  49. }
  50. getInformationForExcelService.saveByExcel();
  51. }
  52. /**
  53. * 添加未上传文件邮件通知定時任務
  54. */
  55. @Scheduled(cron = "${task.data.sendEmail}" )
  56. public void sendEmail() throws MessagingException, UnsupportedEncodingException {
  57. if(!taskEnabled){
  58. return;
  59. }
  60. eamProjectService.sendEmail();
  61. }
  62. /**
  63. * 读取Modbus数据
  64. */
  65. @Scheduled(cron = "${task.data.modbusCommunicate}")
  66. public void getModbus(){
  67. if(!taskEnabled){
  68. return;
  69. }
  70. modbusCommunicateService.getInfoByModbus();
  71. }
  72. @Scheduled(cron = "${task.data.readPerSecond}")
  73. public void readPerSecond(){
  74. if(!taskEnabled){
  75. return;
  76. }
  77. modbusCommunicateService.readPerSecond();
  78. }
  79. @Scheduled(cron = "${loraurl.getLoraWatchTime}")
  80. //@Scheduled(cron = "0/30 * * * * ?")
  81. public void getLoraWatchMessage(){
  82. if(!taskEnabled){
  83. return;
  84. }
  85. eamService.getLoraWatch();};
  86. //@Scheduled(cron = "${loraurl.sendLoraWatchTime}")
  87. public void sendLoraWatchMessage(){
  88. if(!taskEnabled){
  89. return;
  90. }
  91. eamService.sendLoraWatch();};
  92. //@Scheduled(cron = "${loraurl.sendThreeColourTime}")
  93. public void sendThreeColourLight(){
  94. if(!taskEnabled){
  95. return;
  96. }
  97. eamService.sendThreeColourLight();};
  98. @Scheduled(cron = "${loraurl.sendRedColourTime}")
  99. //@Scheduled(cron = "0/10 * * * * ?")
  100. public void sendLoraRedLight(){
  101. if(!taskEnabled){
  102. return;
  103. }
  104. eamService.sendLoraRedLight();}
  105. /**
  106. * 创建质量任务
  107. */
  108. @Scheduled(cron = "${task.data.createQCInspection}")
  109. public void createQCInspection() {
  110. if(!taskEnabled){
  111. return;
  112. }
  113. qcService.createQCInspection();
  114. }
  115. }