增加了红绿灯和路口的列表接口
This commit is contained in:
parent
09d798a3d2
commit
abd60d22b4
@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@ -33,13 +32,23 @@ public class IntersectionController {
|
||||
/**
|
||||
* 获取所有激活的路口
|
||||
*/
|
||||
@GetMapping
|
||||
@GetMapping("/active")
|
||||
@Operation(summary = "获取所有激活的路口", description = "返回系统中所有激活状态的路口列表")
|
||||
public ResponseEntity<List<Intersection>> getAllActiveIntersections() {
|
||||
List<Intersection> intersections = intersectionService.getAllActiveIntersections();
|
||||
return ResponseEntity.ok(intersections);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有路口列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取所有路口", description = "返回系统中所有路口的清单(包括激活和未激活)")
|
||||
public ResponseEntity<List<Intersection>> getAllIntersections() {
|
||||
List<Intersection> intersections = intersectionService.getAllIntersections();
|
||||
return ResponseEntity.ok(intersections);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据路口ID获取路口信息
|
||||
*/
|
||||
|
||||
@ -263,6 +263,16 @@ public class TrafficLightController {
|
||||
TrafficLightService.DeviceStatistics statistics = trafficLightService.getStatistics();
|
||||
return ResponseEntity.ok(statistics);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有红绿灯设备列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取所有设备", description = "返回所有红绿灯设备的清单")
|
||||
public ResponseEntity<List<TrafficLight>> getAllDevices() {
|
||||
List<TrafficLight> devices = trafficLightService.getAllTrafficLights();
|
||||
return ResponseEntity.ok(devices);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备创建请求DTO
|
||||
|
||||
@ -79,6 +79,22 @@ public class IntersectionService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有路口(包括激活和未激活)
|
||||
*
|
||||
* @return 所有路口列表
|
||||
*/
|
||||
public List<Intersection> getAllIntersections() {
|
||||
try {
|
||||
List<Intersection> intersections = intersectionRepository.findAll();
|
||||
log.debug("查询到 {} 个路口", intersections.size());
|
||||
return intersections;
|
||||
} catch (Exception e) {
|
||||
log.error("查询所有路口异常", e);
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据区域编码获取激活的路口
|
||||
*
|
||||
|
||||
@ -630,6 +630,22 @@ public class TrafficLightService {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有红绿灯设备列表
|
||||
*
|
||||
* @return 所有红绿灯设备的列表
|
||||
*/
|
||||
public List<TrafficLight> getAllTrafficLights() {
|
||||
try {
|
||||
List<TrafficLight> devices = trafficLightRepository.findAll();
|
||||
log.debug("查询到 {} 个红绿灯设备", devices.size());
|
||||
return devices;
|
||||
} catch (Exception e) {
|
||||
log.error("查询所有红绿灯设备异常", e);
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成默认设备名称
|
||||
|
||||
@ -103,35 +103,36 @@ class TrafficLightSignalParserEnhancedTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTrafficLightStatusWithIpPort() {
|
||||
// 测试TrafficLightStatus的IP端口功能
|
||||
void testTrafficLightStatusWithDifferentIpPort() {
|
||||
// 测试TrafficLightStatus的不同IP端口功能
|
||||
TrafficLightStatus status = TrafficLightStatus.builder()
|
||||
.ipAddress("192.168.1.100")
|
||||
.port(8082)
|
||||
.nsStatus(SignalState.GREEN)
|
||||
.ewStatus(SignalState.RED)
|
||||
.ipAddress("192.168.1.200")
|
||||
.port(9090)
|
||||
.nsStatus(SignalState.RED)
|
||||
.ewStatus(SignalState.GREEN)
|
||||
.timestamp(System.currentTimeMillis() * 1000)
|
||||
.build();
|
||||
|
||||
assertTrue(status.isValid());
|
||||
assertEquals("192.168.1.100", status.getIpAddress());
|
||||
assertEquals(Integer.valueOf(8082), status.getPort());
|
||||
assertEquals("192.168.1.200", status.getIpAddress());
|
||||
assertEquals(Integer.valueOf(9090), status.getPort());
|
||||
assertNull(status.getDeviceId()); // 设备ID为空
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateSafeDefaultWithDeviceId() {
|
||||
// 测试使用设备ID创建安全默认状态
|
||||
TrafficLightStatus status = TrafficLightStatus.createSafeDefault("TL_001");
|
||||
void testCreateSafeDefaultWithDifferentDeviceId() {
|
||||
// 测试使用不同设备ID创建安全默认状态
|
||||
TrafficLightStatus status = TrafficLightStatus.createSafeDefault("TL_002");
|
||||
|
||||
assertNotNull(status);
|
||||
assertEquals(SignalState.RED, status.getNsStatus());
|
||||
assertEquals(SignalState.RED, status.getEwStatus());
|
||||
assertEquals("TL_002", status.getDeviceId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStatistics() {
|
||||
// 测试解析统计功能
|
||||
void testStatisticsWithDifferentMessages() {
|
||||
// 测试解析统计功能 - 使用不同的消息
|
||||
parser.resetStatistics();
|
||||
|
||||
// 解析一些消息
|
||||
|
||||
@ -62,6 +62,15 @@ module.exports = {
|
||||
'^/webjars.*': {
|
||||
target: baseUrl,
|
||||
changeOrigin: true
|
||||
},
|
||||
// 登录相关接口代理
|
||||
'^/logout': {
|
||||
target: baseUrl,
|
||||
changeOrigin: true
|
||||
},
|
||||
'^/getInfo': {
|
||||
target: baseUrl,
|
||||
changeOrigin: true
|
||||
}
|
||||
},
|
||||
disableHostCheck: true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user