| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.zy.ai.domain.autotune.AutoTuneParameterSnapshot; |
| | | import com.zy.ai.domain.autotune.AutoTuneRuleDefinition; |
| | | import com.zy.ai.domain.autotune.AutoTuneRuleSnapshotItem; |
| | | import com.zy.ai.domain.autotune.AutoTuneSnapshot; |
| | | import com.zy.ai.domain.autotune.AutoTuneStationRuntimeItem; |
| | | import com.zy.ai.domain.autotune.AutoTuneTaskSnapshot; |
| | |
| | | import com.zy.asrs.domain.vo.StationCycleCapacityVo; |
| | | import com.zy.asrs.domain.vo.StationCycleLoopVo; |
| | | import com.zy.asrs.entity.BasCrnp; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.BasDualCrnp; |
| | | import com.zy.asrs.entity.BasStation; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.entity.StationFlowCapacity; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasCrnpService; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.service.BasDualCrnpService; |
| | | import com.zy.asrs.service.BasStationService; |
| | | import com.zy.asrs.service.DeviceConfigService; |
| | | import com.zy.asrs.service.StationCycleCapacityService; |
| | | import com.zy.asrs.service.StationFlowCapacityService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | 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.model.protocol.StationProtocol; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.system.service.ConfigService; |
| | |
| | | private static final int DEFAULT_CRN_OUT_BATCH_RUNNING_LIMIT = 5; |
| | | private static final int DEFAULT_CONVEYOR_STATION_TASK_LIMIT = 30; |
| | | private static final int DEFAULT_AI_AUTO_TUNE_INTERVAL_MINUTES = 10; |
| | | private static final String DIRECTION_OUT = "OUT"; |
| | | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | |
| | | private BasStationService basStationService; |
| | | |
| | | @Autowired |
| | | private StationFlowCapacityService stationFlowCapacityService; |
| | | private BasDevpService basDevpService; |
| | | |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | |
| | | snapshot.setCycleLoadSnapshot(buildCycleLoadSnapshot()); |
| | | snapshot.setFlowTopologySnapshot(flowTopologySnapshotService.buildSnapshot(stationRuntimeSnapshot)); |
| | | snapshot.setCurrentParameterSnapshot(buildCurrentParameterSnapshot()); |
| | | snapshot.setRuleSnapshot(buildRuleSnapshot()); |
| | | snapshot.setSnapshotTime(new Date()); |
| | | return snapshot; |
| | | } |
| | | |
| | | List<AutoTuneRuleSnapshotItem> buildRuleSnapshot() { |
| | | List<AutoTuneRuleSnapshotItem> result = new ArrayList<>(); |
| | | for (AutoTuneRuleDefinition.Rule rule : AutoTuneRuleDefinition.rules().values()) { |
| | | AutoTuneRuleSnapshotItem item = new AutoTuneRuleSnapshotItem(); |
| | | item.setTargetType(rule.getTargetType().getCode()); |
| | | item.setTargetKey(rule.getTargetKey()); |
| | | item.setMinValue(rule.getMinValue()); |
| | | item.setMaxValue(rule.getMaxValue()); |
| | | item.setMaxStep(rule.getMaxStep()); |
| | | item.setCooldownMinutes(rule.getCooldownMinutes()); |
| | | item.setDynamicMaxValue(rule.isDynamicMaxValue()); |
| | | item.setDynamicMaxSource(rule.getDynamicMaxSource()); |
| | | item.setNote(rule.getNote()); |
| | | result.add(item); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private AutoTuneTaskSnapshot buildTaskSnapshot() { |
| | |
| | | )); |
| | | List<BasCrnp> crnList = loadCrnList(); |
| | | List<BasDualCrnp> dualCrnList = loadDualCrnList(); |
| | | snapshot.setStationOutTaskLimits(loadStationOutTaskLimits()); |
| | | List<BasStation> outStationList = loadOutStationList(); |
| | | snapshot.setStationOutTaskLimits(buildStationOutTaskLimitMap(outStationList)); |
| | | snapshot.setStationOutBufferCapacities(buildStationOutBufferCapacityMap(outStationList)); |
| | | snapshot.setCrnMaxOutTask(buildCrnMaxOutTask(crnList)); |
| | | snapshot.setCrnMaxInTask(buildCrnMaxInTask(crnList)); |
| | | snapshot.setDualCrnMaxOutTask(buildDualCrnMaxOutTask(dualCrnList)); |
| | |
| | | } |
| | | } |
| | | |
| | | private Map<String, Integer> loadStationOutTaskLimits() { |
| | | Map<String, Integer> result = new LinkedHashMap<>(); |
| | | private List<BasStation> loadOutStationList() { |
| | | if (basStationService == null) { |
| | | return result; |
| | | return Collections.emptyList(); |
| | | } |
| | | Set<Integer> outStationIds = loadOutStationIds(); |
| | | if (outStationIds.isEmpty()) { |
| | | return result; |
| | | return Collections.emptyList(); |
| | | } |
| | | QueryWrapper<BasStation> wrapper = new QueryWrapper<>(); |
| | | wrapper.in("station_id", outStationIds); |
| | | wrapper.orderByAsc("station_id"); |
| | | return buildStationOutTaskLimitMap(basStationService.list(wrapper)); |
| | | return safeList(basStationService.list(wrapper)); |
| | | } |
| | | |
| | | private Set<Integer> loadOutStationIds() { |
| | | LinkedHashSet<Integer> stationIds = new LinkedHashSet<>(); |
| | | if (stationFlowCapacityService == null) { |
| | | if (basDevpService == null) { |
| | | return stationIds; |
| | | } |
| | | QueryWrapper<StationFlowCapacity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("direction_code", DIRECTION_OUT); |
| | | wrapper.orderByAsc("station_id"); |
| | | List<StationFlowCapacity> capacityList = safeList(stationFlowCapacityService.list(wrapper)); |
| | | for (StationFlowCapacity capacity : capacityList) { |
| | | if (capacity != null && capacity.getStationId() != null) { |
| | | stationIds.add(capacity.getStationId()); |
| | | QueryWrapper<BasDevp> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("status", 1); |
| | | wrapper.orderByAsc("devp_no"); |
| | | List<BasDevp> basDevpList = safeList(basDevpService.list(wrapper)); |
| | | for (BasDevp basDevp : basDevpList) { |
| | | if (basDevp == null) { |
| | | continue; |
| | | } |
| | | List<StationObjModel> outStationList = safeList(basDevp.getOutStationList$()); |
| | | for (StationObjModel stationObjModel : outStationList) { |
| | | if (stationObjModel != null && stationObjModel.getStationId() != null) { |
| | | stationIds.add(stationObjModel.getStationId()); |
| | | } |
| | | } |
| | | } |
| | | return stationIds; |
| | |
| | | return result; |
| | | } |
| | | |
| | | Map<String, Integer> buildStationOutBufferCapacityMap(List<BasStation> stationList) { |
| | | Map<String, Integer> result = new LinkedHashMap<>(); |
| | | for (BasStation station : safeList(stationList)) { |
| | | if (station != null && station.getStationId() != null) { |
| | | result.put(String.valueOf(station.getStationId()), station.getOutBufferCapacity()); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private Map<String, Integer> buildCrnMaxOutTask(List<BasCrnp> crnList) { |
| | | Map<String, Integer> result = new LinkedHashMap<>(); |
| | | for (BasCrnp crn : safeList(crnList)) { |