From 4453cdecbc6e7a925ae76e3223418654f1cf0b18 Mon Sep 17 00:00:00 2001
From: taisheng <taisheng@qq.com>
Date: 星期二, 22 四月 2025 16:01:15 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/controller/ShuttleController.java |  464 ++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 294 insertions(+), 170 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/ShuttleController.java b/src/main/java/com/zy/asrs/controller/ShuttleController.java
index acff75b..2c0f5bc 100644
--- a/src/main/java/com/zy/asrs/controller/ShuttleController.java
+++ b/src/main/java/com/zy/asrs/controller/ShuttleController.java
@@ -1,6 +1,7 @@
 package com.zy.asrs.controller;
 
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.core.annotations.ManagerAuth;
 import com.core.common.BaseRes;
 import com.core.common.Cools;
@@ -9,21 +10,27 @@
 import com.zy.asrs.domain.param.ShuttleOperatorParam;
 import com.zy.asrs.domain.vo.*;
 import com.zy.asrs.entity.BasShuttle;
-import com.zy.asrs.entity.LocMast;
 import com.zy.asrs.entity.WrkMast;
 import com.zy.asrs.service.BasShuttleService;
 import com.zy.asrs.service.LocMastService;
 import com.zy.asrs.service.WrkMastService;
 import com.zy.asrs.utils.Utils;
-import com.zy.common.utils.NavigatePositionConvert;
-import com.zy.core.cache.MessageQueue;
+import com.zy.common.model.enums.NavigationMapType;
+import com.zy.common.service.CommonService;
+import com.zy.common.utils.NavigateMapUtils;
+import com.zy.common.utils.RedisUtil;
+import com.zy.common.utils.ShuttleOperaUtils;
+import com.zy.core.News;
+import com.zy.core.action.ShuttleAction;
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.cache.SlaveConnection;
+import com.zy.core.dispatcher.ShuttleDispatchUtils;
 import com.zy.core.enums.*;
 import com.zy.core.model.ShuttleSlave;
-import com.zy.core.model.Task;
 import com.zy.core.model.command.ShuttleAssignCommand;
 import com.zy.core.model.command.ShuttleCommand;
+import com.zy.core.model.command.ShuttleRedisCommand;
+import com.zy.core.model.param.ShuttleMoveLocParam;
 import com.zy.core.model.protocol.ShuttleProtocol;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.ShuttleThread;
@@ -32,7 +39,7 @@
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
-import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -51,74 +58,59 @@
     private WrkMastService wrkMastService;
     @Autowired
     private LocMastService locMastService;
+    @Autowired
+    private CommonService commonService;
+    @Autowired
+    private RedisUtil redisUtil;
+    @Autowired
+    private ShuttleDispatchUtils shuttleDispatchUtils;
+    @Autowired
+    private ShuttleOperaUtils shuttleOperaUtils;
+    @Autowired
+    private ShuttleAction shuttleAction;
+    @Autowired
+    private NavigateMapUtils navigateMapUtils;
 
     @PostMapping("/table/shuttle/state")
     @ManagerAuth(memo = "鍥涘悜绌挎杞︿俊鎭〃")
