lsh
2026-04-21 720e0926fa1c94b952c26e111206c5d6e1ed5ba2
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -1,16 +1,24 @@
package com.zy.core.utils;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.utils.Utils;
import com.zy.asrs.service.*;
import com.zy.common.service.CommonService;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.dispatch.StationCommandDispatcher;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.StationCommandType;
import com.zy.core.enums.WrkIoType;
import com.zy.core.enums.WrkStsType;
import com.zy.core.model.StationObjModel;
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.task.MainProcessLane;
import com.zy.core.task.MainProcessTaskSubmitter;
@@ -30,6 +38,8 @@
@Component
public class StationOperateProcessUtils {
    private static final String STATION_COMMAND_SOURCE = "station-operate-process";
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
@@ -52,10 +62,106 @@
    private StationOutboundDecisionSupport stationOutboundDecisionSupport;
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private CommonService commonService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private StationCommandDispatcher stationCommandDispatcher;
    public void submitStationEnableInTasks(long minIntervalMs) {
        submitStationEnableInTasks(MainProcessLane.STATION_ENABLE_IN, minIntervalMs);
    }
    public void submitStationEnableInTasks(MainProcessLane lane,
                                           long minIntervalMs) {
        List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>());
        for (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;
            }
            for (StationObjModel stationObjModel : basDevp.getInStationList$()) {
                Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId();
                if (stationId == null || !stationMap.containsKey(stationId)) {
                    continue;
                }
                mainProcessTaskSubmitter.submitKeyedSerialTask(
                        lane,
                        stationId,
                        "stationEnableInExecute",
                        minIntervalMs,
                        () -> stationEnableInExecute(basDevp, stationObjModel)
                );
            }
        }
    }
    // 执行单个站点的入库任务下发
    public void stationInExecute(BasDevp basDevp, StationObjModel stationObjModel) {
        stationRegularDispatchProcessor.stationInExecute(basDevp, stationObjModel);
    }
    // 执行单个站点的启动入库下发
    public void stationEnableInExecute(BasDevp basDevp, StationObjModel stationObjModel) {
        if (basDevp == null || stationObjModel == null || stationObjModel.getStationId() == null) {
            return;
        }
        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
        if (stationThread == null) {
            return;
        }
        Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
        if (stationMap == null || stationMap.isEmpty()) {
            return;
        }
        Integer stationId = stationObjModel.getStationId();
        if (!stationMap.containsKey(stationId)) {
            return;
        }
        StationProtocol stationProtocol = stationMap.get(stationId);
        if (stationProtocol == null) {
            return;
        }
        Object lock = redisUtil.get(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId);
        if (lock != null) {
            return;
        }
        if (!stationProtocol.isAutoing()
                || !stationProtocol.isLoading()
                || stationProtocol.getTaskNo() != 0
                || !stationProtocol.isEnableIn()) {
            return;
        }
        Integer barcodeStationId = stationObjModel.getBarcodeStation() == null ? null : stationObjModel.getBarcodeStation().getStationId();
        if (barcodeStationId == null) {
            return;
        }
        StationCommand command = stationThread.getCommand(
                StationCommandType.MOVE,
                commonService.getWorkNo(WrkIoType.ENABLE_IN.id),
                stationId,
                barcodeStationId,
                0
        );
        stationCommandDispatcher.dispatch(basDevp.getDevpNo(), command, STATION_COMMAND_SOURCE, "enable-in");
        Utils.precomputeInTaskEnableRow(barcodeStationId);
        redisUtil.set(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 15);
        // 启动入库时删除退回控制key,允许后续异常时再次生成退回命令
        redisUtil.del(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + barcodeStationId);
        News.info("{}站点启动入库成功,数据包:{}", stationId, JSON.toJSONString(command));
    }
    // 执行单个出库任务对应的输送站点下发
@@ -94,9 +200,24 @@
        if (wrkMast == null) {
            return;
        }
        if (!Objects.equals(wrkMast.getStaNo(), stationObjModel.getStationId())) {
            News.info("入库站点到达扫描忽略,工作号={},扫描站点={},任务目标站={},原因=target_mismatch",
                    wrkMast.getWrkNo(), stationObjModel.getStationId(), wrkMast.getStaNo());
            return;
        }
        if (!Objects.equals(wrkMast.getWrkSts(), WrkStsType.INBOUND_STATION_RUN.sts)) {
            News.info("入库站点到达扫描忽略,工作号={},扫描站点={},任务状态={},原因=wrk_sts_mismatch",
                    wrkMast.getWrkNo(), stationObjModel.getStationId(), wrkMast.getWrkSts());
            return;
        }
        News.info("入库站点到达扫描命中,工作号={},扫描站点={},目标站={},站点taskNo={},准备转状态3",
                wrkMast.getWrkNo(), stationObjModel.getStationId(), wrkMast.getStaNo(), stationProtocol.getTaskNo());
        boolean updated = wrkAnalysisService.completeInboundStationRun(wrkMast, new Date());
        if (updated) {
            News.info("入库站点到达扫描命中,工作号={},目标站={}", wrkMast.getWrkNo(), wrkMast.getStaNo());
            News.info("入库站点到达扫描完成,工作号={},目标站={},结果=updated_to_3", wrkMast.getWrkNo(), wrkMast.getStaNo());
        }
        else {
            News.info("入库站点到达扫描结束,工作号={},目标站={},结果=skip_update", wrkMast.getWrkNo(), wrkMast.getStaNo());
        }
    }