#
Junjie
2026-01-15 ef1cd5823fe7cf724e1de875a1a5737a44f160f1
src/main/java/com/zy/core/plugin/FakeProcess.java
@@ -88,6 +88,7 @@
    /**
     * 带超时保护执行方法
     *
     * @param taskName 任务名称(用于日志)
     * @param task 要执行的任务
     */
@@ -140,22 +141,26 @@
        asyncFakeRunThread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    Config enableFakeConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "enableFake"));
                    Config enableFakeConfig = configService
                            .selectOne(new EntityWrapper<Config>().eq("code", "enableFake"));
                    if (enableFakeConfig != null) {
                        enableFake = enableFakeConfig.getValue();
                    }
                    Config fakeRealTaskRequestWmsConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeRealTaskRequestWms"));
                    Config fakeRealTaskRequestWmsConfig = configService
                            .selectOne(new EntityWrapper<Config>().eq("code", "fakeRealTaskRequestWms"));
                    if (fakeRealTaskRequestWmsConfig != null) {
                        fakeRealTaskRequestWms = fakeRealTaskRequestWmsConfig.getValue();
                    }
                    Config fakeGenerateInTaskConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateInTask"));
                    Config fakeGenerateInTaskConfig = configService
                            .selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateInTask"));
                    if (fakeGenerateInTaskConfig != null) {
                        fakeGenerateInTask = fakeGenerateInTaskConfig.getValue();
                    }
                    Config fakeGenerateOutTaskConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateOutTask"));
                    Config fakeGenerateOutTaskConfig = configService
                            .selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateOutTask"));
                    if (fakeGenerateOutTaskConfig != null) {
                        fakeGenerateOutTask = fakeGenerateOutTaskConfig.getValue();
                    }
@@ -197,7 +202,7 @@
    }
    //检测入库站是否有任务生成,并仿真生成模拟入库站点数据
    private void checkInStationHasTask() {
    private synchronized void checkInStationHasTask() {
        if (!enableFake.equals("Y")) {
            return;
        }
@@ -235,9 +240,10 @@
                //满足自动、无物、工作号0,生成入库数据
                if (stationProtocol.isAutoing()
                        && !stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() == 0
                ) {
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId, entity.getBarcodeStation().getStationId(), 0);
                        && stationProtocol.getTaskNo() == 0) {
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE,
                            commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId,
                            entity.getBarcodeStation().getStationId(), 0);
                    MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                    redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 5);
                }
@@ -246,7 +252,7 @@
    }
    //生成仿真模拟入库任务
    private void generateFakeInTask() {
    private synchronized void generateFakeInTask() {
        if (!enableFake.equals("Y")) {
            return;
        }
@@ -288,19 +294,20 @@
                //满足自动、有物、有工作号,生成入库数据
                if (stationProtocol.isAutoing()
                        && stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() > 0
                ) {
                        && stationProtocol.getTaskNo() > 0) {
                    if (Cools.isEmpty(stationProtocol.getBarcode())) {
                        continue;
                    }
                    //检测任务是否生成
                    List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                    List<WrkMast> wrkMasts = wrkMastService
                            .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                    if (!wrkMasts.isEmpty()) {
                        continue;
                    }
                    List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.O)));
                    List<LocMast> locMastList = locMastService
                            .selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.O)));
                    if (locMastList.isEmpty()) {
                        continue;
                    }
@@ -326,7 +333,8 @@
                    taskParam.setBarcode(stationProtocol.getBarcode());
                    WrkMast wrkMast = commonService.createInTask(taskParam);
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationId, stationId, 0);
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(),
                            stationId, stationId, 0);
                    if(command == null){
                        News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                        continue;
@@ -339,7 +347,7 @@
    }
    //生成仿真模拟出库任务
    private void generateFakeOutTask() {
    private synchronized void generateFakeOutTask() {
        if (!enableFake.equals("Y")) {
            return;
        }
@@ -381,9 +389,9 @@
                //满足自动、无物、工作号0,生成出库数据
                if (stationProtocol.isAutoing()
                        && !stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() == 0
                ) {
                    List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.F)));
                        && stationProtocol.getTaskNo() == 0) {
                    List<LocMast> locMastList = locMastService
                            .selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.F)));
                    if (locMastList.isEmpty()) {
                        continue;
                    }
