From 7381c3f093f3b98d169f5f75b05bb8f01a9e799a Mon Sep 17 00:00:00 2001
From: LSH
Date: 星期五, 22 十二月 2023 12:52:45 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/controller/CommandInfoController.java |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/CommandInfoController.java b/src/main/java/com/zy/asrs/controller/CommandInfoController.java
index 5bd8726..26e7ce6 100644
--- a/src/main/java/com/zy/asrs/controller/CommandInfoController.java
+++ b/src/main/java/com/zy/asrs/controller/CommandInfoController.java
@@ -1,5 +1,6 @@
 package com.zy.asrs.controller;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
@@ -13,6 +14,13 @@
 import com.core.common.Cools;
 import com.core.common.R;
 import com.zy.common.web.BaseController;
+import com.zy.core.cache.MessageQueue;
+import com.zy.core.enums.CommandStatusType;
+import com.zy.core.enums.SlaveType;
+import com.zy.core.model.Task;
+import com.zy.core.model.command.CommandPackage;
+import com.zy.core.model.command.CrnCommand;
+import com.zy.core.model.protocol.StaProtocol;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -40,7 +48,6 @@
         EntityWrapper<CommandInfo> wrapper = new EntityWrapper<>();
         excludeTrash(param);
         convert(param, wrapper);
-        wrapper.in("command_status", "1,2");
         if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
         return R.ok(commandInfoService.selectPage(new Page<>(curr, limit), wrapper));
     }
@@ -55,7 +62,6 @@
         EntityWrapper<CommandInfo> wrapper = new EntityWrapper<>();
         excludeTrash(param);
         convert(param, wrapper);
-        wrapper.in("command_status", "3");
         if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
         return R.ok(commandInfoService.selectPage(new Page<>(curr, limit), wrapper));
     }
@@ -136,4 +142,50 @@
         return R.ok();
     }
 
+    @PostMapping(value = "/commandInfo/executeCommand")
+    @ManagerAuth
+    public R executeCommand(@RequestParam("id") Integer id) {
+        CommandInfo commandInfo = commandInfoService.selectById(id);
+        if (commandInfo == null) {
+            return R.error("鎸囦护涓嶅瓨鍦�");
+        }
+
+        commandInfo.setCommandStatus(CommandStatusType.EXECUTE.id);//鎵ц鐘舵��
+        commandInfo.setExecuteTime(new Date());
+        if (commandInfoService.updateById(commandInfo)) {
+            //灏嗘寚浠よ繘琛屾姇閫�
+            CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);
+            SlaveType type = SlaveType.findInstance(commandInfo.getDevice());
+            if (type == null) {
+                return R.error("鏈煡璁惧");
+            }
+
+            switch (type) {
+                case Crn:
+                    CrnCommand crnCommand = JSON.parseObject(commandPackage.getCommand().toString(), CrnCommand.class);
+                    MessageQueue.offer(type, crnCommand.getCrnNo(), new Task(5, crnCommand));
+                    break;
+                case Devp:
+                    StaProtocol staProtocol = JSON.parseObject(commandPackage.getCommand().toString(), StaProtocol.class);
+                    MessageQueue.offer(type, staProtocol.getSiteId(), new Task(3, staProtocol));
+                    break;
+            }
+        }
+        return R.ok();
+    }
+
+    @PostMapping(value = "/commandInfo/completeCommand")
+    @ManagerAuth
+    public R completeCommand(@RequestParam("id") Integer id) {
+        CommandInfo commandInfo = commandInfoService.selectById(id);
+        if (commandInfo == null) {
+            return R.error("鎸囦护涓嶅瓨鍦�");
+        }
+
+        commandInfo.setCommandStatus(CommandStatusType.COMPLETE.id);//瀹屾垚鐘舵��
+        commandInfo.setCompleteTime(new Date());
+        commandInfoService.updateById(commandInfo);
+        return R.ok();
+    }
+
 }

--
Gitblit v1.9.1