From 04c4a9bdc5c4bccd05fb0092bdb4552af2d09bb1 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期一, 29 十二月 2025 08:36:51 +0800
Subject: [PATCH] #

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java |  107 +++++++++++++++++++++++++++++++++++------------------
 1 files changed, 70 insertions(+), 37 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
index dbf5fd2..790ab43 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -2,19 +2,19 @@
 
 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.domain.AgvAction;
 import com.zy.acs.common.domain.AgvActionItem;
 import com.zy.acs.common.domain.AgvProtocol;
 import com.zy.acs.common.domain.BaseResult;
-import com.zy.acs.common.domain.protocol.AGV_11_UP;
-import com.zy.acs.common.domain.protocol.AGV_70_UP;
-import com.zy.acs.common.domain.protocol.IMessageBody;
+import com.zy.acs.common.domain.protocol.*;
 import com.zy.acs.common.domain.protocol.action.*;
 import com.zy.acs.common.enums.AgvBackpackType;
 import com.zy.acs.common.enums.AgvCompleteType;
 import com.zy.acs.common.enums.AgvDirectionType;
 import com.zy.acs.common.enums.AgvSpeedType;
 import com.zy.acs.common.utils.GsonUtils;
+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.SnowflakeIdWorker;
@@ -49,6 +49,8 @@
 @Slf4j
 @Service("mainService")
 public class MainService {
+
+    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
 
     @Autowired
     private BusService busService;
@@ -96,6 +98,8 @@
     private LaneService laneService;
     @Autowired
     private ActionSorter actionSorter;
+    @Autowired
+    private StaReserveService staReserveService;
 
     @SuppressWarnings("all")
     @Transactional
@@ -176,24 +180,14 @@
                     }
 
                     destSta = staService.getById(task.getDestSta());
