From 3a49654f51096d4f9f95f4a5e8198e168e38a0c5 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期六, 16 八月 2025 08:34:13 +0800
Subject: [PATCH] 1

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java |  323 ++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 230 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 2092f91..f3acf60 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
@@ -1,6 +1,7 @@
 package com.zy.acs.manager.core.service;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.acs.common.domain.AgvAction;
 import com.zy.acs.common.domain.AgvActionItem;
@@ -26,6 +27,7 @@
 import com.zy.acs.manager.core.domain.Lane;
 import com.zy.acs.manager.core.domain.TaskPosDto;
 import com.zy.acs.manager.core.service.astart.MapDataDispatcher;
+import com.zy.acs.manager.core.utils.HttpHandler;
 import com.zy.acs.manager.manager.controller.param.OpenBusSubmitParam;
 import com.zy.acs.manager.manager.entity.*;
 import com.zy.acs.manager.manager.enums.*;
@@ -40,7 +42,9 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
+import java.io.IOException;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -132,6 +136,8 @@
         if (!busService.save(bus)) {
             throw new BusinessException("Internal Server Error!");
         }
+        Boolean locStaStatusCheck = configService.getVal("LOC_STA_STATUS_CHECK", Boolean.class, true);
+
 
         // 淇濆瓨浠诲姟
         for (Task task : taskList) {
@@ -149,7 +155,7 @@
             switch (TaskTypeType.get(task.getTaskTypeEl())) {
                 case LOC_TO_LOC:
                     oriLoc = locService.getById(task.getOriLoc());
-                    if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
+                    if (locStaStatusCheck && !oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
                         throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " is not in STOCK status");
                     }
                     oriLoc.setLocSts(LocStsType.PAKOUT.val());
@@ -159,7 +165,7 @@
                     }
 
                     destLoc = locService.getById(task.getDestLoc());
-                    if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
+                    if (locStaStatusCheck && !destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
                         throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " is not in IDLE status");
                     }
                     destLoc.setLocSts(LocStsType.PAKIN.val());
@@ -170,7 +176,7 @@
                     break;
                 case LOC_TO_STA:
                     oriLoc = locService.getById(task.getOriLoc());
-                    if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
+                    if (locStaStatusCheck && !oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
                         throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " is not in STOCK status");
                     }
                     oriLoc.setLocSts(LocStsType.PAKOUT.val());
@@ -180,8 +186,10 @@
                     }
 
                     destSta = staService.getById(task.getDestSta());
-                    if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) {
-                        throw new BusinessException("destSta锛�" + task.getDestSta$() + " is not in IDLE status");
+                    if (destSta.getStaTypeIsCheck() != 1) {
+                        if (locStaStatusCheck && !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);
@@ -191,8 +199,10 @@
                     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");
+                    if (oriSta.getStaTypeIsCheck() != 1) {
+                        if (locStaStatusCheck && !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);
@@ -201,7 +211,7 @@
                     }
 
                     destLoc = locService.getById(task.getDestLoc());
-                    if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
+                    if (locStaStatusCheck && !destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
                         throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " is not in IDLE status");
                     }
                     destLoc.setLocSts(LocStsType.PAKIN.val());
@@ -212,8 +222,10 @@
                     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");
+                    if (oriSta.getStaTypeIsCheck() != 1) {
+                        if (locStaStatusCheck && !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);
@@ -222,8 +234,10 @@
                     }
 
                     destSta = staService.getById(task.getDestSta());
-                    if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) {
-                        throw new BusinessException("destSta锛�" + task.getDestSta$() + " is not in IDLE status");
+                    if (destSta.getStaTypeIsCheck() != 1) {
+                        if (locStaStatusCheck && !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);
@@ -277,6 +291,7 @@
                 if (!taskService.updateById(task)) {
                     throw new BusinessException("seqNum: " + task.getSeqNum() + " failed to update");
                 }
+                report(task, null, TaskReportStsType.START);
             }
         } catch (Exception e) {
             log.error("mainService.infuseAgvForTask", e);
@@ -989,7 +1004,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(),    // 鍔ㄤ綔绫诲瀷
@@ -1014,7 +1029,9 @@
                                 ActionTypeType.ReadyTakeFromConveyorSta.val(),    // 鍔ㄤ綔绫诲瀷
                                 actionPrepareSts,    // 鍔ㄤ綔杩涘害
                                 agvId,    // AGV
-                                now    // 宸ヤ綔鏃堕棿
+                                now,    // 宸ヤ綔鏃堕棿
+                                oriSta.getStaTypeIsCheck() == 1 ? 1 : 0,
+                                oriSta.getStaNo()
                         ));
                         // 鏆傚瓨鐐规斁璐�
                         assert backpackType != null;
@@ -1025,7 +1042,7 @@
                                 null,    // 鍔ㄤ綔鍙�
                                 null,    // 浼樺厛绾�
                                 ActionTypeType.ReadyReleaseToAgvSite.desc,    // 鍚嶇О
