From 4593926f14da39a1a241b996d3d2453c28587207 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期六, 09 八月 2025 14:56:45 +0800
Subject: [PATCH] 保存一个版本

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java |  321 ++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 228 insertions(+), 93 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 7a4edd4..afc92d9 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
@@ -96,6 +96,10 @@
     private LaneService laneService;
     @Autowired
     private ActionSorter actionSorter;
+    @Autowired
+    private TaskReportService taskReportService;
+    @Autowired
+    private AgvDurationService agvDurationService;
 
     @SuppressWarnings("all")
     @Transactional
@@ -249,10 +253,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;
             }
@@ -271,6 +277,7 @@
                 if (!taskService.updateById(task)) {
                     throw new BusinessException("seqNum: " + task.getSeqNum() + " failed to update");
                 }
+                report(task, TaskReportStsType.START);
             }
         } catch (Exception e) {
             log.error("mainService.infuseAgvForTask", e);
@@ -284,7 +291,9 @@
      */
     @Transactional(propagation = Propagation.REQUIRES_NEW)
     public void buildMajorTask(Long agvId, List<Task> taskList) {
-        if (Cools.isEmpty(agvId, taskList)) { return; }
+        if (Cools.isEmpty(agvId, taskList)) {
+            return;
+        }
         try {
             // valid -----------------------------------------------
             Agv agv = agvService.getById(agvId);
@@ -324,16 +333,18 @@
              * val: new TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType)
              */
             Map<String, List<TaskPosDto>> groups = new HashMap<>();
-            final String sameGroupXy = configService.getVal( "sameGroupXy", String.class);
+            final String sameGroupXy = configService.getVal("sameGroupXy", String.class);
 
             int backpackLev = 0;
             for (Task task : taskList) {
 
-                backpackLev ++;
+                backpackLev++;
                 Code startCode = null;
                 Code endCode = null;
-                Loc oriLoc = null; Loc destLoc = null;
-                Sta oriSta = null; Sta destSta = null;
+                Loc oriLoc = null;
+                Loc destLoc = null;
+                Sta oriSta = null;
+                Sta destSta = null;
                 switch (Objects.requireNonNull(TaskTypeType.get(task.getTaskTypeEl()))) {
                     case LOC_TO_LOC:
                         oriLoc = locService.getById(task.getOriLoc());
@@ -436,7 +447,7 @@
 
             // re-order by agv current position
             Code currCode = codeService.getCacheById(agvDetail.getRecentCode());
-            Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()};
+            Double[] currPosition = new Double[]{currCode.getX(), currCode.getY()};
 
             List<List<TaskPosDto>> pickGroups = new ArrayList<>();
             List<List<TaskPosDto>> dropGroups = new ArrayList<>();
@@ -482,7 +493,7 @@
             List<Segment> segmentList = new ArrayList<>();
             for (List<TaskPosDto> dtoList : list) {
                 for (TaskPosDto taskPosDto : dtoList) {
-                    segSerial ++;
+                    segSerial++;
                     AgvBackpackType backpackType = AgvBackpackDto.find(backpackDtoList, taskPosDto.getTaskId());
                     assert null != backpackType;
 
@@ -530,9 +541,12 @@
     /**
      * 鍏呯數 鍥炲緟鏈轰綅浠诲姟
      */
-    @Transactional(propagation = Propagation.REQUIRES_NEW) // although there is a Transactional here that the lock is isolated, but we can't join the caller's Transactional
+    @Transactional(propagation = Propagation.REQUIRES_NEW)
+    // although there is a Transactional here that the lock is isolated, but we can't join the caller's Transactional
     public boolean buildMinorTask(Long agvId, TaskTypeType taskType, String destination, Jam jam) {
-        if (Cools.isEmpty(agvId, taskType)) { return false; }
+        if (Cools.isEmpty(agvId, taskType)) {
+            return false;
+        }
         try {
             String agvNo = agvService.getAgvNo(agvId);
             if (!agvService.judgeEnable(agvId)) {
@@ -579,7 +593,7 @@
             task.setAgvId(agvId);
             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(Utils.generateSeqNum(Cools.isEmpty(lastTasks) ? null : lastTasks.get(0).getSeqNum()));
             task.setOriCode(agvDetail.getCode());
             task.setDestCode(endCode.getId());
             // lane
@@ -587,7 +601,7 @@
             if (null != destLane) {
                 task.setDestLaneHash(destLane.getHashCode());
             }
-            task.setPriority(taskType.equals(TaskTypeType.TO_CHARGE)?2:1);
+            task.setPriority(taskType.equals(TaskTypeType.TO_CHARGE) ? 2 : 1);
             task.setTaskSts(TaskStsType.ASSIGN.val());
             task.setTaskType(taskType.val());
             task.setIoTime(now);
@@ -595,6 +609,7 @@
             if (!taskService.save(task)) {
                 throw new BusinessException(task.getSeqNum() + " failed to save");
             }
+
 
             // generate travel
             Travel travel = new Travel();
@@ -609,13 +624,20 @@
             }
 
             // generate segment
-            int segSerial = 0;     segSerial ++;
+            int segSerial = 0;
+            segSerial++;
             List<Segment> segmentList = new ArrayList<>();
 
             String posType = "";
-            switch (taskType){
+            switch (taskType) {
                 case TO_CHARGE:
                     posType = TaskPosDto.PosType.TO_CHARGE.toString();
+                    //鎻掑叆鍏呯數浠诲姟
+                    AgvDuration agvDuration = new AgvDuration();
+                    agvDuration.setHappenTime(now);
+                    agvDuration.setAgvId(agvId);
+                    agvDuration.setTaskNo(task.getId());
+                    agvDurationService.save(agvDuration);
                     break;
                 case TO_STANDBY:
                     posType = TaskPosDto.PosType.TO_STANDBY.toString();
@@ -685,7 +707,9 @@
     @Transactional
     public synchronized void generateAction(Long agvId, List<Segment> segmentList, List<String> pathList, Date algoStartTime) {
         try {
-            if (Cools.isEmpty(agvId, segmentList)) { return; }
+            if (Cools.isEmpty(agvId, segmentList)) {
+                return;
+            }
             Date now = new Date();
             long actionPrepareSts = ActionStsType.PREPARE.val();
 //            JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class);
@@ -727,7 +751,9 @@
                     List<String> pathListPart = pathList.subList(pathList.indexOf(lastCode.getData()), pathList.indexOf(code.getData()) + 1);
 
                     for (int i = 0; i < pathListPart.size(); i++) {
-                        if (i == 0) { continue; }
+                        if (i == 0) {
+                            continue;
+                        }
 
                         String next = pathListPart.get(i);
 
@@ -859,6 +885,7 @@
 
                 // 浣滀笟鐐瑰姩浣�
                 AgvDirectionType agvDirectionType;
+                Double staWorkDirection;
                 AgvBackpackType backpackType = AgvBackpackType.query(segment.getBackpack());
                 switch (Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType()))) {
                     case ORI_LOC:
@@ -935,7 +962,7 @@
                                 task.getBusId(),    // 鎬荤嚎
                                 task.getId(),    // 浠诲姟
                                 null,    // 鍔ㄤ綔鍙�
-                                 null,    // 浼樺厛绾�
+                                null,    // 浼樺厛绾�
                                 ActionTypeType.ReadyReleaseToShelvesLoc.desc,    // 鍚嶇О
                                 (double) agvDirectionType.val,    // 灞炴�у��
                                 lastCode.getData(),    // 鍦伴潰鐮�
@@ -963,7 +990,7 @@
                                     null,    // 鍔ㄤ綔鍙�
                                     null,    // 浼樺厛绾�
                                     ActionTypeType.TurnCorner.desc,    // 鍚嶇О
-                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 灞炴�у��
+                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 灞炴�ш皰
                                     lastCode.getData(),    // 鍦伴潰鐮�
                                     String.valueOf(oriStaWorkDirection),   // 鍔ㄤ綔鍙傛暟
                                     ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
@@ -974,18 +1001,18 @@
                             lastDirection = oriStaWorkDirection;
                         }
                         // 璁$畻璐у弶宸ヤ綔鏂瑰悜
-                        agvDirectionType = mapService.calculateAgvWorkDirectionByStation(oriSta, lastCode);
+                        staWorkDirection = mapService.calculateAgvWorkDirectionByStation(oriStaWorkDirection, lastDirection);
                         actionList.add(new Action(
                                 null,    // 缂栧彿
                                 task.getBusId(),    // 鎬荤嚎
                                 task.getId(),    // 浠诲姟
                                 null,    // 鍔ㄤ綔鍙�
                                 null,    // 浼樺厛绾�
-                                ActionTypeType.ReadyTakeFromShelvesLoc.desc,    // 鍚嶇О
-                                (double) agvDirectionType.val,    // 灞炴�у��
+                                ActionTypeType.ReadyTakeFromConveyorSta.desc,    // 鍚嶇О
+                                staWorkDirection,    // 灞炴�у��
                                 lastCode.getData(),    // 鍦伴潰鐮�
                                 String.valueOf(oriSta.getOffset()),   // 鍔ㄤ綔鍙傛暟
-                                ActionTypeType.ReadyTakeFromShelvesLoc.val(),    // 鍔ㄤ綔绫诲瀷
+                                ActionTypeType.ReadyTakeFromConveyorSta.val(),    // 鍔ㄤ綔绫诲瀷
                                 actionPrepareSts,    // 鍔ㄤ綔杩涘害
                                 agvId,    // AGV
                                 now    // 宸ヤ綔鏃堕棿
@@ -999,7 +1026,7 @@
                                 null,    // 鍔ㄤ綔鍙�
                                 null,    // 浼樺厛绾�
                                 ActionTypeType.ReadyReleaseToAgvSite.desc,    // 鍚嶇О
-                                (double) backpackType.lev,    // 灞炴�у��
+                                (double) backpackType.lev,    // 灞炴�ш皰
                                 lastCode.getData(),    // 鍦伴潰鐮�
                                 String.valueOf(backpackType.height),   // 鍔ㄤ綔鍙傛暟
                                 ActionTypeType.ReadyReleaseToAgvSite.val(),    // 鍔ㄤ綔绫诲瀷
@@ -1025,7 +1052,7 @@
                                     null,    // 鍔ㄤ綔鍙�
                                     null,    // 浼樺厛绾�
                                     ActionTypeType.TurnCorner.desc,    // 鍚嶇О
-                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 灞炴�у��
+                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 灞炴�ш皰
                                     lastCode.getData(),    // 鍦伴潰鐮�
                                     String.valueOf(destStaWorkDirection),   // 鍔ㄤ綔鍙傛暟
                                     ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
@@ -1044,7 +1071,7 @@
                                 null,    // 鍔ㄤ綔鍙�
                                 null,    // 浼樺厛绾�
                                 ActionTypeType.ReadyTakeFromAgvSite.desc,    // 鍚嶇О
-                                (double) backpackType.lev,    // 灞炴�у��
+                                (double) backpackType.lev,    // 灞炴�ш皰
                                 lastCode.getData(),    // 鍦伴潰鐮�
                                 String.valueOf(backpackType.height),   // 鍔ㄤ綔鍙傛暟
                                 ActionTypeType.ReadyTakeFromAgvSite.val(),    // 鍔ㄤ綔绫诲瀷
@@ -1053,18 +1080,18 @@
                                 now    // 宸ヤ綔鏃堕棿
                         ));
                         // 璁$畻璐у弶宸ヤ綔鏂瑰悜
-                        agvDirectionType = mapService.calculateAgvWorkDirectionByStation(destSta, lastCode);
+                        staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, lastDirection);
                         actionList.add(new Action(
                                 null,    // 缂栧彿
                                 task.getBusId(),    // 鎬荤嚎
                                 task.getId(),    // 浠诲姟
                                 null,    // 鍔ㄤ綔鍙�
                                 null,    // 浼樺厛绾�
-                                ActionTypeType.ReadyReleaseToShelvesLoc.desc,    // 鍚嶇О
-                                (double) agvDirectionType.val,    // 灞炴�у��
+                                ActionTypeType.ReadyReleaseToConveyorSta.desc,    // 鍚嶇О
+                                staWorkDirection,    // 灞炴�ш皰
                                 lastCode.getData(),    // 鍦伴潰鐮�
                                 String.valueOf(destSta.getOffset()),   // 鍔ㄤ綔鍙傛暟
-                                ActionTypeType.ReadyReleaseToShelvesLoc.val(),    // 鍔ㄤ綔绫诲瀷
+                                ActionTypeType.ReadyReleaseToConveyorSta.val(),    // 鍔ㄤ綔绫诲瀷
                                 actionPrepareSts,    // 鍔ㄤ綔杩涘害
                                 agvId,    // AGV
                                 now    // 宸ヤ綔鏃堕棿
@@ -1082,7 +1109,7 @@
                                     null,    // 鍔ㄤ綔鍙�
                                     null,    // 浼樺厛绾�
                                     ActionTypeType.TurnCorner.desc,    // 鍚嶇О
-                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 灞炴�у��
+                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 灞炴�ш皰
                                     lastCode.getData(),    // 鍦伴潰鐮�
                                     String.valueOf(chargeDirection),   // 鍔ㄤ綔鍙傛暟
                                     ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
@@ -1101,7 +1128,7 @@
                                 null,    // 鍔ㄤ綔鍙�
                                 null,    // 浼樺厛绾�
                                 ActionTypeType.DockingCharge.desc,    // 鍚嶇О
-                                null,    // 灞炴�у��
+                                null,    // 灞炴�ш皰
                                 lastCode.getData(),    // 鍦伴潰鐮�
                                 null,   // 鍔ㄤ綔鍙傛暟
                                 ActionTypeType.DockingCharge.val(),    // 鍔ㄤ綔绫诲瀷
@@ -1121,7 +1148,7 @@
 //                                    null,    // 鍔ㄤ綔鍙�
 //                                    null,    // 浼樺厛绾�
 //                                    ActionTypeType.TurnCorner.desc,    // 鍚嶇О
-//                                    null,    // 灞炴�у��
+//                                    null,    // 灞炴�ш皰
 //                                    lastCode.getData(),    // 鍦伴潰鐮�
 //                                    String.valueOf(standByDirection),   // 鍔ㄤ綔鍙傛暟
 //                                    ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
@@ -1131,6 +1158,36 @@
 //                            ));
 //                            lastDirection = standByDirection;
 //                        }
+                        String runToWaitHeightFlag = configService.getVal("RunToWaitHeightFlag", String.class);
+                        if (!Cools.isEmpty(runToWaitHeightFlag) && runToWaitHeightFlag.contains(agvId.toString())) {
+                            String runToWaitHeight = configService.getVal("RunToWaitHeight", String.class);
+                            if (Cools.isEmpty(runToWaitHeight)) {
+                                runToWaitHeight = "800";
+                            }
+                            Double runToWaitHeightValue = configService.getVal("RunToWaitHeightValue", Double.class);
+                            if (runToWaitHeightValue == 0) {
+                                runToWaitHeightValue = 1D;
+                            }
+                            // 淇绌烘寚閽堝紓甯革細妫�鏌astCode鏄惁涓簄ull
+                            if (lastCode == null) {
+                                throw new BusinessException("AGV瀹氫綅淇℃伅寮傚父锛屾棤娉曠敓鎴愬緟鏈哄姩浣�");
+                            }
+                            actionList.add(new Action(
+                                    null,    // 缂栧彿
+                                    task.getBusId(),    // 鎬荤嚎
+                                    task.getId(),    // 浠诲姟
+                                    null,    // 鍔ㄤ綔鍙�
+                                    null,    // 浼樺厛绾�
+                                    ActionTypeType.RunToWaitHeight.desc,    // 鍚嶇О
+                                    runToWaitHeightValue,    // 灞炴�ш皰
+                                    lastCode.getData(),    // 鍦伴潰鐮�
+                                    runToWaitHeight,   // 鍔ㄤ綔鍙傛暟
+                                    ActionTypeType.RunToWaitHeight.val(),    // 鍔ㄤ綔绫诲瀷
+                                    actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                    agvId,    // AGV
+                                    now    // 宸ヤ綔鏃堕棿
+                            ));
+                        }
                         break;
                     case MOVE:
                         break;
@@ -1200,6 +1257,7 @@
         }
     }
 
+
     @Transactional
     public void publishAction(String actionGroupId) {
         try {
@@ -1212,6 +1270,13 @@
             if (Cools.isEmpty(actionList)) {
                 return;
             }
+
+            Long agvId = actionList.get(0).getAgvId();
+            String agvNo = agvService.getAgvNo(agvId);
+            if (!agvService.judgeOnline(agvId)) {
+                return;
+            }
+
             long actionIssuedSts = ActionStsType.ISSUED.val();
             for (Action action : actionList) {
                 action.setActionSts(actionIssuedSts);
@@ -1238,10 +1303,8 @@
                 }
             }
 
-            String agvNo = agvService.getAgvNo(actionList.get(0).getAgvId());
             AgvAction agvAction = new AgvAction(agvNo, actionGroupId);
             for (Action action : actionList) {
-
                 switch (Objects.requireNonNull(ActionTypeType.get(action.getActionTypeEl()))) {
                     case TurnCorner:
                         agvAction.add(new AgvActionItem<>(TurnCornerAction.class)
@@ -1275,6 +1338,13 @@
                                 .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
                         );
                         break;
+                    case ReadyTakeFromConveyorSta:
+                        agvAction.add(new AgvActionItem<>(ReadyTakeFromConveyorSta.class)
+                                .setVal(action.getVal().intValue())
+                                .setQrCode(action.getCode())
+                                .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
+                        );
+                        break;
                     case ReadyTakeFromAgvSite:
                         agvAction.add(new AgvActionItem<>(ReadyTakeFromAgvSite.class)
                                 .setVal(action.getVal().intValue())
@@ -1289,11 +1359,25 @@
                                 .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
                         );
                         break;
+                    case ReadyReleaseToConveyorSta:
+                        agvAction.add(new AgvActionItem<>(ReadyReleaseToConveyorSta.class)
+                                .setVal(action.getVal().intValue())
+                                .setQrCode(action.getCode())
+                                .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
+                        );
+                        break;
                     case ReadyReleaseToAgvSite:
                         agvAction.add(new AgvActionItem<>(ReadyReleaseToAgvSite.class)
                                 .setVal(action.getVal().intValue())
                                 .setQrCode(action.getCode())
                                 .bodySync(body -> body.setDepth((short) Double.parseDouble(action.getParams())))
+                        );
+                        break;
+                    case RunToWaitHeight:
+                        agvAction.add(new AgvActionItem<>(RunToWaitHeight.class)
+                                .setVal(action.getVal().intValue())
+                                .setQrCode(action.getCode())
+                                .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
                         );
                         break;
                     case FinishPath:
@@ -1350,32 +1434,39 @@
             if (agv_11_up.getCompleteType().equals(AgvCompleteType.RELEASE_FROM_SHELVES_COMPLETE)) {
                 WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode();
 
-                Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, String.valueOf(Integer.parseInt(agv_11_up.getLocCode()))));
-                if (null == loc) {
-                    log.warn("Agv [{}] 涓婃姤寰�璐ф灦鏀捐揣瀹屾垚鏃讹紝搴撲綅鐮乕{}]鏃犳晥銆�", protocol.getAgvNo(), agv_11_up.getLocCode());
-                } else {
-                    List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
-                    for (Long taskId : taskIds) {
-                        Task task = taskService.getById(taskId);
-                        if (task.getDestLoc().equals(loc.getId())) {
+//                Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, String.valueOf(Integer.parseInt(agv_11_up.getLocCode()))));
+//                if (null == loc) {
+//                    log.warn("Agv [{}] 涓婃姤寰�璐ф灦鏀捐揣瀹屾垚鏃讹紝搴撲綅鐮乕{}]鏃犳晥銆�", protocol.getAgvNo(), agv_11_up.getLocCode());
+//                } else {
+//                    List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
+//                    for (Long taskId : taskIds) {
+//                        Task task = taskService.getById(taskId);
+//                        if (task.getDestLoc().equals(loc.getId())) {
+//
+//                            Action action = actionService.getOne(new LambdaQueryWrapper<Action>()
+//                                    .eq(Action::getTaskId, task.getId())
+//                                    .eq(Action::getActionType, ActionTypeType.ReadyReleaseToShelvesLoc.val())
+//                                    .eq(Action::getActionSts, ActionStsType.ISSUED.val())
+//                            );
+//
+//                            if (null != action) {
+//                                action.setActionSts(ActionStsType.FINISH.val());
+//                                action.setEndTime(now);
+//                                action.setUpdateTime(now);
+//                                if (!actionService.updateById(action)) {
+//                                    log.error("Action [{}] 鏇存柊澶辫触 锛侊紒锛�", action.getPriority() + " - " + action.getName());
+//                                }
+//                            }
+//                            //鎻掑叆涓�鏉�
+//                            report(task, TaskReportStsType.END);
+//                        }
+//                    }
+//                }
 
-                            Action action = actionService.getOne(new LambdaQueryWrapper<Action>()
-                                    .eq(Action::getTaskId, task.getId())
-                                    .eq(Action::getActionType, ActionTypeType.ReadyReleaseToShelvesLoc.val())
-                                    .eq(Action::getActionSts, ActionStsType.ISSUED.val())
-                            );
-
-                            if (null != action) {
-                                action.setActionSts(ActionStsType.FINISH.val());
-                                action.setEndTime(now);
-                                action.setUpdateTime(now);
-                                if (!actionService.updateById(action)) {
-                                    log.error("Action [{}] 鏇存柊澶辫触 锛侊紒锛�", action.getPriority() + " - " + action.getName());
-                                }
-                            }
-
-                        }
-                    }
+                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
+                for (Long taskId : taskIds) {
+                    Task task = taskService.getById(taskId);
+                    report(task, TaskReportStsType.END);
                 }
             }
 
@@ -1383,31 +1474,56 @@
             if (agv_11_up.getCompleteType().equals(AgvCompleteType.TAKE_FROM_SHELVES_COMPLETE)) {
                 WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode();
 
-                Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, String.valueOf(Integer.parseInt(agv_11_up.getLocCode()))));
-                if (null == loc) {
-                    log.warn("Agv [{}] 涓婃姤浠庤揣鏋跺彇璐у畬鎴愶紝搴撲綅鐮乕{}]鏃犳晥銆�", protocol.getAgvNo(), agv_11_up.getLocCode());
-                } else {
+//                Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, String.valueOf(Integer.parseInt(agv_11_up.getLocCode()))));
+//                if (null == loc) {
+//                    log.warn("Agv [{}] 涓婃姤浠庤揣鏋跺彇璐у畬鎴愶紝搴撲綅鐮乕{}]鏃犳晥銆�", protocol.getAgvNo(), agv_11_up.getLocCode());
+//                } else {
+//
+//                    List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
+//                    for (Long taskId : taskIds) {
+//                        Task task = taskService.getById(taskId);
+//                        if (task.getOriLoc().equals(loc.getId())) {
+//
+//                            Action action = actionService.getOne(new LambdaQueryWrapper<Action>()
+//                                    .eq(Action::getTaskId, task.getId())
+//                                    .eq(Action::getActionType, ActionTypeType.ReadyTakeFromShelvesLoc.val())
+//                                    .eq(Action::getActionSts, ActionStsType.ISSUED.val())
+//                            );
+//                            if (null != action) {
+//                                action.setActionSts(ActionStsType.FINISH.val());
+//                                action.setEndTime(now);
+//                                action.setUpdateTime(now);
+//                                if (!actionService.updateById(action)) {
+//                                    log.error("Action [{}] 鏇存柊澶辫触 锛侊紒锛�", action.getPriority() + " - " + action.getName());
+//                                }
+//                            }
+//                            report(task, TaskReportStsType.OTBIN);
+//                        }
+//                    }
+//                }
+                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
+                for (Long taskId : taskIds) {
+                    Task task = taskService.getById(taskId);
+                    report(task, TaskReportStsType.OTBIN);
+                }
 
-                    List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
-                    for (Long taskId : taskIds) {
-                        Task task = taskService.getById(taskId);
-                        if (task.getOriLoc().equals(loc.getId())) {
-
-                            Action action = actionService.getOne(new LambdaQueryWrapper<Action>()
-                                    .eq(Action::getTaskId, task.getId())
-                                    .eq(Action::getActionType, ActionTypeType.ReadyTakeFromShelvesLoc.val())
-                                    .eq(Action::getActionSts, ActionStsType.ISSUED.val())
-                            );
-                            if (null != action) {
-                                action.setActionSts(ActionStsType.FINISH.val());
-                                action.setEndTime(now);
-                                action.setUpdateTime(now);
-                                if (!actionService.updateById(action)) {
-                                    log.error("Action [{}] 鏇存柊澶辫触 锛侊紒锛�", action.getPriority() + " - " + action.getName());
-                                }
-                            }
-                        }
-                    }
+            }
+            //浠庤緭閫佺嚎鍙栬揣瀹屾垚
+            if (agv_11_up.getCompleteType().equals(AgvCompleteType.TAKE_FROM_STA_COMPLETE)) {
+                WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode();
+                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
+                for (Long taskId : taskIds) {
+                    Task task = taskService.getById(taskId);
+                    report(task, TaskReportStsType.OTBIN);
+                }
+            }
+            //寰�杈撻�佺嚎鏀捐揣瀹屾垚
+            if (agv_11_up.getCompleteType().equals(AgvCompleteType.RELEASE_FROM_STA_COMPLETE)) {
+                WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode();
+                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
+                for (Long taskId : taskIds) {
+                    Task task = taskService.getById(taskId);
+                    report(task, TaskReportStsType.END);
                 }
             }
 
@@ -1417,9 +1533,9 @@
 
                 // segment list
                 List<Segment> segmentList = segmentService.list(new LambdaQueryWrapper<Segment>()
-                        .eq(Segment::getGroupId, serialNo)
+                                .eq(Segment::getGroupId, serialNo)
 //                        .eq(Segment::getState, SegmentStateType.RUNNING.toString())
-                        .orderByAsc(Segment::getSerial)
+                                .orderByAsc(Segment::getSerial)
                 );
 
                 // settlement
@@ -1438,6 +1554,7 @@
         }
     }
 
+
     @Transactional
     public void settleSegmentList(List<Segment> segmentList, String serialNo) {
         if (Cools.isEmpty(segmentList)) {
@@ -1449,8 +1566,10 @@
         for (Segment segment : segmentList) {
             boolean taskComplete = false;
 
-            Task task = taskService.getById(segment.getTaskId());   assert null != task;
-            TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl());     assert null != typeType;
+            Task task = taskService.getById(segment.getTaskId());
+            assert null != task;
+            TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl());
+            assert null != typeType;
 
             TaskPosDto.PosType posType = TaskPosDto.queryPosType(segment.getPosType());
             switch (Objects.requireNonNull(posType)) {
@@ -1484,10 +1603,7 @@
                 task.setUpdateTime(now);
                 if (!taskService.updateById(task)) {
                     log.error("Task [{}] 鏇存柊澶辫触 锛侊紒锛�", task.getSeqNum());
-                } else {
-                    log.info("Task [{}] 浣滀笟瀹屾瘯 ==========>> ", task.getSeqNum());
                 }
-
             }
         }
 
@@ -1520,4 +1636,23 @@
         segmentService.processNext(segmentList);
     }
 
+    /**
+     * 涓婃姤缁欎笂娓哥郴缁燂紝灏辨槸鎻掑叆涓�鏉℃暟鎹埌涓婃姤琛�
+     */
+    private void report(Task task, TaskReportStsType taskReportStsType) {
+        // TODO 鎻掑叆涓�鏉′笂鎶ヨ褰�
+        TaskReport taskReport = new TaskReport();
+        taskReport.setAgvId(task.getAgvId());
+        taskReport.setBusNo(task.getBusId$());
+        taskReport.setCreateTime(new Date());
+        taskReport.setReportTimes(0);
+        taskReport.setTaskSts(taskReportStsType.status);
+        taskReport.setSeqNum(task.getSeqNum());
+        taskReport.setZpallet(task.getZpallet());
+        if (!taskReportService.save(taskReport)) {
+            log.info("TaskReport [{}] 鎻掑叆澶辫触 ==========>> ", JSON.toJSONString(taskReport));
+        } else {
+            log.info("Task [{}] 鐘舵�佽褰曟彃鍏ユ暟鎹簱 ==========>> ", task.getSeqNum());
+        }
+    }
 }

--
Gitblit v1.9.1