#
Junjie
昨天 37348c5855649e98defe0f5b1557750cb7c84aa5
#
11个文件已修改
545 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/entity/BasDevp.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/service/CommonService.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/utils/NavigateSolution.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/utils/NavigateUtils.java 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/enums/RedisKeyType.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/enums/WrkStsType.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java 101 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/plugin/FakeProcess.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java 342 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/entity/BasDevp.java
@@ -243,4 +243,43 @@
        return list;
    }
    public List<StationObjModel> getOutOrderList$(){
        List<StationObjModel> list = new ArrayList<>();
        if (Cools.isEmpty(this.isOutOrderList)){
            return list;
        }
        List<StationObjModel> jsonList = JSON.parseArray(this.isOutOrderList, StationObjModel.class);
        for (StationObjModel json : jsonList){
            list.add(json);
        }
        return list;
    }
    public List<Integer> getOutOrderIntList(){
        List<Integer> list = new ArrayList<>();
        if (Cools.isEmpty(this.isOutOrderList)){
            return list;
        }
        List<StationObjModel> jsonList = JSON.parseArray(this.isOutOrderList, StationObjModel.class);
        for (StationObjModel json : jsonList){
            list.add(json.getStationId());
        }
        return list;
    }
    public List<StationObjModel> getLiftTransferList$(){
        List<StationObjModel> list = new ArrayList<>();
        if (Cools.isEmpty(this.isLiftTransferList)){
            return list;
        }
        List<StationObjModel> jsonList = JSON.parseArray(this.isLiftTransferList, StationObjModel.class);
        for (StationObjModel json : jsonList){
            list.add(json);
        }
        return list;
    }
}
src/main/java/com/zy/common/service/CommonService.java
@@ -12,10 +12,7 @@
import com.zy.common.utils.NavigateUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.WrkIoType;
import com.zy.core.enums.WrkStsType;
import com.zy.core.enums.*;
import com.zy.core.model.StationObjModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
src/main/java/com/zy/common/utils/NavigateSolution.java
@@ -302,22 +302,22 @@
        for(String direction : directionList) {
            if(direction.equals("top")) {
                NavigateNode node = getValidNavigateNode(map, x - 1, y);
                NavigateNode node = getValidNavigateNode(map, current_node, x - 1, y, direction);
                if(node != null) {
                    neighbour_node.add(node);
                }
            }else if(direction.equals("bottom")) {
                NavigateNode node = getValidNavigateNode(map, x + 1, y);
                NavigateNode node = getValidNavigateNode(map, current_node, x + 1, y, direction);
                if(node != null) {
                    neighbour_node.add(node);
                }
            }else if(direction.equals("left")) {
                NavigateNode node = getValidNavigateNode(map, x, y - 1);
                NavigateNode node = getValidNavigateNode(map, current_node, x, y - 1, direction);
                if(node != null) {
                    neighbour_node.add(node);
                }
            }else if(direction.equals("right")) {
                NavigateNode node = getValidNavigateNode(map, x, y + 1);
                NavigateNode node = getValidNavigateNode(map, current_node, x, y + 1, direction);
                if(node != null) {
                    neighbour_node.add(node);
                }
@@ -325,6 +325,22 @@
        }
        return neighbour_node;
    }
    /**
     * 邻接点校验:可达 + 方向一致(当前节点与下一节点对本次行走方向一致)
     */
    public NavigateNode getValidNavigateNode(List<List<NavigateNode>> map, NavigateNode currentNode, int x, int y, String moveDirection) {
        NavigateNode node = getValidNavigateNode(map, x, y);
        if (node == null) {
            return null;
        }
        if (!isDirectionConsistent(currentNode, node, moveDirection)) {
            return null;
        }
        return node;
    }
    public NavigateNode getValidNavigateNode(List<List<NavigateNode>> map, int x, int y) {
@@ -341,6 +357,25 @@
        return node;
    }
    private boolean isDirectionConsistent(NavigateNode currentNode, NavigateNode nextNode, String moveDirection) {
        if (currentNode == null || nextNode == null) {
            return false;
        }
        if (moveDirection == null) {
            return false;
        }
        List<String> currentDirectionList = currentNode.getDirectionList();
        List<String> nextDirectionList = nextNode.getDirectionList();
        if (currentDirectionList == null || nextDirectionList == null) {
            return false;
        }
        // 当前节点允许向 moveDirection 出发,且下一节点在该方向上保持一致,才允许通行
        return currentDirectionList.contains(moveDirection) && nextDirectionList.contains(moveDirection);
    }
    public NavigateNode findStationNavigateNode(List<List<NavigateNode>> map, int stationId) {
        for(int x = 0; x < map.size(); x++) {
            for(int y = 0; y < map.get(0).size(); y++) {
src/main/java/com/zy/common/utils/NavigateUtils.java
src/main/java/com/zy/core/enums/RedisKeyType.java
@@ -59,6 +59,8 @@
    DUAL_CRN_OUT_TASK_COMPLETE_STATION_INFO("dual_crn_out_task_complete_station_info_"),
    CRN_OUT_TASK_COMPLETE_STATION_INFO("crn_out_task_complete_station_info_"),
    WATCH_CIRCLE_STATION_("watch_circle_station_"),
    CURRENT_CIRCLE_TASK_CRN_NO("current_circle_task_crn_no_"),
    ASYNC_WMS_IN_TASK_REQUEST("async_wms_in_task_request_"),
    ASYNC_WMS_IN_TASK_RESPONSE("async_wms_in_task_response_"),
src/main/java/com/zy/core/enums/WrkStsType.java
@@ -15,6 +15,7 @@
    OUTBOUND_RUN(102, "设备搬运中"),
    OUTBOUND_RUN_COMPLETE(103, "设备搬运完成"),
    STATION_RUN(104, "站点运行中"),
    STATION_RUN_COMPLETE(105, "站点运行完成"),
    COMPLETE_OUTBOUND(109, "出库完成"),
    SETTLE_OUTBOUND(110, "出库库存更新"),
src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
@@ -128,6 +128,8 @@
            boolean initialized = false;
            // 上一步执行时间(用于堵塞检测)
            long stepExecuteTime = System.currentTimeMillis();
            // 避免在到达目标后重复执行到位逻辑
            boolean arrivalHandled = false;
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
@@ -144,12 +146,21 @@
                if (command != null) {
                    taskLastUpdateTime.put(taskNo, System.currentTimeMillis());
                    // 首次接收命令时初始化
                    if (finalTargetStationId == null) {
                        finalTargetStationId = command.getTargetStaNo();
                        if (checkTaskNoInArea(taskNo)) {
                            generateBarcode = true;
                    // 每次接收命令都刷新目标,避免沿用旧目标导致状态抖动
                    Integer commandTargetStationId = command.getTargetStaNo();
                    if (commandTargetStationId != null) {
                        if (!commandTargetStationId.equals(finalTargetStationId)) {
                            arrivalHandled = false;
                            News.info("[WCS Debug] 任务{}切换目标: {} -> {}", taskNo, finalTargetStationId,
                                    commandTargetStationId);
                        }
                        finalTargetStationId = commandTargetStationId;
                        // 当前站点先同步最新目标,避免上层在窗口期重复下发同一路径
                        syncCurrentStationTarget(taskNo, currentStationId, finalTargetStationId);
                    }
                    if (!generateBarcode && checkTaskNoInArea(taskNo)) {
                        generateBarcode = true;
                    }
                    // 将新路径追加到待执行队列
@@ -157,15 +168,7 @@
                    if (newPath != null && !newPath.isEmpty()) {
                        // 获取队列中最后一个站点(用于衔接点去重)
                        Integer lastInQueue = getLastInQueue(pendingPathQueue);
                        if (lastInQueue == null) {
                            lastInQueue = currentStationId;
                        }
                        int startIndex = 0;
                        // 如果新路径的起点与当前位置或队列末尾重复,则跳过
                        if (lastInQueue != null && !newPath.isEmpty() && newPath.get(0).equals(lastInQueue)) {
                            startIndex = 1;
                        }
                        int startIndex = getPathAppendStartIndex(newPath, currentStationId, lastInQueue);
                        for (int i = startIndex; i < newPath.size(); i++) {
                            pendingPathQueue.offer(newPath.get(i));
@@ -232,6 +235,7 @@
                            currentStationId = nextStationId;
                            pendingPathQueue.poll();
                            stepExecuteTime = System.currentTimeMillis();
                            arrivalHandled = false;
                            News.info("[WCS Debug] 任务{}移动到站点: {}, 剩余队列: {}", taskNo, currentStationId,
                                    pendingPathQueue.size());
                            sleep(1000); // 模拟移动耗时
@@ -261,7 +265,8 @@
                    // 路径队列为空,等待新的分段命令
                    if (currentStationId != null && finalTargetStationId != null
                            && currentStationId.equals(finalTargetStationId)) {
                        // 已到达最终目标,正常结束
                        // 已到达目标,先执行一次到位逻辑,然后继续等待下一条移动命令
                        if (!arrivalHandled) {
                        if (generateBarcode) {
                            Integer targetDeviceNo = getDeviceNoByStationId(finalTargetStationId);
                            if (targetDeviceNo != null) {
@@ -269,10 +274,11 @@
                                News.info("[WCS Debug] 任务{}到达目标{}并生成条码", taskNo, finalTargetStationId);
                            }
                        }
                        break;
                            arrivalHandled = true;
                        }
                    }
                    // 未到达最终目标,等待新的分段命令
                    // 继续等待新的分段命令
                    Long lastTime = taskLastUpdateTime.get(taskNo);
                    if (lastTime != null && System.currentTimeMillis() - lastTime > 30000) {
                        // 超时:30秒内没有收到新分段命令
@@ -305,6 +311,67 @@
    }
    /**
     * 计算新路径在队列中的追加起点,避免重复下发导致路径来回跳
     */
    private int getPathAppendStartIndex(List<Integer> newPath, Integer currentStationId, Integer lastInQueue) {
        if (newPath == null || newPath.isEmpty()) {
            return 0;
        }
        if (lastInQueue != null) {
            int idx = newPath.lastIndexOf(lastInQueue);
            if (idx >= 0) {
                return idx + 1;
            }
        }
        if (currentStationId != null) {
            int idx = newPath.lastIndexOf(currentStationId);
            if (idx >= 0) {
                return idx + 1;
            }
        }
        return 0;
    }
    /**
     * 命令刚到达时同步当前站点目标,降低上层重复发同一路径的概率
     */
    private void syncCurrentStationTarget(Integer taskNo, Integer currentStationId, Integer targetStationId) {
        if (currentStationId == null || targetStationId == null) {
            return;
        }
        Integer currentDeviceNo = getDeviceNoByStationId(currentStationId);
        if (currentDeviceNo == null) {
            return;
        }
        lockStations(currentStationId);
        try {
            List<ZyStationStatusEntity> statusList = deviceStatusMap.get(currentDeviceNo);
            if (statusList == null) {
                return;
            }
            ZyStationStatusEntity currentStatus = statusList.stream()
                    .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null);
            if (currentStatus == null) {
                return;
            }
            if (currentStatus.getTaskNo() != null && currentStatus.getTaskNo() > 0
                    && !currentStatus.getTaskNo().equals(taskNo) && currentStatus.isLoading()) {
                return;
            }
            updateStationDataInternal(currentStationId, currentDeviceNo, taskNo, targetStationId, null, null, null);
        } finally {
            unlockStations(currentStationId);
        }
    }
    /**
     * 获取是否允许检查堵塞的配置
     */
    private boolean getFakeAllowCheckBlock() {
src/main/java/com/zy/core/plugin/FakeProcess.java
@@ -125,6 +125,12 @@
        stationOperateProcessUtils.crnStationOutExecute();
        // 检测输送站点出库任务执行完成
        stationOperateProcessUtils.stationOutExecuteFinish();
        // 检测任务转完成
        stationOperateProcessUtils.checkTaskToComplete();
        // 检测出库排序
        stationOperateProcessUtils.checkStationOutOrder();
        // 监控绕圈站点
        stationOperateProcessUtils.watchCircleStation();
        // 执行双工位堆垛机任务
        dualCrnOperateProcessUtils.dualCrnIoExecute();
@@ -600,7 +606,7 @@
                    continue;
                }
                if (System.currentTimeMillis() - stayTime > 1000 * 15) {
                if (System.currentTimeMillis() - stayTime > 1000 * 60) {
                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
                            stationObjModel.getDeviceNo());
                    if (stationThread == null) {
src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
@@ -84,6 +84,7 @@
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .eq("crn_no", basCrnp.getCrnNo())
                    .in("wrk_sts", WrkStsType.INBOUND_RUN.sts, WrkStsType.OUTBOUND_RUN.sts)
                    .orderBy("batch_seq", false)
            );
            if(!wrkMasts.isEmpty()){
                continue;
@@ -262,6 +263,7 @@
        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                .eq("crn_no", crnNo)
                .eq("wrk_sts", WrkStsType.NEW_OUTBOUND.sts)
                .orderBy("batch_seq", false)
        );
        for (WrkMast wrkMast : wrkMasts) {
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -2,15 +2,19 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.domain.enums.NotifyMsgType;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.NotifyUtils;
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.MessageQueue;
@@ -36,10 +40,6 @@
    @Autowired
    private CommonService commonService;
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private BasDualCrnpService basDualCrnpService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private LocMastService locMastService;
@@ -47,6 +47,10 @@
    private WmsOperateUtils wmsOperateUtils;
    @Autowired
    private NotifyUtils notifyUtils;
    @Autowired
    private NavigateUtils navigateUtils;
    @Autowired
    private BasStationService basStationService;
    //执行输送站点入库任务
    public synchronized void stationInExecute() {
@@ -136,6 +140,8 @@
                    .eq("wrk_sts", WrkStsType.OUTBOUND_RUN_COMPLETE.sts)
                    .isNotNull("crn_no")
            );
            List<Integer> outOrderList = getAllOutOrderList();
            for (WrkMast wrkMast : wrkMasts) {
                Object infoObj = redisUtil.get(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + wrkMast.getWrkNo());
                if (infoObj == null) {
@@ -165,7 +171,24 @@
                        && stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() == 0
                ) {
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
                    Integer moveStaNo = wrkMast.getStaNo();
                    if (!outOrderList.isEmpty()) {
                        List<NavigateNode> nodes = navigateUtils.calcByStationId(stationProtocol.getStationId(), wrkMast.getStaNo());
                        for (int i = nodes.size() - 1; i >= 0; i--) {
                            NavigateNode node = nodes.get(i);
                            JSONObject v = JSONObject.parseObject(node.getNodeValue());
                            if (v != null) {
                                Integer stationId = v.getInteger("stationId");
                                if (outOrderList.contains(stationId)) {
                                    moveStaNo = stationId;
                                    break;
                                }
                            }
                        }
                    }
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), moveStaNo, 0);
                    if (command == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                        continue;
@@ -178,7 +201,6 @@
                        MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                        News.info("输送站点出库命令下发成功,站点号={},工作号={},命令数据={}", stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command));
                        redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId(), "lock", 5);
                        redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkMast.getWrkNo(), "lock", 60);
                        redisUtil.del(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + wrkMast.getWrkNo());
                    }
                }
@@ -238,7 +260,6 @@
                        notifyUtils.notify(String.valueOf(SlaveType.Devp), stationObjModel.getDeviceNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.STATION_OUT_TASK_RUN, null);
                        News.info("输送站点出库命令下发成功,站点号={},工作号={},命令数据={}", stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command));
                        redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId(), "lock", 5);
                        redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkMast.getWrkNo(), "lock", 60);
                        redisUtil.del(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + wrkMast.getWrkNo());
                    }
                }
