| | |
| | | |
| | | public void crnStationOutExecute() { |
| | | try { |
| | | DispatchLimitConfig baseLimitConfig = |
| | | stationDispatchLoadSupport.getDispatchLimitConfig(null, null); |
| | | int[] currentStationTaskCountRef = new int[]{stationDispatchLoadSupport.countCurrentStationTask()}; |
| | | LoadGuardState loadGuardState = |
| | | stationDispatchLoadSupport.buildLoadGuardState(baseLimitConfig); |
| | | |
| | | List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>() |
| | | .eq("wrk_sts", WrkStsType.OUTBOUND_RUN_COMPLETE.sts) |
| | | .isNotNull("crn_no")); |
| | | List<Integer> outOrderList = stationOutboundDecisionSupport.getAllOutOrderList(); |
| | | |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | Object infoObj = redisUtil.get(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + wrkMast.getWrkNo()); |
| | | if (infoObj == null) { |
| | | News.info("出库任务{}数据缓存不存在", wrkMast.getWrkNo()); |
| | | continue; |
| | | } |
| | | crnStationOutExecute(wrkMast); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | StationObjModel stationObjModel = JSON.parseObject(infoObj.toString(), StationObjModel.class); |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | public void crnStationOutExecute(WrkMast wrkMast) { |
| | | try { |
| | | if (wrkMast == null || wrkMast.getWrkNo() == null) { |
| | | return; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = stationMap.get(stationObjModel.getStationId()); |
| | | if (stationProtocol == null) { |
| | | continue; |
| | | } |
| | | Object infoObj = redisUtil.get(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + wrkMast.getWrkNo()); |
| | | if (infoObj == null) { |
| | | News.info("出库任务{}数据缓存不存在", wrkMast.getWrkNo()); |
| | | return; |
| | | } |
| | | |
| | | Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId()); |
| | | if (lock != null) { |
| | | continue; |
| | | } |
| | | StationObjModel stationObjModel = JSON.parseObject(infoObj.toString(), StationObjModel.class); |
| | | if (stationObjModel == null || stationObjModel.getDeviceNo() == null || stationObjModel.getStationId() == null) { |
| | | return; |
| | | } |
| | | |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 0) { |
| | | Double pathLenFactor = stationOutboundDecisionSupport.resolveOutboundPathLenFactor(wrkMast); |
| | | OutOrderDispatchDecision dispatchDecision = |
| | | stationOutboundDecisionSupport.resolveOutboundDispatchDecision( |
| | | stationProtocol.getStationId(), |
| | | wrkMast, |
| | | outOrderList, |
| | | pathLenFactor |
| | | ); |
| | | Integer moveStaNo = dispatchDecision == null ? null : dispatchDecision.getTargetStationId(); |
| | | if (moveStaNo == null) { |
| | | continue; |
| | | } |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | return; |
| | | } |
| | | |
| | | DispatchLimitConfig limitConfig = |
| | | stationDispatchLoadSupport.getDispatchLimitConfig(stationProtocol.getStationId(), moveStaNo); |
| | | LoopHitResult loopHitResult = |
| | | stationDispatchLoadSupport.findPathLoopHit( |
| | | limitConfig, |
| | | stationProtocol.getStationId(), |
| | | moveStaNo, |
| | | loadGuardState, |
| | | wrkMast, |
| | | pathLenFactor |
| | | ); |
| | | if (stationDispatchLoadSupport.isDispatchBlocked( |
| | | limitConfig, |
| | | currentStationTaskCountRef[0], |
| | | loadGuardState, |
| | | loopHitResult.isThroughLoop())) { |
| | | return; |
| | | } |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = stationMap == null ? null : stationMap.get(stationObjModel.getStationId()); |
| | | if (stationProtocol == null) { |
| | | return; |
| | | } |
| | | |
| | | StationCommand command = stationOutboundDecisionSupport.buildOutboundMoveCommand( |
| | | stationThread, |
| | | wrkMast, |
| | | Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId()); |
| | | if (lock != null) { |
| | | return; |
| | | } |
| | | |
| | | if (!(stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 0)) { |
| | | return; |
| | | } |
| | | |
| | | Double pathLenFactor = stationOutboundDecisionSupport.resolveOutboundPathLenFactor(wrkMast); |
| | | List<Integer> outOrderList = stationOutboundDecisionSupport.getAllOutOrderList(); |
| | | OutOrderDispatchDecision dispatchDecision = |
| | | stationOutboundDecisionSupport.resolveOutboundDispatchDecision( |
| | | stationProtocol.getStationId(), |
| | | moveStaNo, |
| | | wrkMast, |
| | | outOrderList, |
| | | pathLenFactor |
| | | ); |
| | | if (command == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | continue; |
| | | } |
| | | Integer moveStaNo = dispatchDecision == null ? null : dispatchDecision.getTargetStationId(); |
| | | if (moveStaNo == null) { |
| | | return; |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | wrkMast.setWrkSts(WrkStsType.STATION_RUN.sts); |
| | | wrkMast.setSystemMsg(""); |
| | | wrkMast.setIoTime(now); |
| | | wrkMast.setModiTime(now); |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | wrkAnalysisService.markOutboundStationStart(wrkMast, now); |
| | | boolean offered = offerDevpCommandWithDedup(stationObjModel.getDeviceNo(), command, "crnStationOutExecute"); |
| | | if (offered && stationMoveCoordinator != null) { |
| | | stationMoveCoordinator.recordDispatch( |
| | | wrkMast.getWrkNo(), |
| | | stationProtocol.getStationId(), |
| | | "crnStationOutExecute", |
| | | command, |
| | | false |
| | | ); |
| | | } |
| | | News.info("输送站点出库命令下发成功,站点号={},工作号={},命令数据={}", |
| | | stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command)); |
| | | redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId(), "lock", 5); |
| | | redisUtil.del(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + wrkMast.getWrkNo()); |
| | | currentStationTaskCountRef[0]++; |
| | | loadGuardState.reserveLoopTask(loopHitResult.getLoopNo()); |
| | | stationDispatchLoadSupport.saveLoopLoadReserve(wrkMast.getWrkNo(), loopHitResult); |
| | | } |
| | | DispatchLimitConfig limitConfig = |
| | | stationDispatchLoadSupport.getDispatchLimitConfig(stationProtocol.getStationId(), moveStaNo); |
| | | int currentStationTaskCount = stationDispatchLoadSupport.countCurrentStationTask(); |
| | | LoadGuardState loadGuardState = stationDispatchLoadSupport.buildLoadGuardState(limitConfig); |
| | | LoopHitResult loopHitResult = |
| | | stationDispatchLoadSupport.findPathLoopHit( |
| | | limitConfig, |
| | | stationProtocol.getStationId(), |
| | | moveStaNo, |
| | | loadGuardState, |
| | | wrkMast, |
| | | pathLenFactor |
| | | ); |
| | | if (stationDispatchLoadSupport.isDispatchBlocked( |
| | | limitConfig, |
| | | currentStationTaskCount, |
| | | loadGuardState, |
| | | loopHitResult.isThroughLoop())) { |
| | | return; |
| | | } |
| | | |
| | | StationCommand command = stationOutboundDecisionSupport.buildOutboundMoveCommand( |
| | | stationThread, |
| | | wrkMast, |
| | | stationProtocol.getStationId(), |
| | | moveStaNo, |
| | | pathLenFactor |
| | | ); |
| | | if (command == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | return; |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | wrkMast.setWrkSts(WrkStsType.STATION_RUN.sts); |
| | | wrkMast.setSystemMsg(""); |
| | | wrkMast.setIoTime(now); |
| | | wrkMast.setModiTime(now); |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | wrkAnalysisService.markOutboundStationStart(wrkMast, now); |
| | | boolean offered = offerDevpCommandWithDedup(stationObjModel.getDeviceNo(), command, "crnStationOutExecute"); |
| | | if (offered && stationMoveCoordinator != null) { |
| | | stationMoveCoordinator.recordDispatch( |
| | | wrkMast.getWrkNo(), |
| | | stationProtocol.getStationId(), |
| | | "crnStationOutExecute", |
| | | command, |
| | | false |
| | | ); |
| | | } |
| | | News.info("输送站点出库命令下发成功,站点号={},工作号={},命令数据={}", |
| | | stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command)); |
| | | redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId(), "lock", 5); |
| | | redisUtil.del(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + wrkMast.getWrkNo()); |
| | | loadGuardState.reserveLoopTask(loopHitResult.getLoopNo()); |
| | | stationDispatchLoadSupport.saveLoopLoadReserve(wrkMast.getWrkNo(), loopHitResult); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |