From 3a641d32f53e378e5cfa1bd4b1ae5590f4883bda Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 25 七月 2023 10:42:54 +0800
Subject: [PATCH] 捡料

---
 src/main/java/com/zy/asrs/controller/ShuttleController.java |  154 +++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 118 insertions(+), 36 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/ShuttleController.java b/src/main/java/com/zy/asrs/controller/ShuttleController.java
index 6a5b55f..035c9f6 100644
--- a/src/main/java/com/zy/asrs/controller/ShuttleController.java
+++ b/src/main/java/com/zy/asrs/controller/ShuttleController.java
@@ -1,5 +1,6 @@
 package com.zy.asrs.controller;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.annotations.ManagerAuth;
 import com.core.common.BaseRes;
@@ -17,6 +18,7 @@
 import com.zy.asrs.utils.Utils;
 import com.zy.common.service.CommonService;
 import com.zy.common.utils.NavigatePositionConvert;
+import com.zy.common.utils.RedisUtil;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.cache.SlaveConnection;
@@ -24,6 +26,8 @@
 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.protocol.ShuttleProtocol;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.ShuttleThread;
@@ -32,7 +36,6 @@
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -53,6 +56,8 @@
     private LocMastService locMastService;
     @Autowired
     private CommonService commonService;
+    @Autowired
+    private RedisUtil redisUtil;
 
     @PostMapping("/table/shuttle/state")
     @ManagerAuth(memo = "鍥涘悜绌挎杞︿俊鎭〃")
@@ -242,43 +247,82 @@
         return R.ok().add(vo);
     }
 
-    @PostMapping("/detl/update")
-    @ManagerAuth(memo = "淇敼鏁版嵁")
-    public R liftUpdate(@RequestParam Integer shuttleNo,
-                        @RequestParam Short workNo,
-                        @RequestParam String pakMk){
-        for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) {
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId());
-            if (shuttleThread == null) {
-                return R.error("plc宸叉帀绾�");
-            }
-            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-            if (shuttleProtocol == null) {
-                return R.error("plc宸叉帀绾�");
-            }
-            if (workNo != null) {
-                shuttleProtocol.setTaskNo(workNo);
-            }
-            if (pakMk != null) {
-                shuttleProtocol.setPakMk(pakMk.equals("Y"));
-            }
-        }
-        return R.error("plc宸叉帀绾�");
-    }
-
-    @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)) {
+    @RequestMapping(value = "/command/query")
+    public R shuttleCommandQuery(@RequestParam("wrkNo") Integer wrkNo) {
+        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+        if (o == null) {
             return R.error();
         }
+        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
+        return R.ok().add(redisCommand);
+    }
+
+    //鍥為��鍛戒护
+    @RequestMapping(value = "/command/rollback")
+    public R shuttleCommandRollback(@RequestParam("wrkNo") Integer wrkNo
+            , @RequestParam("commandStep") Integer commandStep) {
+        Object o = redisUtil.get("shuttle_wrk_no_" + 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));
+        return R.ok();
+    }
+
+    //鍛戒护瀹屾垚鐘舵�佸垏鎹�
+    @RequestMapping(value = "/command/completeSwitch")
+    public R shuttleCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo
+            , @RequestParam("commandStep") Integer commandStep
+            , @RequestParam("complete") Integer complete) {
+        Object o = redisUtil.get("shuttle_wrk_no_" + 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("shuttle_wrk_no_" + 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);
+        if (o == null) {
+            return R.error();
+        }
+        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
+        Short shuttleNo = redisCommand.getShuttleNo();
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo.intValue());
+        if (shuttleThread == null) {
+            return R.error();
+        }
+        ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+        if (shuttleProtocol == null) {
+            return R.error();
+        }
+        if (!shuttleProtocol.isIdle()) {
+            return R.error();
+        }
+        //鍥涘悜绌挎杞﹀浜庣┖闂茬姸鎬侊紝杩涜浠诲姟鐨勬仮澶�
+        shuttleProtocol.setTaskNo(redisCommand.getWrkNo());//灏嗗洓鍚戠┛姊溅绾跨▼鍒嗛厤浠诲姟鍙�
+        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);//宸ヤ綔鐘舵��
+        return R.ok();
+    }
+
+    //鍒犻櫎浠诲姟(鍛戒护)
+    @RequestMapping(value = "/command/del")
+    public R liftCommandDel(@RequestParam("wrkNo") Integer wrkNo) {
+        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+        if (o == null) {
+            return R.error();
+        }
+        redisUtil.del("shuttle_wrk_no_" + wrkNo);
         return R.ok();
     }
 
@@ -330,4 +374,42 @@
         return R.error();
     }
 
+    @PostMapping("/detl/update")
+    @ManagerAuth(memo = "淇敼鏁版嵁")
+    public R shuttleUpdate(@RequestParam Integer shuttleNo,
+                        @RequestParam Short workNo,
+                        @RequestParam String pakMk){
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+        if (shuttleThread == null) {
+            return R.error("plc宸叉帀绾�");
+        }
+        ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+        if (shuttleProtocol == null) {
+            return R.error("plc宸叉帀绾�");
+        }
+        if (workNo != null) {
+            shuttleProtocol.setTaskNo(workNo);
+        }
+        if (pakMk != null) {
+            shuttleProtocol.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();
+    }
+
 }

--
Gitblit v1.9.1