From 0c4b48edb964d47a6db0e2f6a6073fade51c3c4d Mon Sep 17 00:00:00 2001
From: whycq <10027870+whycq@user.noreply.gitee.com>
Date: 星期四, 09 十一月 2023 09:27:54 +0800
Subject: [PATCH] # 显示器

---
 src/main/java/com/zy/asrs/controller/ShuttleController.java |  138 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 115 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/ShuttleController.java b/src/main/java/com/zy/asrs/controller/ShuttleController.java
index ce4aa87..18777ea 100644
--- a/src/main/java/com/zy/asrs/controller/ShuttleController.java
+++ b/src/main/java/com/zy/asrs/controller/ShuttleController.java
@@ -1,7 +1,7 @@
 package com.zy.asrs.controller;
 
 import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.alibaba.fastjson.JSONObject;
 import com.core.annotations.ManagerAuth;
 import com.core.common.BaseRes;
 import com.core.common.Cools;
@@ -16,10 +16,12 @@
 import com.zy.asrs.service.WrkMastService;
 import com.zy.asrs.utils.Utils;
 import com.zy.common.model.NyShuttleOperaResult;
+import com.zy.common.model.enums.NavigationMapType;
 import com.zy.common.service.CommonService;
 import com.zy.common.utils.NyHttpUtils;
 import com.zy.common.utils.NyShuttleOperaUtils;
 import com.zy.common.utils.RedisUtil;
+import com.zy.common.utils.ShuttleDispatchUtils;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.cache.SlaveConnection;
@@ -61,23 +63,49 @@
     private CommonService commonService;
     @Autowired
     private RedisUtil redisUtil;
+    @Autowired
+    private ShuttleDispatchUtils shuttleDispatchUtils;
 
     @PostMapping("/table/shuttle/state")
     @ManagerAuth(memo = "鍥涘悜绌挎杞︿俊鎭〃")
     public R shuttleStateTable(){
-        ArrayList<NyShuttleProtocol> list = new ArrayList<>();
-        List<BasShuttle> shuttles = basShuttleService.selectList(new EntityWrapper<BasShuttle>().orderBy("shuttle_no"));
-        for (BasShuttle basShuttle : shuttles) {
+        ArrayList<JSONObject> list = new ArrayList<>();
+        for (ShuttleSlave slave : slaveProperties.getShuttle()) {
+            // 琛ㄦ牸琛�
+            JSONObject baseObj = new JSONObject();
+            baseObj.put("shuttleNo", slave.getId());
+            list.add(baseObj);
             // 鑾峰彇鍥涘悜绌挎杞︿俊鎭�
-            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, basShuttle.getShuttleNo());
+            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
             if (shuttleThread == null) {
                 continue;
             }
             NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            JSONObject shuttleData = JSON.parseObject(JSON.toJSONString(shuttleProtocol));
             if (shuttleProtocol == null || shuttleProtocol.getShuttleNo()==null) {
+                if (shuttleData != null) {
+                    baseObj.putAll(shuttleData);
+                }
                 continue;
             }
-            list.add(shuttleProtocol);
+
+            shuttleData.put("moveAdvancePath", null);//绌挎杞﹂璁¤矾寰�
+            if (shuttleProtocol.getTaskNo() != 0) {
+                //瀛樺湪浠诲姟锛岃幏鍙栨寚浠�
+                Object object = redisUtil.get(RedisKeyType.SHUTTLE.key + shuttleProtocol.getTaskNo());
+                if (object != null) {
+                    ShuttleRedisCommand redisCommand = JSON.parseObject(object.toString(), ShuttleRedisCommand.class);
+                    shuttleData.put("moveAdvancePath", redisCommand.getAssignCommand().getNodes());//绌挎杞﹂璁¤矾寰�
+                }
+            }
+
+            Integer chargeLine = basShuttleService.selectById(slave.getId()).getChargeLine();
+            String lowerPower = "N";
+            if (chargeLine != null && shuttleProtocol.getPowerPercent() != null) {
+                lowerPower = shuttleProtocol.getPowerPercent() <= chargeLine ? "Y" : "N";
+            }
+            shuttleData.put("lowerPower", lowerPower);//鏄惁浣庣數閲�
+            baseObj.putAll(shuttleData);
         }
         return R.ok().add(list);
     }