-                    if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) {
-                        throw new BusinessException("destSta锛�" + task.getDestSta$() + " is not in IDLE status");
-                    }
-                    destSta.setStaSts(StaStsType.READY_RELEASE.val());
-                    destSta.setUpdateTime(now);
-                    if (!staService.updateById(destSta)) {
-                        throw new BusinessException("destSta锛�" + task.getDestSta$() + " failed to update");
+                    if (null == staReserveService.reserveStaIn(destSta, task, 1)) {
+                        throw new BusinessException("destSta锛�" + task.getDestSta$() + " failed to reserve");
                     }
                     break;
                 case STA_TO_LOC:
                     oriSta = staService.getById(task.getOriSta());
-                    if (!oriSta.getStaSts().equals(StaStsType.STOCK.val())) {
-                        throw new BusinessException("oriSta锛�" + task.getOriSta$() + " is not in STOCK status");
-                    }
-                    oriSta.setStaSts(StaStsType.READY_TAKE.val());
-                    oriSta.setUpdateTime(now);
-                    if (!staService.updateById(oriSta)) {
-                        throw new BusinessException("oriSta锛�" + task.getOriSta$() + " failed to update");
+                    if (null == staReserveService.reserveStaOut(oriSta, task, 1)) {
+                        throw new BusinessException("oriSta锛�" + task.getOriSta$() + " failed to reserve");
                     }
 
                     destLoc = locService.getById(task.getDestLoc());
@@ -208,23 +202,13 @@
                     break;
                 case STA_TO_STA:
                     oriSta = staService.getById(task.getOriSta());
-                    if (!oriSta.getStaSts().equals(StaStsType.STOCK.val())) {
-                        throw new BusinessException("oriSta锛�" + task.getOriSta$() + " is not in STOCK status");
-                    }
-                    oriSta.setStaSts(StaStsType.READY_TAKE.val());
-                    oriSta.setUpdateTime(now);
-                    if (!staService.updateById(oriSta)) {
-                        throw new BusinessException("oriSta锛�" + task.getOriSta$() + " failed to update");
+                    if (null == staReserveService.reserveStaOut(oriSta, task, 1)) {
+                        throw new BusinessException("oriSta锛�" + task.getOriSta$() + " failed to reserve");
                     }
 
                     destSta = staService.getById(task.getDestSta());
-                    if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) {
-                        throw new BusinessException("destSta锛�" + task.getDestSta$() + " is not in IDLE status");
-                    }
-                    destSta.setStaSts(StaStsType.READY_RELEASE.val());
-                    destSta.setUpdateTime(now);
-                    if (!staService.updateById(destSta)) {
-                        throw new BusinessException("destSta锛�" + task.getDestSta$() + " failed to update");
+                    if (null == staReserveService.reserveStaIn(destSta, task, 1)) {
+                        throw new BusinessException("destSta锛�" + task.getDestSta$() + " failed to reserve");
                     }
                     break;
                 default:
@@ -249,10 +233,12 @@
             );
 
             if (Cools.isEmpty(taskList)) {
-                bus.setBusSts(BusStsType.PROGRESS.val());
-                bus.setUpdateTime(now);
-                if (!busService.updateById(bus)) {
-                    log.error("Bus [{}] failed to Update 锛侊紒锛�", bus.getUuid());
+                if (bus.getBusSts().equals(BusStsType.RECEIVE.val())) {
+                    bus.setBusSts(BusStsType.PROGRESS.val());
+                    bus.setUpdateTime(now);
+                    if (!busService.updateById(bus)) {
+                        log.error("Bus [{}] failed to Update 锛侊紒锛�", bus.getUuid());
+                    }
                 }
                 return;
             }
@@ -1112,7 +1098,24 @@
                         ));
                         break;
                     case TO_STANDBY:
-//                        FuncSta standByFuncSta = funcStaService.query(agvId, lastCode.getId(), 2);
+                        // load lift
+//                        actionList.add(new Action(
+//                                null,    // 缂栧彿
+//                                null,    // 鎬荤嚎
+//                                task.getId(),    // 浠诲姟
+//                                null,    // 鍔ㄤ綔鍙�
+//                                null,    // 浼樺厛绾�
+//                                ActionTypeType.LoadPlatformLift.desc,    // 鍚嶇О
+//                                null,    // 灞炴�у��
+//                                lastCode.getData(),    // 鍦伴潰鐮�
+//                                String.valueOf(0),   // 鍔ㄤ綔鍙傛暟
+//                                ActionTypeType.LoadPlatformLift.val(),    // 鍔ㄤ綔绫诲瀷
+//                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+//                                agvId,    // AGV
+//                                now    // 宸ヤ綔鏃堕棿
+//                        ));
+                        // turn
+//                        FuncSta standByFuncSta = funcStaService.query(lastCode.getId(), FuncStaType.STANDBY.toString());
 //                        Double standByDirection = Double.parseDouble(standByFuncSta.getAngle());
 //                        if (!lastDirection.equals(standByDirection)) {
 //                            actionList.add(new Action(
@@ -1177,6 +1180,7 @@
             for (Segment item : segmentList) {
                 item.setGroupId(groupId);
                 item.setState(SegmentStateType.RUNNING.toString());
+                item.setStartTime(now);
                 item.setUpdateTime(now);
                 if (null != algoStartTime) {
                     item.setAlgoTime((int) (now.getTime() - algoStartTime.getTime()));
@@ -1297,6 +1301,13 @@
                         break;
                     case ReadyReleaseToShelvesLoc:
                         agvAction.add(new AgvActionItem<>(ReadyReleaseToShelvesLoc.class)
+                                .setVal(action.getVal().intValue())
+                                .setQrCode(action.getCode())
+                                .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
+                        );
+                        break;
+                    case LoadPlatformLift:
+                        agvAction.add(new AgvActionItem<>(LoadPlatformLift.class)
                                 .setVal(action.getVal().intValue())
                                 .setQrCode(action.getCode())
                                 .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
@@ -1450,6 +1461,26 @@
             }
         }
 
+        // 鍙栨斁璐ц姹傚寘
+        if (msgBody instanceof AGV_06_UP) {
+            AGV_06_UP agv_06_up = (AGV_06_UP) msgBody;
+
+            log.info("Agv [{}] 鍙栨斁璐ц姹傚寘 ===>> {}", protocol.getAgvNo(), JSON.toJSONString(agv_06_up));
+
+            // query current segment
+            Segment currSeg = segmentService.getCurrRunningSeg(agv.getId(), agv_06_up.getQrCode());
+
+
+            // todo:vincent 鏍¢獙鏄惁鍙互鍙栨斁璐�
+
+            AGV_06_DOWN agv_06_down = new AGV_06_DOWN();
+            agv_06_down.setSerialNo(agv_06_up.getSerialNo());
+            agv_06_down.setActionCode(agv_06_up.getActionCode());
+            agv_06_down.setResult(1);
+
+            redis.push(RedisConstant.AGV_PATH_DOWN_FLAG, AgvProtocol.build(protocol.getAgvNo()).setMessageBody(agv_06_down));
+        }
+
         // 鏂欎粨淇℃伅鍖�
         if (msgBody instanceof AGV_70_UP) {
             AGV_70_UP agv_70_up = (AGV_70_UP) msgBody;
@@ -1497,7 +1528,7 @@
             }
 
             if (taskComplete) {
-                locService.taskCallBack(task);
+//                locService.taskCallBack(task);
 
                 task.setTaskSts(TaskStsType.COMPLETE.val());
                 task.setEndTime(now);
@@ -1505,6 +1536,7 @@
                 if (!taskService.updateById(task)) {
                     log.error("Task [{}] 鏇存柊澶辫触 锛侊紒锛�", task.getSeqNum());
                 } else {
+                    taskService.maintainLocAndSta(task);
                     log.info("Task [{}] 浣滀笟瀹屾瘯 ==========>> ", task.getSeqNum());
                 }
 
@@ -1530,6 +1562,7 @@
         // segment
         for (Segment segment : segmentList) {
             segment.setState(SegmentStateType.FINISH.toString());
+            segment.setEndTime(now);
             segment.setUpdateTime(now);
             if (!segmentService.updateById(segment)) {
                 log.error("Segment [{}] 鏇存柊澶辫触 锛侊紒锛�", segment.getGroupId() + " - " + segment.getSerial());

--
Gitblit v1.9.1