#
zwl
2026-02-09 ad79ba405b2d1ac96423f88f4e8a76c584b9d38a
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -4,8 +4,10 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
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.StartupDto;
import com.zy.common.service.CommonService;
@@ -13,13 +15,13 @@
import com.zy.core.News;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.WrkStsType;
import com.zy.core.enums.*;
import com.zy.core.model.StationObjModel;
import com.zy.core.model.Task;
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.thread.CrnThread;
import com.zy.core.thread.StationThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -38,18 +40,22 @@
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private BasDualCrnpService basDualCrnpService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private WmsOperateUtils wmsOperateUtils;
    @Autowired
    private NotifyUtils notifyUtils;
    //执行输送站点入库任务
    public synchronized void stationInExecute() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if(stationThread == null){
            if (stationThread == null) {
                continue;
            }
@@ -58,7 +64,7 @@
            List<StationObjModel> list = basDevp.getBarcodeStationList$();
            for (StationObjModel entity : list) {
                Integer stationId = entity.getStationId();
                if(!stationMap.containsKey(stationId)){
                if (!stationMap.containsKey(stationId)) {
                    continue;
                }
@@ -68,7 +74,7 @@
                }
                Object lock = redisUtil.get(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId);
                if(lock != null){
                if (lock != null) {
                    continue;
                }
@@ -87,27 +93,22 @@
                        continue;
                    }
                    if (!wrkMast.getWrkNo().equals(stationProtocol.getTaskNo())) {
                        News.taskInfo(stationProtocol.getStationId(), "输送站点工作号:{}与条码搜索到的任务工作号:{}不一致", stationProtocol.getTaskNo(), wrkMast.getWrkNo());
                        continue;
                    }
                    String locNo = wrkMast.getLocNo();
                    FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
                    if (findCrnNoResult == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "未匹配到堆垛机");
                        News.taskInfo(wrkMast.getWrkNo(), "{}工作,未匹配到堆垛机", wrkMast.getWrkNo());
                        continue;
                    }
                    Integer targetStationId = commonService.findInStationId(findCrnNoResult, stationId);
                    if (targetStationId == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "搜索入库站点失败");
                        News.taskInfo(wrkMast.getWrkNo(), "{}站点,搜索入库站点失败", stationId);
                        continue;
                    }
                    StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationId, targetStationId, 0);
                    if(command == null){
                        News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationId, targetStationId, 0);
                    if (command == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "{}工作,获取输送线命令失败", wrkMast.getWrkNo());
                        continue;
                    }
@@ -130,20 +131,29 @@
    public synchronized void stationOutExecute() {
        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.OUTBOUND_RUN_COMPLETE.sts));
        for (WrkMast wrkMast : wrkMasts) {
            List<StationObjModel> outStationList = new ArrayList<>();
            BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", wrkMast.getCrnNo()));
            if (basCrnp == null) {
                continue;
            if (basCrnp != null) {
                outStationList = basCrnp.getOutStationList$();
                if (outStationList.isEmpty()) {
                    News.info("堆垛机:{} 出库站点未设置", basCrnp.getCrnNo());
                    continue;
                }
            }
            List<StationObjModel> outStationList = basCrnp.getOutStationList$();
            if(outStationList.isEmpty()){
                News.info("堆垛机:{} 出库站点未设置", basCrnp.getCrnNo());
                continue;
            BasDualCrnp basDualCrnp = basDualCrnpService.selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", wrkMast.getDualCrnNo()));
            if (basDualCrnp != null) {
                outStationList = basDualCrnp.getOutStationList$();
                if (outStationList.isEmpty()) {
                    News.info("双工位堆垛机:{} 出库站点未设置", basDualCrnp.getCrnNo());
                    continue;
                }
            }
            for (StationObjModel stationObjModel : outStationList) {
                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
                if(stationThread == null){
                if (stationThread == null) {
                    continue;
                }
@@ -163,8 +173,8 @@
                        && stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() == 0
                ) {
                    StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
                    if(command == null){
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
                    if (command == null) {
                        News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                        continue;
                    }
@@ -176,17 +186,104 @@
                        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 * 5);
                        redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_DESTINATION_LIMIT.key + wrkMast.getWrkNo(), "lock", 60 * 5);
                    }
                }
            }
        }
    }
    //检测输送站点出库任务执行完成
    public synchronized void stationOutExecuteFinish() {
    //检测出库任务到达目的地
    public synchronized void arriveAtTheDestination() {
        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN.sts));
        for (WrkMast wrkMast : wrkMasts) {
            Integer wrkNo = wrkMast.getWrkNo();
//            Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_DESTINATION_LIMIT.key + wrkNo);
//            if (lock != null) {
//                continue;
//            }
            boolean complete = false;
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, 1);
            if (stationThread == null) {
                continue;
            }
            List<StationProtocol> list = stationThread.getStatus();
            for (StationProtocol stationProtocol : list) {
                if (stationProtocol.getTaskNo().equals(wrkNo)&&stationProtocol.getStationId().equals(wrkMast.getStaNo())) {
                    complete = true;
                }
            }
            if (complete) {
                //上报--到达目的地上报wms
                notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.ARRIVE_AT_THE_DESTINATION, JSON.toJSONString(wrkMast));
                wrkMast.setWrkSts(WrkStsType.ARRIVE_AT_THE_DESTINATION.sts);
                wrkMast.setIoTime(new Date());
                wrkMastService.updateById(wrkMast);
            }
        }
    }
    //检测库位橙色按钮信号 1:员工确认(常亮) 2 :上位机确认(闪烁)0 :熄灭
    public synchronized void locNo() {
        List<BasCrnp> basCrnps = basCrnpService.selectList(null);
        for (BasCrnp basCrnp : basCrnps) {
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
            if(crnThread == null){
                continue;
            }
            CrnProtocol crnProtocol = crnThread.getStatus();
            if(crnProtocol == null){
                continue;
            }
        }
//        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.ARRIVE_AT_THE_DESTINATION.sts));
//        for (WrkMast wrkMast : wrkMasts) {
//            Integer wrkNo = wrkMast.getWrkNo();
//
//            Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkNo);
//            if (lock != null) {
//                continue;
//            }
//
//            boolean complete = false;
//
//            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, wrkMast.getStaNo());
//            if (stationThread == null) {
//                continue;
//            }
//            List<StationProtocol> list = stationThread.getStatus();
//            for (StationProtocol stationProtocol : list) {
//                if (stationProtocol.getTaskNo().equals(wrkNo)) {
//                    complete = true;
//                }
//            }
//            if (complete) {
//                //上报--到达目的地上报wms
//                notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.ARRIVE_AT_THE_DESTINATION, JSON.toJSONString(wrkMast));
//                wrkMast.setWrkSts(WrkStsType.ARRIVE_AT_THE_DESTINATION.sts);
//                wrkMast.setIoTime(new Date());
//                wrkMastService.updateById(wrkMast);
//            }
//        }
    }
    //检测输送站点出库任务执行完成
    public synchronized void stationOutExecuteFinish() {
        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.ARRIVE_AT_THE_DESTINATION.sts));
        for (WrkMast wrkMast : wrkMasts) {
            Integer wrkNo = wrkMast.getWrkNo();
            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<>());