-    public R steStateTable(){
-        List<ShuttleStateTableVo> list = new ArrayList<>();
-        List<BasShuttle> shuttles = basShuttleService.selectList(new EntityWrapper<BasShuttle>().orderBy("shuttle_no"));
-        for (BasShuttle basShuttle : shuttles) {
+    public R shuttleStateTable(){
+        ArrayList<JSONObject> list = new ArrayList<>();
+        for (ShuttleSlave slave : slaveProperties.getShuttle()) {
             // 琛ㄦ牸琛�
-            ShuttleStateTableVo vo = new ShuttleStateTableVo();
-            vo.setShuttleNo(basShuttle.getShuttleNo());   //鍥涘悜绌挎杞﹀彿
-            list.add(vo);
+            JSONObject baseObj = new JSONObject();
+            baseObj.put("shuttleNo", slave.getId());
+            list.add(baseObj);
             // 鑾峰彇鍥涘悜绌挎杞︿俊鎭�
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, basShuttle.getShuttleNo());
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
             if (shuttleThread == null) {
                 continue;
             }
-            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+            JSONObject shuttleData = JSON.parseObject(JSON.toJSONString(shuttleProtocol));
             if (shuttleProtocol == null || shuttleProtocol.getShuttleNo()==null) {
+                if (shuttleData != null) {
+                    baseObj.putAll(shuttleData);
+                }
                 continue;
             }
-            vo.setTaskNo(shuttleProtocol.getTaskNo().intValue());  //  浠诲姟鍙�
-            vo.setBusyStatus(shuttleProtocol.getBusyStatusType().desc); //鍥涘悜绌挎杞︾姸鎬�
-            vo.setStatus(shuttleProtocol.getProtocolStatusType().desc);//褰撳墠浠诲姟鐘舵��
-            vo.setCurrentCode(shuttleProtocol.getCurrentCode());//褰撳墠浜岀淮鐮�
-            LocMast currentLocMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
-            if (currentLocMast == null) {
-                vo.setLocNo("");//鑾峰彇褰撳墠搴撲綅鍙�
-                vo.setLocNoX(0);
-                vo.setLocNoY(0);
-                vo.setLocNoLev(0);//褰撳墠搴撲綅灞傞珮
-            }else {
-                vo.setLocNo(currentLocMast.getLocNo());//鑾峰彇褰撳墠搴撲綅鍙�
-                int[] locNoXY = NavigatePositionConvert.positionToXY(currentLocMast.getLocNo());//鑾峰彇搴撲綅鍙稾Y鍧愭爣
-                vo.setLocNoX(locNoXY[0]);
-                vo.setLocNoY(locNoXY[1]);
-                vo.setLocNoLev(Utils.getLev(currentLocMast.getLocNo()));//褰撳墠搴撲綅灞傞珮
+
+            shuttleData.put("moveAdvancePath", null);//绌挎杞﹂璁¤矾寰�
+            if (shuttleProtocol.getTaskNo() != 0) {
+                //瀛樺湪浠诲姟锛岃幏鍙栨寚浠�
+                Object object = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + shuttleProtocol.getTaskNo());
+                if (object != null) {
+                    ShuttleRedisCommand redisCommand = JSON.parseObject(object.toString(), ShuttleRedisCommand.class);
+                    shuttleData.put("moveAdvancePath", redisCommand.getAssignCommand().getNodes());//绌挎杞﹂璁¤矾寰�
+                }
             }
-            vo.setBatteryPower(shuttleProtocol.getBatteryPower$() == null ? "" : shuttleProtocol.getBatteryPower$() + "%");//鐢垫睜鐢甸噺
-            vo.setBatteryTemp(shuttleProtocol.getBatteryTemp$() == null ? "" : shuttleProtocol.getBatteryTemp$() + "掳");//鐢垫睜娓╁害
-            if (!Cools.isEmpty(shuttleProtocol.getErrorCode())) {
-                vo.setErrorCode(shuttleProtocol.getErrorCodeType());//閿欒缂栧彿
+
+            Integer chargeLine = basShuttleService.selectById(slave.getId()).getChargeLine();
+            String lowerPower = "N";
+            if (chargeLine != null && shuttleProtocol.getBatteryPower() != null) {
+                lowerPower = Integer.parseInt(shuttleProtocol.getBatteryPower()) <= chargeLine ? "Y" : "N";
             }
-            vo.setPlcOutputStatusIO(shuttleProtocol.getPlcOutputStatusIO());//Plc杈撳嚭鐘舵�両O
-            if (!Cools.isEmpty(shuttleProtocol.getPlcOutputLift())) {
-                vo.setPlcOutputLift(shuttleProtocol.getPlcOutputLift());
-            }
-            if (!Cools.isEmpty(shuttleProtocol.getPlcOutputTransfer())) {
-                vo.setPlcOutputTransfer(shuttleProtocol.getPlcOutputTransfer());
-            }
-            if (!Cools.isEmpty(shuttleProtocol.getPlcOutputBrake())) {
-                vo.setPlcOutputBrake(shuttleProtocol.getPlcOutputBrake());
-            }
-            if (!Cools.isEmpty(shuttleProtocol.getPlcOutputCharge())) {
-                vo.setPlcOutputCharge(shuttleProtocol.getPlcOutputCharge());
-            }
-            if (!Cools.isEmpty(shuttleProtocol.getStatusErrorCode())) {
-                vo.setStatusErrorCode(shuttleProtocol.getStatusErrorCode$());//閿欒淇℃伅鐮�
-            }
-            vo.setPlcInputStatus(shuttleProtocol.getPlcInputStatus());//PLC杈撳叆鐘舵��
-            vo.setCurrentOrBeforeCode(shuttleProtocol.getCurrentOrBeforeCode());//褰撳墠鎴栬�呬箣鍓嶈鍒扮殑浜岀淮鐮佸��
-            vo.setCodeOffsetX(shuttleProtocol.getCodeOffsetX());//璇诲埌鐨勪簩缁寸爜X鏂瑰悜鍋忕Щ閲�
-            vo.setCodeOffsetY(shuttleProtocol.getCodeOffsetY());//璇诲埌鐨勪簩缁寸爜Y鏂瑰悜鍋忕Щ閲�
-            vo.setCurrentVoltage(shuttleProtocol.getCurrentVoltage() * 0.1);//褰撳墠鐨勭數鍘嬪��
-            vo.setCurrentAnalogValue(shuttleProtocol.getCurrentAnalogValue());//褰撳墠鐨勬ā鎷熼噺鍊�
-            vo.setCurrentLiftServoSpeed(shuttleProtocol.getCurrentLiftServoSpeed());//褰撳墠鐨勫崌闄嶄己鏈嶉�熷害
-            vo.setCurrentMoveServoSpeed(shuttleProtocol.getCurrentMoveServoSpeed());//褰撳墠鐨勮璧颁己鏈嶉�熷害
-            vo.setCurrentLiftServoLoad(shuttleProtocol.getCurrentLiftServoLoad());//褰撳墠鐨勫崌闄嶄己鏈嶈礋杞界巼
-            vo.setCurrentMoveServoLoad(shuttleProtocol.getCurrentMoveServoLoad());//褰撳墠鐨勮璧颁己鏈嶈礋杞界巼
+            shuttleData.put("lowerPower", lowerPower);//鏄惁浣庣數閲�
+            baseObj.putAll(shuttleData);
         }
         return R.ok().add(list);
     }
@@ -127,23 +119,25 @@
     @ManagerAuth(memo = "鍥涘悜绌挎杞︽暟鎹〃")
     public R steMsgTable(){
         List<ShuttleMsgTableVo> list = new ArrayList<>();
-        List<BasShuttle> shuttles = basShuttleService.selectList(new EntityWrapper<BasShuttle>().orderBy("shuttle_no"));
-        for (BasShuttle basShuttle : shuttles) {
+        for (ShuttleSlave slave : slaveProperties.getShuttle()) {
             // 琛ㄦ牸琛�
             ShuttleMsgTableVo vo = new ShuttleMsgTableVo();
-            vo.setShuttleNo(basShuttle.getShuttleNo());   //  鍥涘悜绌挎杞﹀彿
+            vo.setShuttleNo(slave.getId());   //  鍥涘悜绌挎杞﹀彿
             list.add(vo);
             // 鑾峰彇绌挎杞︿俊鎭�
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, basShuttle.getShuttleNo());
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
             if (shuttleThread == null) {
                 continue;
             }
-            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
             if (shuttleProtocol == null) {
                 continue;
             }
+            if (shuttleProtocol.getShuttleNo() == null) {
+                continue;
+            }
 
-            vo.setWorkNo(shuttleProtocol.getTaskNo().intValue());//浠诲姟鍙�
+            vo.setWorkNo(shuttleProtocol.getTaskNo());//浠诲姟鍙�
             if (shuttleProtocol.getTaskNo() > 0) {
                 WrkMast wrkMast = wrkMastService.selectById(shuttleProtocol.getTaskNo());
                 if (wrkMast != null) {
@@ -154,17 +148,14 @@
             if (shuttleProtocol.getProtocolStatusType() != null) {
                 vo.setStatus(shuttleProtocol.getProtocolStatusType().desc);//鐘舵��
             }
-            vo.setCodeOffsetX(shuttleProtocol.getCodeOffsetX());//璇诲埌鐨勪簩缁寸爜X鏂瑰悜鍋忕Щ閲�
-            vo.setCodeOffsetY(shuttleProtocol.getCodeOffsetY());//璇诲埌鐨勪簩缁寸爜Y鏂瑰悜鍋忕Щ閲�
-            vo.setCurrentVoltage(shuttleProtocol.getCurrentVoltage());//褰撳墠鐨勭數鍘嬪��
-            vo.setCurrentAnalogValue(shuttleProtocol.getCurrentAnalogValue());//褰撳墠鐨勬ā鎷熼噺鍊�
-            vo.setCurrentMoveServoSpeed(shuttleProtocol.getCurrentMoveServoSpeed());//褰撳墠鐨勮璧颁己鏈嶉�熷害
-            vo.setCurrentMoveServoLoad(shuttleProtocol.getCurrentMoveServoLoad() == null ? "" : shuttleProtocol.getCurrentMoveServoLoad() + "%");//褰撳墠鐨勮璧颁己鏈嶈礋杞界巼
-            vo.setCurrentLiftServoLoad(shuttleProtocol.getCurrentLiftServoLoad() == null ? "" : shuttleProtocol.getCurrentLiftServoLoad() + "%");//褰撳墠鐨勫崌闄嶄己鏈嶈礋杞界巼
-            vo.setCurrentLiftServoSpeed(shuttleProtocol.getCurrentLiftServoSpeed());//褰撳墠鐨勫崌闄嶄己鏈嶉�熷害
             vo.setPakMk(shuttleProtocol.getPakMk()?"Y" : "N");    // 浣滀笟鏍囪
             vo.setLocNo(shuttleProtocol.getLocNo());//鍥涘悜绌挎杞﹀綋鍓嶅簱浣嶅彿
-            vo.setLev(Utils.getLev(shuttleProtocol.getLocNo()));//鍥涘悜绌挎杞﹀綋鍓嶅眰楂�
+            vo.setLev(shuttleProtocol.getLocNo() == null ? 0 : Utils.getLev(shuttleProtocol.getLocNo()));//鍥涘悜绌挎杞﹀綋鍓嶅眰楂�
+
+            BasShuttle basShuttle = basShuttleService.selectById(slave.getId());
+            if (basShuttle != null) {
+                vo.setChargeLine(basShuttle.getChargeLine());//鍏呯數闃堝��
+            }
         }
         return R.ok().add(list);
     }
@@ -188,82 +179,87 @@
         return R.ok().add(str.toString());
     }
 
-    @GetMapping("/detl/{shuttleNo}")
-    public R steDetl(@PathVariable("shuttleNo") Integer shuttleNo){
-        ShuttleDataVo vo = new ShuttleDataVo();
-        for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) {
-            if (shuttleNo.equals(shuttleSlave.getId())) {
-                vo.setShuttleNo(shuttleSlave.getId());
-                BasShuttle basShuttle = basShuttleService.selectById(shuttleSlave.getId());
-                if (!Cools.isEmpty(basShuttle)) {
-                    vo.setWorkNo(basShuttle.getWrkNo());
-                    vo.setPakMk(basShuttle.getPakMk());
-                }
-                break;
-            }
+    @RequestMapping(value = "/command/query")
+    public R shuttleCommandQuery(@RequestParam("wrkNo") Integer wrkNo) {
+        Object o = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + wrkNo);
+        if (o == null) {
+            return R.error("鎸囦护涓嶅瓨鍦�");
         }
-        return R.ok().add(vo);
+        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
+        ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
+        List<ShuttleCommand> commands = assignCommand.getCommands();
+
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("commands", commands);
+        map.put("shuttleNo", redisCommand.getShuttleNo());
+        map.put("commandStep", redisCommand.getCommandStep());
+        map.put("wrkNo", redisCommand.getWrkNo());
+
+        return R.ok().add(map);
     }
 
-    @GetMapping("/sensor/detl/{shuttleNo}")
-    public R shuttleSensorDetl(@PathVariable("shuttleNo") Integer shuttleNo){
-        ShuttleSensorDataVo vo = new ShuttleSensorDataVo();
-        for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) {
-            if (shuttleNo.equals(shuttleSlave.getId())) {
-                vo.setShuttleNo(shuttleSlave.getId());
-                // 鑾峰彇绌挎杞︿俊鎭�
-                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId());
-                if (shuttleThread == null) {
-                    return R.error("璁惧涓嶅湪绾�");
-                }
-                ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-                if (shuttleProtocol == null) {
-                    return R.error("璁惧涓嶅湪绾�");
-                }
-
-                // 绌挎杞﹀紓甯� -----------
-
-                // 绌挎杞︽彁绀轰俊鎭� ----------------------
-
-                // 鐘舵�佷俊鎭� -------------
-
-                break;
-            }
-        }
-        return R.ok().add(vo);
-    }
-
-    @PostMapping("/detl/update")
-    @ManagerAuth
-    public R steUpdate(ShuttleDataVo vo){
-        BasShuttle basShuttle = basShuttleService.selectById(vo.getShuttleNo());
-        if (basShuttle == null) {
+    //鍥為��鍛戒护
+    @RequestMapping(value = "/command/rollback")
+    public R shuttleCommandRollback(@RequestParam("wrkNo") Integer wrkNo
+            , @RequestParam("commandStep") Integer commandStep) {
+        Object o = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + wrkNo);
+        if (o == null) {
             return R.error();
         }
-        // 鑾峰彇鍥涘悜绌挎杞︿俊鎭�
-        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, vo.getShuttleNo());
-        ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-        if (shuttleProtocol == null) {
-            throw new CoolException(vo.getShuttleNo() + "鍙峰洓鍚戠┛姊溅涓嶅湪绾匡紝鏃犳硶淇濆瓨");
-        }
-//        if (!Cools.isEmpty(vo.getRow(), vo.getBay(), vo.getLev())) {
-//            if (!shuttleThread.modifyPosHandle(vo.getRow(), vo.getBay(), vo.getLev())) {
-//                throw new CoolException("鏈嶅姟鍣ㄩ敊璇�");
-//            }
-//        }
-        ShuttleCommand shuttleCommand = new ShuttleCommand();
-        shuttleCommand.setTaskNo(vo.getWorkNo().shortValue());
-        if (MessageQueue.offer(SlaveType.Shuttle, vo.getShuttleNo(), new Task(2, shuttleCommand))) {
-        } else {
-            throw new CoolException("鍛戒护涓嬪彂澶辫触");
-        }
+        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
+        redisCommand.setCommandStep(commandStep);
+        redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + wrkNo, JSON.toJSONString(redisCommand));
+        return R.ok();
+    }
 