@@ -86,14 +114,13 @@
     @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;
             }
@@ -127,8 +154,11 @@
             vo.setPakMk(shuttleProtocol.getPakMk()?"Y" : "N");    // 浣滀笟鏍囪
             vo.setLocNo(shuttleProtocol.getLocNo());//鍥涘悜绌挎杞﹀綋鍓嶅簱浣嶅彿
             vo.setLev(shuttleProtocol.getLocNo() == null ? 0 : Utils.getLev(shuttleProtocol.getLocNo()));//鍥涘悜绌挎杞﹀綋鍓嶅眰楂�
-//            vo.setRunSpeed(basShuttle.getRunSpeed());//鍥涘悜绌挎杞﹁繍琛岄�熷害(璁剧疆)
-            vo.setChargeLine(basShuttle.getChargeLine());//鍏呯數闃堝��
+
+            BasShuttle basShuttle = basShuttleService.selectById(slave.getId());
+            if (basShuttle != null) {
+                vo.setChargeLine(basShuttle.getChargeLine());//鍏呯數闃堝��
+            }
         }
         return R.ok().add(list);
     }
@@ -154,7 +184,7 @@
 
     @RequestMapping(value = "/command/query")
     public R shuttleCommandQuery(@RequestParam("wrkNo") Integer wrkNo) {
-        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+        Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo);
         if (o == null) {
             return R.error();
         }
@@ -166,13 +196,13 @@
     @RequestMapping(value = "/command/rollback")
     public R shuttleCommandRollback(@RequestParam("wrkNo") Integer wrkNo
             , @RequestParam("commandStep") Integer commandStep) {
-        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+        Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo);
         if (o == null) {
             return R.error();
         }
         ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
         redisCommand.setCommandStep(commandStep);
-        redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
+        redisUtil.set(RedisKeyType.SHUTTLE.key + wrkNo, JSON.toJSONString(redisCommand));
         return R.ok();
     }
 
@@ -181,7 +211,7 @@
     public R shuttleCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo
             , @RequestParam("commandStep") Integer commandStep
             , @RequestParam("complete") Integer complete) {
-        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+        Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo);
         if (o == null) {
             return R.error();
         }
@@ -190,14 +220,14 @@
         List<NyShuttleHttpCommand> commands = assignCommand.getCommands();
         NyShuttleHttpCommand command = commands.get(commandStep);
         command.setComplete(complete != 0);
-        redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
+        redisUtil.set(RedisKeyType.SHUTTLE.key + wrkNo, JSON.toJSONString(redisCommand));
         return R.ok();
     }
 
     //閲嶅惎浠诲姟(鍛戒护)
     @RequestMapping(value = "/command/restart")
     public R shuttleCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo) {
-        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+        Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo);
         if (o == null) {
             return R.error();
         }
@@ -223,11 +253,11 @@
     //鍒犻櫎浠诲姟(鍛戒护)
     @RequestMapping(value = "/command/del")
     public R liftCommandDel(@RequestParam("wrkNo") Integer wrkNo) {
-        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+        Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo);
         if (o == null) {
             return R.error();
         }
-        redisUtil.del("shuttle_wrk_no_" + wrkNo);
+        redisUtil.del(RedisKeyType.SHUTTLE.key + wrkNo);
         return R.ok();
     }
 
