#
DELL
2025-09-18 53a71007458bdded764dc52a39d596f8c4ca28db
#
2个文件已修改
186 ■■■■ 已修改文件
src/main/java/com/zy/core/thread/fake/FakeNyLiftThread.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/NyLiftThread.java 142 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/fake/FakeNyLiftThread.java
@@ -1,6 +1,7 @@
package com.zy.core.thread.fake;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zy.common.Cools;
import com.zy.common.SpringUtils;
@@ -28,7 +29,7 @@
public class FakeNyLiftThread implements FakeThread {
    private RedisUtil redisUtil;
    private JSONObject fakeStatusDemo = JSONObject.parseObject("{\"model\":2,\"plcTaskNo\":0,\"lev\":1,\"deviceStatus\":0,\"taskMode\":0,\"pick\":0,\"put\":0,\"iOMode\":0,\"errorCode\":0,\"hasTray\":0,\"hasCar\":0,\"trayList\":[0,0,0,0],\"carList\":[0,0,0,0],\"extend\":{\"frontOverrun\":false,\"backOverrun\":false,\"leftOverrun\":false,\"rightOverrun\":false,\"overHeight\":false,\"overWeight\":false}}");
    private JSONObject fakeStatusDemo = JSONObject.parseObject("{\"model\":2,\"plcTaskNo\":0,\"lev\":1,\"deviceStatus\":0,\"taskMode\":0,\"pick\":0,\"put\":0,\"iOMode\":0,\"errorCode\":0,\"hasTray\":0,\"hasCar\":0,\"stationList\":[{\"siteId\":101,\"model\":1,\"busy\":0,\"hasTray\":0,\"deviceError\":0,\"taskNo\":0,\"staNo\":0,\"allowShuttleTake\":0,\"allowShuttlePut\":0,\"barcode\":\"\"},{\"siteId\":102,\"model\":1,\"busy\":0,\"hasTray\":0,\"deviceError\":0,\"taskNo\":0,\"staNo\":0,\"allowShuttleTake\":0,\"allowShuttlePut\":0,\"barcode\":\"\"},{\"siteId\":103,\"model\":1,\"busy\":0,\"hasTray\":0,\"deviceError\":0,\"taskNo\":0,\"staNo\":0,\"allowShuttleTake\":0,\"allowShuttlePut\":0,\"barcode\":\"\"},{\"siteId\":1001,\"model\":1,\"busy\":0,\"hasTray\":0,\"deviceError\":0,\"taskNo\":0,\"staNo\":0,\"allowShuttleTake\":0,\"allowShuttlePut\":0,\"barcode\":\"\"},{\"siteId\":1002,\"model\":1,\"busy\":0,\"hasTray\":0,\"deviceError\":0,\"taskNo\":0,\"staNo\":0,\"allowShuttleTake\":0,\"allowShuttlePut\":0,\"barcode\":\"\"},{\"siteId\":1003,\"model\":1,\"busy\":0,\"hasTray\":0,\"deviceError\":0,\"taskNo\":0,\"staNo\":0,\"allowShuttleTake\":0,\"allowShuttlePut\":0,\"barcode\":\"\"}],\"extend\":{\"frontOverrun\":false,\"backOverrun\":false,\"leftOverrun\":false,\"rightOverrun\":false,\"overHeight\":false,\"overWeight\":false}}");
    private ConcurrentHashMap<String, Thread> fakeThreadMap = new ConcurrentHashMap();
    private ConcurrentHashMap<String, JSONObject> fakeStatusMap = new ConcurrentHashMap();
    private ConcurrentHashMap<String, JSONObject> fakeCommandMap = new ConcurrentHashMap();
@@ -244,6 +245,27 @@
                    //切换出库模式
                    fakeStatus.put("iOMode", 2);//出入库模式
                    fakeStatusMap.put(key, fakeStatus);
                } else if (commandType == 10000) {
                    //写入输送线数据
                    Integer siteId = commandBody.getInteger("siteId");
                    Integer staNo = commandBody.getInteger("staNo");
                    Integer taskNo = commandBody.getInteger("taskNo");
                    String address = commandBody.getString("address");
                    short[] array = new short[2];
                    array[0] = staNo.shortValue();//目标站
                    array[1] = taskNo.shortValue();//任务号
                    JSONArray stationList = fakeStatus.getJSONArray("stationList");
                    for (int i = 0; i < stationList.size(); i++) {
                        JSONObject staObj = stationList.getJSONObject(i);
                        if (staObj.getInteger("siteId").equals(siteId)) {
                            staObj.put("taskNo", taskNo);
                            staObj.put("staNo", staNo);
                        }
                    }
                    fakeStatusMap.put(key, fakeStatus);
                }
            }catch (Exception e){
@@ -333,6 +355,10 @@
            //读取状态
            response = genereateFakeStatusResponse(fakeStatus);
            deviceMsgType = "status";
        } else if (mode == 10000) {
            //写入输送线数据
            fakeCommandMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), fakeCommand);
            response = genereateFakeCommandResponse();
        }
        fakeStatusMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), fakeStatus);
