From f41fe0f4ac015caecd46f468ebb0236c540a4275 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期五, 10 五月 2024 10:32:41 +0800
Subject: [PATCH] #
---
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/FlowExecute.java | 202 +------------------------
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/ShuttleExecute.java | 80 ++++++++++
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/DevpExecute.java | 23 ++
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/BaseExecute.java | 52 ++++++
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/LiftExecute.java | 112 ++++++++++++++
5 files changed, 275 insertions(+), 194 deletions(-)
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/BaseExecute.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/BaseExecute.java
new file mode 100644
index 0000000..60e20da
--- /dev/null
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/BaseExecute.java
@@ -0,0 +1,52 @@
+package com.zy.asrs.wcs.asrs.execute;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.zy.asrs.wcs.core.utils.RedisUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class BaseExecute {
+
+ @Autowired
+ private RedisUtil redisUtil;
+
+ public boolean redisSet(String redisKey, String key, Object data) {
+ if (redisUtil.hasKey(redisKey)) {
+ Object obj = redisUtil.get(redisKey);
+ JSONObject object = JSON.parseObject(String.valueOf(obj));
+ object.put(key, data);
+ redisUtil.set(redisKey, JSON.toJSONString(object));
+ } else {
+ JSONObject object = new JSONObject();
+ object.put(key, data);
+ redisUtil.set(redisKey, JSON.toJSONString(object));
+ }
+ return true;
+ }
+
+ public Object redisGet(String redisKey, String key) {
+ if (redisUtil.hasKey(redisKey)) {
+ Object obj = redisUtil.get(redisKey);
+ JSONObject object = JSON.parseObject(String.valueOf(obj));
+ if (!object.containsKey(key)) {
+ return null;
+ }
+ return object.get(key);
+ }
+ return null;
+ }
+
+ public JSONObject findFLow(List<JSONObject> list, String id) {
+ for (JSONObject flow : list) {
+ if (flow.getString("id").equals(id)) {
+ return flow;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/DevpExecute.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/DevpExecute.java
new file mode 100644
index 0000000..b556e83
--- /dev/null
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/DevpExecute.java
@@ -0,0 +1,23 @@
+package com.zy.asrs.wcs.asrs.execute;
+
+import com.alibaba.fastjson.JSONObject;
+import com.zy.asrs.wcs.core.entity.Task;
+import com.zy.asrs.wcs.core.utils.RedisUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class DevpExecute extends BaseExecute {
+
+ @Autowired
+ private RedisUtil redisUtil;
+
+ public boolean execute(Task task, JSONObject data, String redisKey) {
+ JSONObject devpType = data.getJSONObject("devpType");
+ String staNo = devpType.getString("staNo");
+ //鎼滅储宸ヤ綔
+
+ return true;
+ }
+
+}
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/FlowExecute.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/FlowExecute.java
index 07dca21..a666188 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/FlowExecute.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/FlowExecute.java
@@ -4,22 +4,10 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.framework.common.Cools;
-import com.zy.asrs.framework.exception.CoolException;
-import com.zy.asrs.wcs.core.domain.dto.MotionDto;
import com.zy.asrs.wcs.core.entity.Motion;
import com.zy.asrs.wcs.core.entity.Task;
-import com.zy.asrs.wcs.core.kernel.KernelService;
import com.zy.asrs.wcs.core.service.TaskService;
import com.zy.asrs.wcs.core.utils.RedisUtil;
-import com.zy.asrs.wcs.core.utils.ShuttleDispatcher;
-import com.zy.asrs.wcs.core.utils.Utils;
-import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
-import com.zy.asrs.wcs.rcs.entity.Device;
-import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
-import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
-import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
-import com.zy.asrs.wcs.rcs.thread.LiftThread;
-import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -28,16 +16,18 @@
import java.util.List;
@Component
-public class FlowExecute {
+public class FlowExecute extends BaseExecute {
@Autowired
private RedisUtil redisUtil;
@Autowired
private TaskService taskService;
@Autowired
- private ShuttleDispatcher shuttleDispatcher;
+ private ShuttleExecute shuttleExecute;
@Autowired
- private KernelService kernelService;
+ private LiftExecute liftExecute;
+ @Autowired
+ private DevpExecute devpExecute;
//鎵ц娴佺▼鍥�
public boolean execute(List<JSONObject> list) {
@@ -85,191 +75,15 @@
String type = data.getString("type");
boolean result = false;
if (type.equals("devp")) {
- result = executeDevpFlow(task, data, redisKey);
+ result = devpExecute.execute(task, data, redisKey);
} else if (type.equals("shuttle")) {
- result = executeShuttleFlow(task, data, redisKey);
+ result = shuttleExecute.execute(task, data, redisKey);
} else if (type.equals("lift")) {
- result = executeLiftFlow(task, data, redisKey);
+ result = liftExecute.execute(task, data, redisKey);
}
return result;
}
- private JSONObject findFLow(List<JSONObject> list, String id) {
- for (JSONObject flow : list) {
- if (flow.getString("id").equals(id)) {
- return flow;
- }
- }
- return null;
- }
-
- private boolean executeDevpFlow(Task task, JSONObject data, String redisKey) {
- JSONObject devpType = data.getJSONObject("devpType");
- String staNo = devpType.getString("staNo");
- //鎼滅储宸ヤ綔
-
- return true;
- }
-
- private boolean executeShuttleFlow(Task task, JSONObject data, String redisKey) {
- JSONObject shuttleType = data.getJSONObject("shuttleType");
- String oper = shuttleType.getString("shuttleOper");
- if (oper.equals("searchIdleShuttle")) {
- //鎼滅储绌洪棽杞�
- ShuttleThread shuttleThread = shuttleDispatcher.searchIdleShuttle(task);
- if (shuttleThread == null) {
- throw new CoolException("绌挎杞︿笉瀛樺湪");
- }
- //瀛樺叆缂撳瓨
- redisSet(redisKey, "shuttleDevice", shuttleThread.getDevice());
- return true;
- } else if (oper.equals("judgeShuttleCurrentTaskLev")) {
- //鍒ゆ柇灏忚溅鏄惁鍦ㄤ换鍔℃ゼ灞�
- //鍙栧嚭缂撳瓨灏忚溅
- Object shuttleDeviceObj = redisGet(redisKey, "shuttleDevice");
- if (shuttleDeviceObj == null) {
- throw new CoolException("绌挎杞︾紦瀛樹负绌�");
- }
- Device device = JSON.parseObject(String.valueOf(shuttleDeviceObj), Device.class);
- if (device == null) {
- throw new CoolException("绌挎杞﹁澶囦笉瀛樺湪");
- }
-
- ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
- if (shuttleThread == null) {
- throw new CoolException("绌挎杞︿笉瀛樺湪");
- }
-
- ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
- if (shuttleProtocol == null) {
- throw new CoolException("绌挎杞︿笉瀛樺湪");
- }
-
- //灏忚溅鍧愭爣
- String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
- String taskLocNo = null;
- if (task.getTaskSts() < 100) {
- taskLocNo = task.getDestLoc();
- } else if (task.getTaskSts() > 100 && task.getTaskSts() < 200) {
- taskLocNo = task.getOriginLoc();
- }
-
- // 灏忚溅鍜屼换鍔℃ゼ灞備竴鑷�
- if (Utils.getLev(shuttleLocNo) == Utils.getLev(taskLocNo)) {
- return true;
- }else {
- return false;
- }
- }
-
- return true;
- }
-
- private boolean executeLiftFlow(Task task, JSONObject data, String redisKey) {
- Object object = redisGet(redisKey, "motionList");
- List<Motion> motionList = JSON.parseArray(JSON.toJSONString(object), Motion.class);
-
- Object liftDeviceObj = redisGet(redisKey, "liftDevice");
- if (liftDeviceObj == null) {
- throw new CoolException("鎻愬崌鏈虹紦瀛樹负绌�");
- }
-
- Device device = JSON.parseObject(String.valueOf(liftDeviceObj), Device.class);
- if (device == null) {
- throw new CoolException("鎻愬崌鏈鸿澶囦笉瀛樺湪");
- }
-
- LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getId().intValue());
- if (liftThread == null) {
- throw new CoolException("鎻愬崌鏈轰笉瀛樺湪");
- }
-
- LiftProtocol liftProtocol = liftThread.getStatus();
- if (liftProtocol == null) {
- throw new CoolException("鎻愬崌鏈轰笉瀛樺湪");
- }
-
- JSONObject liftType = data.getJSONObject("liftType");
- String opera = liftType.getString("liftOper");
- if (opera.equals("move")) {
- //鎻愬崌鏈哄崌闄�
- String sourceLevStr = liftType.getString("sourceLev");
- String targetLevStr = liftType.getString("targetLev");
- Integer sourceLev = getLiftOperaLev(sourceLevStr, task, redisKey);
- Integer targetLev = getLiftOperaLev(targetLevStr, task, redisKey);
-
- motionList.addAll(kernelService.liftMove(
- MotionDto.build((dto -> {
- dto.setLiftNo(device.getId().intValue());
- dto.setLev(sourceLev);
- }))
- , MotionDto.build((dto -> {
- dto.setLiftNo(device.getId().intValue());
- dto.setLev(targetLev);
- }))
- ));
- }
-
- return true;
- }
-
- private Integer getLiftOperaLev(String opera, Task task, String redisKey) {
- if (opera.equals("sourceLev")) {
- return Utils.getLev(task.getOriginLoc());
- } else if (opera.equals("targetLev")) {
- return Utils.getLev(task.getDestLoc());
- } else if (opera.equals("shuttleLev")) {
- //鍙栧嚭缂撳瓨灏忚溅
- Object shuttleDeviceObj = redisGet(redisKey, "shuttleDevice");
- if (shuttleDeviceObj == null) {
- throw new CoolException("绌挎杞︾紦瀛樹负绌�");
- }
- Device device = JSON.parseObject(String.valueOf(shuttleDeviceObj), Device.class);
- if (device == null) {
- throw new CoolException("绌挎杞﹁澶囦笉瀛樺湪");
- }
-
- ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
- if (shuttleThread == null) {
- throw new CoolException("绌挎杞︿笉瀛樺湪");
- }
-
- ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
- if (shuttleProtocol == null) {
- throw new CoolException("绌挎杞︿笉瀛樺湪");
- }
-
- return Utils.getLev(shuttleProtocol.getCurrentLocNo());
- }
-
- throw new CoolException("绫诲瀷寮傚父");
- }
-
- private boolean redisSet(String redisKey, String key, Object data) {
- if (redisUtil.hasKey(redisKey)) {
- Object obj = redisUtil.get(redisKey);
- JSONObject object = JSON.parseObject(String.valueOf(obj));
- object.put(key, data);
- redisUtil.set(redisKey, JSON.toJSONString(object));
- } else {
- JSONObject object = new JSONObject();
- object.put(key, data);
- redisUtil.set(redisKey, JSON.toJSONString(object));
- }
- return true;
- }
-
- private Object redisGet(String redisKey, String key) {
- if (redisUtil.hasKey(redisKey)) {
- Object obj = redisUtil.get(redisKey);
- JSONObject object = JSON.parseObject(String.valueOf(obj));
- if (!object.containsKey(key)) {
- return null;
- }
- return object.get(key);
- }
- return null;
- }
// private boolean executeFlow(List<Map<String, Object>> list) {
// for (Map<String, Object> map : list) {
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/LiftExecute.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/LiftExecute.java
new file mode 100644
index 0000000..156151e
--- /dev/null
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/LiftExecute.java
@@ -0,0 +1,112 @@
+package com.zy.asrs.wcs.asrs.execute;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.zy.asrs.framework.exception.CoolException;
+import com.zy.asrs.wcs.core.domain.dto.MotionDto;
+import com.zy.asrs.wcs.core.entity.Motion;
+import com.zy.asrs.wcs.core.entity.Task;
+import com.zy.asrs.wcs.core.kernel.KernelService;
+import com.zy.asrs.wcs.core.utils.RedisUtil;
+import com.zy.asrs.wcs.core.utils.Utils;
+import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
+import com.zy.asrs.wcs.rcs.entity.Device;
+import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
+import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
+import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
+import com.zy.asrs.wcs.rcs.thread.LiftThread;
+import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class LiftExecute extends BaseExecute{
+
+ @Autowired
+ private RedisUtil redisUtil;
+ @Autowired
+ private KernelService kernelService;
+
+ public boolean execute(Task task, JSONObject data, String redisKey) {
+ Object object = redisGet(redisKey, "motionList");
+ List<Motion> motionList = JSON.parseArray(JSON.toJSONString(object), Motion.class);
+
+ Object liftDeviceObj = redisGet(redisKey, "liftDevice");
+ if (liftDeviceObj == null) {
+ throw new CoolException("鎻愬崌鏈虹紦瀛樹负绌�");
+ }
+
+ Device device = JSON.parseObject(String.valueOf(liftDeviceObj), Device.class);
+ if (device == null) {
+ throw new CoolException("鎻愬崌鏈鸿澶囦笉瀛樺湪");
+ }
+
+ LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getId().intValue());
+ if (liftThread == null) {
+ throw new CoolException("鎻愬崌鏈轰笉瀛樺湪");
+ }
+
+ LiftProtocol liftProtocol = liftThread.getStatus();
+ if (liftProtocol == null) {
+ throw new CoolException("鎻愬崌鏈轰笉瀛樺湪");
+ }
+
+ JSONObject liftType = data.getJSONObject("liftType");
+ String opera = liftType.getString("liftOper");
+ if (opera.equals("move")) {
+ //鎻愬崌鏈哄崌闄�
+ String sourceLevStr = liftType.getString("sourceLev");
+ String targetLevStr = liftType.getString("targetLev");
+ Integer sourceLev = getLiftOperaLev(sourceLevStr, task, redisKey);
+ Integer targetLev = getLiftOperaLev(targetLevStr, task, redisKey);
+
+ motionList.addAll(kernelService.liftMove(
+ MotionDto.build((dto -> {
+ dto.setLiftNo(device.getId().intValue());
+ dto.setLev(sourceLev);
+ }))
+ , MotionDto.build((dto -> {
+ dto.setLiftNo(device.getId().intValue());
+ dto.setLev(targetLev);
+ }))
+ ));
+ }
+
+ return true;
+ }
+
+ private Integer getLiftOperaLev(String opera, Task task, String redisKey) {
+ if (opera.equals("sourceLev")) {
+ return Utils.getLev(task.getOriginLoc());
+ } else if (opera.equals("targetLev")) {
+ return Utils.getLev(task.getDestLoc());
+ } else if (opera.equals("shuttleLev")) {
+ //鍙栧嚭缂撳瓨灏忚溅
+ Object shuttleDeviceObj = redisGet(redisKey, "shuttleDevice");
+ if (shuttleDeviceObj == null) {
+ throw new CoolException("绌挎杞︾紦瀛樹负绌�");
+ }
+ Device device = JSON.parseObject(String.valueOf(shuttleDeviceObj), Device.class);
+ if (device == null) {
+ throw new CoolException("绌挎杞﹁澶囦笉瀛樺湪");
+ }
+
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+ if (shuttleThread == null) {
+ throw new CoolException("绌挎杞︿笉瀛樺湪");
+ }
+
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (shuttleProtocol == null) {
+ throw new CoolException("绌挎杞︿笉瀛樺湪");
+ }
+
+ return Utils.getLev(shuttleProtocol.getCurrentLocNo());
+ }
+
+ throw new CoolException("绫诲瀷寮傚父");
+ }
+
+}
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/ShuttleExecute.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/ShuttleExecute.java
new file mode 100644
index 0000000..62cb72f
--- /dev/null
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/asrs/execute/ShuttleExecute.java
@@ -0,0 +1,80 @@
+package com.zy.asrs.wcs.asrs.execute;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.zy.asrs.framework.exception.CoolException;
+import com.zy.asrs.wcs.core.entity.Task;
+import com.zy.asrs.wcs.core.utils.RedisUtil;
+import com.zy.asrs.wcs.core.utils.ShuttleDispatcher;
+import com.zy.asrs.wcs.core.utils.Utils;
+import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
+import com.zy.asrs.wcs.rcs.entity.Device;
+import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
+import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
+import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ShuttleExecute extends BaseExecute {
+
+ @Autowired
+ private RedisUtil redisUtil;
+ @Autowired
+ private ShuttleDispatcher shuttleDispatcher;
+
+ public boolean execute(Task task, JSONObject data, String redisKey) {
+ JSONObject shuttleType = data.getJSONObject("shuttleType");
+ String oper = shuttleType.getString("shuttleOper");
+ if (oper.equals("searchIdleShuttle")) {
+ //鎼滅储绌洪棽杞�
+ ShuttleThread shuttleThread = shuttleDispatcher.searchIdleShuttle(task);
+ if (shuttleThread == null) {
+ throw new CoolException("绌挎杞︿笉瀛樺湪");
+ }
+ //瀛樺叆缂撳瓨
+ redisSet(redisKey, "shuttleDevice", shuttleThread.getDevice());
+ return true;
+ } else if (oper.equals("judgeShuttleCurrentTaskLev")) {
+ //鍒ゆ柇灏忚溅鏄惁鍦ㄤ换鍔℃ゼ灞�
+ //鍙栧嚭缂撳瓨灏忚溅
+ Object shuttleDeviceObj = redisGet(redisKey, "shuttleDevice");
+ if (shuttleDeviceObj == null) {
+ throw new CoolException("绌挎杞︾紦瀛樹负绌�");
+ }
+ Device device = JSON.parseObject(String.valueOf(shuttleDeviceObj), Device.class);
+ if (device == null) {
+ throw new CoolException("绌挎杞﹁澶囦笉瀛樺湪");
+ }
+
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+ if (shuttleThread == null) {
+ throw new CoolException("绌挎杞︿笉瀛樺湪");
+ }
+
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (shuttleProtocol == null) {
+ throw new CoolException("绌挎杞︿笉瀛樺湪");
+ }
+
+ //灏忚溅鍧愭爣
+ String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
+ String taskLocNo = null;
+ if (task.getTaskSts() < 100) {
+ taskLocNo = task.getDestLoc();
+ } else if (task.getTaskSts() > 100 && task.getTaskSts() < 200) {
+ taskLocNo = task.getOriginLoc();
+ }
+
+ // 灏忚溅鍜屼换鍔℃ゼ灞備竴鑷�
+ if (Utils.getLev(shuttleLocNo) == Utils.getLev(taskLocNo)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+}
--
Gitblit v1.9.1