-                                (double) backpackType.lev,    // 灞炴�у��
+                                (double) backpackType.lev,    // 灞炴�ш皰
                                 lastCode.getData(),    // 鍦伴潰鐮�
                                 String.valueOf(backpackType.height),   // 鍔ㄤ綔鍙傛暟
                                 ActionTypeType.ReadyReleaseToAgvSite.val(),    // 鍔ㄤ綔绫诲瀷
@@ -1051,13 +1068,13 @@
                                     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(),    // 鍔ㄤ綔绫诲瀷
                                     actionPrepareSts,    // 鍔ㄤ綔杩涘害
                                     agvId,    // AGV
-                                    now    // 宸ヤ綔鏃堕棿
+                                    now   // 宸ヤ綔鏃堕棿
                             ));
                             lastDirection = destStaWorkDirection;
                         }
@@ -1070,13 +1087,15 @@
                                 null,    // 鍔ㄤ綔鍙�
                                 null,    // 浼樺厛绾�
                                 ActionTypeType.ReadyTakeFromAgvSite.desc,    // 鍚嶇О
-                                (double) backpackType.lev,    // 灞炴�у��
+                                (double) backpackType.lev,    // 灞炴�ш皰
                                 lastCode.getData(),    // 鍦伴潰鐮�
                                 String.valueOf(backpackType.height),   // 鍔ㄤ綔鍙傛暟
                                 ActionTypeType.ReadyTakeFromAgvSite.val(),    // 鍔ㄤ綔绫诲瀷
                                 actionPrepareSts,    // 鍔ㄤ綔杩涘害
                                 agvId,    // AGV
-                                now    // 宸ヤ綔鏃堕棿
+                                now,    // 宸ヤ綔鏃堕棿
+                                destSta.getStaTypeIsCheck() == 1 ? 2 : 0,
+                                destSta.getStaNo()
                         ));
                         // 璁$畻璐у弶宸ヤ綔鏂瑰悜
                         staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, lastDirection);
@@ -1087,7 +1106,7 @@
                                 null,    // 鍔ㄤ綔鍙�
                                 null,    // 浼樺厛绾�
                                 ActionTypeType.ReadyReleaseToConveyorSta.desc,    // 鍚嶇О
-                                staWorkDirection,    // 灞炴�у��
+                                staWorkDirection,    // 灞炴�ш皰
                                 lastCode.getData(),    // 鍦伴潰鐮�
                                 String.valueOf(destSta.getOffset()),   // 鍔ㄤ綔鍙傛暟
                                 ActionTypeType.ReadyReleaseToConveyorSta.val(),    // 鍔ㄤ綔绫诲瀷
@@ -1108,7 +1127,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(),    // 鍔ㄤ綔绫诲瀷
@@ -1127,7 +1146,7 @@
                                 null,    // 鍔ㄤ綔鍙�
                                 null,    // 浼樺厛绾�
                                 ActionTypeType.DockingCharge.desc,    // 鍚嶇О
-                                null,    // 灞炴�у��
+                                null,    // 灞炴�ш皰
                                 lastCode.getData(),    // 鍦伴潰鐮�
                                 null,   // 鍔ㄤ綔鍙傛暟
                                 ActionTypeType.DockingCharge.val(),    // 鍔ㄤ綔绫诲瀷
@@ -1147,7 +1166,7 @@
 //                                    null,    // 鍔ㄤ綔鍙�
 //                                    null,    // 浼樺厛绾�
 //                                    ActionTypeType.TurnCorner.desc,    // 鍚嶇О
-//                                    null,    // 灞炴�у��
+//                                    null,    // 灞炴�ш皰
 //                                    lastCode.getData(),    // 鍦伴潰鐮�
 //                                    String.valueOf(standByDirection),   // 鍔ㄤ綔鍙傛暟
 //                                    ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
@@ -1157,6 +1176,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;
@@ -1226,11 +1275,12 @@
         }
     }
 
+
     @Transactional
     public void publishAction(String actionGroupId) {
         try {
             Date now = new Date();
-
+            boolean flag = true;
             // action
             List<Action> actionList = actionService.list(new LambdaQueryWrapper<Action>()
                     .eq(Action::getGroupId, actionGroupId).eq(Action::getActionSts, ActionStsType.PREPARE.val())
@@ -1341,6 +1391,13 @@
                                 .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:
                         agvAction.add(new AgvActionItem<>(FinishPathAction.class)
                                 .setQrCode(action.getCode())
@@ -1354,9 +1411,14 @@
                     default:
                         break;
                 }
-
+                if (!Cools.isEmpty(action.getAskType()) && (action.getAskType() == 1 || action.getAskType() == 2)) {
+                    flag = askSta(action.getAskType(), action.getAskSta());
+                }
             }
-
+            if (!flag) {
+                log.error("浠诲姟缁� [{}] 鍔ㄤ綔鎸囦护涓嬪彂澶辫触 ,鍚戣緭閫佺嚎璇㈤棶鎶ラ敊锛侊紒锛�", actionGroupId);
+                throw new CoolException("浠诲姟缁� [{" + actionGroupId + "}] 鍔ㄤ綔鎸囦护涓嬪彂澶辫触 锛侊紒锛�");
+            }
             BaseResult<?> result = agvCmdService.executeAgvActionCmd(agvAction);
             if (result.success()) {
                 log.info("浠诲姟缁� [{}] 鍔ㄤ綔鎸囦护宸蹭笅鍙� ===>> 鎸囦护鏁伴噺锛歿}", actionGroupId, actionList.size());
@@ -1395,32 +1457,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, agv_11_up.getQrCode(), TaskReportStsType.END);
                 }
             }
 