@@ -368,20 +394,8 @@
        device.put("hasCar", fakeStatus.getInteger("hasCar"));
        device.put("lev", fakeStatus.getInteger("lev"));
        Object trayListObj = fakeStatus.get("trayList");
        List<Integer> trayList = new ArrayList<>();
        if (trayListObj != null) {
            trayList = JSON.parseArray(JSON.toJSONString(trayListObj), Integer.class);
        }
        Object carListObj = fakeStatus.get("carList");
        List<Integer> carList = new ArrayList<>();
        if (carListObj != null) {
            carList = JSON.parseArray(JSON.toJSONString(carListObj), Integer.class);
        }
        device.put("trayList", trayList);
        device.put("carList", carList);
        JSONArray stationList = fakeStatus.getJSONArray("stationList");
        device.put("stationList", stationList);
        JSONObject extend = fakeStatus.getJSONObject("extend");
        device.put("frontOverrun", extend.getBoolean("frontOverrun"));
src/main/java/com/zy/core/thread/impl/NyLiftThread.java
@@ -22,10 +22,7 @@
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.*;
@Slf4j
@SuppressWarnings("all")
@@ -130,6 +127,9 @@
                    resultData.put("result", "success");
                }
            }
            resultData.put("commandResult1", JSON.toJSONString(result));
            resultData.put("commandResult2", JSON.toJSONString(result2));
        } else if (commandObj.getInteger("mode") == 4) {
            //小车换层
            short[] array = new short[4];
@@ -146,6 +146,9 @@
                    resultData.put("result", "success");
                }
            }
            resultData.put("commandResult1", JSON.toJSONString(result));
            resultData.put("commandResult2", JSON.toJSONString(result2));
        } else if (commandObj.getInteger("mode") == 5) {
            //提升机移动
            short[] array = new short[4];
@@ -162,6 +165,9 @@
                    resultData.put("result", "success");
                }
            }
            resultData.put("commandResult1", JSON.toJSONString(result));
            resultData.put("commandResult2", JSON.toJSONString(result2));
        } else if (commandObj.getInteger("mode") == 9996) {
            //复位
            short[] array = new short[1];
@@ -172,6 +178,9 @@
            if (result.IsSuccess) {
                resultData.put("result", "success");
            }
            resultData.put("commandResult1", JSON.toJSONString(result));
            resultData.put("commandResult2", JSON.toJSONString(result2));
        } else if (commandObj.getInteger("mode") == 9997) {
            //切换入库模式
            short[] array = new short[1];
@@ -182,6 +191,9 @@
            if (result.IsSuccess) {
                resultData.put("result", "success");
            }
            resultData.put("commandResult1", JSON.toJSONString(result));
            resultData.put("commandResult2", JSON.toJSONString(result2));
        } else if (commandObj.getInteger("mode") == 9998) {
            //切换出库模式
            short[] array = new short[1];
@@ -192,64 +204,124 @@
            if (result.IsSuccess) {
                resultData.put("result", "success");
            }
            resultData.put("commandResult1", JSON.toJSONString(result));
            resultData.put("commandResult2", JSON.toJSONString(result2));
        } else if (commandObj.getInteger("mode") == 9999) {
            //读取状态
            JSONObject device = new JSONObject();
            OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB101.0", (short) 18);
            OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB82.0", (short) 14);
            if (readResult1.IsSuccess) {
                //读取4.0-4.7数据
                boolean[] status1 = siemensS7Net.getByteTransform().TransBool(readResult1.Content, 4, 1);
                //读取5.0-5.7数据
                boolean[] status2 = siemensS7Net.getByteTransform().TransBool(readResult1.Content, 5, 1);
                //模式
                device.put("model", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 0));
                device.put("model", status1[0] ? 2 : 1);
                //PLC任务号
                device.put("wrkNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 2));
                device.put("wrkNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 6));
                //设备状态
                device.put("deviceStatus", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 4));
                device.put("deviceStatus", status1[0] ? 0 : 1);
                //任务模式
                device.put("taskMode", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 6));
                device.put("taskMode", 0);
                //取货数据
                device.put("pick", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 8));
                device.put("pick", 0);
                //放货数据
                device.put("put", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 10));
                device.put("put", 0);
                //出入库模式
                device.put("iOMode", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 12));
                device.put("iOMode", 0);
                //有托盘
                device.put("hasTray", status2[5] ? 1 : 0);
                //有小车
                device.put("hasCar", status2[6] ? 1 : 0);
                //故障码
                device.put("errorCode", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 14));
                device.put("errorCode", status2[7] ? 1 : 0);
                //层
                device.put("lev", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 16));
                device.put("lev", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 12));
                JSONObject extend = new JSONObject();
                device.put("extend", extend);
                //前超限
                extend.put("frontOverrun", status1[4] ? 1 : 0);
                //后超限
                extend.put("backOverrun", status1[5] ? 1 : 0);
                //左超限
                extend.put("leftOverrun", status1[6] ? 1 : 0);
                //右超限
                extend.put("rightOverrun", status1[7] ? 1 : 0);
                //超高
                extend.put("overHeight", status2[0] ? 1 : 0);
                //超重
                extend.put("overWeight", status2[1] ? 1 : 0);
                resultData.put("deviceStatus", device);
            }
            //站点个数
            int staCount = 4;
            //读取托盘数据
            List<Integer> trayList = new ArrayList<>();
            OperateResultExOne<byte[]> readResult2 = siemensS7Net.Read("DB102.0", (short) (staCount * 2));
            List<Integer> staList = new ArrayList<>();
            staList.add(101);
            staList.add(102);
            staList.add(103);
            staList.add(1001);
            staList.add(1002);
            staList.add(1003);
            List<JSONObject> stationList = new ArrayList<>();
            OperateResultExOne<byte[]> readResult2 = siemensS7Net.Read("DB82.14", (short) 156);
            if(readResult2.IsSuccess) {
                for (int i = 0; i < staCount; i++) {
                    short val = siemensS7Net.getByteTransform().TransInt16(readResult2.Content, i * 2);
                    trayList.add((int) val);
                int i = 0;
                for (Integer siteId : staList) {
                    //读取4.0-4.7数据
                    boolean[] status1 = siemensS7Net.getByteTransform().TransBool(readResult2.Content, i*26, 1);
                    //读取5.0-5.7数据
                    boolean[] status2 = siemensS7Net.getByteTransform().TransBool(readResult2.Content, i*26 + 1, 1);
                    String barcode = siemensS7Net.getByteTransform().TransString(readResult2.Content, i * 26 + 10, 12, "UTF-8");
                    JSONObject station = new JSONObject();
                    station.put("siteId", siteId);
                    station.put("model", status1[0] ? 1 : 0);
                    station.put("busy", status1[1] ? 1 : 0);
                    station.put("hasTray", status1[2] ? 1 : 0);
                    station.put("allowShuttleTake", status2[5] ? 1 : 0);
                    station.put("allowShuttlePut", status2[6] ? 1 : 0);
                    station.put("deviceError", status2[7] ? 1 : 0);
                    station.put("taskNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult2.Content, i*26 + 2));
                    station.put("staNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult2.Content, i*28 + 2));
                    station.put("barcode", barcode);
                }
            }
            //读取小车数据
            OperateResultExOne<byte[]> readResult3 = siemensS7Net.Read("DB102.50", (short) (staCount * 2));
            List<Integer> carList = new ArrayList<>();
            if(readResult3.IsSuccess) {
                for (int i = 0; i < staCount; i++) {
                    short val = siemensS7Net.getByteTransform().TransInt16(readResult3.Content, i * 2);
                    carList.add((int) val);
                }
            }
            device.put("stationList", stationList);
            device.put("trayList", trayList);
            device.put("carList", carList);
            resultData.put("commandResult1", JSON.toJSONString(readResult1.Content));
            resultData.put("commandResult2", JSON.toJSONString(readResult2.Content));
            deviceMsgType = "status";
        }
        } else if (commandObj.getInteger("mode") == 10000) {
            //写入输送线数据
        resultData.put("commandResult1", JSON.toJSONString(result));
        resultData.put("commandResult2", JSON.toJSONString(result2));
            JSONObject commandBody = commandObj.getJSONObject("commandBody");
            Integer siteId = commandBody.getInteger("siteId");
            Integer staNo = commandBody.getInteger("staNo");
            Integer taskNo = commandBody.getInteger("taskNo");
            String address = commandBody.getString("address");
            short[] array = new short[2];
            array[0] = staNo.shortValue();//目标站
            array[1] = taskNo.shortValue();//任务号
            resultData.put("commandData", array);
            result = siemensS7Net.Write("address", array);
            if (result.IsSuccess) {
                resultData.put("result", "success");
            }
            resultData.put("commandResult1", JSON.toJSONString(result));
        }
        if (deviceMsgType.equals("command")) {
            log.info("收到Rcs Lift Command Data: {}", JSON.toJSONString(deviceCommandMsg));