From 5c3f2ceeaead80ce4b12be933ddf759cf8bddefc Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期一, 02 二月 2026 15:07:42 +0800
Subject: [PATCH] #

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/HandlerController.java |  105 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 77 insertions(+), 28 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/HandlerController.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/HandlerController.java
index 9142b9c..56079cf 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/HandlerController.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/HandlerController.java
@@ -3,12 +3,13 @@
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.acs.common.constant.RedisConstant;
+import com.zy.acs.common.utils.Base62;
 import com.zy.acs.common.utils.RedisSupport;
-import com.zy.acs.common.utils.Utils;
 import com.zy.acs.framework.common.Cools;
 import com.zy.acs.framework.common.R;
 import com.zy.acs.framework.common.SnowflakeIdWorker;
 import com.zy.acs.manager.common.annotation.OperationLog;
+import com.zy.acs.manager.common.config.UplinkProperties;
 import com.zy.acs.manager.common.domain.param.HandlerPublishParam;
 import com.zy.acs.manager.common.exception.BusinessException;
 import com.zy.acs.manager.core.service.*;
@@ -64,7 +65,7 @@
     @Autowired
     private StaService staService;
     @Autowired
-    private TrafficService trafficService;
+    private UplinkProperties uplinkProperties;
     @Autowired
     private ThreadPoolRegulator threadPoolRegulator;
     @Autowired
@@ -75,6 +76,8 @@
     private PatrolService patrolService;
     @Autowired
     private StaReserveService staReserveService;
+    @Autowired
+    private AgvAreaDispatcher agvAreaDispatcher;
 
     @PreAuthorize("hasAuthority('manager:agv:update')")
     @OperationLog("Locate All Agv")
@@ -151,12 +154,30 @@
                     .eq(Task::getTaskSts, TaskStsType.ASSIGN.val())
                             .or().eq(Task::getTaskSts, TaskStsType.PROGRESS.val());
                 })) > 0) {
-            log.info(agv.getUuid() + "鍙稟GV涓嶅彲鐢紝宸茬粡瀛樺湪杩涜涓殑浠诲姟...");
+            log.info("{}鍙稟GV涓嶅彲鐢紝宸茬粡瀛樺湪杩涜涓殑浠诲姟...", agv.getUuid());
             return R.error();
         }
         if (!agvService.judgeEnable(agv.getId())) {
-            log.info(agv.getUuid() + "鍙稟GV涓嶅彲鐢紝浠诲姟鏃犳硶璁$畻...");
+            log.info("{}鍙稟GV涓嶅彲鐢紝浠诲姟鏃犳硶璁$畻...", agv.getUuid());
             return R.error();
+        }
+
+        Task task = new Task();
+        task.setAgvId(agv.getId());
+        task.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
+//        List<Task> lastTasks = taskService.list(new LambdaQueryWrapper<Task>().orderByDesc(Task::getId));
+//        task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks)?null:lastTasks.get(0).getSeqNum()));
+        task.setSeqNum(Base62.encode(snowflakeIdWorker.nextId()));
+
+        task.setTaskType(param.getTaskMode().val());
+        task.setTaskSts(TaskStsType.WAITING.val());
+        task.setUplinkSts(uplinkProperties.getEnabled() ? TaskUplinkStateType.PENDING.toString() : TaskUplinkStateType.SKIPPED.toString());
+        task.setPriority(999);
+        task.setIoTime(now);
+        task.setStartTime(now);
+        task.setMemo("AUTO");
+        if (!taskService.save(task)) {
+            throw new BusinessException(task.getSeqNum() + "浠诲姟淇濆瓨澶辫触");
         }
 
         // generate
@@ -164,7 +185,6 @@
         Loc destLoc = null;
         Sta oriSta = null;
         Sta destSta = null;
-        Task task = null;
         switch (param.getTaskMode()) {
             case MOVE:
                 Code endCode = null;
@@ -177,12 +197,23 @@
                 if (null == endCode) {
                     return R.error();
                 }
+                if (!agvAreaDispatcher.match(agv.getId(), endCode.getId())) {
+                    throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + endCode.getData());
+                }
+                if (!taskService.removeById(task.getId())) {
+                    throw new BusinessException("failed to remove task");
+                }
+                task = null;
                 if (!mainLockWrapService.buildMinorTask(agv.getId(), param.getTaskMode(), endCode.getData(), null)) {
                     return R.error();
                 }
                 break;
             case TO_CHARGE:
             case TO_STANDBY:
+                if (!taskService.removeById(task.getId())) {
+                    throw new BusinessException("failed to remove task");
+                }
+                task = null;
                 if (!mainLockWrapService.buildMinorTask(agv.getId(), param.getTaskMode(), null, null)) {
                     return R.error();
                 }
@@ -197,6 +228,10 @@
                 }
                 if (null == oriLoc) {
                     return R.error();
+                }
+                if (!agvAreaDispatcher.match(agv.getId(), oriLoc.getCode())) {
+//                    throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + oriLoc.getCode$());
+                    throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈捐捣濮嬪簱浣嶃��" + oriLoc.getLocNo() + "銆�");
                 }
                 if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
                     throw new BusinessException("oriLoc锛�" + oriLoc.getLocNo() + " 涓嶆槸鍦ㄥ簱鐘舵��");
@@ -217,6 +252,10 @@
                 if (null == destLoc) {
                     return R.error();
                 }
+                if (!agvAreaDispatcher.match(agv.getId(), destLoc.getCode())) {
+//                    throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + destLoc.getCode$());
+                    throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈剧洰鏍囧簱浣嶃��" + destLoc.getLocNo() + "銆�");
+                }
                 if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
                     throw new BusinessException("destLoc锛�" + destLoc.getLocNo() + " 涓嶆槸绌洪棽鐘舵��");
                 }
