fix(ft546): preserve legacy vehicle snapshots

This commit is contained in:
zgw
2026-08-11 15:43:51 +08:00
parent 3e704d0b10
commit f53b250336
2 changed files with 69 additions and 5 deletions

View File

@@ -27,7 +27,6 @@ import com.ruoyi.job.domain.MydoJob;
import com.ruoyi.job.service.IMydoJobService;
import com.ruoyi.queue.agv.domain.AgvQueue;
import com.ruoyi.queue.agv.service.IAgvQueueService;
import com.ruoyi.project.ft546.wms.Ft546WmsAdapterService;
import com.ruoyi.system.domain.AgvContainerTask;
import com.ruoyi.system.service.IAgvContainerTaskService;
import lombok.extern.slf4j.Slf4j;
@@ -61,8 +60,6 @@ public class ApiServiceImpl implements IApiService {
private IAgvContainerTaskService agvContainerTaskService;
@Autowired
private DeviceSrgvMapper deviceSrgvMapper;
@Autowired
private Ft546WmsAdapterService ft546WmsAdapterService;
/**
@@ -523,8 +520,39 @@ public class ApiServiceImpl implements IApiService {
@Override
public AjaxResult tidyVehicleSnapshot() {
return AjaxResult.success(ft546WmsAdapterService
.tidyVehicleSnapshot());
List<DeviceSrgv> vehicles = deviceSrgvMapper
.selectDeviceSrgvList(new DeviceSrgv());
List<SrgvVehicleSnapshot> snapshots = new ArrayList<>();
for (DeviceSrgv vehicle : vehicles) {
boolean online = "1".equals(vehicle.getAgvStatus());
boolean healthy = online && value(vehicle.getAlarm()) <= 1
&& value(vehicle.getErrMsg()) == 0;
boolean idle = healthy && value(vehicle.getTaskNo()) == 0
&& value(vehicle.getLocked()) == 0
&& value(vehicle.getChargeFlag()) == 0;
SrgvVehicleSnapshot snapshot = new SrgvVehicleSnapshot();
snapshot.setGuid(vehicle.getGuid());
snapshot.setDeviceId(vehicle.getDeviceId());
snapshot.setDeviceName(vehicle.getDeviceName());
snapshot.setAgvStatus(vehicle.getAgvStatus());
snapshot.setOnline(online);
snapshot.setHealthy(healthy);
snapshot.setIdle(idle);
snapshot.setTaskNo(vehicle.getTaskNo());
snapshot.setAlarm(vehicle.getAlarm());
snapshot.setErrMsg(vehicle.getErrMsg());
snapshot.setChargeFlag(vehicle.getChargeFlag());
snapshot.setLocked(vehicle.getLocked());
snapshot.setBattery(vehicle.getBattery());
snapshot.setCurrSite(vehicle.getCurrSite());
snapshot.setCurrFloor(vehicle.getCurrFloor());
snapshots.add(snapshot);
}
return AjaxResult.success(snapshots);
}
private int value(Integer number) {
return number == null ? 0 : number;
}
}

View File

@@ -6,9 +6,13 @@ import com.ruoyi.api.controller.Wcs2WmsController;
import com.ruoyi.api.domain.RequestLog;
import com.ruoyi.api.domain.wcs2wms.JobParam;
import com.ruoyi.api.domain.wcs2wms.ReceiveJob;
import com.ruoyi.api.domain.wcs2wms.SrgvVehicleSnapshot;
import com.ruoyi.api.service.IApiService;
import com.ruoyi.api.service.impl.ApiServiceImpl;
import com.ruoyi.api.service.impl.RequestLogServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.device.srgv.domain.DeviceSrgv;
import com.ruoyi.device.srgv.mapper.DeviceSrgvMapper;
import com.ruoyi.project.ft546.config.Ft546WcsProperties;
import com.ruoyi.wcs.application.task.CreateTransportOrderCommand;
import com.ruoyi.wcs.application.task.TransportOrderResult;
@@ -18,6 +22,7 @@ import com.ruoyi.wcs.port.in.TransportOrderUseCase;
import com.ruoyi.wcs.port.out.WmsNotification;
import com.ruoyi.wcs.port.out.WmsNotificationReceipt;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
import java.time.Instant;
import java.util.ArrayList;
@@ -141,6 +146,37 @@ class Ft546WmsAdapterServiceTest {
verify(legacy, never()).tidyVehicleSnapshot();
}
@Test
void legacySnapshotDoesNotDependOnTheStandardWcsAdapter() {
DeviceSrgvMapper deviceMapper = mock(DeviceSrgvMapper.class);
DeviceSrgv vehicle = new DeviceSrgv();
vehicle.setGuid("GUID-1");
vehicle.setDeviceId(1);
vehicle.setAgvStatus("1");
vehicle.setAlarm(0);
vehicle.setErrMsg(0);
vehicle.setTaskNo(0);
vehicle.setLocked(0);
vehicle.setChargeFlag(0);
vehicle.setCurrSite("070501");
when(deviceMapper.selectDeviceSrgvList(any(DeviceSrgv.class)))
.thenReturn(Collections.singletonList(vehicle));
ApiServiceImpl legacy = new ApiServiceImpl();
ReflectionTestUtils.setField(legacy, "deviceSrgvMapper", deviceMapper);
AjaxResult result = legacy.tidyVehicleSnapshot();
assertTrue(result.isSuccess());
List<?> snapshots = (List<?>) result.get(AjaxResult.DATA_TAG);
assertEquals(1, snapshots.size());
SrgvVehicleSnapshot snapshot = (SrgvVehicleSnapshot) snapshots.get(0);
assertEquals("GUID-1", snapshot.getGuid());
assertTrue(snapshot.getOnline());
assertTrue(snapshot.getHealthy());
assertTrue(snapshot.getIdle());
assertEquals("070501", snapshot.getCurrSite());
}
@Test
void notificationUsesEventIdAsLegacyCallbackIdempotencyKey() {
FakeRequestLogService requestLogs = new FakeRequestLogService();