-        basShuttle.setPakMk(vo.getPakMk());
-        basShuttle.setWrkNo(vo.getWorkNo());
-        basShuttle.setUpdateTime(new Date());
-        if (!basShuttleService.updateById(basShuttle)) {
-            throw new CoolException("淇敼澶辫触");
+    //鍛戒护瀹屾垚鐘舵�佸垏鎹�
+    @RequestMapping(value = "/command/completeSwitch")
+    public R shuttleCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo
+            , @RequestParam("commandStep") Integer commandStep
+            , @RequestParam("complete") Integer complete) {
+        Object o = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + wrkNo);
+        if (o == null) {
+            return R.error();
         }
+        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
+        ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
+        List<ShuttleCommand> commands = assignCommand.getCommands();
+        ShuttleCommand command = commands.get(commandStep);
+        command.setComplete(complete != 0);
+        redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + wrkNo, JSON.toJSONString(redisCommand));
+        return R.ok();
+    }
+
+    //閲嶅惎浠诲姟(鍛戒护)
+    @RequestMapping(value = "/command/restart")
+    public R shuttleCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo) {
+        Object o = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + wrkNo);
+        if (o == null) {
+            return R.error();
+        }
+        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
+        Integer shuttleNo = redisCommand.getShuttleNo();
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+        if (shuttleThread == null) {
+            return R.error();
+        }
+        if (!shuttleThread.isIdle()) {
+            return R.error();
+        }
+        //鍥涘悜绌挎杞﹀浜庣┖闂茬姸鎬侊紝杩涜浠诲姟鐨勬仮澶�
+        shuttleThread.setTaskNo(redisCommand.getWrkNo());//灏嗗洓鍚戠┛姊溅绾跨▼鍒嗛厤浠诲姟鍙�
+        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WORKING);//宸ヤ綔鐘舵��
+        return R.ok();
+    }
+
+    //鍒犻櫎浠诲姟(鍛戒护)
+    @RequestMapping(value = "/command/del")
+    public R liftCommandDel(@RequestParam("wrkNo") Integer wrkNo) {
+        Object o = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + wrkNo);
+        if (o == null) {
+            return R.error();
+        }
+        redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + wrkNo);
         return R.ok();
     }
 
