| | |
| | | package com.zy.asrs.task; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.core.common.Cools; |
| | | import com.zy.asrs.entity.BasCrnp; |
| | | import com.zy.asrs.entity.BasStation; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasCrnpService; |
| | | import com.zy.asrs.service.BasStationService; |
| | | import com.zy.asrs.service.WrkAnalysisService; |
| | | 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 com.zy.core.enums.WrkStsType; |
| | | import com.zy.core.model.StationObjModel; |
| | | import com.zy.core.move.StationMoveCoordinator; |
| | | import com.zy.core.move.StationMoveSession; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.core.utils.CrnOperateProcessUtils; |
| | | import com.zy.core.utils.StationOperateProcessUtils; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | @Component |
| | | public class WrkAnalysisStationArrivalScanner { |
| | |
| | | private final BasStationService basStationService; |
| | | private final WrkAnalysisService wrkAnalysisService; |
| | | private final StationOperateProcessUtils stationOperateProcessUtils; |
| | | private final StationMoveCoordinator stationMoveCoordinator; |
| | | private final CommonService commonService; |
| | | private final BasCrnpService basCrnpService; |
| | | private final CrnOperateProcessUtils crnOperateProcessUtils; |
| | | |
| | | public WrkAnalysisStationArrivalScanner(WrkMastService wrkMastService, |
| | | BasStationService basStationService, |
| | | WrkAnalysisService wrkAnalysisService, |
| | | StationOperateProcessUtils stationOperateProcessUtils, |
| | | StationMoveCoordinator stationMoveCoordinator, |
| | | CommonService commonService, |
| | | BasCrnpService basCrnpService, |
| | | CrnOperateProcessUtils crnOperateProcessUtils) { |
| | | StationOperateProcessUtils stationOperateProcessUtils) { |
| | | this.wrkMastService = wrkMastService; |
| | | this.basStationService = basStationService; |
| | | this.wrkAnalysisService = wrkAnalysisService; |
| | | this.stationOperateProcessUtils = stationOperateProcessUtils; |
| | | this.stationMoveCoordinator = stationMoveCoordinator; |
| | | this.commonService = commonService; |
| | | this.basCrnpService = basCrnpService; |
| | | this.crnOperateProcessUtils = crnOperateProcessUtils; |
| | | } |
| | | |
| | | @Scheduled(fixedDelay = 1000L) |
| | |
| | | } |
| | | Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = statusMap == null ? null : statusMap.get(basStation.getStationId()); |
| | | tryDispatchInboundCrnMove(wrkMast, stationProtocol); |
| | | boolean arrived = stationProtocol != null |
| | | && wrkMast.getWrkNo().equals(stationProtocol.getTaskNo()) |
| | | && stationProtocol.isLoading(); |
| | |
| | | News.info("入库站点到达扫描命中,工作号={},目标站={}", wrkMast.getWrkNo(), wrkMast.getStaNo()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void tryDispatchInboundCrnMove(WrkMast wrkMast, StationProtocol targetStationProtocol) { |
| | | if (wrkMast == null || wrkMast.getWrkNo() == null || wrkMast.getStaNo() == null || Cools.isEmpty(wrkMast.getLocNo())) { |
| | | return; |
| | | } |
| | | if (targetStationProtocol != null |
| | | && targetStationProtocol.isLoading() |
| | | && targetStationProtocol.getTaskNo() > 0 |
| | | && targetStationProtocol.isInEnable()) { |
| | | return; |
| | | } |
| | | |
| | | StationMoveSession session = stationMoveCoordinator == null ? null : stationMoveCoordinator.loadSession(wrkMast.getWrkNo()); |
| | | if (!isInboundCrnMoveDispatchWindow(wrkMast, session)) { |
| | | return; |
| | | } |
| | | |
| | | FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(wrkMast.getLocNo()); |
| | | if (findCrnNoResult == null || !Objects.equals(findCrnNoResult.getCrnType(), SlaveType.Crn) || findCrnNoResult.getCrnNo() == null) { |
| | | return; |
| | | } |
| | | |
| | | BasCrnp basCrnp = basCrnpService.getOne(new QueryWrapper<BasCrnp>() |
| | | .eq("crn_no", findCrnNoResult.getCrnNo()) |
| | | .last("limit 1")); |
| | | if (basCrnp == null) { |
| | | return; |
| | | } |
| | | |
| | | for (StationObjModel stationObjModel : basCrnp.getInStationList$()) { |
| | | if (stationObjModel == null || !Objects.equals(stationObjModel.getStationId(), wrkMast.getStaNo())) { |
| | | continue; |
| | | } |
| | | if (stationObjModel.getDeviceRow() == null || stationObjModel.getDeviceBay() == null || stationObjModel.getDeviceLev() == null) { |
| | | continue; |
| | | } |
| | | String inletLocNo = Utils.getLocNo(stationObjModel.getDeviceRow(), stationObjModel.getDeviceBay(), stationObjModel.getDeviceLev()); |
| | | boolean dispatched = crnOperateProcessUtils.dispatchCrnMove(findCrnNoResult.getCrnNo(), inletLocNo); |
| | | if (dispatched) { |
| | | News.info("入库任务即将到达入库口,已触发堆垛机预移车,工作号={},堆垛机号={},入库口位置={}", |
| | | wrkMast.getWrkNo(), findCrnNoResult.getCrnNo(), inletLocNo); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | | private boolean isInboundCrnMoveDispatchWindow(WrkMast wrkMast, StationMoveSession session) { |
| | | if (wrkMast == null || session == null || !session.isActive() || wrkMast.getStaNo() == null) { |
| | | return false; |
| | | } |
| | | List<Integer> fullPathStationIds = session.getFullPathStationIds(); |
| | | Integer currentStationId = session.getCurrentStationId(); |
| | | if (fullPathStationIds == null || fullPathStationIds.isEmpty() || currentStationId == null) { |
| | | return false; |
| | | } |
| | | int currentIndex = fullPathStationIds.lastIndexOf(currentStationId); |
| | | if (currentIndex < 0 || currentIndex >= fullPathStationIds.size() - 1) { |
| | | return false; |
| | | } |
| | | int remainingStationCount = fullPathStationIds.size() - currentIndex - 1; |
| | | if (remainingStationCount != 1) { |
| | | return false; |
| | | } |
| | | Integer nextStationId = fullPathStationIds.get(currentIndex + 1); |
| | | return Objects.equals(nextStationId, wrkMast.getStaNo()); |
| | | } |
| | | } |