From 0f69561e397093b5165c4aac58530721d5c62178 Mon Sep 17 00:00:00 2001
From: zjj <3272660260@qq.com>
Date: 星期一, 25 十一月 2024 11:03:16 +0800
Subject: [PATCH] #led

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java |  124 +++++++++++++++++++++++++++++------------
 1 files changed, 87 insertions(+), 37 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 1be358f..5d825f1 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());
@@ -76,12 +79,13 @@
         redisCommand.setAssignCommand(assignCommand);//鍛戒护
         //浠诲姟鏁版嵁淇濆瓨鍒皉edis
         if (redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect))) {
-            if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id
-                    || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id
-                    || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_LOC_NO.id
-                    || assignCommand.getTaskMode() == ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id) {
+            if (assignCommand.getTaskMode() == ShuttleTaskModeType.SHUTTLE_MOVE.id
+                    || assignCommand.getTaskMode() == ShuttleTaskModeType.TRANSPORT.id
+                    || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_PALLET_LIFT.id
+                    || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_PALLET_DOWN.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;
                 }
@@ -132,13 +136,36 @@
         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;
         if (commandStep != 0) {
             ShuttleCommand command = commands.get(commandStep - 1);
             if (command.getMode() == ShuttleCommandModeType.MOVE.id) {
                 // 姝e父绉诲姩
                 if (command.getTargetLocNo().equals(shuttleProtocol.getCurrentLocNo())) {
                     command.setComplete(true);
+                    updateCommand = true;
                     //瑙i攣閿佸畾璺緞锛屼笂涓�鏉¤矾寰�
                     List<NavigateNode> nodes = null;
                     try {
@@ -166,6 +193,7 @@
                 //鍒ゆ柇鏄惁椤跺崌鍒颁綅
                 if (shuttleProtocol.getHasLift()) {
                     command.setComplete(true);
+                    updateCommand = true;
 //                    //鍒ゆ柇鏄惁鏈夌墿
 //                    if (shuttleProtocol.getHasPallet()) {
 //                        command.setComplete(true);
@@ -176,19 +204,24 @@
                 // 鍒ゆ柇鏄惁涓嬮檷鍒颁綅
                 if (!shuttleProtocol.getHasLift()) {
                     command.setComplete(true);
+                    updateCommand = true;
                 }
             } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id) {
                 // 鍏呯數寮�
                 //鍒ゆ柇灏忚溅鍏呯數鐘舵��
                 if (shuttleProtocol.getHasCharge()) {
                     command.setComplete(true);
+                    updateCommand = true;
                 }
             }else {
                 command.setComplete(true);//鍏朵粬鍛戒护榛樿璁や负瀹屾垚
+                updateCommand = true;
             }
 
-            // 鏇存柊redis鏁版嵁
-            redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
+            if(updateCommand) {
+                // 鏇存柊redis鏁版嵁
+                redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
+            }
 
             if (!command.getComplete()) {
                 return false;
@@ -229,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(ShuttleTaskModeType.get(assignCommand.getTaskMode()).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;
         }
@@ -323,8 +363,10 @@
                     shuttleDispatcher.generateMoveTask(device, start.getLocNo());
                 }else {
                     //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
-                    shuttleDispatcher.generateMoveTask(device, target.getLocNo());
-                    shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//鍒囨崲y杞�
+                    Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo());
+                    if (task != null) {
+                        shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//鍒囨崲y杞�
+                    }
 
                     if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
                         //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
@@ -362,8 +404,10 @@
                     shuttleDispatcher.generateMoveTask(device, start.getLocNo());
                 }else {
                     //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
-                    shuttleDispatcher.generateMoveTask(device, target.getLocNo());
-                    shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//鍒囨崲x杞�
+                    Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo());
+                    if (task != null) {
+                        shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//鍒囨崲x杞�
+                    }
 
                     if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
                         //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
@@ -486,6 +530,7 @@
                             return;
                         }
                     }
+                    return;
                 }
 
                 //璋冨害鍘诲簱浣�
@@ -622,27 +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) {//鏇存柊鍧愭爣
+            response = shuttleThread.updateLocation(command);
         }
-        return result;
+
+//        News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戯紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", device.getDeviceNo(), JSON.toJSON(command));
+        return response;
     }
 
 }

--
Gitblit v1.9.1