@@ -254,26 +275,73 @@
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN.sts));
            for (WrkMast wrkMast : wrkMasts) {
                Integer wrkNo = wrkMast.getWrkNo();
                Integer targetStaNo = wrkMast.getStaNo();
                boolean complete = false;
                BasStation basStation = basStationService.selectOne(new EntityWrapper<BasStation>().eq("station_id", targetStaNo));
                if (basStation == null) {
                    continue;
                }
                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
                if (stationThread == null) {
                    continue;
                }
                Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
                StationProtocol stationProtocol = statusMap.get(basStation.getStationId());
                if (stationProtocol == null) {
                    continue;
                }
                if (stationProtocol.getTaskNo().equals(wrkNo)) {
                    complete = true;
                }
                if (complete) {
                    wrkMast.setWrkSts(WrkStsType.STATION_RUN_COMPLETE.sts);
                    wrkMast.setIoTime(new Date());
                    wrkMastService.updateById(wrkMast);
                    redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkMast.getWrkNo(), "lock", 60);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // 检测任务转完成
    public synchronized void checkTaskToComplete() {
        try {
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN_COMPLETE.sts));
            for (WrkMast wrkMast : wrkMasts) {
                Integer wrkNo = wrkMast.getWrkNo();
                Integer targetStaNo = wrkMast.getStaNo();
                Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkNo);
                if (lock != null) {
                    continue;
                }
                boolean complete = true;
                List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
                for (BasDevp basDevp : basDevps) {
                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
                boolean complete = false;
                BasStation basStation = basStationService.selectOne(new EntityWrapper<BasStation>().eq("station_id", targetStaNo));
                if (basStation == null) {
                    continue;
                }
                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
                    if (stationThread == null) {
                        continue;
                    }
                    List<StationProtocol> list = stationThread.getStatus();
                    for (StationProtocol stationProtocol : list) {
                        if (stationProtocol.getTaskNo().equals(wrkNo)) {
                            complete = false;
                Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
                StationProtocol stationProtocol = statusMap.get(basStation.getStationId());
                if (stationProtocol == null) {
                    continue;
                        }
                    }
                if (!stationProtocol.getTaskNo().equals(wrkNo)) {
                    complete = true;
                }
                if (complete) {
@@ -444,5 +512,247 @@
        return currentStationTaskCount;
    }
    // 检测出库排序
    public synchronized void checkStationOutOrder() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getId());
            if (stationThread == null) {
                continue;
            }
            Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
            List<StationObjModel> orderList = basDevp.getOutOrderList$();
            for (StationObjModel stationObjModel : orderList) {
                StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId());
                if (stationProtocol == null) {
                    continue;
                }
                if (!stationProtocol.isAutoing()) {
                    continue;
                }
                if (!stationProtocol.isLoading()) {
                    continue;
                }
                if (stationProtocol.getTaskNo() <= 0) {
                    continue;
                }
                if (!stationProtocol.getStationId().equals(stationProtocol.getTargetStaNo())) {
                    continue;
                }
                WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
                if (wrkMast == null) {
                    continue;
                }
                if (Cools.isEmpty(wrkMast.getBatch())) {
                    continue;
                }
                if (Cools.isEmpty(wrkMast.getBatchSeq())) {
                    continue;
                }
                List<WrkMast> batchWrkList = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                        .notIn("wrk_sts", WrkStsType.STATION_RUN_COMPLETE.sts, WrkStsType.COMPLETE_OUTBOUND.sts)
                        .eq("batch", wrkMast.getBatch())
                        .orderBy("batch")
                );
                if (batchWrkList.isEmpty()) {
                    continue;
                }
                WrkMast firstWrkMast = batchWrkList.get(0);
                Integer currentBatchSeq = firstWrkMast.getBatchSeq();
                List<NavigateNode> initPath = navigateUtils.calcByStationId(wrkMast.getSourceStaNo(), wrkMast.getStaNo());
                String commandType = "none";
                Integer seq = getOutStationBatchSeq(initPath, stationProtocol.getStationId(), wrkMast.getBatch());
                if (seq == null) {
                    if (currentBatchSeq.equals(wrkMast.getBatchSeq())) {
                        commandType = "toTarget";
                    }else {
                        commandType = "toCircle";
                    }
                }else {
                    seq++;
                    if (seq.equals(wrkMast.getBatchSeq()) && currentBatchSeq.equals(wrkMast.getBatchSeq())) {
                        commandType = "toTarget";
                    }else {
                        commandType = "toCircle";
                    }
                }
                if (commandType.equals("toTarget")) {
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
                    if (command == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                        continue;
                    }
                    MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                    News.info("{}任务直接去目标点", wrkMast.getWrkNo());
                } else if (commandType.equals("toCircle")) {
                    Integer circleTarget = null;
                    for (NavigateNode node : initPath) {
                        JSONObject v = JSONObject.parseObject(node.getNodeValue());
                        if (v != null) {
                            Integer stationId = v.getInteger("stationId");
                            try {
                                List<NavigateNode> enableMovePath = navigateUtils.calcByStationId(stationProtocol.getStationId(), stationId);
                                if (enableMovePath.isEmpty()) {
                                    continue;
                                }
                            } catch (Exception e) {
                                continue;
                            }
                            circleTarget = stationId;
                            break;
                        }
                    }
                    if (circleTarget == null) {
                        continue;
                    }
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), circleTarget, 0);
                    if (command == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                        continue;
                    }
                    MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                    redisUtil.set(RedisKeyType.WATCH_CIRCLE_STATION_.key + wrkMast.getWrkNo(), JSON.toJSONString(command, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24);
                    News.info("{}任务进行绕圈", wrkMast.getWrkNo());
                }
            }
        }
    }
    // 监控绕圈站点
    public synchronized void watchCircleStation() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getId());
            if (stationThread == null) {
                continue;
            }
            List<Integer> outOrderList = basDevp.getOutOrderIntList();
            for (StationProtocol stationProtocol : stationThread.getStatus()) {
                if (!stationProtocol.isAutoing()) {
                    continue;
                }
                if (!stationProtocol.isLoading()) {
                    continue;
                }
                if (stationProtocol.getTaskNo() <= 0) {
                    continue;
                }
                Object circleObj = redisUtil.get(RedisKeyType.WATCH_CIRCLE_STATION_.key + stationProtocol.getTaskNo());
                if (circleObj == null) {
                    continue;
                }
                StationCommand circleCommand = JSON.parseObject(circleObj.toString(), StationCommand.class);
                if (!stationProtocol.getStationId().equals(circleCommand.getTargetStaNo())) {
                    continue;
                }
                WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
                if (wrkMast == null) {
                    continue;
                }
                Integer moveStaNo = wrkMast.getStaNo();
                if (!outOrderList.isEmpty()) {
                    List<NavigateNode> nodes = navigateUtils.calcByStationId(stationProtocol.getStationId(), wrkMast.getStaNo());
                    for (int i = nodes.size() - 1; i >= 0; i--) {
                        NavigateNode node = nodes.get(i);
                        JSONObject v = JSONObject.parseObject(node.getNodeValue());
                        if (v != null) {
                            Integer stationId = v.getInteger("stationId");
                            if (outOrderList.contains(stationId)) {
                                moveStaNo = stationId;
                                break;
                            }
                        }
                    }
                }
                StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), moveStaNo, 0);
                if (command == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                    continue;
                }
                MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
            }
        }
    }
    public List<Integer> getAllOutOrderList() {
        List<Integer> list = new ArrayList<>();
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
        for (BasDevp basDevp : basDevps) {
            List<Integer> orderList = basDevp.getOutOrderIntList();
            list.addAll(orderList);
        }
        return list;
    }
    public Integer getOutStationBatchSeq(List<NavigateNode> pathList, Integer searchStationId, String searchBatch) {
        List<Integer> checkList = new ArrayList<>();
        for (int i = pathList.size() - 1; i >= 0; i--) {
            NavigateNode node = pathList.get(i);
            JSONObject v = JSONObject.parseObject(node.getNodeValue());
            if (v != null) {
                Integer stationId = v.getInteger("stationId");
                if (searchStationId.equals(stationId)) {
                    break;
                } else {
                    checkList.add(stationId);
                }
            }
        }
        HashMap<String, Integer> batchMap = new HashMap<>();
        for (Integer station : checkList) {
            BasStation basStation = basStationService.selectOne(new EntityWrapper<BasStation>().eq("station_id", station));
            if (basStation == null) {
                continue;
            }
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo());
            if (stationThread == null) {
                continue;
            }
            Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
            StationProtocol checkStationProtocol = statusMap.get(station);
            if (checkStationProtocol == null) {
                continue;
            }
            if (checkStationProtocol.getTaskNo() > 0) {
                WrkMast checkWrkMast = wrkMastService.selectByWorkNo(checkStationProtocol.getTaskNo());
                if (checkWrkMast == null) {
                    continue;
                }
                if (!Cools.isEmpty(checkWrkMast.getBatch())) {
                    batchMap.put(checkWrkMast.getBatch(), checkWrkMast.getBatchSeq());
                }
            }
        }
        Integer seq = batchMap.get(searchBatch);
        return seq;
    }
}
src/main/resources/application.yml
@@ -1,6 +1,6 @@
# 系统版本信息
app:
  version: 1.0.4.0
  version: 1.0.4.1
  version-type: dev  # prd 或 dev
server: