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.

195 lines
8.3 KiB

10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. package com.gaotao.modules.automatedWarehouse.task;
  2. import com.gaotao.common.utils.ErrorLogUtils;
  3. import com.gaotao.modules.api.entity.NeedPalletTask;
  4. import com.gaotao.modules.automatedWarehouse.entity.AgvStation;
  5. import com.gaotao.modules.automatedWarehouse.entity.WcsCallbackTask;
  6. import com.gaotao.modules.automatedWarehouse.entity.WmsTransportTask;
  7. import com.gaotao.modules.automatedWarehouse.mapper.WcsIntegrationMapper;
  8. import com.gaotao.modules.automatedWarehouse.service.AgvTaskService;
  9. import com.gaotao.modules.automatedWarehouse.service.AutoTaskService;
  10. import com.gaotao.modules.automatedWarehouse.service.WcsTaskService;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.beans.factory.annotation.Value;
  14. import org.springframework.scheduling.annotation.Scheduled;
  15. import org.springframework.stereotype.Component;
  16. import java.util.List;
  17. @Slf4j
  18. @Component
  19. public class AutoTaskScheduler {
  20. @Autowired
  21. private WcsTaskService wcsTaskService;
  22. @Value("${scheduler.autoTask.enabled:true}")
  23. private boolean enabled;
  24. @Autowired
  25. private AgvTaskService agvTaskService;
  26. @Autowired
  27. private AutoTaskService autoTaskService;
  28. @Autowired
  29. private WcsIntegrationMapper wcsIntegrationMapper;
  30. /**
  31. * 定时任务10秒运行一次 自动化处理预约获取托盘任务
  32. * cron表达式0 * * * * ? 表示每分钟的第0秒执行
  33. * 配置说明通过 scheduler.wcs.enabled 控制是否启用
  34. */
  35. @Scheduled(fixedDelay = 8800)
  36. public void scheduleNeedPalletTask(){
  37. // 检查定时任务开关
  38. if (!enabled) {
  39. return;
  40. }
  41. log.info("=== 开始处理预约获取托盘任务相关业务 ===");
  42. try {
  43. // 获取待处理的WCS回调任务
  44. List<WmsTransportTask> list = agvTaskService.getNeedPalletTask();
  45. log.info("获取到 {} 个待处理任务(正常: {}, 超时恢复: {})", list.size());
  46. int successCount = 0;
  47. int failCount = 0;
  48. for (WmsTransportTask wmsTransportTask : list) {
  49. try {
  50. // 委托给业务服务处理
  51. autoTaskService.processNeedPalletTask(wmsTransportTask);
  52. successCount++;
  53. } catch (Exception e) {
  54. ErrorLogUtils.logException(wmsTransportTask.getSite(), "立库自动化", "处理获取栈板任务:"+wmsTransportTask.getSourceType(), wmsTransportTask.getTaskNo(), e);
  55. log.error("处理预约获取托盘任务失败:TaskNo={}, error={}", wmsTransportTask.getTaskNo(), e.getMessage());
  56. failCount++;
  57. // 继续处理下一个数据
  58. }
  59. }
  60. log.info("=== 预约获取托盘任务处理完成:总数={}, 成功={}, 失败={} ===", list.size(), successCount, failCount);
  61. } catch (Exception e) {
  62. log.error("=== 预约获取托盘任务定时任务执行失败 ===", e);
  63. }
  64. }
  65. /**
  66. * @Description 定时任务10秒运行一次 自动化处理预约运输栈板任务 - rqrq
  67. * @Title scheduleTransportPalletTask
  68. * @author rqrq
  69. * @date 2025/10/18
  70. */
  71. @Scheduled(fixedDelay = 7755)
  72. public void scheduleTransportPalletTask(){
  73. // 检查定时任务开关 - rqrq
  74. if (!enabled) {
  75. return;
  76. }
  77. log.info("=== 开始处理预约运输栈板任务 - rqrq ===");
  78. try {
  79. // 获取待处理的预约运输栈板任务 - rqrq
  80. List<WmsTransportTask> list = agvTaskService.getScheduledTransportPalletTask();
  81. log.info("获取到 {} 个待处理的预约运输栈板任务 - rqrq", list.size());
  82. int successCount = 0;
  83. int failCount = 0;
  84. for (WmsTransportTask wmsTransportTask : list) {
  85. try {
  86. // 委托给业务服务处理 - rqrq
  87. autoTaskService.processScheduledTransportPalletTask(wmsTransportTask);
  88. successCount++;
  89. } catch (Exception e) {
  90. ErrorLogUtils.logException(wmsTransportTask.getSite(), "立库自动化", "处理运输栈板任务:"+wmsTransportTask.getSourceType(), wmsTransportTask.getTaskNo(), e);
  91. log.error("处理预约运输栈板任务失败 - rqrq:TaskNo={}, error={}",
  92. wmsTransportTask.getTaskNo(), e.getMessage(), e);
  93. failCount++;
  94. // 继续处理下一个任务 - rqrq
  95. }
  96. }
  97. log.info("=== 预约运输栈板任务处理完成 - rqrq:总数={}, 成功={}, 失败={} ===",
  98. list.size(), successCount, failCount);
  99. } catch (Exception e) {
  100. log.error("=== 预约运输栈板任务定时任务执行失败 - rqrq ===", e);
  101. }
  102. }
  103. /**
  104. * @Description 定时任务30秒运行一次 自动续盘为空闲站点自动调用空托盘- rqrq
  105. * @Title scheduleAutoCallBlankPallet
  106. * @author rqrq
  107. * @date 2025/10/19
  108. */
  109. @Scheduled(fixedDelay = 8888)
  110. public void scheduleAutoCallBlankPallet() {
  111. // 检查定时任务开关 - rqrq
  112. if (!enabled) {
  113. return;
  114. }
  115. log.info("=== 开始自动续盘任务 - rqrq ===");
  116. try {
  117. // 查询需要自动续盘的站点 - rqrq
  118. // 条件:auto_call_blank_pallet='Y', auto_call_blank_pallet_type有值, station_type='正式站点', status_db=0
  119. List<AgvStation> stations = wcsIntegrationMapper.getAutoCallBlankPalletStations();
  120. log.info("查询到 {} 个需要自动续盘的站点 - rqrq", stations.size());
  121. int successCount = 0;
  122. int failCount = 0;
  123. for (AgvStation station : stations) {
  124. NeedPalletTask needPalletTask=new NeedPalletTask();
  125. try {
  126. log.info("开始为站点 {} 自动调用空托盘 - rqrq,站点编码={}, 托盘类型={}, 等待站点={}",
  127. station.getStationName(),
  128. station.getStationCode(),
  129. station.getAutoCallBlankPalletType(),
  130. station.getWaitStationCode());
  131. // 构建NeedPalletTask参数 - rqrq
  132. needPalletTask.setSite("55"); // 固定站点为55 - rqrq
  133. needPalletTask.setStationCode(station.getStationCode()); // 使用wait_station_code作为目标站点 - rqrq
  134. needPalletTask.setPalletType(station.getAutoCallBlankPalletType()); // 使用auto_call_blank_pallet_type作为栈板类型 - rqrq
  135. needPalletTask.setPalletId(null); // 不指定具体栈板,由WCS自动分配 - rqrq
  136. needPalletTask.setUsername("SYS_WMS"); // 系统自动调用 - rqrq
  137. needPalletTask.setSourceBillNo("自动续盘-" + station.getStationCode()); // 来源单号 - rqrq
  138. // 调用autoNeedPalletTask创建预约任务 - rqrq
  139. autoTaskService.autoNeedPalletTask(needPalletTask);
  140. successCount++;
  141. log.info("站点 {} 自动续盘成功 - rqrq", station.getStationCode());
  142. } catch (Exception e) {
  143. ErrorLogUtils.logException(needPalletTask.getSite(), "立库自动化", "站点自动续盘", needPalletTask.getStationCode(), e);
  144. failCount++;
  145. log.error("站点 {} 自动续盘失败 - rqrq:stationCode={}, error={}",
  146. station.getStationName(),
  147. station.getStationCode(),
  148. e.getMessage(),
  149. e);
  150. // 继续处理下一个站点 - rqrq
  151. }
  152. }
  153. log.info("=== 自动续盘任务处理完成 - rqrq:总数={}, 成功={}, 失败={} ===",
  154. stations.size(), successCount, failCount);
  155. } catch (Exception e) {
  156. log.error("=== 自动续盘定时任务执行失败 - rqrq ===", e);
  157. }
  158. }
  159. }