| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | //入出库 ===>> 堆垛机入出库作业下发 |
| | | public synchronized void crnIoExecuteNormal() { |
| | | List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<>()); |
| | | Map<Integer, BasCrnp> dispatchCrnMap = new HashMap<>(); |
| | | Map<Integer, CrnThread> dispatchThreadMap = new HashMap<>(); |
| | | Map<Integer, CrnProtocol> dispatchProtocolMap = new HashMap<>(); |
| | | for (BasCrnp basCrnp : basCrnps) { |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo()); |
| | | if(crnThread == null){ |
| | |
| | | continue; |
| | | } |
| | | |
| | | List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>() |
| | | long runningCount = wrkMastService.count(new QueryWrapper<WrkMast>() |
| | | .eq("crn_no", basCrnp.getCrnNo()) |
| | | .in("wrk_sts", WrkStsType.INBOUND_RUN.sts, WrkStsType.OUTBOUND_RUN.sts, WrkStsType.LOC_MOVE_RUN.sts) |
| | | .orderBy(true, false, "batch_seq") |
| | | ); |
| | | if(!wrkMasts.isEmpty()){ |
| | | .in("wrk_sts", WrkStsType.INBOUND_RUN.sts, WrkStsType.OUTBOUND_RUN.sts, WrkStsType.LOC_MOVE_RUN.sts)); |
| | | if (runningCount > 0) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | if (clearLock != null) { |
| | | continue; |
| | | } |
| | | |
| | | // 如果最近一次是入库模式 |
| | | if (crnProtocol.getLastIo().equals("I")) { |
| | | if (basCrnp.getInEnable().equals("Y")) { |
| | | boolean result = this.crnExecuteIn(basCrnp, crnThread);// 入库 |
| | | crnProtocol.setLastIo("O"); |
| | | if (result) { |
| | | break; |
| | | } |
| | | } else if (basCrnp.getOutEnable().equals("Y")) { |
| | | boolean result = this.crnExecuteOut(basCrnp, crnThread);// 出库 |
| | | crnProtocol.setLastIo("I"); |
| | | if (result) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | // 如果最近一次是出库模式 |
| | | else if (crnProtocol.getLastIo().equals("O")) { |
| | | if (basCrnp.getOutEnable().equals("Y")) { |
| | | boolean result = this.crnExecuteOut(basCrnp, crnThread);// 出库 |
| | | crnProtocol.setLastIo("I"); |
| | | if (result) { |
| | | break; |
| | | } |
| | | } else if (basCrnp.getInEnable().equals("Y")) { |
| | | boolean result = this.crnExecuteIn(basCrnp, crnThread);// 入库 |
| | | crnProtocol.setLastIo("O"); |
| | | if (result) { |
| | | break; |
| | | } |
| | | dispatchCrnMap.put(basCrnp.getCrnNo(), basCrnp); |
| | | dispatchThreadMap.put(basCrnp.getCrnNo(), crnThread); |
| | | dispatchProtocolMap.put(basCrnp.getCrnNo(), crnProtocol); |
| | | } |
| | | } |
| | | |
| | | //库位移转 |
| | | boolean transfer = this.crnExecuteLocTransfer(basCrnp, crnThread); |
| | | if (dispatchCrnMap.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | List<WrkMast> taskQueue = wrkMastService.list(new QueryWrapper<WrkMast>() |
| | | .in("crn_no", new ArrayList<>(dispatchCrnMap.keySet())) |
| | | .in("wrk_sts", |
| | | WrkStsType.INBOUND_DEVICE_RUN.sts, |
| | | WrkStsType.NEW_OUTBOUND.sts, |
| | | WrkStsType.NEW_LOC_MOVE.sts)); |
| | | taskQueue.sort(Comparator |
| | | .comparingInt(this::resolveBatchOutboundRank) |
| | | .thenComparingInt(this::resolveBatchSeqOrder) |
| | | .thenComparingDouble(this::resolveTaskIoPri) |
| | | .thenComparingLong(this::resolveTaskQueueTime) |
| | | .thenComparingInt(this::resolveTaskQueueNo)); |
| | | |
| | | for (WrkMast wrkMast : taskQueue) { |
| | | if (wrkMast == null || wrkMast.getCrnNo() == null) { |
| | | continue; |
| | | } |
| | | |
| | | Integer crnNo = wrkMast.getCrnNo(); |
| | | BasCrnp basCrnp = dispatchCrnMap.get(crnNo); |
| | | CrnThread crnThread = dispatchThreadMap.get(crnNo); |
| | | CrnProtocol crnProtocol = dispatchProtocolMap.get(crnNo); |
| | | if (basCrnp == null || crnThread == null || crnProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.INBOUND_DEVICE_RUN.sts) { |
| | | boolean result = this.crnExecuteInPlanner(basCrnp, crnThread, wrkMast); |
| | | if (result) { |
| | | crnProtocol.setLastIo("O"); |
| | | return; |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.NEW_OUTBOUND.sts) { |
| | | boolean result = this.crnExecuteOutPlanner(basCrnp, crnThread, wrkMast); |
| | | if (result) { |
| | | crnProtocol.setLastIo("I"); |
| | | return; |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() != null && wrkMast.getWrkSts() == WrkStsType.NEW_LOC_MOVE.sts) { |
| | | boolean transfer = this.crnExecuteMovePlanner(basCrnp, crnThread, wrkMast); |
| | | if (transfer) { |
| | | break; |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private int resolveBatchOutboundRank(WrkMast wrkMast) { |
| | | return isBatchOutboundTask(wrkMast) ? 0 : 1; |
| | | } |
| | | |
| | | private int resolveBatchSeqOrder(WrkMast wrkMast) { |
| | | if (!isBatchOutboundTask(wrkMast) || wrkMast.getBatchSeq() == null) { |
| | | return Integer.MAX_VALUE; |
| | | } |
| | | return wrkMast.getBatchSeq(); |
| | | } |
| | | |
| | | private double resolveTaskIoPri(WrkMast wrkMast) { |
| | | if (wrkMast == null || wrkMast.getIoPri() == null) { |
| | | return Double.MAX_VALUE; |
| | | } |
| | | return wrkMast.getIoPri(); |
| | | } |
| | | |
| | | private long resolveTaskQueueTime(WrkMast wrkMast) { |
| | | if (wrkMast == null) { |
| | | return Long.MAX_VALUE; |
| | | } |
| | | Date queueTime = wrkMast.getAppeTime() != null ? wrkMast.getAppeTime() : wrkMast.getIoTime(); |
| | | return queueTime == null ? Long.MAX_VALUE : queueTime.getTime(); |
| | | } |
| | | |
| | | private int resolveTaskQueueNo(WrkMast wrkMast) { |
| | | if (wrkMast == null || wrkMast.getWrkNo() == null) { |
| | | return Integer.MAX_VALUE; |
| | | } |
| | | return wrkMast.getWrkNo(); |
| | | } |
| | | |
| | | private boolean isBatchOutboundTask(WrkMast wrkMast) { |
| | | return wrkMast != null |
| | | && Integer.valueOf(WrkIoType.OUT.id).equals(wrkMast.getIoType()) |
| | | && !Cools.isEmpty(wrkMast.getBatch()); |
| | | } |
| | | |
| | | private synchronized boolean crnExecuteIn(BasCrnp basCrnp, CrnThread crnThread) { |
| | |
| | | return false; |
| | | } |
| | | |
| | | int stationMaxTaskCount = 30; |
| | | Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key); |
| | | if (systemConfigMapObj != null) { |
| | | try { |
| | | HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj; |
| | | stationMaxTaskCount = Integer.parseInt(systemConfigMap.getOrDefault("stationMaxTaskCountLimit", "30")); |
| | | } catch (Exception ignore) {} |
| | | } |
| | | |
| | | int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount(); |
| | | if (stationMaxTaskCount > 0 && currentStationTaskCount >= stationMaxTaskCount) { |
| | | News.warn("输送站点任务数量达到上限,已停止任务下发。当前任务数={},上限={}", currentStationTaskCount, stationMaxTaskCount); |
| | | if (isOutboundStationTaskLimitReached()) { |
| | | return false; |
| | | } |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | if (isOutboundStationTaskLimitReached()) { |
| | | return false; |
| | | } |
| | | |
| | | Integer crnNo = basCrnp.getCrnNo(); |
| | | |
| | | if (!allowBatchOutboundExecute(wrkMast)) { |
| | |
| | | return true; |
| | | } |
| | | |
| | | private boolean isOutboundStationTaskLimitReached() { |
| | | int stationMaxTaskCount = getSystemConfigInt("stationMaxTaskCountLimit", 30); |
| | | if (stationMaxTaskCount <= 0) { |
| | | return false; |
| | | } |
| | | |
| | | int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount(); |
| | | if (currentStationTaskCount >= stationMaxTaskCount) { |
| | | News.warn("输送站点任务数量达到上限,已停止任务下发。当前任务数={},上限={}", currentStationTaskCount, stationMaxTaskCount); |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private int getSystemConfigInt(String code, int defaultValue) { |
| | | Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key); |
| | | if (systemConfigMapObj == null) { |