@@ -280,7 +310,11 @@
                     assignCommand.setNodes(result.getNodes());
                 } else if (shuttleTaskModeType == ShuttleTaskModeType.MOVE_LOC_NO) {
                     //绉诲姩鍒扮洰鏍囧簱浣�
-                    NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), shuttleProtocol.getCurrentLocNo(), param.getDistLocNo());
+                    Integer mapType = NavigationMapType.NORMAL.id;
+                    if (shuttleProtocol.getLiftPosition() == 2) {
+                        mapType = NavigationMapType.DFX.id;
+                    }
+                    NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), shuttleProtocol.getCurrentLocNo(), param.getDistLocNo(), mapType);
                     if (result == null) {
                         throw new CoolException("璺緞璁$畻澶辫触");
                     }
@@ -301,15 +335,33 @@
                     assignCommand.setCommands(commands);
                 } else if (shuttleTaskModeType == ShuttleTaskModeType.CHARGE) {
                     //鍏呯數寮�鍏�
-                    NyShuttleHttpCommand command = NyHttpUtils.getChargeCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), true);
+                    boolean charge = false;
+                    if (shuttleProtocol.getChargState() == 1) {
+                        //宸插厖鐢碉紝鍏抽棴鍏呯數
+                        charge = false;
+                    }else {
+                        //寮�鍚厖鐢�
+                        charge = true;
+                    }
+                    NyShuttleHttpCommand command = NyHttpUtils.getChargeCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), charge);
                     ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>();
                     commands.add(command);
                     assignCommand.setCommands(commands);
                 } else if (shuttleTaskModeType == ShuttleTaskModeType.RESET) {
                     //澶嶄綅
                     shuttleProtocol.setTaskNo(0);//宸ヤ綔鍙锋竻绌�
+                    shuttleProtocol.setToken(0);//浠ょ墝娓呯┖
                     shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);//浠诲姟鐘舵��-绌洪棽
-                    shuttleProtocol.setPakMk(true);//浣滀笟鏍囪澶嶄綅
+                    shuttleProtocol.setPakMk(false);//浣滀笟鏍囪澶嶄綅
+
+                    shuttleProtocol.setMoveLoc(false);
+                    shuttleProtocol.setMoveType(0);
+                    shuttleProtocol.setXStart(0);
+                    shuttleProtocol.setXTarget(0);
+                    shuttleProtocol.setXCurrent(0);
+                    shuttleProtocol.setYStart(0);
+                    shuttleProtocol.setYTarget(0);
+                    shuttleProtocol.setYCurrent(0);
                     return R.ok();
                 } else if (shuttleTaskModeType == ShuttleTaskModeType.SHUTTLE_CONTROL) {
                     //灏忚溅绠″埗
@@ -323,6 +375,10 @@
                     ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>();
                     commands.add(suspendCommand);
                     assignCommand.setCommands(commands);
+                } else if (shuttleTaskModeType == ShuttleTaskModeType.MOVE_LOC_NO_WRK_MAST) {
+                    //绉诲姩鍒扮洰鏍囧簱浣�(鐢熸垚绉诲姩浠诲姟)
+                    shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(3), param.getDistLocNo(), param.getShuttleNo());
+                    return R.ok();
                 } else {
                     throw new CoolException("鏈煡鍛戒护");
                 }
@@ -378,4 +434,40 @@
         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) {
+        NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+        if (shuttleThread == null) {
+            return R.error();
+        }
+
+        NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+        if (shuttleProtocol == null) {
+            return R.error();
+        }
+
+        if (!shuttleProtocol.isIdle()) {
+            return R.error("灏忚溅蹇欑涓�");
+        }
+
+        shuttleProtocol.setMoveLoc(true);//寮�鍚窇搴�
+        shuttleProtocol.setMoveType(moveType);
+        shuttleProtocol.setXStart(xStart);
+        shuttleProtocol.setXTarget(xTarget);
+        shuttleProtocol.setXCurrent(xStart);
+        shuttleProtocol.setYStart(yStart);
+        shuttleProtocol.setYTarget(yTarget);
+        shuttleProtocol.setYCurrent(yStart);
+        return R.ok();
+    }
+
 }

--
Gitblit v1.9.1