| | |
| | | import com.zy.asrs.service.BasStationService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.entity.FindCrnNoResult; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | public class InboundCrnMoveDispatchScheduler { |
| | | |
| | | private final WrkMastService wrkMastService; |
| | | private final BasStationService basStationService; |
| | | private final CommonService commonService; |
| | | private final BasCrnpService basCrnpService; |
| | | private final CrnOperateProcessUtils crnOperateProcessUtils; |
| | | |
| | | public InboundCrnMoveDispatchScheduler(WrkMastService wrkMastService, |
| | | BasStationService basStationService, |
| | | CommonService commonService, |
| | | BasCrnpService basCrnpService, |
| | | CrnOperateProcessUtils crnOperateProcessUtils) { |
| | | this.wrkMastService = wrkMastService; |
| | | this.basStationService = basStationService; |
| | | this.commonService = commonService; |
| | | this.basCrnpService = basCrnpService; |
| | | this.crnOperateProcessUtils = crnOperateProcessUtils; |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000L) |
| | | public void dispatchInboundCrnMove() { |
| | | List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>() |
| | | .eq("io_type", WrkIoType.IN.id) |
| | | .eq("wrk_sts", WrkStsType.INBOUND_STATION_RUN.sts) |
| | | .isNotNull("sta_no")); |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | if (wrkMast == null || wrkMast.getWrkNo() == null || wrkMast.getStaNo() == null || Cools.isEmpty(wrkMast.getLocNo())) { |
| | | List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<BasCrnp>() |
| | | .orderByAsc("crn_no")); |
| | | if (basCrnps == null || basCrnps.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | for (BasCrnp basCrnp : basCrnps) { |
| | | if (basCrnp == null || basCrnp.getCrnNo() == null) { |
| | | continue; |
| | | } |
| | | Integer crnNo = basCrnp.getCrnNo(); |
| | | if (hasBlockingOutboundTask(crnNo)) { |
| | | continue; |
| | | } |
| | | |
| | | BasStation basStation = basStationService.getOne(new QueryWrapper<BasStation>() |
| | | .eq("station_id", wrkMast.getStaNo()) |
| | | WrkMast inboundWrkMast = wrkMastService.getOne(new QueryWrapper<WrkMast>() |
| | | .eq("io_type", WrkIoType.IN.id) |
| | | .eq("wrk_sts", WrkStsType.INBOUND_STATION_RUN.sts) |
| | | .last("limit 1")); |
| | | if (basStation == null || basStation.getDeviceNo() == null) { |
| | | if (inboundWrkMast == null) { |
| | | continue; |
| | | } |
| | | |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | StationProtocol targetStationProtocol = resolveTargetStationProtocol(inboundWrkMast.getStaNo()); |
| | | if (targetStationProtocol != null |
| | | && targetStationProtocol.isLoading() |
| | | && targetStationProtocol.getTaskNo() > 0 |
| | | && targetStationProtocol.isInEnable()) { |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(basStation.getStationId()); |
| | | tryDispatchInboundCrnMove(wrkMast, stationProtocol); |
| | | String inboundPickupLocNo = resolveInboundPickupLocNo(basCrnp, inboundWrkMast.getStaNo()); |
| | | if (Cools.isEmpty(inboundPickupLocNo)) { |
| | | continue; |
| | | } |
| | | |
| | | boolean dispatched = crnOperateProcessUtils.dispatchCrnMove(crnNo, inboundPickupLocNo, true); |
| | | if (dispatched) { |
| | | News.info("已触发堆垛机直接移动到入库任务取货位等待,工作号={},堆垛机号={},取货位={}", |
| | | inboundWrkMast.getWrkNo(), crnNo, inboundPickupLocNo); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void tryDispatchInboundCrnMove(WrkMast wrkMast, StationProtocol targetStationProtocol) { |
| | | if (targetStationProtocol != null |
| | | && targetStationProtocol.isLoading() |
| | | && targetStationProtocol.getTaskNo() > 0 |
| | | && targetStationProtocol.isInEnable()) { |
| | | return; |
| | | private StationProtocol resolveTargetStationProtocol(Integer stationId) { |
| | | if (stationId == null) { |
| | | return null; |
| | | } |
| | | |
| | | FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(wrkMast.getLocNo()); |
| | | if (findCrnNoResult == null || !Objects.equals(findCrnNoResult.getCrnType(), SlaveType.Crn) || findCrnNoResult.getCrnNo() == null) { |
| | | return; |
| | | } |
| | | Integer crnNo = findCrnNoResult.getCrnNo(); |
| | | |
| | | BasCrnp basCrnp = basCrnpService.getOne(new QueryWrapper<BasCrnp>() |
| | | .eq("crn_no", crnNo) |
| | | BasStation basStation = basStationService.getOne(new QueryWrapper<BasStation>() |
| | | .eq("station_id", stationId) |
| | | .last("limit 1")); |
| | | if (basCrnp == null) { |
| | | return; |
| | | if (basStation == null || basStation.getDeviceNo() == null) { |
| | | return null; |
| | | } |
| | | |
| | | String inboundPickupLocNo = resolveInboundPickupLocNo(basCrnp, wrkMast.getStaNo()); |
| | | if (Cools.isEmpty(inboundPickupLocNo)) { |
| | | return; |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basStation.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | return null; |
| | | } |
| | | |
| | | // 同堆垛机没有需要参与当前调度判断的出库任务时,优先直接到当前入库任务取货位等待。 |
| | | if (!hasBlockingOutboundTask(crnNo)) { |
| | | boolean dispatched = crnOperateProcessUtils.dispatchCrnMove(crnNo, inboundPickupLocNo); |
| | | if (dispatched) { |
| | | News.info("检测到仅有入库任务,已触发堆垛机直接移动到入库任务取货位等待,工作号={},堆垛机号={},取货位={}", |
| | | wrkMast.getWrkNo(), crnNo, inboundPickupLocNo); |
| | | } |
| | | } else { |
| | | News.taskInfo(wrkMast.getWrkNo(), "当前存在阻塞入库预移车的出库任务,暂不触发堆垛机预移车"); |
| | | } |
| | | Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap(); |
| | | return statusMap == null ? null : statusMap.get(stationId); |
| | | } |
| | | |
| | | private String resolveInboundPickupLocNo(BasCrnp basCrnp, Integer targetStationId) { |
| | |
| | | .eq("io_type", WrkIoType.OUT.id) |
| | | .in("wrk_sts", |
| | | WrkStsType.NEW_OUTBOUND.sts, |
| | | WrkStsType.OUTBOUND_RUN.sts, |
| | | WrkStsType.OUTBOUND_RUN_COMPLETE.sts, |
| | | WrkStsType.STATION_RUN.sts, |
| | | WrkStsType.STATION_RUN_COMPLETE.sts, |
| | | WrkStsType.OUTBOUND_MANUAL.sts) |
| | | WrkStsType.OUTBOUND_RUN.sts) |
| | | .orderByAsc("wrk_no")); |
| | | if (pendingOutboundTasks == null || pendingOutboundTasks.isEmpty()) { |
| | | return false; |