@@ -280,7 +276,9 @@
 
         ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
 
-        if (param.getShuttleTaskMode() == 1 || param.getShuttleTaskMode() == 2 || param.getShuttleTaskMode() == 14) {
+        if (param.getShuttleTaskMode().intValue() == ShuttleTaskModeType.MOVE_LOC_NO.id
+                || param.getShuttleTaskMode().intValue() == ShuttleTaskModeType.MOVE_LOC_NO_TASK.id
+                || param.getShuttleTaskMode().intValue() == ShuttleTaskModeType.TRANSPORT.id) {
             if (Cools.isEmpty(param.getSourceLocNo(), param.getDistLocNo())) {
                 return R.parse(BaseRes.PARAM);
             }
@@ -288,31 +286,157 @@
             assignCommand.setLocNo(param.getDistLocNo());
         }
 
-        for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) {
-            if (param.getShuttleNo().equals(shuttleSlave.getId())) {
-                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId());
-                if (shuttleThread == null) {
-                    throw new CoolException("鍥涘悜绌挎杞︿笉鍦ㄧ嚎");
-                }
-                ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-                if (shuttleProtocol == null) {
-                    throw new CoolException("鍥涘悜绌挎杞︿笉鍦ㄧ嚎");
-                }
-
-                ShuttleTaskModeType shuttleTaskModeType = ShuttleTaskModeType.get(param.getShuttleTaskMode());
-                assignCommand.setShuttleNo(shuttleSlave.getId().shortValue()); // 鍥涘悜绌挎杞︾紪鍙�
-                assignCommand.setTaskMode(shuttleTaskModeType.id.shortValue());
-                assignCommand.setTaskNo((short) 9999);
-                assignCommand.setAuto(false);//鎵嬪姩妯″紡
-
-                if (MessageQueue.offer(SlaveType.Shuttle, shuttleSlave.getId(), new Task(3, assignCommand))) {
-                    return R.ok();
-                } else {
-                    throw new CoolException("鍛戒护涓嬪彂澶辫触");
-                }
-            }
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, param.getShuttleNo());
+        if (shuttleThread == null) {
+            throw new CoolException("鍥涘悜绌挎杞︿笉鍦ㄧ嚎");
         }
