From 8ee999ed31c9c45b3acefdcdda51e97f236ee9c5 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 08 八月 2023 10:02:26 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/asrs/utils/CommandUtils.java | 107 +++++++++++++++++------------------
src/main/java/com/zy/common/utils/RedisUtil.java | 29 ++++++++-
src/main/java/com/zy/core/model/command/RedisCommand.java | 23 +++++++
3 files changed, 99 insertions(+), 60 deletions(-)
diff --git a/src/main/java/com/zy/asrs/utils/CommandUtils.java b/src/main/java/com/zy/asrs/utils/CommandUtils.java
index 2fad65c..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,71 +27,65 @@
if (wrkMastService == null) {
return;
}
+ RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
+ if (redisUtil == null) {
+ return;
+ }
CommandInfo commandInfo = null;
WrkMast wrkMast = null;
int wrkNo = 0;
String taskNo = null;
- switch (type) {
- case Crn:
- CrnCommand command = (CrnCommand) task.getData();
- wrkNo = command.getTaskNo();
- if (wrkNo != 0) {
- wrkMast = wrkMastService.selectById(wrkNo);
- taskNo = wrkMast.getTaskNo();
- }
- 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);
+ 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();
- wrkNo = staProtocol.getWorkNo();
- if (wrkNo != 0) {
- wrkMast = wrkMastService.selectById(wrkNo);
- taskNo = wrkMast.getTaskNo();
- }
+ CrnCommand command = (CrnCommand) task.getData();
+ wrkNo = command.getTaskNo();
+ if (wrkNo != 0) {
+ wrkMast = wrkMastService.selectById(wrkNo);
+ taskNo = wrkMast.getTaskNo();
+ }
- 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);
+ 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) {
- wrkNo = ledCommand.getWorkNo();
- if (wrkNo != 0) {
- wrkMast = wrkMastService.selectById(wrkNo);
- taskNo = wrkMast.getTaskNo();
- }
+ 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.setTaskNo(taskNo);
- 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);
}
}
diff --git a/src/main/java/com/zy/common/utils/RedisUtil.java b/src/main/java/com/zy/common/utils/RedisUtil.java
index b2df114..95da6dc 100644
--- a/src/main/java/com/zy/common/utils/RedisUtil.java
+++ b/src/main/java/com/zy/common/utils/RedisUtil.java
@@ -2,8 +2,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -13,13 +16,16 @@
* redisTemplate灏佽
*
*/
-//@Component
+@Component
public class RedisUtil {
- @Autowired
- private RedisTemplate<String, Object> redisTemplate;
+// @Autowired
+// private RedisTemplate<String, Object> redisTemplate;
- public RedisUtil(RedisTemplate<String, Object> redisTemplate) {
+ @Autowired
+ private RedisTemplate redisTemplate;
+
+ public RedisUtil(RedisTemplate redisTemplate) {
this.redisTemplate = redisTemplate;
}
@@ -96,6 +102,21 @@
}
/**
+ * 鑾峰彇鍏ㄩ儴鏁版嵁
+ * @return
+ */
+ public HashMap<Object, Object> getRedis() {
+ Set<String> keys = redisTemplate.keys("*");
+ HashMap<Object, Object> map = new HashMap<>();
+ for (String key : keys) {
+ Object value = redisTemplate.opsForValue().get(key);
+ map.put(key, value);
+ }
+
+ return map;//杩斿洖鍏ㄩ儴鏁版嵁闆嗗悎
+ }
+
+ /**
* 鏅�氱紦瀛樻斁鍏�
*
* @param key 閿�
diff --git a/src/main/java/com/zy/core/model/command/RedisCommand.java b/src/main/java/com/zy/core/model/command/RedisCommand.java
new file mode 100644
index 0000000..fb6c863
--- /dev/null
+++ b/src/main/java/com/zy/core/model/command/RedisCommand.java
@@ -0,0 +1,23 @@
+package com.zy.core.model.command;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Redis鎸囦护
+ */
+@Data
+public class RedisCommand<T> {
+
+ //宸ヤ綔鍙�
+ private Integer wrkNo;
+
+ //鍛戒护鎵ц姝ュ簭
+ private Integer commandStep = 0;
+
+ //鍛戒护闆嗗悎
+ private List<T> commands = new ArrayList<>();
+
+}
--
Gitblit v1.9.1