From d835d1b51f832889929cdf69010034a30ef44d02 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期四, 17 十月 2024 13:57:29 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java |   91 +++++++++++++++++++++++++++++++--------------
 1 files changed, 62 insertions(+), 29 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
index 730dcd8..6bcfefc 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
@@ -23,19 +23,20 @@
 import com.zy.asrs.wcs.rcs.News;
 import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
 import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
+import com.zy.asrs.wcs.rcs.entity.BasShuttleOpt;
 import com.zy.asrs.wcs.rcs.entity.Device;
+import com.zy.asrs.wcs.rcs.model.CommandResponse;
 import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType;
 import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
 import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
+import com.zy.asrs.wcs.rcs.service.BasShuttleOptService;
 import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
 import com.zy.asrs.wcs.system.entity.Dict;
 import com.zy.asrs.wcs.system.service.DictService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 @Component
 public class ShuttleAction {
@@ -56,6 +57,8 @@
     private DictService dictService;
     @Autowired
     private ConveyorDispatcher conveyorDispatcher;
+    @Autowired
+    private BasShuttleOptService basShuttleOptService;
 
     public synchronized boolean assignWork(Device device, ShuttleAssignCommand assignCommand) {
         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
@@ -81,7 +84,8 @@
                     || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_LOC_NO.id
                     || assignCommand.getTaskMode() == ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id) {
                 //涓嬪彂琛岄┒璺緞
-                boolean result = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getDeviceTaskNo());
+                CommandResponse response = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getDeviceTaskNo());
+                Boolean result = response.getResult();
                 if (!result) {
                     return false;
                 }
@@ -131,6 +135,27 @@
 
         ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
         int commandStep = redisCommand.getCommandStep();
+
+        Integer mode = -1;
+        if(commandStep < commands.size()) {
+            //鍙栧嚭鍛戒护
+            ShuttleCommand currentCommand = commands.get(commandStep);
+            mode = currentCommand.getMode();
+        }
+
+        //鍒ゆ柇璁惧鏄惁绌洪棽
+        Integer finalMode = mode;
+        if (!shuttleThread.isDeviceIdle(new ExecuteSupport() {
+            @Override
+            public Boolean judgement() {
+                if (ShuttleCommandModeType.CHARGE_CLOSE.id.equals(finalMode)) {//鍏抽棴鍏呯數motion
+                    return false;//涓嶉渶瑕佸垽鏂姸鎬�
+                }
+                return true;//闇�瑕佸垽鏂姸鎬�
+            }
+        })) {
+            return false;
+        }
 
         // 瀹岀粨涓婁竴鏉″懡浠�
         boolean updateCommand = false;
@@ -237,22 +262,29 @@
         //鍙栧嚭鍛戒护
         ShuttleCommand command = commands.get(commandStep);
 
-        Integer mode = command.getMode();
-        //鍒ゆ柇璁惧鏄惁绌洪棽
-        if (!shuttleThread.isDeviceIdle(new ExecuteSupport() {
-            @Override
-            public Boolean judgement() {
-                if (ShuttleCommandModeType.CHARGE_CLOSE.id.equals(mode)) {//鍏抽棴鍏呯數motion
-                    return false;//涓嶉渶瑕佸垽鏂姸鎬�
-                }
-                return true;//闇�瑕佸垽鏂姸鎬�
-            }
-        })) {
-            return false;
-        }
-
         // 涓嬪彂鍛戒护
-        if (!write(command, device)) {
+        CommandResponse response = write(command, device);
+
+        //淇濆瓨鍛戒护鏃ュ織
+        BasShuttleOpt basShuttleOpt = new BasShuttleOpt();
+        basShuttleOpt.setTaskNo(redisCommand.getTaskNo());
+        basShuttleOpt.setShuttleNo(Integer.parseInt(device.getDeviceNo()));
+
+        basShuttleOpt.setMode(ShuttleCommandModeType.get(command.getMode()).desc);
+        basShuttleOpt.setSourceLocNo(assignCommand.getSourceLocNo());
+        basShuttleOpt.setDistLocNo(assignCommand.getLocNo());
+        basShuttleOpt.setCommand(JSON.toJSONString(command));
+        basShuttleOpt.setSystemStatus(JSON.toJSONString(shuttleProtocol));
+        basShuttleOpt.setDeviceId(device.getId());
+        basShuttleOpt.setDeviceWrk(String.valueOf(command.getTaskNo()));
+        basShuttleOpt.setResponse(response.getMessage());//鑾峰彇鍝嶅簲
+        basShuttleOpt.setSendTime(new Date());//鎸囦护涓嬪彂鏃堕棿
+        basShuttleOpt.setSend(response.getResult() ? 1 : 0);
+        basShuttleOpt.setHostId(device.getHostId());
+        //淇濆瓨鍛戒护娴佹按
+        basShuttleOptService.save(basShuttleOpt);
+
+        if (!response.getResult()) {
             News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
             return false;
         }
@@ -635,31 +667,32 @@
         }
     }
 
-    private synchronized boolean write(ShuttleCommand command, Device device) {
+    private synchronized CommandResponse write(ShuttleCommand command, Device device) {
+        CommandResponse response = new CommandResponse(false);
         if (null == command) {
             News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");
-            return false;
+            response.setMessage("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");
+            return response;
         }
         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
-        boolean result = false;
         if (command.getMode() == ShuttleCommandModeType.MOVE.id
                 || command.getMode() == ShuttleCommandModeType.IN_LIFT.id
                 || command.getMode() == ShuttleCommandModeType.OUT_LIFT.id) {//绉诲姩
-            result = shuttleThread.move(command);
+            response = shuttleThread.move(command);
         } else if (command.getMode() == ShuttleCommandModeType.PALLET_LIFT.id
                 || command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {//椤跺崌
-            result = shuttleThread.lift(command);
+            response = shuttleThread.lift(command);
         } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id
                 || command.getMode() == ShuttleCommandModeType.CHARGE_CLOSE.id) {//鍏呯數
-            result = shuttleThread.charge(command);
+            response = shuttleThread.charge(command);
         } else if (command.getMode() == ShuttleCommandModeType.RESET.id) {//澶嶄綅
-            result = shuttleThread.reset(command);
+            response = shuttleThread.reset(command);
         } else if (command.getMode() == ShuttleCommandModeType.UPDATE_LOCATION.id) {//鏇存柊鍧愭爣
-            result = shuttleThread.updateLocation(command);
+            response = shuttleThread.updateLocation(command);
         }
 
-        News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戯紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", device.getDeviceNo(), JSON.toJSON(command));
-        return result;
+//        News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戯紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", device.getDeviceNo(), JSON.toJSON(command));
+        return response;
     }
 
 }

--
Gitblit v1.9.1