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.

218 lines
8.3 KiB

4 months ago
3 months ago
4 months ago
3 months ago
3 months ago
4 months ago
3 months ago
4 months ago
4 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
3 months ago
4 months ago
2 months ago
4 months ago
3 months ago
1 week ago
3 months ago
4 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
3 months ago
4 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
1 month ago
1 month ago
1 month ago
4 months ago
  1. package com.gaotao.modules.automatedWarehouse.task;
  2. import com.gaotao.modules.automatedWarehouse.entity.WcsCallbackTask;
  3. import com.gaotao.modules.automatedWarehouse.entity.WmsOrderTask;
  4. import com.gaotao.modules.automatedWarehouse.entity.WcsCallbackPalletScan;
  5. import com.gaotao.modules.automatedWarehouse.service.WcsTaskService;
  6. import com.gaotao.modules.automatedWarehouse.service.InventoryDiscrepancyService;
  7. import com.gaotao.modules.automatedWarehouse.service.AutoSortService;
  8. import com.gaotao.modules.automatedWarehouse.service.KitTransportService;
  9. import com.gaotao.modules.automatedWarehouse.mapper.WcsCallbackPalletScanMapper;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.scheduling.annotation.Scheduled;
  14. import org.springframework.stereotype.Component;
  15. import java.util.Date;
  16. import java.util.List;
  17. /**
  18. * WCS任务定时处理器
  19. * 每分钟执行一次处理WCS入库/出库任务
  20. */
  21. @Slf4j
  22. @Component
  23. public class WcsTaskScheduler {
  24. @Autowired
  25. private WcsTaskService wcsTaskService;
  26. @Autowired
  27. private InventoryDiscrepancyService inventoryDiscrepancyService;
  28. @Autowired
  29. private AutoSortService autoSortService;
  30. @Autowired
  31. private WcsCallbackPalletScanMapper wcsCallbackPalletScanMapper;
  32. @Autowired
  33. private KitTransportService kitTransportService;
  34. @Value("${scheduler.wcs.enabled:true}")
  35. private boolean enabled;
  36. /**
  37. * 定时任务每分钟执行一次WCS任务处理
  38. * cron表达式0 * * * * ? 表示每分钟的第0秒执行
  39. * 配置说明通过 scheduler.wcs.enabled 控制是否启用
  40. */
  41. @Scheduled(fixedDelay = 2684)
  42. public void scheduleWcsTaskProcessing() {
  43. // 检查定时任务开关
  44. // if (!enabled) {
  45. // return;
  46. // }
  47. log.info("=== 开始处理WCS入库/出库相关业务 ===");
  48. try {
  49. // 获取待处理的WCS回调任务
  50. List<WcsCallbackTask> list = wcsTaskService.getPendingWcsCallbackTasks("55");
  51. if (list.isEmpty()) {
  52. log.info("无待处理的WCS回调任务");
  53. return;
  54. }
  55. // 统计信息
  56. long normalTaskCount = list.stream().filter(t -> !"处理中".equals(t.getStatus())).count();
  57. long timeoutTaskCount = list.stream().filter(t -> "处理中".equals(t.getStatus())).count();
  58. log.info("获取到 {} 个待处理任务(正常: {}, 超时恢复: {})", list.size(), normalTaskCount, timeoutTaskCount);
  59. int successCount = 0;
  60. int failCount = 0;
  61. for (WcsCallbackTask callbackTask : list) {
  62. try {
  63. // 委托给业务服务处理
  64. wcsTaskService.processWcsCallbackTask(callbackTask);
  65. successCount++;
  66. } catch (Exception e) {
  67. log.error("处理WCS回调任务失败:palletId={}, error={}", callbackTask.getPalletId(), e.getMessage());
  68. failCount++;
  69. // 继续处理下一个数据
  70. }
  71. }
  72. log.info("=== WCS入库/出库任务处理完成:总数={}, 成功={}, 失败={} ===", list.size(), successCount, failCount);
  73. } catch (Exception e) {
  74. log.error("=== WCS入库/出库定时任务执行失败 ===", e);
  75. }
  76. }
  77. // /**
  78. // * 定时任务:每分钟执行一次立库调栈板出库处理
  79. // * cron表达式:0 * * * * ? 表示每分钟的第0秒执行
  80. // * 配置说明:通过 scheduler.wcs.enabled 控制是否启用
  81. // */
  82. // @Scheduled(cron = "0 * * * * ?")
  83. // public void scheduleWcsPalletOutTask() {
  84. // // 检查定时任务开关
  85. // if (!enabled) {
  86. // return;
  87. // }
  88. //
  89. // log.info("=== 开始处理立库调栈板出库任务 ===");
  90. //
  91. // try {
  92. // // 获取待处理的立库调栈板出库任务
  93. // List<WmsOrderTask> list = wcsTaskService.getPendingWcsPalletOutTasks("55");
  94. //
  95. // for (WmsOrderTask orderTask : list) {
  96. // try {
  97. // // 委托给业务服务处理
  98. // wcsTaskService.processWcsPalletOutTask(orderTask);
  99. // } catch (Exception e) {
  100. // log.error("处理立库调栈板任务失败:taskNo={}, error={}", orderTask.getTaskNo(), e.getMessage());
  101. // // 继续处理下一个数据
  102. // }
  103. // }
  104. // } catch (Exception e) {
  105. // log.error("=== 立库调栈板出库定时任务执行失败 ===", e);
  106. // }
  107. //
  108. // log.info("=== 立库调栈板出库任务处理完成 ===");
  109. // }
  110. /**
  111. * @Description 定时任务每分钟处理WCS栈板RFID扫描对账只处理人工分拣sore_type=0的记录- rqrq
  112. * @Title scheduleInventoryDiscrepancyProcessing
  113. * @author rqrq
  114. * @date 2025/10/07
  115. *
  116. * cron表达式0 * * * * ? 表示每分钟的第0秒执行
  117. * 配置说明通过 scheduler.wcs.enabled 控制是否启用
  118. */
  119. @Scheduled(fixedDelay = 7745)
  120. public void scheduleInventoryDiscrepancyProcessing() {
  121. // 检查定时任务开关 - rqrq
  122. if (!enabled) {
  123. return;
  124. }
  125. log.info("=== 开始处理WCS栈板RFID扫描对账任务(只处理action_type=N'被分拣回传')- rqrq ===");
  126. try {
  127. // 获取待处理的回调记录(只查询立库内的,重试次数<3)- rqrq
  128. List<WcsCallbackPalletScan> list = wcsCallbackPalletScanMapper.getPendingCallbacks("55", 3);
  129. if (list.isEmpty()) {
  130. log.info("无待处理的WCS栈板RFID扫描对账任务(sore_type=0)- rqrq");
  131. return;
  132. }
  133. log.info("获取到 {} 个待处理的分拣任务- rqrq", list.size());
  134. int successCount = 0;
  135. int failCount = 0;
  136. for (WcsCallbackPalletScan callback : list) {
  137. try {
  138. if("被分拣回传".equals(callback.getActionType())){
  139. inventoryDiscrepancyService.processCallbackScan(callback);
  140. }
  141. if("自动分拣".equals(callback.getActionType())){
  142. autoSortService.processAutoSortCallback(callback);
  143. }
  144. successCount++;
  145. } catch (Exception e) {
  146. log.error("处理WCS栈板分拣失败 - rqrq:palletId={}, error={}",
  147. callback.getPalletId(), e.getMessage());
  148. failCount++;
  149. // 继续处理下一个数据 - rqrq
  150. }
  151. }
  152. log.info("=== WCS栈板RFID扫描对账任务处理完成 - rqrq:总数={}, 成功={}, 失败={} ===",
  153. list.size(), successCount, failCount);
  154. } catch (Exception e) {
  155. log.error("=== WCS栈板RFID扫描分拣任务执行失败 - rqrq ===", e);
  156. }
  157. }
  158. /**
  159. * @Description 定时任务每100秒执行一次齐套运输检查 - rqrq
  160. * @Title scheduleKitTransportCheck
  161. * @author rqrq
  162. * @date 2025/10/21
  163. *
  164. * fixedDelay = 100000 表示上次执行完成后间隔60秒再执行确保串行执行不会并发
  165. * 优化从3.6秒调整为60秒减少pallet表锁竞争避免死锁 - rqrq
  166. * 配置说明通过 scheduler.wcs.enabled 控制是否启用
  167. */
  168. @Scheduled(fixedDelay = 60000)
  169. public void scheduleKitTransportCheck() {
  170. // 检查定时任务开关 - rqrq
  171. if (!enabled) {
  172. return;
  173. }
  174. log.info("=== 开始齐套运输检查定时任务 - rqrq ===");
  175. try {
  176. // 调用齐套运输服务处理 - rqrq
  177. kitTransportService.processKitTransport();
  178. } catch (Exception e) {
  179. log.error("=== 齐套运输检查定时任务执行失败 - rqrq ===", e);
  180. }
  181. log.info("=== 齐套运输检查定时任务执行完成 - rqrq ===");
  182. }
  183. }