From 18f1c7abcea6f2eca1967141e7b5e408893c31a9 Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期四, 03 四月 2025 10:39:47 +0800
Subject: [PATCH] *

---
 src/main/java/com/zy/asrs/utils/CommandUtils.java |  136 ++++++++++++++++++++++++++------------------
 1 files changed, 80 insertions(+), 56 deletions(-)

diff --git a/src/main/java/com/zy/asrs/utils/CommandUtils.java b/src/main/java/com/zy/asrs/utils/CommandUtils.java
index b483ad2..a18ce22 100644
--- a/src/main/java/com/zy/asrs/utils/CommandUtils.java
+++ b/src/main/java/com/zy/asrs/utils/CommandUtils.java
@@ -3,86 +3,110 @@
 import com.alibaba.fastjson.JSON;
 import com.core.common.SpringUtils;
 import com.zy.asrs.entity.CommandInfo;
-import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.entity.TaskWrk;
 import com.zy.asrs.service.CommandInfoService;
-import com.zy.asrs.service.WrkMastService;
+import com.zy.asrs.service.TaskWrkService;
+import com.zy.core.cache.MessageQueue;
+import com.zy.core.enums.CommandStatusType;
+import com.zy.core.enums.CommandType;
 import com.zy.core.enums.SlaveType;
 import com.zy.core.model.Task;
 import com.zy.core.model.command.CrnCommand;
-import com.zy.core.model.command.LedCommand;
+import com.zy.core.model.command.CommandPackage;
 import com.zy.core.model.protocol.StaProtocol;
 
 import java.util.Date;