@@ -1428,31 +1497,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, agv_11_up.getQrCode(), 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, agv_11_up.getQrCode(), 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, agv_11_up.getQrCode(), TaskReportStsType.END);
                 }
             }
 
@@ -1482,6 +1576,7 @@
             log.info("Agv [{}] 鏂欎粨淇℃伅鍖� ===>> {}", protocol.getAgvNo(), JSON.toJSONString(agv_70_up));
         }
     }
+
 
     @Transactional
     public void settleSegmentList(List<Segment> segmentList, String serialNo) {
@@ -1531,25 +1626,7 @@
                 task.setUpdateTime(now);
                 if (!taskService.updateById(task)) {
                     log.error("Task [{}] 鏇存柊澶辫触 锛侊紒锛�", task.getSeqNum());
-                } else {
-                    log.info("Task [{}] 浣滀笟瀹屾瘯 ==========>> ", task.getSeqNum());
-                    // TODO 鎻掑叆涓�鏉′笂鎶ヨ褰�
-                    TaskReport taskReport = new TaskReport();
-                    taskReport.setAgvId(task.getAgvId());
-                    taskReport.setBusNo(task.getBusId$());
-                    taskReport.setCreateTime(new Date());
-                    taskReport.setDestLoc(task.getDestLoc());
-                    taskReport.setDestSta(task.getDestSta());
-                    taskReport.setSeqNum(task.getSeqNum());
-                    taskReport.setTaskSts(task.getTaskSts());
-                    taskReport.setOriLoc(task.getOriLoc());
-                    taskReport.setOriSta(task.getOriSta());
-                    taskReport.setZpallet(task.getZpallet());
-                    if (!taskReportService.save(taskReport)) {
-                        log.info("TaskReport [{}] 鎻掑叆澶辫触 ==========>> ", JSON.toJSONString(taskReport));
-                    }
                 }
-
             }
         }
 
@@ -1582,4 +1659,64 @@
         segmentService.processNext(segmentList);
     }
 
+    /**
+     * 涓婃姤缁欎笂娓哥郴缁燂紝灏辨槸鎻掑叆涓�鏉℃暟鎹埌涓婃姤琛�
+     */
+    private void report(Task task, String qrCode, TaskReportStsType taskReportStsType) {
+        // TODO 鎻掑叆涓�鏉′笂鎶ヨ褰�
+        if (task.getBusId() == null) {
+            return;
+        }
+        List<TaskReport> list = taskReportService.list(new LambdaQueryWrapper<TaskReport>().eq(TaskReport::getSeqNum, task.getSeqNum()).eq(TaskReport::getBusNo, task.getBusId$()).eq(TaskReport::getTaskSts, taskReportStsType.status));
+        if (!Cools.isEmpty(list)) {
+            log.info("TaskReport [{}] 宸查噸澶嶏紝涓嶅啀鎻掑叆 ==========>> ", JSON.toJSONString(task));
+            return;
+        }
+        TaskReport taskReport = new TaskReport();
+        taskReport.setAgvId(task.getAgvId());
+        taskReport.setBusNo(task.getBusId$());
+        taskReport.setCreateTime(new Date());
+        taskReport.setQrCode(qrCode);
+        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());
+        }
+    }
+
+    private boolean askSta(Integer askType, String askSta) {
+        log.info("鏉ヨ闂緭閫佺嚎浜嗭紝{}锛寋}", askType, askSta);
+        String wmsUrl = configService.getVal("WMS_URL", String.class);
+        String wmsPath = configService.getVal("WMS_STA", String.class);
+        if (Cools.isEmpty(wmsPath) || Cools.isEmpty(wmsUrl)) {
+            return true;
+        }
+        Integer time = configService.getVal("TIMEOUT", Integer.class, 5);
+        //Integer times = configService.getVal("REPORT_TIMES", Integer.class, 2);
+        Map<String, Object> data = new HashMap<>();
+        data.put("askType", askType);
+        data.put("askSta", askSta);
+        String response = null;
+        try {
+            response = new HttpHandler.Builder()
+                    .setUri(wmsUrl)
+                    .setPath(wmsPath)
+                    .setTimeout(time, TimeUnit.SECONDS)
+                    .setJson(JSON.toJSONString(data))
+                    .build()
+                    .doPost();
+            log.info("杩斿洖鍙傛暟锛歿}", response);
+            JSONObject jsonObject = JSON.parseObject(response);
+            if (jsonObject.getInteger("code").equals(200)) {
+                return true;
+            }
+        } catch (IOException e) {
+            log.info("鎶ラ敊浜嗭紝{}", e);
+        }
+        return false;
+    }
 }

--
Gitblit v1.9.1