@@ -227,8 +266,6 @@
                 }
 
                 // task
-                task = new Task();
-
                 task.setOriLoc(oriLoc.getId());
                 task.setOriCode(oriLoc.getCode());
                 task.setDestLoc(destLoc.getId());
@@ -245,6 +282,10 @@
                 if (null == oriLoc) {
                     return R.error();
                 }
+                if (!agvAreaDispatcher.match(agv.getId(), oriLoc.getCode())) {
+//                    throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + oriLoc.getCode$());
+                    throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈捐捣濮嬪簱浣嶃��" + oriLoc.getLocNo() + "銆�");
+                }
                 if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
                     throw new BusinessException("oriLoc锛�" + oriLoc.getLocNo() + " 涓嶆槸鍦ㄥ簱鐘舵��");
                 }
@@ -264,17 +305,20 @@
                 if (null == destSta) {
                     return R.error();
                 }
+                if (!agvAreaDispatcher.match(agv.getId(), destSta.getCode())) {
+//                    throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + destSta.getCode$());
+                    throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈剧洰鏍囩珯鐐广��" + destSta.getStaNo() + "銆�");
+                }
                 if (null == staReserveService.reserveStaIn(destSta, task, 1)) {
                     throw new BusinessException("destSta锛�" + destSta.getStaNo() + " 棰勭害澶辫触");
                 }
-
                 // task
-                task = new Task();
-
                 task.setOriLoc(oriLoc.getId());
                 task.setOriCode(oriLoc.getCode());
                 task.setDestSta(destSta.getId());
                 task.setDestCode(destSta.getCode());
+
+                staReserveService.allocateCallBack(task, agv.getId());
                 break;
             case STA_TO_LOC:
                 // oriSta
@@ -286,6 +330,10 @@
                 }
                 if (null == oriSta) {
                     return R.error();
+                }
+                if (!agvAreaDispatcher.match(agv.getId(), oriSta.getCode())) {
+//                    throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + oriSta.getCode$());
+                    throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈捐捣濮嬬珯鐐广��" + oriSta.getStaNo() + "銆�");
                 }
                 if (null == staReserveService.reserveStaOut(oriSta, task, 1)) {
                     throw new BusinessException("oriSta锛�" + oriSta.getStaNo() + " 棰勭害澶辫触");
@@ -301,6 +349,10 @@
                 if (null == destLoc) {
                     return R.error();
                 }
+                if (!agvAreaDispatcher.match(agv.getId(), destLoc.getCode())) {
+//                    throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + destLoc.getCode$());
+                    throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈剧洰鏍囧簱浣嶃��" + destLoc.getLocNo() + "銆�");
+                }
                 if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
                     throw new BusinessException("destLoc锛�" + destLoc.getLocNo() + " 涓嶆槸绌洪棽鐘舵��");
                 }
@@ -311,12 +363,12 @@
                 }
 
                 // task
-                task = new Task();
-
                 task.setOriSta(oriSta.getId());
                 task.setOriCode(oriSta.getCode());
                 task.setDestLoc(destLoc.getId());
                 task.setDestCode(destLoc.getCode());
+
+                staReserveService.allocateCallBack(task, agv.getId());
                 break;
             case STA_TO_STA:
                 // oriSta
@@ -329,9 +381,14 @@
                 if (null == oriSta) {
                     return R.error();
                 }
+                if (!agvAreaDispatcher.match(agv.getId(), oriSta.getCode())) {
+//                    throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + oriSta.getCode$());
+                    throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈捐捣濮嬬珯鐐广��" + oriSta.getStaNo() + "銆�");
+                }
                 if (null == staReserveService.reserveStaOut(oriSta, task, 1)) {
                     throw new BusinessException("oriSta锛�" + oriSta.getStaNo() + " 棰勭害澶辫触");
                 }
+
 
                 // destSta
                 if (!Cools.isEmpty(param.getEndStaNo())) {
@@ -343,39 +400,31 @@
                 if (null == destSta) {
                     return R.error();
                 }
+                if (!agvAreaDispatcher.match(agv.getId(), destSta.getCode())) {
+//                    throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + destSta.getCode$());
+                    throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈剧洰鏍囩珯鐐广��" + destSta.getStaNo() + "銆�");
+                }
                 if (null == staReserveService.reserveStaIn(destSta, task, 1)) {
                     throw new BusinessException("destSta锛�" + destSta.getStaNo() + " 棰勭害澶辫触");
                 }
 
                 // task
-                task = new Task();
-
                 task.setOriSta(oriSta.getId());
                 task.setOriCode(oriSta.getCode());
                 task.setDestSta(destSta.getId());
                 task.setDestCode(destSta.getCode());
+
+                staReserveService.allocateCallBack(task, agv.getId());
                 break;
             default:
                 break;
         }
 
         if (null != task) {
-            task.setAgvId(agv.getId());
-            task.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
-            List<Task> lastTasks = taskService.list(new LambdaQueryWrapper<Task>().orderByDesc(Task::getId));
-            task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks)?null:lastTasks.get(0).getSeqNum()));
-
-            task.setTaskType(param.getTaskMode().val());
-            task.setTaskSts(TaskStsType.WAITING.val());
-
-            task.setPriority(999);
-            task.setIoTime(now);
-            task.setStartTime(now);
-            if (!taskService.save(task)) {
-                throw new BusinessException(task.getSeqNum() + "浠诲姟淇濆瓨澶辫触");
+            if (!taskService.updateById(task)) {
+                throw new BusinessException("浠诲姟鏇存柊澶辫触");
             }
         }
-
         return R.ok();
     }
 

--
Gitblit v1.9.1