refactor(device): 重构设备列表接口返回类型

- 将 DeviceV2ListResponse 和 DeviceV2WithConfigListResponse 替换为通用的 PageResponse 类
- 更新相关控制器、服务和客户端接口以使用新的返回类型
- 删除冗余的 DeviceV2ListResponse 和 DeviceV2WithConfigListResponse 类
- 调整 FilterDevicesByConfigsResponse 中的 total 字段类型
This commit is contained in:
2025-09-05 12:17:15 +08:00
parent 60ce65f3e4
commit aa4a6c29c6
15 changed files with 51 additions and 118 deletions

View File

@@ -1,6 +1,7 @@
package com.ycwl.basic.integration.device.client;
import com.ycwl.basic.integration.common.response.CommonResponse;
import com.ycwl.basic.integration.common.response.PageResponse;
import com.ycwl.basic.integration.device.dto.device.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@@ -55,7 +56,7 @@ public interface DeviceV2Client {
* 分页获取设备列表(核心信息)
*/
@GetMapping("/")
CommonResponse<DeviceV2ListResponse> listDevices(
CommonResponse<PageResponse<DeviceV2DTO>> listDevices(
@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(value = "name", required = false) String name,
@@ -68,7 +69,7 @@ public interface DeviceV2Client {
* 分页获取设备列表(含配置)
*/
@GetMapping("/with-config")
CommonResponse<DeviceV2WithConfigListResponse> listDevicesWithConfig(
CommonResponse<PageResponse<DeviceV2WithConfigDTO>> listDevicesWithConfig(
@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(value = "name", required = false) String name,

View File

@@ -1,13 +0,0 @@
package com.ycwl.basic.integration.device.dto.device;
import lombok.Data;
import java.util.List;
@Data
public class DeviceV2ListResponse {
private List<DeviceV2DTO> list;
private Integer total;
private Integer page;
private Integer pageSize;
}

View File

@@ -1,13 +0,0 @@
package com.ycwl.basic.integration.device.dto.device;
import lombok.Data;
import java.util.List;
@Data
public class DeviceV2WithConfigListResponse {
private List<DeviceV2WithConfigDTO> list;
private Integer total;
private Integer page;
private Integer pageSize;
}

View File

@@ -17,7 +17,7 @@ public class FilterDevicesByConfigsResponse {
/**
* 总数
*/
private String total;
private Integer total;
/**
* 页码

View File

@@ -1,5 +1,6 @@
package com.ycwl.basic.integration.device.example;
import com.ycwl.basic.integration.common.response.PageResponse;
import com.ycwl.basic.integration.device.dto.device.*;
import com.ycwl.basic.integration.device.dto.config.*;
import com.ycwl.basic.integration.device.service.DeviceConfigIntegrationService;
@@ -46,7 +47,7 @@ public class DeviceIntegrationExample {
log.info("获取设备配置: {}", deviceWithConfig.getName());
// 分页查询景区设备列表
DeviceV2ListResponse deviceList = deviceService.getScenicIpcDevices(1001L, 1, 10);
PageResponse<DeviceV2DTO> deviceList = deviceService.getScenicIpcDevices(1001L, 1, 10);
log.info("景区设备列表: 总数={}", deviceList.getTotal());
// 启用设备
@@ -80,7 +81,7 @@ public class DeviceIntegrationExample {
log.info("更新摄像头1排序为1(置顶)");
// 获取排序后的设备列表
DeviceV2ListResponse sortedList = deviceService.listDevices(1, 10, null, null, null, 1, scenicId);
PageResponse<DeviceV2DTO> sortedList = deviceService.listDevices(1, 10, null, null, null, 1, scenicId);
log.info("排序后的设备列表:");
for (DeviceV2DTO device : sortedList.getList()) {
log.info(" - {}: 排序={}, 类型={}", device.getName(), device.getSort(), device.getType());
@@ -147,7 +148,7 @@ public class DeviceIntegrationExample {
log.info("将普通摄像头置顶(排序值: 1)");
// 查看最终排序结果
DeviceV2ListResponse finalList = deviceService.listDevices(1, 10, null, null, null, 1, scenicId);
PageResponse<DeviceV2DTO> finalList = deviceService.listDevices(1, 10, null, null, null, 1, scenicId);
log.info("最终排序结果:");
for (DeviceV2DTO device : finalList.getList()) {
log.info(" - {}: 排序={}", device.getName(), device.getSort());

View File

@@ -4,6 +4,7 @@ import com.ycwl.basic.integration.common.exception.IntegrationException;
import com.ycwl.basic.integration.common.response.CommonResponse;
import com.ycwl.basic.integration.common.service.IntegrationFallbackService;
import com.ycwl.basic.integration.device.client.DeviceV2Client;
import com.ycwl.basic.integration.common.response.PageResponse;
import com.ycwl.basic.integration.device.dto.device.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -91,20 +92,20 @@ public class DeviceIntegrationService {
handleResponse(response, "删除设备失败");
}
public DeviceV2ListResponse listDevices(Integer page, Integer pageSize, String name, String no,
public PageResponse<DeviceV2DTO> listDevices(Integer page, Integer pageSize, String name, String no,
String type, Integer isActive, Long scenicId) {
log.info("分页查询设备列表, page: {}, pageSize: {}, name: {}, no: {}, type: {}, isActive: {}, scenicId: {}",
page, pageSize, name, no, type, isActive, scenicId);
CommonResponse<DeviceV2ListResponse> response = deviceV2Client.listDevices(
CommonResponse<PageResponse<DeviceV2DTO>> response = deviceV2Client.listDevices(
page, pageSize, name, no, type, isActive, scenicId);
return handleResponse(response, "分页查询设备列表失败");
}
public DeviceV2WithConfigListResponse listDevicesWithConfig(Integer page, Integer pageSize, String name, String no,
public PageResponse<DeviceV2WithConfigDTO> listDevicesWithConfig(Integer page, Integer pageSize, String name, String no,
String type, Integer isActive, Long scenicId) {
log.info("分页查询设备带配置列表, page: {}, pageSize: {}, name: {}, no: {}, type: {}, isActive: {}, scenicId: {}",
page, pageSize, name, no, type, isActive, scenicId);
CommonResponse<DeviceV2WithConfigListResponse> response = deviceV2Client.listDevicesWithConfig(
CommonResponse<PageResponse<DeviceV2WithConfigDTO>> response = deviceV2Client.listDevicesWithConfig(
page, pageSize, name, no, type, isActive, scenicId);
return handleResponse(response, "分页查询设备带配置列表失败");
}
@@ -196,14 +197,14 @@ public class DeviceIntegrationService {
/**
* 获取景区的IPC设备列表
*/
public DeviceV2ListResponse getScenicIpcDevices(Long scenicId, Integer page, Integer pageSize) {
public PageResponse<DeviceV2DTO> getScenicIpcDevices(Long scenicId, Integer page, Integer pageSize) {
return listDevices(page, pageSize, null, null, "IPC", 1, scenicId);
}
/**
* 获取景区的所有激活设备
*/
public DeviceV2ListResponse getScenicActiveDevices(Long scenicId, Integer page, Integer pageSize) {
public PageResponse<DeviceV2DTO> getScenicActiveDevices(Long scenicId, Integer page, Integer pageSize) {
return listDevices(page, pageSize, null, null, null, 1, scenicId);
}