#
Junjie
2026-01-15 6200ba627af8af4045155c1bd7e65220ce59d6ba
src/main/java/com/zy/core/plugin/NormalProcess.java
@@ -32,6 +32,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -56,10 +57,10 @@
    @Override
    public void run() {
        //请求生成入库任务
        generateStoreWrkFile();
        //检测入库站是否有任务生成,并启动入库
        checkInStationHasTask();
        //请求生成入库任务
        generateStoreWrkFile();
        //执行堆垛机任务
        crnOperateUtils.crnIoExecute();
@@ -71,6 +72,9 @@
        stationOperateProcessUtils.stationOutExecute();
        //检测输送站点出库任务执行完成
        stationOperateProcessUtils.stationOutExecuteFinish();
        //检测输送站点是否运行堵塞
        stationOperateProcessUtils.checkStationRunBlock();
    }
    /**
@@ -78,73 +82,126 @@
     * 入库站,根据条码扫描生成入库工作档
     */
    public synchronized void generateStoreWrkFile() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if(stationThread == null){
                continue;
        try {
            Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
            if (systemConfigMapObj == null) {
                return;
            }
            HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
            int conveyorStationTaskLimit = 30;
            String conveyorStationTaskLimitStr = systemConfigMap.get("conveyorStationTaskLimit");
            if (conveyorStationTaskLimitStr != null) {
                conveyorStationTaskLimit = Integer.parseInt(conveyorStationTaskLimitStr);
            }
            int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
            if (currentStationTaskCount > conveyorStationTaskLimit) {
                News.error("输送站点任务已达到上限,上限值:{},站点任务数:{}", conveyorStationTaskLimit, currentStationTaskCount);
                return;
            }
            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
            List<StationObjModel> list = basDevp.getBarcodeStationList$();
            for (StationObjModel entity : list) {
                Integer stationId = entity.getStationId();
                if(!stationMap.containsKey(stationId)){
            List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
            for (BasDevp basDevp : basDevps) {
                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
                if (stationThread == null) {
                    continue;
                }
                StationProtocol stationProtocol = stationMap.get(stationId);
                if (stationProtocol == null) {
                    continue;
                }
                Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
                //满足自动、有物、有工作号,生成入库数据
                if (stationProtocol.isAutoing()
                        && stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() > 0
                ) {
                    if (Cools.isEmpty(stationProtocol.getBarcode())) {
                List<StationObjModel> list = basDevp.getBarcodeStationList$();
                for (StationObjModel entity : list) {
                    Integer stationId = entity.getStationId();
                    if (!stationMap.containsKey(stationId)) {
                        continue;
                    }
                    //检测任务是否生成
                    List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                    if (!wrkMasts.isEmpty()) {
                    StationProtocol stationProtocol = stationMap.get(stationId);
                    if (stationProtocol == null) {
                        continue;
                    }
                    Object lock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
                    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);
                        continue;
                    }
                    JSONObject jsonObject = JSON.parseObject(response);
                    if (jsonObject.getInteger("code").equals(200)) {
                        StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                        CreateInTaskParam taskParam = new CreateInTaskParam();
                        taskParam.setTaskNo(dto.getTaskNo());
                        taskParam.setLocNo(dto.getLocNo());
                        taskParam.setTaskPri(dto.getTaskPri());
                        taskParam.setBarcode(stationProtocol.getBarcode());
                        WrkMast wrkMast = commonService.createInTask(taskParam);
                        StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, wrkMast.getWrkNo(), stationId, stationId, 0);
                        if(command == null){
                            News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                    // 满足自动、有物、有工作号,生成入库数据
                    if (stationProtocol.isAutoing()
                            && stationProtocol.isLoading()
                            && stationProtocol.getTaskNo() > 0) {
                        if (Cools.isEmpty(stationProtocol.getBarcode())) {
                            continue;
                        }
                        MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                        // 检测任务是否生成
                        List<WrkMast> wrkMasts = wrkMastService
                                .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                        if (!wrkMasts.isEmpty()) {
                            continue;
                        }
                        Object lock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
                        if (lock != null) {
                            continue;
                        }
                        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);
                                CreateInTaskParam taskParam = new CreateInTaskParam();
                                taskParam.setTaskNo(dto.getTaskNo());
                                taskParam.setLocNo(dto.getLocNo());
                                taskParam.setTaskPri(dto.getTaskPri());
                                taskParam.setBarcode(barcode);
                                WrkMast wrkMast = commonService.createInTask(taskParam);
                                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);
                            }
                            // 如果有请求进行中,等待下次循环再检查
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
@@ -182,9 +239,10 @@
                        && stationProtocol.getTaskNo() == 0
                        && stationProtocol.isEnableIn()
                ) {
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId, entity.getBarcodeStation().getStationId(), 0);
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.ENABLE_IN.id), stationId, entity.getBarcodeStation().getStationId(), 0);
                    MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                    redisUtil.set(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 10);
                    redisUtil.set(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 15);
                    News.info("{}站点启动入库成功,数据包:{}", stationId, JSON.toJSONString(command));
                }
            }
        }