-import java.util.List;
 
 public class CommandUtils {
 
-    public static void offer(SlaveType type, Integer id, Task task) {
+    public static boolean offer(SlaveType type, Integer id, Task task) {
+        return offer(type, id, task, true);
+    }
+
+    public static boolean offer(SlaveType type, Integer id, Task task, Boolean auto) {
         CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
         if (commandInfoService == null) {
-            return;
+            return false;
         }
-        WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
-        if (wrkMastService == null) {
-            return;
+        TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class);
+        if (taskWrkService == null) {
+            return false;
         }
 
         CommandInfo commandInfo = null;
-        WrkMast wrkMast = null;
-        int taskNo = 0;
-        switch (type) {
-            case Crn:
-                CrnCommand command = (CrnCommand) task.getData();
-                taskNo = command.getTaskNo();
-                wrkMast = wrkMastService.selectById(taskNo);
+        TaskWrk taskWrk = null;
+        int wrkNo = 0;//宸ヤ綔鍙�
+        String taskNo = null;//浠诲姟鍙�
 
-                commandInfo = new CommandInfo();
-                commandInfo.setWrkNo(taskNo);
-                commandInfo.setWmsWrkNo(wrkMast.getWmsWrkNo());
-                commandInfo.setCommandStatus(1);
-                commandInfo.setStartTime(new Date());
-                commandInfo.setDevice("crn");
-                commandInfo.setCommand(JSON.toJSONString(command));
-                commandInfoService.insert(commandInfo);
+        if (type == SlaveType.Crn) {
+            CommandPackage<CrnCommand> commandPackage = new CommandPackage<>();
+            CrnCommand command = (CrnCommand) task.getData();
+            wrkNo = command.getTaskNo();
+            if (auto && wrkNo != 0) {
+                taskWrk = taskWrkService.selectByWrkNo(wrkNo);
+                taskNo = taskWrk.getTaskNo();
+            }
 
-                command.setCommandInfo(commandInfo);
-                break;
-            case Devp:
-                StaProtocol staProtocol = (StaProtocol) task.getData();
-                taskNo = staProtocol.getWorkNo();
-                wrkMast = wrkMastService.selectById(taskNo);
+            commandInfo = new CommandInfo();
+            commandInfo.setWrkNo(wrkNo);
+            commandInfo.setTaskNo(taskNo);
+            commandInfo.setCommandStatus(CommandStatusType.CREATE.id);
+            commandInfo.setStartTime(new Date());
+            commandInfo.setDevice(SlaveType.Crn.toString());
+            commandInfo.setCommandType(auto? CommandType.AUTO.id : CommandType.MANUAL.id);
 
-                commandInfo = new CommandInfo();
-                commandInfo.setWrkNo(taskNo);
-                commandInfo.setWmsWrkNo(wrkMast.getWmsWrkNo());
-                commandInfo.setCommandStatus(1);
-                commandInfo.setStartTime(new Date());
-                commandInfo.setDevice("devp");
-                commandInfo.setCommand(JSON.toJSONString(staProtocol));
-                commandInfoService.insert(commandInfo);
+            commandInfoService.insert(commandInfo);//鎻掑叆鎸囦护
 
-                staProtocol.setCommandInfo(commandInfo);
-                break;
-            case Led:
-                List<LedCommand> data = (List<LedCommand>) task.getData();
-                for (LedCommand ledCommand : data) {
-                    taskNo = ledCommand.getWorkNo();
-                    wrkMast = wrkMastService.selectById(taskNo);
+            command.setCommandId(commandInfo.getId());
+            commandPackage.setWrkNo(wrkNo);
+            commandPackage.setDevice("鍫嗗灈鏈�");
+            commandPackage.setCommand(command);//淇濆瓨鍛戒护鎶ユ枃
+            commandInfo.setCommand(JSON.toJSONString(commandPackage));
+            commandInfoService.updateById(commandInfo);
 
-                    commandInfo = new CommandInfo();
-                    commandInfo.setWrkNo(ledCommand.getWorkNo());
-                    commandInfo.setWmsWrkNo(wrkMast.getWmsWrkNo());
-                    commandInfo.setCommandStatus(1);
-                    commandInfo.setStartTime(new Date());
-                    commandInfo.setDevice("led");
-                    commandInfo.setCommand(JSON.toJSONString(ledCommand));
-                    commandInfoService.insert(commandInfo);
-
-                    ledCommand.setCommandInfo(commandInfo);
+            if (!auto) {
+                //灏嗘寚浠よ繘琛屾姇閫�
+                if (!MessageQueue.offer(type, id, task)) {
+                    return false;
                 }
-                break;
+            }
+            return true;
+        } else if (type == SlaveType.Devp) {
+            CommandPackage<StaProtocol> commandPackage = new CommandPackage<>();
+            StaProtocol staProtocol = (StaProtocol) task.getData();
+            wrkNo = staProtocol.getWorkNo();
+            if (auto && wrkNo != 0) {
+                taskWrk = taskWrkService.selectByWrkNo(wrkNo);
+                taskNo = taskWrk.getTaskNo();
+            }
+
+            commandInfo = new CommandInfo();
+            commandInfo.setWrkNo(wrkNo);
+            commandInfo.setTaskNo(taskNo);
+            commandInfo.setCommandStatus(CommandStatusType.CREATE.id);
+            commandInfo.setStartTime(new Date());
+            commandInfo.setDevice(SlaveType.Devp.toString());
+            commandInfo.setCommandType(auto? CommandType.AUTO.id : CommandType.MANUAL.id);
+
+            commandInfoService.insert(commandInfo);//鎻掑叆鎸囦护
+
+            staProtocol.setCommandId(commandInfo.getId());
+            commandPackage.setCommand(staProtocol);
+            commandPackage.setWrkNo(wrkNo);
+            commandPackage.setDevice("杈撻�佺嚎");
+            commandInfo.setCommand(JSON.toJSONString(commandPackage));//淇濆瓨鍛戒护鎶ユ枃
+            commandInfoService.updateById(commandInfo);
+
+            if (!auto) {
+                //灏嗘寚浠よ繘琛屾姇閫�
+                if (!MessageQueue.offer(type, id, task)) {
+                    return false;
+                }
+            }
+            return true;
         }
 
+        return false;
     }
 
 }

--
Gitblit v1.9.1