-        return R.error();
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null) {
+            throw new CoolException("鍥涘悜绌挎杞︿笉鍦ㄧ嚎");
+        }
+
+        ShuttleTaskModeType shuttleTaskModeType = ShuttleTaskModeType.get(param.getShuttleTaskMode().intValue());
+        assignCommand.setShuttleNo(param.getShuttleNo()); // 鍥涘悜绌挎杞︾紪鍙�
+        assignCommand.setTaskMode(shuttleTaskModeType.id);
+        assignCommand.setTaskNo(commonService.getWorkNo(99));//鑾峰彇浠诲姟鍙�
+        assignCommand.setAuto(false);//鎵嬪姩妯″紡
+
+        if (shuttleTaskModeType == ShuttleTaskModeType.MOVE_LOC_NO) {
+            //绉诲姩鍒扮洰鏍囧簱浣�
+            Integer mapType = NavigationMapType.NORMAL.id;
+            if (shuttleProtocol.getHasLift()) {
+                mapType = NavigationMapType.DFX.id;
+            }
+            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), param.getDistLocNo(), mapType, assignCommand, shuttleThread);
+            if (commands == null) {
+                throw new CoolException("璺緞璁$畻澶辫触");
+            }
+
+            assignCommand.setCommands(commands);
+
+            //灏濊瘯閿佸畾鐩爣绔欒矾寰�
+            boolean result2 = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(param.getDistLocNo()), shuttleProtocol.getShuttleNo(), assignCommand.getNodesDeepCopy(), true);//鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
+            if (!result2) {
+                News.info("{}浠诲姟锛寋}灏忚溅锛岃矾寰勯攣瀹氬け璐ワ紝绂佹娲惧彂", param.getDistLocNo(), shuttleProtocol.getShuttleNo());
+                throw new CoolException("璺緞閿佸畾澶辫触");
+            }
+
+        } else if (shuttleTaskModeType == ShuttleTaskModeType.PALLET_LIFT) {
+            //鎵樼洏椤跺崌
+            List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleLiftCommand(assignCommand, shuttleThread, true);
+            assignCommand.setCommands(commands);
+        } else if (shuttleTaskModeType == ShuttleTaskModeType.PALLET_DOWN) {
+            //鎵樼洏涓嬮檷
+            List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleLiftCommand(assignCommand, shuttleThread, false);
+            assignCommand.setCommands(commands);
+        } else if (shuttleTaskModeType == ShuttleTaskModeType.CHARGE) {
+            //鍏呯數寮�鍏�
+            boolean charge = false;
+            if (shuttleProtocol.getHasCharge()) {
+                //宸插厖鐢碉紝鍏抽棴鍏呯數
+                charge = false;
+            }else {
+                //寮�鍚厖鐢�
+                charge = true;
+            }
+            List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleChargeCommand(assignCommand, shuttleThread, charge);
+            assignCommand.setCommands(commands);
+        } else if (shuttleTaskModeType == ShuttleTaskModeType.RESET) {
+            //澶嶄綅
+            shuttleThread.setSyncTaskNo(0);//宸ヤ綔鍙锋竻绌�
+            shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);//浠诲姟鐘舵��-绌洪棽
+            shuttleThread.setPakMk(true);//浣滀笟鏍囪澶嶄綅
+
+            shuttleThread.enableMoveLoc(null, false);
+            return R.ok();
+        } else if (shuttleTaskModeType == ShuttleTaskModeType.MOVE_LOC_NO_TASK) {
+            //绉诲姩鍒扮洰鏍囧簱浣�(鐢熸垚绉诲姩浠诲姟)
+            shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(3), param.getDistLocNo(), param.getShuttleNo());
+            return R.ok();
+        } else if (shuttleTaskModeType == ShuttleTaskModeType.SHUTTLE_DEMO_OPEN) {
+            //婕旂ず妯″紡-寮�
+            shuttleThread.enableDemo(true);
+            return R.ok();
+        } else if (shuttleTaskModeType == ShuttleTaskModeType.SHUTTLE_DEMO_CLOSE) {
+            //婕旂ず妯″紡-鍏�
+            shuttleThread.enableDemo(false);
+            return R.ok();
+        } else {
+            throw new CoolException("鏈煡鍛戒护");
+        }
+
+        shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
+        return R.ok();
+    }
+
+    @PostMapping("/detl/update")
+    @ManagerAuth(memo = "淇敼鏁版嵁")
+    public R shuttleUpdate(@RequestParam Integer shuttleNo,
+                           @RequestParam Integer workNo,
+                           @RequestParam String pakMk) {
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+        if (shuttleThread == null) {
+            return R.error("plc宸叉帀绾�");
+        }
+        if (workNo != null) {
+            shuttleThread.setSyncTaskNo(workNo);
+        }
+        if (pakMk != null) {
+            shuttleThread.setPakMk(pakMk.equals("Y"));
+        }
+        return R.ok();
+    }
+
+    @PostMapping("/runSpeed/{shuttleNo}")
+    @ManagerAuth
+    public R setRunSpeed(@PathVariable("shuttleNo") String shuttleNo, @RequestParam("runSpeed") Integer runSpeed, @RequestParam("chargeLine") Integer chargeLine) {
+        BasShuttle basShuttle = basShuttleService.selectById(shuttleNo);
+        if (basShuttle == null) {
+            return R.error("鍥涘悜绌挎杞︿笉瀛樺湪");
+        }
+        basShuttle.setRunSpeed(runSpeed);
+        basShuttle.setChargeLine(chargeLine);
+        if (!basShuttleService.updateById(basShuttle)) {
+            return R.error();
+        }
+        return R.ok();
+    }
+
+    /**
+     * 璺戝簱绋嬪簭
+     */
+    @PostMapping("/moveLoc")
+    @ManagerAuth
+    public R moveLoc(@RequestParam Integer shuttleNo,
+                     @RequestParam Integer moveType,
+                     @RequestParam Integer xStart,
+                     @RequestParam Integer xTarget,
+                     @RequestParam Integer yStart,
+                     @RequestParam Integer yTarget) {
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+        if (shuttleThread == null) {
+            return R.error();
+        }
+
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null) {
+            return R.error();
+        }
+
+        if (!shuttleThread.isIdle()) {
+            return R.error("灏忚溅蹇欑涓�");
+        }
+
+        ShuttleMoveLocParam param = new ShuttleMoveLocParam();
+        param.setShuttleNo(shuttleNo);
+        param.setMoveType(moveType);
+        param.setStartX(xStart);
+        param.setTargetX(xTarget);
+        param.setStartY(yStart);
+        param.setTargetY(yTarget);
+
+        shuttleThread.enableMoveLoc(param, true);
+        return R.ok();
     }
 
 }

--
Gitblit v1.9.1