@@ -452,14 +460,14 @@
                    //满足自动、有物、有工作号,生成入库数据
                    if (stationProtocol.isAutoing()
                            && stationProtocol.isLoading()
                            && stationProtocol.getTaskNo() > 0
                    ) {
                            && stationProtocol.getTaskNo() > 0) {
                        if (Cools.isEmpty(stationProtocol.getBarcode())) {
                            continue;
                        }
                        //检测任务是否生成
                        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                        List<WrkMast> wrkMasts = wrkMastService
                                .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                        if (!wrkMasts.isEmpty()) {
                            continue;
                        }
@@ -468,13 +476,26 @@
                        if (lock != null) {
                            continue;
                        }
                        redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
                        String response = wmsOperateUtils.applyInTask(stationProtocol.getBarcode(), stationProtocol.getStationId(), stationProtocol.getPalletHeight());
                        if (response == null) {
                            News.error("请求WMS入库接口失败,接口未响应!!!response:{}", response);
                        String barcode = stationProtocol.getBarcode();
                        Integer stationIdVal = stationProtocol.getStationId();
                        // 1. 首先查询是否有已完成的异步响应
                        String response = wmsOperateUtils.queryAsyncInTaskResponse(barcode, stationIdVal);
                        if (response != null) {
                            // 2. 有响应结果,处理响应
                            if (response.equals("FAILED") || response.startsWith("ERROR:")) {
                                // 请求失败,重新发起异步请求
                                News.error("WMS入库请求失败,重新发起请求,barcode={},stationId={},response={}", barcode,
                                        stationIdVal, response);
                                wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal,
                                        stationProtocol.getPalletHeight());
                                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
                            continue;
                        }
                            // 解析响应
                        JSONObject jsonObject = JSON.parseObject(response);
                        if (jsonObject.getInteger("code").equals(200)) {
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
@@ -483,15 +504,34 @@
                            taskParam.setTaskNo(dto.getTaskNo());
                            taskParam.setLocNo(dto.getLocNo());
                            taskParam.setTaskPri(dto.getTaskPri());
                            taskParam.setBarcode(stationProtocol.getBarcode());
                                taskParam.setBarcode(barcode);
                            WrkMast wrkMast = commonService.createInTask(taskParam);
                            StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, wrkMast.getWrkNo(), stationId, stationId, 0);
                                StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO,
                                        wrkMast.getWrkNo(), stationId, stationId, 0);
                            if (command == null) {
                                News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                                continue;
                            }
                            MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                            } else {
                                // 接口返回非200,重新发起请求
                                News.error("WMS入库接口返回非200,重新发起请求,barcode={},stationId={},response={}", barcode,
                                        stationIdVal, response);
                                wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal,
                                        stationProtocol.getPalletHeight());
                                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
                            }
                        } else {
                            // 3. 没有响应结果,检查是否有请求正在进行中
                            if (!wmsOperateUtils.isAsyncRequestInProgress(barcode, stationIdVal)) {
                                // 没有请求进行中,发起新的异步请求
                                News.info("发起异步WMS入库请求,barcode={},stationId={}", barcode, stationIdVal);
                                wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal,
                                        stationProtocol.getPalletHeight());
                                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
                            }
                            // 如果有请求进行中,等待下次循环再检查
                        }
                    }
                }
