From 44e258e4f5370a14e92e3c15bccd32e1e4d7280c Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 02 四月 2026 23:17:25 +0800
Subject: [PATCH] #路径清理

---
 src/main/java/com/zy/asrs/task/WrkMastScheduler.java |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 102 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/zy/asrs/task/WrkMastScheduler.java b/src/main/java/com/zy/asrs/task/WrkMastScheduler.java
index e9d01c5..81946e9 100644
--- a/src/main/java/com/zy/asrs/task/WrkMastScheduler.java
+++ b/src/main/java/com/zy/asrs/task/WrkMastScheduler.java
@@ -3,17 +3,19 @@
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zy.asrs.domain.enums.NotifyMsgType;
+import com.zy.asrs.entity.BasStation;
 import com.zy.asrs.entity.LocMast;
 import com.zy.asrs.entity.WrkMast;
-import com.zy.asrs.service.LocMastService;
-import com.zy.asrs.service.WrkMastLogService;
-import com.zy.asrs.service.WrkMastService;
+import com.zy.asrs.service.*;
 import com.zy.asrs.utils.NotifyUtils;
+import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.LocStsType;
+import com.zy.core.enums.SlaveType;
 import com.zy.core.enums.WrkIoType;
 import com.zy.core.enums.WrkStsType;
+import com.zy.core.thread.StationThread;
+import com.zy.core.utils.StationOperateProcessUtils;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
@@ -26,14 +28,30 @@
 @Slf4j
 public class WrkMastScheduler {
 
-    @Autowired
-    private WrkMastService wrkMastService;
-    @Autowired
-    private WrkMastLogService wrkMastLogService;
-    @Autowired
-    private LocMastService locMastService;
-    @Autowired
-    private NotifyUtils notifyUtils;
+    private final WrkMastService wrkMastService;
+    private final WrkMastLogService wrkMastLogService;
+    private final WrkAnalysisService wrkAnalysisService;
+    private final LocMastService locMastService;
+    private final NotifyUtils notifyUtils;
+    private final StationOperateProcessUtils stationOperateProcessUtils;
+    private final BasStationService basStationService;
+
+    public WrkMastScheduler(WrkMastService wrkMastService,
+                            WrkMastLogService wrkMastLogService,
+                            WrkAnalysisService wrkAnalysisService,
+                            LocMastService locMastService,
+                            NotifyUtils notifyUtils,
+                            StationOperateProcessUtils stationOperateProcessUtils,
+                            BasStationService basStationService
+    ) {
+        this.wrkMastService = wrkMastService;
+        this.wrkMastLogService = wrkMastLogService;
+        this.wrkAnalysisService = wrkAnalysisService;
+        this.locMastService = locMastService;
+        this.notifyUtils = notifyUtils;
+        this.stationOperateProcessUtils = stationOperateProcessUtils;
+        this.basStationService = basStationService;
+    }
 
     @Scheduled(cron = "0/1 * * * * ? ")
     @Transactional
@@ -44,6 +62,10 @@
         }
 
         for (WrkMast wrkMast : wrkMasts) {
+            Integer taskNo = wrkMast.getWrkNo();
+            Integer sourceStaNo = wrkMast.getSourceStaNo();
+            Integer staNo = wrkMast.getStaNo();
+
             String locNo = wrkMast.getLocNo();
             LocMast locMast = locMastService.queryByLoc(locNo);
             if (locMast == null) {
@@ -68,6 +90,8 @@
             // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
             if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
                 log.info("淇濆瓨宸ヤ綔鍘嗗彶妗workNo={}]澶辫触", wrkMast.getWrkNo());
+            } else {
+                wrkAnalysisService.finishTask(wrkMast, resolveFinishTime(wrkMast));
             }
             // 鍒犻櫎宸ヤ綔涓绘。
             if (!wrkMastService.removeById(wrkMast.getWrkNo())) {
@@ -76,6 +100,17 @@
 
             //涓婃姤
             notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.TASK_COMPLETE, JSON.toJSONString(wrkMast));
+
+            //娓呯悊璺緞
+            List<BasStation> basStations = basStationService.list(new QueryWrapper<BasStation>().in("station_id", sourceStaNo, staNo));
+            if (!basStations.isEmpty()) {
+                for (BasStation basStation : basStations) {
+                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
+                    if (stationThread != null) {
+                        stationOperateProcessUtils.attemptClearTaskPath(stationThread, taskNo);
+                    }
+                }
+            }
         }
     }
 
