Junjie
2026-04-13 3e28500e76ffd71b7da90f40d1f3126c00a0e5f0
#站点运行优化
3个文件已修改
195 ■■■■■ 已修改文件
AGENTS.md 39 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/enums/RedisKeyType.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java 155 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
AGENTS.md
@@ -174,7 +174,36 @@
- 不新增与现有体系并行但职责重复的 Service、Util、线程或页面。
- 不绕过 Mapper XML 直接拼接杂散 SQL。
## 5. 执行前检查
## 5. 代码可读性要求
Agent 生成的代码必须易于人类阅读和维护,禁止以下写法:
### 5.1 命名
- 禁止单字母变量名(循环计数器 `i`/`j` 除外)、无意义缩写(`mgr`、`hdl`、`proc` 除非是项目既有约定)。
- 变量名和方法名必须能表达意图,读名字就知道"这是什么"或"做什么"。
- 中文业务术语可直接用拼音或英文全称,不要发明缩写。
### 5.2 控制流
- 禁止超过 3 层的嵌套 if/for。遇到深层嵌套,提取为独立方法或用 early-return 扁平化。
- 禁止超长方法(超过 80 行应考虑拆分)。
- 禁止在一个表达式里链式调用超过 3 个操作(如 `a.getB().getC().getD().do()`),应拆成中间变量并命名。
- 三元运算符只用于简单赋值,禁止嵌套三元。
### 5.3 注释与意图
- 不写"翻译式注释"(如 `// 获取用户名称` 放在 `getUserName()` 上方)。
- 注释只解释"为什么这样做",不重复"做了什么"。
- 复杂业务逻辑、非显而易见的边界处理、绕过的坑,必须加注释说明原因。
### 5.4 结构
- 不把多步逻辑压缩成一行以"减少行数"。一行只做一件事。
- 不为了"通用"而提前抽象。三次以上重复才考虑提取。
- 异常处理必须有实际意义,禁止空 catch、`e.printStackTrace()` 或吞掉异常后继续跑。
## 6. 执行前检查
开始实现前至少确认以下几点:
@@ -187,7 +216,7 @@
如果这些问题里有任何一项答案是“是”,实现时必须把相关链路一并纳入。
## 6. 搜索与排查方式
## 7. 搜索与排查方式
优先用快速定位,不做无边界扫读:
@@ -205,7 +234,7 @@
4. 状态回写点
5. 页面渲染或 WebSocket 消费点
## 7. 校验与验证
## 8. 校验与验证
按成本从低到高执行,无法执行时要明确说明原因。
@@ -251,7 +280,7 @@
- `/wcs/views/locMap/locMap.html`
- `/wcs/views/ai/*.html`
## 8. 高风险改动提醒
## 9. 高风险改动提醒
- 改 Mapper XML 时,重点防字段漏映射、别名不一致、结果集类型错误。
- 改线程/调度逻辑时,重点防竞态、重复下发、状态不回收、死循环、异常丢失。
@@ -260,7 +289,7 @@
- 改 AI 配置时,重点防把数据库配置链路和 YAML 回退链路混淆。
- 改监控/地图逻辑时,重点防“后端数据正确但前端渲染错位”和“前端显示正常但状态源错误”互相误判。
## 9. 输出要求
## 10. 输出要求
完成任务后,结果说明应尽量包含:
src/main/java/com/zy/core/enums/RedisKeyType.java
@@ -49,6 +49,7 @@
    STATION_OUT_PENDING_DISPATCH_("station_out_pending_dispatch_"),
    STATION_OUT_ORDER_DISPATCH_LIMIT_("station_out_order_dispatch_limit_"),
    STATION_RUN_BLOCK_DIRECT_REASSIGN_LIMIT_("station_run_block_direct_reassign_limit_"),
    STATION_RUN_BLOCK_DIRECT_REASSIGN_NEAREST_CACHE_("station_run_block_direct_reassign_nearest_cache_"),
    STATION_OUT_EXECUTE_COMPLETE_LIMIT("station_out_execute_complete_limit_"),
    CHECK_STATION_RUN_BLOCK_LIMIT_("check_station_run_block_limit_"),
    STATION_RUN_BLOCK_REROUTE_STATE_("station_run_block_reroute_state_"),