@@ -502,7 +542,7 @@
    }
    //计算所有站点停留时间
    public void calcAllStationStayTime() {
    public synchronized void calcAllStationStayTime() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
@@ -512,11 +552,13 @@
            List<StationProtocol> list = stationThread.getStatus();
            for (StationProtocol stationProtocol : list) {
                if (stationProtocol.getTaskNo() > 0 && !stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
                if (stationProtocol.getTaskNo() > 0
                        && !stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
                    stationStayTimeMap.put(stationProtocol.getStationId(), System.currentTimeMillis());
                }
                if(stationProtocol.getTaskNo() <= 0 && stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
                if (stationProtocol.getTaskNo() <= 0
                        && stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
                    stationStayTimeMap.remove(stationProtocol.getStationId());
                }
            }
@@ -524,7 +566,7 @@
    }
    //检测出库站点停留是否超时
    public void checkOutStationStayTimeOut() {
    public synchronized void checkOutStationStayTimeOut() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            List<StationObjModel> outStationList = basDevp.getOutStationList$();
@@ -534,7 +576,8 @@
            }
            for (StationObjModel stationObjModel : outStationList) {
                Object lock = redisUtil.get(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
                Object lock = redisUtil
                        .get(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
                if(lock != null){
                    continue;
                }
@@ -545,26 +588,31 @@
                }
                if(System.currentTimeMillis() - stayTime > 1000 * 15) {
                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
                            stationObjModel.getDeviceNo());
                    if(stationThread == null){
                        continue;
                    }
                    StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, stationObjModel.getStationId(), 0, 0);
                    StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0,
                            stationObjModel.getStationId(), 0, 0);
                    if(command == null){
                        continue;
                    }
                    MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                    redisUtil.set(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
                    News.info("输送站点出库重置命令下发成功,站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command));
                    redisUtil.set(
                            RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(),
                            "lock", 10);
                    News.info("输送站点出库重置命令下发成功,站点号={},命令数据={}", stationObjModel.getStationId(),
                            JSON.toJSONString(command));
                }
            }
        }
    }
    //检测入库站点堆垛机是否取走货物
    public void checkInStationCrnTake() {
    public synchronized void checkInStationCrnTake() {
        List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
        for (BasCrnp basCrnp : basCrnps) {
            List<StationObjModel> inStationList = basCrnp.getInStationList$();
@@ -586,14 +634,16 @@
        }
    }
    private void checkInStationListCrnTake(List<StationObjModel> inStationList) {
    private synchronized void checkInStationListCrnTake(List<StationObjModel> inStationList) {
        for (StationObjModel stationObjModel : inStationList) {
            Object lock = redisUtil.get(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
            Object lock = redisUtil
                    .get(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
            if(lock != null){
                continue;
            }
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
                    stationObjModel.getDeviceNo());
            if(stationThread == null){
                continue;
            }
@@ -605,7 +655,8 @@
            }
            if(stationProtocol.getTaskNo() > 0) {
                StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, stationObjModel.getStationId(), 0, 0);
                StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0,
                        stationObjModel.getStationId(), 0, 0);
                if(command == null){
                    continue;
                }
@@ -613,10 +664,14 @@
                WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
                if (wrkMast == null) {
                    MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                    redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
                    News.info("输送站点重置命令下发成功(task_over),站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command));
                    redisUtil.set(
                            RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(),
                            "lock", 10);
                    News.info("输送站点重置命令下发成功(task_over),站点号={},命令数据={}", stationObjModel.getStationId(),
                            JSON.toJSONString(command));
                }else {
                    if (wrkMast.getWrkSts() != WrkStsType.NEW_INBOUND.sts && wrkMast.getWrkSts() != WrkStsType.INBOUND_DEVICE_RUN.sts) {
                    if (wrkMast.getWrkSts() != WrkStsType.NEW_INBOUND.sts
                            && wrkMast.getWrkSts() != WrkStsType.INBOUND_DEVICE_RUN.sts) {
                        Integer crnNo = wrkMast.getCrnNo();
                        if (crnNo != null) {
                            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnNo);
@@ -624,16 +679,20 @@
                                continue;
                            }
                            CrnProtocol crnProtocol = crnThread.getStatus();
                            if (!crnProtocol.getStatusType().equals(CrnStatusType.PUT_MOVING) && !crnProtocol.getStatusType().equals(CrnStatusType.PUTTING)) {
                            if (!crnProtocol.getStatusType().equals(CrnStatusType.PUT_MOVING)
                                    && !crnProtocol.getStatusType().equals(CrnStatusType.PUTTING)) {
                                continue;
                            }
                            MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
                            News.info("输送站点重置命令下发成功(crn_fetch),站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command));
                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key
                                    + stationObjModel.getStationId(), "lock", 10);
                            News.info("输送站点重置命令下发成功(crn_fetch),站点号={},命令数据={}", stationObjModel.getStationId(),
                                    JSON.toJSONString(command));
                        }else {
                            Integer dualCrnNo = wrkMast.getDualCrnNo();
                            DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, dualCrnNo);
                            DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn,
                                    dualCrnNo);
                            if (dualCrnThread == null) {
                                continue;
                            }
@@ -653,8 +712,10 @@
                            }
                            MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
                            News.info("输送站点重置命令下发成功(crn_fetch),站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command));
                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key
                                    + stationObjModel.getStationId(), "lock", 10);
                            News.info("输送站点重置命令下发成功(crn_fetch),站点号={},命令数据={}", stationObjModel.getStationId(),
                                    JSON.toJSONString(command));
                        }
                    }
                }
@@ -663,7 +724,7 @@
    }
    //堆垛机任务执行完成
    public void crnIoExecuteFinish() {
    public synchronized void crnIoExecuteFinish() {
        List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
        for (BasCrnp basCrnp : basCrnps) {
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
@@ -678,8 +739,7 @@
            if (crnProtocol.getMode() == CrnModeType.AUTO.id
                    && crnProtocol.getTaskNo() > 0
                    && crnProtocol.getStatus() == CrnStatusType.WAITING.id
            ) {
                    && crnProtocol.getStatus() == CrnStatusType.WAITING.id) {
                Object lock = redisUtil.get(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo());
                if(lock != null){
                    continue;
@@ -710,12 +770,14 @@
                            continue;
                        }
                        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
                        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
                                stationObjModel.getDeviceNo());
                        if (stationThread == null) {
                            continue;
                        }
                        //生成仿真站点数据
                        StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9998, wrkMast.getSourceStaNo(), 0, 0);
                        StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9998,
                                wrkMast.getSourceStaNo(), 0, 0);
                        MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                    }
                }else if(wrkMast.getWrkSts() == WrkStsType.LOC_MOVE_RUN.sts){