Junjie
2026-04-27 25533b6d08d3aa1d137c0e3537f432c33a23e945
fix: source auto tune out stations from devp
2个文件已修改
84 ■■■■■ 已修改文件
src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java
@@ -10,21 +10,22 @@
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;
@@ -47,7 +48,6 @@
    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;
@@ -68,7 +68,7 @@
    private BasStationService basStationService;
    @Autowired
    private StationFlowCapacityService stationFlowCapacityService;
    private BasDevpService basDevpService;
    @Autowired
    private BasCrnpService basCrnpService;
@@ -264,16 +264,22 @@
    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;
src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java
@@ -1,12 +1,14 @@
package com.zy.ai.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.StationFlowCapacity;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasStationService;
import com.zy.asrs.service.StationFlowCapacityService;
import com.zy.asrs.service.WrkMastService;
import com.zy.core.model.StationObjModel;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@@ -66,14 +68,14 @@
    }
    @Test
    void loadStationOutTaskLimitsOnlyQueriesConfiguredOutDirectionStations() {
    void loadStationOutTaskLimitsOnlyQueriesBasDevpOutStations() {
        BasStationService basStationService = mock(BasStationService.class);
        StationFlowCapacityService stationFlowCapacityService = mock(StationFlowCapacityService.class);
        BasDevpService basDevpService = mock(BasDevpService.class);
        ReflectionTestUtils.setField(service, "basStationService", basStationService);
        ReflectionTestUtils.setField(service, "stationFlowCapacityService", stationFlowCapacityService);
        when(stationFlowCapacityService.list(any(Wrapper.class))).thenReturn(Arrays.asList(
                capacity(101, "OUT"),
                capacity(102, "OUT")
        ReflectionTestUtils.setField(service, "basDevpService", basDevpService);
        when(basDevpService.list(any(Wrapper.class))).thenReturn(Arrays.asList(
                basDevp(1, 101, 102),
                basDevp(2, 102)
        ));
        when(basStationService.list(any(Wrapper.class))).thenReturn(Arrays.asList(
                station(101, 2),
@@ -86,9 +88,9 @@
        assertEquals(2, result.get("101"));
        assertEquals(3, result.get("102"));
        ArgumentCaptor<Wrapper<StationFlowCapacity>> capacityWrapperCaptor = ArgumentCaptor.forClass(Wrapper.class);
        verify(stationFlowCapacityService).list(capacityWrapperCaptor.capture());
        assertTrue(capacityWrapperCaptor.getValue().getSqlSegment().contains("direction_code ="));
        ArgumentCaptor<Wrapper<BasDevp>> basDevpWrapperCaptor = ArgumentCaptor.forClass(Wrapper.class);
        verify(basDevpService).list(basDevpWrapperCaptor.capture());
        assertTrue(basDevpWrapperCaptor.getValue().getSqlSegment().contains("status ="));
        ArgumentCaptor<Wrapper<BasStation>> stationWrapperCaptor = ArgumentCaptor.forClass(Wrapper.class);
        verify(basStationService).list(stationWrapperCaptor.capture());
@@ -96,12 +98,12 @@
    }
    @Test
    void loadStationOutTaskLimitsDoesNotQueryStationsWhenNoOutCapacityExists() {
    void loadStationOutTaskLimitsDoesNotQueryStationsWhenBasDevpOutStationsAreEmpty() {
        BasStationService basStationService = mock(BasStationService.class);
        StationFlowCapacityService stationFlowCapacityService = mock(StationFlowCapacityService.class);
        BasDevpService basDevpService = mock(BasDevpService.class);
        ReflectionTestUtils.setField(service, "basStationService", basStationService);
        ReflectionTestUtils.setField(service, "stationFlowCapacityService", stationFlowCapacityService);
        when(stationFlowCapacityService.list(any(Wrapper.class))).thenReturn(Collections.emptyList());
        ReflectionTestUtils.setField(service, "basDevpService", basDevpService);
        when(basDevpService.list(any(Wrapper.class))).thenReturn(Collections.singletonList(basDevp(1)));
        Map<String, Integer> result = ReflectionTestUtils.invokeMethod(service, "loadStationOutTaskLimits");
@@ -116,10 +118,22 @@
        return station;
    }
    private StationFlowCapacity capacity(Integer stationId, String directionCode) {
        StationFlowCapacity capacity = new StationFlowCapacity();
        capacity.setStationId(stationId);
        capacity.setDirectionCode(directionCode);
        return capacity;
    private BasDevp basDevp(Integer devpNo, Integer... stationIds) {
        BasDevp basDevp = new BasDevp();
        basDevp.setDevpNo(devpNo);
        basDevp.setStatus(1);
        if (stationIds == null || stationIds.length == 0) {
            return basDevp;
        }
        basDevp.setOutStationList(JSON.toJSONString(Arrays.stream(stationIds)
                .map(this::stationObjModel)
                .toList()));
        return basDevp;
    }
    private StationObjModel stationObjModel(Integer stationId) {
        StationObjModel stationObjModel = new StationObjModel();
        stationObjModel.setStationId(stationId);
        return stationObjModel;
    }
}