@@ -217,7 +314,7 @@
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if(stationThread == null){
            if (stationThread == null) {
                continue;
            }
@@ -228,10 +325,10 @@
            List<StationProtocol> list = stationThread.getStatus();
            for (StationProtocol stationProtocol : list) {
                if(stationProtocol.isAutoing()
                    && stationProtocol.isLoading()
                    && stationProtocol.getTaskNo() > 0
                    && stationProtocol.isRunBlock()
                if (stationProtocol.isAutoing()
                        && stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() > 0
                        && stationProtocol.isRunBlock()
                ) {
                    WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
                    if (wrkMast == null) {
@@ -245,7 +342,7 @@
                    }
                    redisUtil.set(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo(), "lock", 15);
                    if (runBlockReassignLocStationList.contains(stationProtocol.getStationId())) {
                    if (wrkMast.getIoType() == WrkIoType.IN.id && runBlockReassignLocStationList.contains(stationProtocol.getStationId())) {
                        //站点处于重新分配库位区域
                        //运行堵塞,重新申请任务
                        String response = wmsOperateUtils.applyReassignTaskLocNo(wrkMast.getWrkNo(), stationProtocol.getStationId());
@@ -284,20 +381,20 @@
                            FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
                            if (findCrnNoResult == null) {
                                News.taskInfo(wrkMast.getWrkNo(), "未匹配到堆垛机");
                                News.taskInfo(wrkMast.getWrkNo(), "{}工作,未匹配到堆垛机", wrkMast.getWrkNo());
                                continue;
                            }
                            Integer crnNo = findCrnNoResult.getCrnNo();
                            Integer targetStationId = commonService.findInStationId(findCrnNoResult, stationProtocol.getStationId());
                            if (targetStationId == null) {
                                News.taskInfo(wrkMast.getWrkNo(), "搜索入库站点失败");
                                News.taskInfo(wrkMast.getWrkNo(), "{}站点,搜索入库站点失败", stationProtocol.getStationId());
                                continue;
                            }
                            StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), targetStationId, 0);
                            if(command == null){
                                News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                            StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), targetStationId, 0);
                            if (command == null) {
                                News.taskInfo(wrkMast.getWrkNo(), "{}工作,获取输送线命令失败", wrkMast.getWrkNo());
                                continue;
                            }
@@ -319,7 +416,7 @@
                                wrkMast.setCrnNo(crnNo);
                            } else if (findCrnNoResult.getCrnType().equals(SlaveType.DualCrn)) {
                                wrkMast.setDualCrnNo(crnNo);
                            }else {
                            } else {
                                throw new CoolException("未知设备类型");
                            }
@@ -329,10 +426,10 @@
                        } else {
                            News.error("请求WMS接口失败!!!response:{}", response);
                        }
                    }else {
                    } else {
                        //运行堵塞,重新计算路线
                        StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
                        if(command == null){
                        StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
                        if (command == null) {
                            News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                            continue;
                        }
@@ -345,5 +442,25 @@
        }
    }
    //获取输送线任务数量
    public synchronized int getCurrentStationTaskCount() {
        int currentStationTaskCount = 0;
        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;
            }
            for (StationProtocol stationProtocol : stationThread.getStatus()) {
                if (stationProtocol.getTaskNo() > 0) {
                    currentStationTaskCount++;
                }
            }
        }
        return currentStationTaskCount;
    }
}