@@ -88,6 +123,10 @@
         }
 
         for (WrkMast wrkMast : wrkMasts) {
+            Integer taskNo = wrkMast.getWrkNo();
+            Integer sourceStaNo = wrkMast.getSourceStaNo();
+            Integer staNo = wrkMast.getStaNo();
+
             String locNo = wrkMast.getSourceLocNo();
             LocMast locMast = locMastService.queryByLoc(locNo);
             if (locMast == null) {
@@ -112,6 +151,8 @@
             // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
             if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
                 log.info("淇濆瓨宸ヤ綔鍘嗗彶妗workNo={}]澶辫触", wrkMast.getWrkNo());
+            } else {
+                wrkAnalysisService.finishTask(wrkMast, resolveFinishTime(wrkMast));
             }
             // 鍒犻櫎宸ヤ綔涓绘。
             if (!wrkMastService.removeById(wrkMast.getWrkNo())) {
@@ -120,6 +161,17 @@
 
             //涓婃姤
             notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.TASK_COMPLETE, JSON.toJSONString(wrkMast));
+
+            //娓呯悊璺緞
+            List<BasStation> basStations = basStationService.list(new QueryWrapper<BasStation>().in("station_id", sourceStaNo, staNo));
+            if (!basStations.isEmpty()) {
+                for (BasStation basStation : basStations) {
+                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
+                    if (stationThread != null) {
+                        stationOperateProcessUtils.attemptClearTaskPath(stationThread, taskNo);
+                    }
+                }
+            }
         }
     }
 
@@ -177,6 +229,8 @@
             // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
             if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
                 log.info("淇濆瓨宸ヤ綔鍘嗗彶妗workNo={}]澶辫触", wrkMast.getWrkNo());
+            } else {
+                wrkAnalysisService.finishTask(wrkMast, resolveFinishTime(wrkMast));
             }
             // 鍒犻櫎宸ヤ綔涓绘。
             if (!wrkMastService.removeById(wrkMast.getWrkNo())) {
@@ -185,6 +239,27 @@
 
             //涓婃姤
             notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.TASK_COMPLETE, JSON.toJSONString(wrkMast));
+        }
+    }
+
+    @Scheduled(cron = "0/1 * * * * ? ")
+    @Transactional
+    public void executeCrnMove(){
+        List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>().eq("wrk_sts", WrkStsType.COMPLETE_CRN_MOVE.sts));
+        if (wrkMasts.isEmpty()) {
+            return;
+        }
+
+        for (WrkMast wrkMast : wrkMasts) {
+            if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
+                log.info("淇濆瓨宸ヤ綔鍘嗗彶妗workNo={}]澶辫触", wrkMast.getWrkNo());
+            } else {
+                wrkAnalysisService.finishTask(wrkMast, resolveFinishTime(wrkMast));
+            }
+
+            if (!wrkMastService.removeById(wrkMast.getWrkNo())) {
+                log.info("鍒犻櫎宸ヤ綔涓绘。[workNo={}]澶辫触", wrkMast.getWrkNo());
+            }
         }
     }
 
@@ -200,6 +275,8 @@
             // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
             if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
                 log.info("淇濆瓨宸ヤ綔鍘嗗彶妗workNo={}]澶辫触", wrkMast.getWrkNo());
+            } else {
+                wrkAnalysisService.finishTask(wrkMast, resolveFinishTime(wrkMast));
             }
             // 鍒犻櫎宸ヤ綔涓绘。
             if (!wrkMastService.removeById(wrkMast.getWrkNo())) {
@@ -273,4 +350,17 @@
         }
     }
 
+    private Date resolveFinishTime(WrkMast wrkMast) {
+        if (wrkMast == null) {
+            return new Date();
+        }
+        if (wrkMast.getModiTime() != null) {
+            return wrkMast.getModiTime();
+        }
+        if (wrkMast.getIoTime() != null) {
+            return wrkMast.getIoTime();
+        }
+        return new Date();
+    }
+
 }

--
Gitblit v1.9.1