src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java
@@ -2,18 +2,18 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.entity.FindCrnNoResult;
import com.zy.common.model.NavigateNode;
import com.zy.common.model.StartupDto;
import com.zy.common.service.CommonService;
import com.zy.common.utils.NavigateUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.cache.SlaveConnection;
@@ -29,7 +29,6 @@
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.model.protocol.StationTaskBufferItem;
import com.zy.core.move.StationMoveCoordinator;
import com.zy.core.move.StationMoveSession;
import com.zy.core.thread.StationThread;
import com.zy.core.utils.station.model.OutOrderDispatchDecision;
import com.zy.core.utils.station.model.RerouteCommandPlan;
@@ -42,6 +41,7 @@
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -51,10 +51,9 @@
public class StationRerouteProcessor {
    private static final int OUT_ORDER_DISPATCH_LIMIT_SECONDS = 2;
    private static final long STATION_MOVE_RESET_WAIT_MS = 1000L;
    private static final int RUN_BLOCK_DIRECT_REASSIGN_LIMIT_SECONDS = 15 * 60;
    private static final int RUN_BLOCK_DIRECT_REASSIGN_LIMIT_SECONDS = 8 * 60;
    private static final int RUN_BLOCK_DIRECT_REASSIGN_NEAREST_CACHE_SECONDS = 60 * 60 * 24;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
@@ -73,6 +72,8 @@
    private StationOutboundDecisionSupport stationOutboundDecisionSupport;
    @Autowired
    private StationDispatchRuntimeStateSupport stationDispatchRuntimeStateSupport;
    @Autowired
    private NavigateUtils navigateUtils;
    public void checkStationRunBlock(BasDevp basDevp, Integer stationId) {
        try {
@@ -316,11 +317,141 @@
    public boolean shouldUseRunBlockDirectReassign(WrkMast wrkMast,
                                                   Integer stationId,
                                                   List<Integer> runBlockReassignLocStationList) {
        return wrkMast != null
                && Objects.equals(wrkMast.getIoType(), WrkIoType.IN.id)
                && stationId != null
                && runBlockReassignLocStationList != null
                && runBlockReassignLocStationList.contains(stationId);
        if (wrkMast == null || stationId == null) {
            return false;
        }
        if (!Objects.equals(wrkMast.getIoType(), WrkIoType.IN.id)) {
            return false;
        }
        if (runBlockReassignLocStationList == null || !runBlockReassignLocStationList.contains(stationId)) {
            return false;
        }
        if (shouldForceRunBlockPathReroute(wrkMast, stationId, runBlockReassignLocStationList)) {
            return false;
        }
        return true;
    }
    private boolean shouldForceRunBlockPathReroute(WrkMast wrkMast,
                                                   Integer stationId,
                                                   List<Integer> runBlockReassignLocStationList) {
        if (wrkMast == null || stationId == null) {
            return false;
        }
        Integer nearestStationId = resolveNearestRunBlockDirectReassignStationId(wrkMast, runBlockReassignLocStationList);
        return nearestStationId != null && !Objects.equals(stationId, nearestStationId);
    }
    private Integer resolveNearestRunBlockDirectReassignStationId(WrkMast wrkMast,
                                                                  List<Integer> runBlockReassignLocStationList) {
        if (wrkMast == null
                || wrkMast.getStaNo() == null
                || navigateUtils == null
                || runBlockReassignLocStationList == null
                || runBlockReassignLocStationList.isEmpty()) {
            return null;
        }
        Integer targetStationId = wrkMast.getStaNo();
        Integer cachedStationId = loadCachedNearestRunBlockDirectReassignStationId(targetStationId, runBlockReassignLocStationList);
        if (cachedStationId != null) {
            return cachedStationId;
        }
        Integer nearestStationId = null;
        int nearestPathLen = Integer.MAX_VALUE;
        for (Integer candidateStationId : runBlockReassignLocStationList) {
            if (candidateStationId == null) {
                continue;
            }
            List<NavigateNode> path = navigateUtils.calcOptimalPathByStationId(candidateStationId, targetStationId, wrkMast.getWrkNo(), null);
            if (path == null || path.isEmpty()) {
                continue;
            }
            int pathLen = countStationNodes(path);
            if (pathLen <= 0) {
                continue;
            }
            if (pathLen < nearestPathLen
                    || (pathLen == nearestPathLen && nearestStationId != null && candidateStationId < nearestStationId)) {
                nearestStationId = candidateStationId;
                nearestPathLen = pathLen;
            }
        }
        cacheNearestRunBlockDirectReassignStationId(targetStationId, runBlockReassignLocStationList, nearestStationId);
        return nearestStationId;
    }
    private Integer loadCachedNearestRunBlockDirectReassignStationId(Integer targetStationId,
                                                                     List<Integer> runBlockReassignLocStationList) {
        String cacheKey = buildNearestRunBlockDirectReassignCacheKey(targetStationId, runBlockReassignLocStationList);
        if (cacheKey == null || redisUtil == null) {
            return null;
        }
        Object cacheValue = redisUtil.get(cacheKey);
        if (cacheValue == null) {
            return null;
        }
        try {
            Integer stationId = Integer.valueOf(String.valueOf(cacheValue));
            return runBlockReassignLocStationList.contains(stationId) ? stationId : null;
        } catch (Exception ignore) {
            return null;
        }
    }
    private void cacheNearestRunBlockDirectReassignStationId(Integer targetStationId,
                                                             List<Integer> runBlockReassignLocStationList,
                                                             Integer nearestStationId) {
        String cacheKey = buildNearestRunBlockDirectReassignCacheKey(targetStationId, runBlockReassignLocStationList);
        if (cacheKey == null || nearestStationId == null || redisUtil == null) {
            return;
        }
        redisUtil.set(cacheKey, nearestStationId, RUN_BLOCK_DIRECT_REASSIGN_NEAREST_CACHE_SECONDS);
    }
    private String buildNearestRunBlockDirectReassignCacheKey(Integer targetStationId,
                                                              List<Integer> runBlockReassignLocStationList) {
        if (targetStationId == null || runBlockReassignLocStationList == null || runBlockReassignLocStationList.isEmpty()) {
            return null;
        }
        List<Integer> normalizedStationIdList = new ArrayList<>();
        for (Integer stationId : runBlockReassignLocStationList) {
            if (stationId != null && !normalizedStationIdList.contains(stationId)) {
                normalizedStationIdList.add(stationId);
            }
        }
        if (normalizedStationIdList.isEmpty()) {
            return null;
        }
        Collections.sort(normalizedStationIdList);
        return RedisKeyType.STATION_RUN_BLOCK_DIRECT_REASSIGN_NEAREST_CACHE_.key
                + targetStationId
                + "_"
                + JSON.toJSONString(normalizedStationIdList);
    }
    private int countStationNodes(List<NavigateNode> path) {
        if (path == null || path.isEmpty()) {
            return 0;
        }
        int count = 0;
        for (NavigateNode node : path) {
            if (extractStationId(node) != null) {
                count++;
            }
        }
        return count;
    }
    private Integer extractStationId(NavigateNode node) {
        if (node == null || Cools.isEmpty(node.getNodeValue())) {
            return null;
        }
        try {
            JSONObject valueObject = JSONObject.parseObject(node.getNodeValue());
            return valueObject == null ? null : valueObject.getInteger("stationId");
        } catch (Exception ignore) {
            return null;
        }
    }
    private boolean shouldSkipRunBlockStation(BasDevp basDevp, Integer stationId) {
@@ -461,7 +592,7 @@
        if (stationDispatchRuntimeStateSupport.hasRunBlockDirectReassignLimit(
                wrkMast.getWrkNo(),
                stationProtocol.getStationId())) {
            News.info("输送站点运行堵塞重分配已跳过,15分钟内不允许重复申请。站点号={},工作号={}",
            News.info("输送站点运行堵塞重分配已跳过,8分钟内不允许重复申请。站点号={},工作号={}",
                    stationProtocol.getStationId(),
                    wrkMast.getWrkNo());
            return;