#
Administrator
2026-04-25 4eb9cd026398e50c36a5c0339ea8992dc76e8318
src/main/java/com/zy/core/plugin/XiaosongProcess.java
@@ -95,18 +95,52 @@
    private void submitGenerateStoreWrkFileTask() {
        mainProcessTaskSubmitter.submitSerialTask(
                MainProcessLane.GENERATE_STORE,
                "generateStoreWrkFile",
                "submitGenerateStoreWrkFileTask",
                DISPATCH_INTERVAL_MS,
                this::generateStoreWrkFile
                this::submitGenerateStoreWrkFileTasksInternal
        );
    }
    /**
     * 请求生成入库任务
     * 入库站,根据条码扫描生成入库工作档
     */
    public synchronized void generateStoreWrkFile() {
        try {
    private void submitGenerateStoreWrkFileTasksInternal() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (final BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if (stationThread == null) {
                continue;
            }
            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
            if (stationMap == null || stationMap.isEmpty()) {
                continue;
            }
            List<StationObjModel> list = basDevp.getBarcodeStationList$();
            for (final StationObjModel entity : list) {
                Integer stationId = entity == null ? null : entity.getStationId();
                if (stationId == null || !stationMap.containsKey(stationId)) {
                    continue;
                }
                mainProcessTaskSubmitter.submitKeyedSerialTask(
                        MainProcessLane.GENERATE_STORE,
                        stationId,
                        "generateStoreWrkFile",
                        DISPATCH_INTERVAL_MS,
                        new Runnable() {
                            @Override
                            public void run() {
                                generateStoreWrkFile(basDevp, entity);
                            }
                        }
                );
            }
        }
    }
    private void generateStoreWrkFile(BasDevp basDevp, StationObjModel entity) {
        if (basDevp == null || entity == null || entity.getStationId() == null) {
            return;
        }
            Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
            if (systemConfigMapObj == null) {
                return;
@@ -124,57 +158,58 @@
                return;
            }
            List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
            for (BasDevp basDevp : basDevps) {
        Integer stationId = entity.getStationId();
                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
                if (stationThread == null) {
                    continue;
            return;
                }
                Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
                List<StationObjModel> list = basDevp.getBarcodeStationList$();
                for (StationObjModel entity : list) {
                    Integer stationId = entity.getStationId();
                    if (!stationMap.containsKey(stationId)) {
                        continue;
        if (stationMap == null || !stationMap.containsKey(stationId)) {
            return;
                    }
                    StationProtocol stationProtocol = stationMap.get(stationId);
                    if (stationProtocol == null) {
                        continue;
            return;
                    }
                    if (stationProtocol.isAutoing()
        if (!(stationProtocol.isAutoing()
                            && stationProtocol.isLoading()
                            && stationProtocol.isInEnable()
                            && stationProtocol.getTaskNo() > 0) {
                && stationProtocol.getTaskNo() > 0)) {
            return;
        }
                        if (Cools.isEmpty(stationProtocol.getBarcode())) {
                            continue;
            return;
                        }
                        if (stationProtocol.getError() > 0) {
                            Object lock = redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo());
                            if (lock != null) {
                                continue;
            Object backLock = redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo());
            if (backLock != null) {
                return;
                            }
                            StationObjModel backStation = entity.getBackStation();
                            StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.STATION_BACK.id), stationId, backStation.getStationId(), 0);
                            if (command == null) {
                                News.taskInfo(stationProtocol.getTaskNo(), "{}工作,获取输送线命令失败", stationProtocol.getTaskNo());
                                continue;
                return;
                            }
                            MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                            News.taskInfo(stationProtocol.getTaskNo(), "{}扫码异常,已退回至{}", backStation.getStationId());
                            redisUtil.set(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo(), "lock", 10);
                                continue;
            return;
                        }
                        // 检测任务是否生成
                        List<WrkMast> wrkMasts = wrkMastService
                                .selectList(new EntityWrapper<WrkMast>()
                                        .eq("barcode", stationProtocol.getBarcode()));
                        if (!wrkMasts.isEmpty()) {
            WrkMast firstWrkMast = wrkMasts.get(0);
            News.info("[WCS Debug][条码站入库] 条码已有工作档,跳过生成。stationId={},barcode={},当前站点taskNo={},已存在数量={},首个工作号={},状态={},locNo={}",
                    stationId, stationProtocol.getBarcode(), stationProtocol.getTaskNo(),
                    wrkMasts.size(), firstWrkMast.getWrkNo(), firstWrkMast.getWrkSts(),
                    firstWrkMast.getLocNo());
                            for (WrkMast wrkMast : wrkMasts) {
                                if (wrkMast.getIoType().equals(WrkIoType.OUT.id) && wrkMast.getWrkSts().equals(WrkStsType.STATION_RUN.sts)) {
                                    wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts);
@@ -182,49 +217,62 @@
                                    wrkMastService.updateById(wrkMast);
                                }
                            }
                            continue;
            return;
                        }
                        Object lock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
                        if (lock != null) {
                            continue;
        Object generateLock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
        if (generateLock != null) {
            return;
                        }
                        String barcode = stationProtocol.getBarcode();
                        Integer stationIdVal = stationProtocol.getStationId();
        long applyStartMs = System.currentTimeMillis();
        News.info("[WCS Debug][条码站入库] 准备请求WMS生成入库任务。stationId={},barcode={},stationTaskNo={},palletHeight={},isInEnable={}",
                stationIdVal, barcode, stationProtocol.getTaskNo(),
                stationProtocol.getPalletHeight(), stationProtocol.isInEnable());
                        String response = wmsOperateUtils.applyInTask(barcode, stationIdVal,
                                stationProtocol.getPalletHeight());
        News.info("[WCS Debug][条码站入库] WMS生成入库任务返回。stationId={},barcode={},stationTaskNo={},costMs={},response={}",
                stationIdVal, barcode, stationProtocol.getTaskNo(),
                System.currentTimeMillis() - applyStartMs, response);
                        if (response == null) {
                            News.error("WMS入库同步请求失败,接口未响应,barcode={},stationId={}", barcode, stationIdVal);
                            redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
                            stationProtocol.setSystemWarning("请求入库失败,WMS无返回");
                            continue;
            return;
                        }
                        JSONObject jsonObject = JSON.parseObject(response);
                        Integer code = jsonObject.getInteger("code");
                        if (code != null && code.equals(200)) {
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
            if (dto == null || Cools.isEmpty(dto.getLocNo())) {
                News.warn("[WCS Debug][条码站入库] WMS返回成功但库位为空,等待下一轮生成。stationId={},barcode={},stationTaskNo={},response={}",
                        stationIdVal, barcode, stationProtocol.getTaskNo(), response);
                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
                stationProtocol.setSystemWarning("WMS已返回任务但库位为空");
                return;
            }
                            CreateInTaskParam taskParam = new CreateInTaskParam();
                            taskParam.setTaskNo(dto.getTaskNo());
                            taskParam.setLocNo(dto.getLocNo());
                            taskParam.setTaskPri(dto.getTaskPri());
                            taskParam.setBarcode(barcode);
            News.info("[WCS Debug][条码站入库] 准备创建入库工作档。stationId={},barcode={},wmsTaskNo={},locNo={},taskPri={}",
                    stationIdVal, barcode, dto.getTaskNo(), dto.getLocNo(), dto.getTaskPri());
                            WrkMast wrkMast = commonService.createInTask(taskParam);
            News.info("[WCS Debug][条码站入库] 入库工作档创建完成。stationId={},barcode={},wmsTaskNo={},wrkNo={},locNo={}",
                    stationIdVal, barcode, dto.getTaskNo(),
                    wrkMast == null ? null : wrkMast.getWrkNo(), dto.getLocNo());
                            stationProtocol.setSystemWarning("");
                        } else {
                            News.error("WMS入库同步请求失败,接口返回Code异常,barcode={},stationId={},response={}",
                                    barcode, stationIdVal, response);
                            redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
                            stationProtocol.setSystemWarning("请求入库失败,WMS返回=" + response);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }