From f5e49b2c04137fdc88c453cbe5d190cf7daab079 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期二, 30 十二月 2025 15:39:53 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java | 92 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 88 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java b/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
index 3e354a4..9ac77c5 100644
--- a/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
@@ -1,6 +1,8 @@
package com.zy.core.thread.impl;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
@@ -12,11 +14,10 @@
import com.zy.asrs.service.BasDualCrnpService;
import com.zy.asrs.utils.Utils;
import com.zy.common.utils.RedisUtil;
+import com.zy.core.News;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
-import com.zy.core.enums.DualCrnTaskModeType;
-import com.zy.core.enums.RedisKeyType;
-import com.zy.core.enums.SlaveType;
+import com.zy.core.enums.*;
import com.zy.core.model.CommandResponse;
import com.zy.core.model.Task;
import com.zy.core.model.command.DualCrnCommand;
@@ -30,6 +31,8 @@
import java.text.MessageFormat;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
@@ -51,6 +54,7 @@
private volatile boolean closed = false;
private ScheduledExecutorService readExecutor;
private ScheduledExecutorService processExecutor;
+ private ScheduledExecutorService commandExecutor;
public ZySiemensDualCrnThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
this.deviceConfig = deviceConfig;
@@ -102,13 +106,93 @@
if (task != null) {
step = task.getStep();
}
- if (step == 2 && task != null) {
+
+ if (step == 2) {
+ List<DualCrnCommand> commandList = (List<DualCrnCommand>) task.getData();
+ DualCrnCommand command = commandList.get(0);
+
+ HashMap<String, Object> map = new HashMap<>();
+ map.put("commands", commandList);
+ map.put("idx", 1);
+ redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + command.getTaskNo(), JSON.toJSONString(map, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24);
+ sendCommand(command);
+ } else if (step == 3) {
sendCommand((DualCrnCommand) task.getData());
}
} catch (Exception e) {
e.printStackTrace();
}
}, 0, 200, TimeUnit.MILLISECONDS);
+
+ commandExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread t = new Thread(r);
+ t.setName("DualCrnCommand-" + deviceConfig.getDeviceNo());
+ t.setDaemon(true);
+ return t;
+ }
+ });
+ commandExecutor.scheduleAtFixedRate(() -> {
+ if (closed || Thread.currentThread().isInterrupted()) {
+ return;
+ }
+ try {
+ if(crnProtocol.getMode() != DualCrnModeType.AUTO.id) {
+ return;
+ }
+
+ if(crnProtocol.getAlarm() != 0) {
+ return;
+ }
+
+ //绛夊緟涓嬩竴涓换鍔�
+ Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
+ if (wait != null) {
+ return;
+ }
+
+ if(crnProtocol.getTaskNo() > 0 && crnProtocol.getStatus() == DualCrnStatusType.IDLE.id) {
+ Integer taskNo = crnProtocol.getTaskNo();
+ Object commandObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo);
+ if (commandObj == null) {
+ News.error("鍙屽伐浣嶅爢鍨涙満锛屽伐浣�1绌洪棽绛夊緟涓嬪彂鍛戒护锛屼絾鏈壘鍒板懡浠ゃ�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crnProtocol.getCrnNo(), taskNo);
+ return;
+ }
+
+ JSONObject commandMap = JSON.parseObject(commandObj.toString());
+ Integer idx = commandMap.getInteger("idx");
+ List<DualCrnCommand> commandList = commandMap.getJSONArray("commands").toJavaList(DualCrnCommand.class);
+ DualCrnCommand dualCommand = commandList.get(idx);
+ idx++;
+ commandMap.put("idx", idx);
+ sendCommand(dualCommand);
+ redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo, commandMap.toJSONString(), 60 * 60 * 24);
+ }
+
+ if(crnProtocol.getTaskNoTwo() > 0 && crnProtocol.getStatusTwo() == DualCrnStatusType.IDLE.id) {
+ Integer taskNo = crnProtocol.getTaskNoTwo();
+ Object commandObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo);
+ if (commandObj == null) {
+ News.error("鍙屽伐浣嶅爢鍨涙満锛屽伐浣�2绌洪棽绛夊緟涓嬪彂鍛戒护锛屼絾鏈壘鍒板懡浠ゃ�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crnProtocol.getCrnNo(), taskNo);
+ return;
+ }
+
+ JSONObject commandMap = JSON.parseObject(commandObj.toString());
+ Integer idx = commandMap.getInteger("idx");
+ List<DualCrnCommand> commandList = commandMap.getJSONArray("commands").toJavaList(DualCrnCommand.class);
+ DualCrnCommand dualCommand = commandList.get(idx);
+ idx++;
+ commandMap.put("idx", idx);
+ sendCommand(dualCommand);
+ redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo, commandMap.toJSONString(), 60 * 60 * 24);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ log.error("DualCrnCommandThread Fail", e);
+ }
+ }, 0, 200, TimeUnit.MILLISECONDS);
}
/**
--
Gitblit v1.9.1