From dc51e6bf7f20b2786bd16dc3e951ab8a299f4a34 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 09 八月 2023 09:32:12 +0800
Subject: [PATCH] 接口频率限制注解

---
 src/main/java/com/zy/asrs/utils/CommandUtils.java |  101 ++++++++++++++++++++++++++------------------------
 1 files changed, 53 insertions(+), 48 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..6f450de 100644
--- a/src/main/java/com/zy/asrs/utils/CommandUtils.java
+++ b/src/main/java/com/zy/asrs/utils/CommandUtils.java
@@ -6,14 +6,15 @@
 import com.zy.asrs.entity.WrkMast;
 import com.zy.asrs.service.CommandInfoService;
 import com.zy.asrs.service.WrkMastService;
+import com.zy.common.utils.RedisUtil;
 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.RedisCommand;
 import com.zy.core.model.protocol.StaProtocol;
 
+import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
 
 public class CommandUtils {
 
@@ -26,61 +27,65 @@
         if (wrkMastService == null) {
             return;
         }
+        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
+        if (redisUtil == null) {
+            return;
+        }
 
         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);
+        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) {
+            RedisCommand<CrnCommand> redisCommand = new RedisCommand();
+            ArrayList<CrnCommand> commands = new ArrayList<>();
 
-                command.setCommandInfo(commandInfo);
-                break;
-            case Devp:
-                StaProtocol staProtocol = (StaProtocol) task.getData();
-                taskNo = staProtocol.getWorkNo();
-                wrkMast = wrkMastService.selectById(taskNo);
+            CrnCommand command = (CrnCommand) task.getData();
+            wrkNo = command.getTaskNo();
+            if (wrkNo != 0) {
+                wrkMast = wrkMastService.selectById(wrkNo);
+                taskNo = wrkMast.getTaskNo();
+            }
 
-                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);
+            commandInfo = new CommandInfo();
+            commandInfo.setWrkNo(wrkNo);
+            commandInfo.setTaskNo(taskNo);
+            commandInfo.setCommandStatus(1);
+            commandInfo.setStartTime(new Date());
+            commandInfo.setDevice("crn");
+            commandInfo.setCommand(JSON.toJSONString(command));
+            commandInfoService.insert(commandInfo);
+            command.setCommandInfo(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);
+            commands.add(command);
+            redisCommand.setWrkNo(wrkNo);
+            redisCommand.setCommands(commands);
+        } else if (type == SlaveType.Devp) {
+            RedisCommand<StaProtocol> redisCommand = new RedisCommand();
+            ArrayList<StaProtocol> commands = new ArrayList<>();
 
-                    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);
+            StaProtocol staProtocol = (StaProtocol) task.getData();
+            wrkNo = staProtocol.getWorkNo();
+            if (wrkNo != 0) {
+                wrkMast = wrkMastService.selectById(wrkNo);
+                taskNo = wrkMast.getTaskNo();
+            }
 
-                    ledCommand.setCommandInfo(commandInfo);
-                }
-                break;
+            commandInfo = new CommandInfo();
+            commandInfo.setWrkNo(wrkNo);
+            commandInfo.setTaskNo(taskNo);
+            commandInfo.setCommandStatus(1);
+            commandInfo.setStartTime(new Date());
+            commandInfo.setDevice("devp");
+            commandInfo.setCommand(JSON.toJSONString(staProtocol));
+            commandInfoService.insert(commandInfo);
+
+            staProtocol.setCommandInfo(commandInfo);
+
+            commands.add(staProtocol);
+            redisCommand.setWrkNo(wrkNo);
+            redisCommand.setCommands(commands);
         }
 
     }

--
Gitblit v1.9.1