#
Junjie
2025-07-09 44b027ef477f5af53491783c7c66771814951c70
src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
@@ -25,10 +25,10 @@
@SuppressWarnings("all")
public class FakeNyShuttleThread implements ThreadHandler {
    private RedisUtil redisUtil;
    private JSONObject fakeStatusDemo = JSONObject.parseObject("{\"mode\":1,\"extend\":{\"countQuantity\":400,\"suspendState\":0,\"minCellVoltage\":3279,\"chargeCycleTimes\":0,\"maxCellVoltage\":3281,\"surplusQuantity\":204,\"voltage\":5248},\"hasLift\":false,\"hasPallet\":false,\"batteryVoltage\":5248,\"runDirection\":\"2\",\"currentCode\":\"{\\\"x\\\":19,\\\"y\\\":11,\\\"z\\\":2}\",\"errorCode\":\"0\",\"hasCharge\":false,\"batteryPower\":\"51\",\"speed\":0,\"deviceStatus\":1}");
    private ServerSocket serverSocket;
    private Integer gatewayPort;
    private HashMap<String, Thread> fakeThreadMap = new HashMap();
    private HashMap<String, Socket> fakeServerMap = new HashMap();
    private HashMap<String, JSONObject> fakeStatusMap = new HashMap();
@@ -36,8 +36,9 @@
    private boolean fake = false;
    public FakeNyShuttleThread(RedisUtil redisUtil) {
    public FakeNyShuttleThread(RedisUtil redisUtil, Integer gatewayPort) {
        this.redisUtil = redisUtil;
        this.gatewayPort = gatewayPort;
    }
    @Override
@@ -54,11 +55,7 @@
                    if(fakeDeviceUtils == null){
                        continue;
                    }
                    String fakeDeviceConfig = fakeDeviceUtils.getFakeDeviceConfig();
                    if(null == fakeDeviceConfig) {
                        continue;
                    }
                    List<DeviceConfig> deviceConfigs = JSON.parseArray(fakeDeviceConfig, DeviceConfig.class);
                    List<DeviceConfig> deviceConfigs = fakeDeviceUtils.getFakeDeviceConfig();
                    for (DeviceConfig device : deviceConfigs) {
                        excuteFakeCommand(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo());
                    }
@@ -73,7 +70,7 @@
            try {
                try {
                    if (serverSocket == null) {
                        serverSocket = new ServerSocket(8888);
                        serverSocket = new ServerSocket(gatewayPort);
                    }
                }catch (Exception e){
                    e.printStackTrace();
@@ -98,54 +95,51 @@
        if(fakeDeviceUtils == null){
            return;
        }
        String fakeDeviceConfig = fakeDeviceUtils.getFakeDeviceConfig();
        if(null != fakeDeviceConfig){
            List<DeviceConfig> deviceConfigs = JSON.parseArray(fakeDeviceConfig, DeviceConfig.class);
            for (DeviceConfig device : deviceConfigs) {
                if (!device.getDeviceType().equals(String.valueOf(SlaveType.Shuttle))) {
                    continue;
                }
        List<DeviceConfig> deviceConfigs = fakeDeviceUtils.getFakeDeviceConfig();
        for (DeviceConfig device : deviceConfigs) {
            if (!device.getDeviceType().equals(String.valueOf(SlaveType.Shuttle))) {
                continue;
            }
                if (!device.getThreadImpl().equals("NyShuttleThread")) {
                    continue;
                }
            if (!device.getThreadImpl().equals("NyShuttleThread")) {
                continue;
            }
                if (fakeThreadMap.containsKey(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo())) {
                    continue;
                }
            if (fakeThreadMap.containsKey(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo())) {
                continue;
            }
                log.info("{}:device is run,devices:{}", device.getDeviceNo(),JSON.toJSONString(fakeServerMap));
            log.info("{}:device is run,devices:{}", device.getDeviceNo(),JSON.toJSONString(fakeServerMap));
                Thread fakeThread = new Thread(() -> {
                    log.info("{}:device is start handle client", device.getDeviceNo());
                    try {
                        while (true) {
                            if(!fakeServerMap.containsKey(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo())){
                                log.info("{}:device is start,devices:{}", device.getDeviceNo(),JSON.toJSONString(fakeServerMap));
                                Socket fakeSocket = serverSocket.accept();
                                String fakeStatus = JSON.toJSONString(fakeStatusDemo);
                                if (!Cools.isEmpty(device.getFakeInitStatus())) {
                                    fakeStatus = device.getFakeInitStatus();
                                }
                                fakeServerMap.put(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo(), fakeSocket);
                                fakeStatusMap.put(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo(), JSON.parseObject(fakeStatus));
            Thread fakeThread = new Thread(() -> {
                log.info("{}:device is start handle client", device.getDeviceNo());
                try {
                    while (true) {
                        if(!fakeServerMap.containsKey(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo())){
                            log.info("{}:device is start,devices:{}", device.getDeviceNo(),JSON.toJSONString(fakeServerMap));
                            Socket fakeSocket = serverSocket.accept();
                            String fakeStatus = JSON.toJSONString(fakeStatusDemo);
                            if (!Cools.isEmpty(device.getFakeInitStatus())) {
                                fakeStatus = device.getFakeInitStatus();
                            }
                            handleClient(device);
                            fakeServerMap.put(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo(), fakeSocket);
                            fakeStatusMap.put(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo(), JSON.parseObject(fakeStatus));
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                });
                fakeThread.start();
                fakeThreadMap.put(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo(), fakeThread);
                // init
                ThreadHandler thread = new NyShuttleThread(device, redisUtil);;
                new Thread(thread).start();
                SlaveConnection.put(SlaveType.Shuttle, device.getDeviceNo(), thread);
            }
                        handleClient(device);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            });
            fakeThread.start();
            fakeThreadMap.put(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo(), fakeThread);
            // init
            ThreadHandler thread = new NyShuttleThread(device, redisUtil);;
            new Thread(thread).start();
            SlaveConnection.put(SlaveType.Shuttle, device.getDeviceNo(), thread);
        }
    }