feat(iot,ops): 区域设备关联接口返回更多设备信息,修复 N+1 和代码质量问题

- IotDeviceSimpleRespDTO 新增 nickname、serialNumber、state、deviceType 字段
- IotDeviceQueryApi 新增 batchGetDevices 批量查询接口
- IotDeviceQueryApiImpl 提取 toSimpleDTO 统一转换、通过产品缓存解析 productName、
  移除 blanket try-catch 让异常正确传播、删除无用 import
- AreaDeviceRelationRespVO 新增 nickname、serialNumber、deviceState、deviceType 字段
- AreaDeviceRelationServiceImpl.listByAreaId 改为批量查询避免 N+1 RPC、
  增加 null 防护;bindDevice 改为 fail-fast 不再存脏数据
- ErrorCodeConstants 新增 IOT_SERVICE_UNAVAILABLE 错误码

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
lzh
2026-03-07 21:06:10 +08:00
parent 3bcdb4119f
commit 26c4ce07eb
6 changed files with 203 additions and 133 deletions

View File

@@ -10,6 +10,7 @@ import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Collection;
import java.util.List;
/**
@@ -38,4 +39,9 @@ public interface IotDeviceQueryApi {
@Parameter(name = "id", description = "设备ID", required = true)
CommonResult<IotDeviceSimpleRespDTO> getDevice(@RequestParam("id") Long id);
@GetMapping(PREFIX + "/batch-get")
@Operation(summary = "批量获取设备详情")
@Parameter(name = "ids", description = "设备ID列表", required = true, example = "[1,2,3]")
CommonResult<List<IotDeviceSimpleRespDTO>> batchGetDevices(@RequestParam("ids") Collection<Long> ids);
}

View File

@@ -29,4 +29,16 @@ public class IotDeviceSimpleRespDTO {
@Schema(description = "产品名称", example = "客流计数器")
private String productName;
@Schema(description = "设备备注名称", example = "A栋3层客流计数器")
private String nickname;
@Schema(description = "设备序列号", example = "SN20250101001")
private String serialNumber;
@Schema(description = "设备状态0-未激活 1-在线 2-离线)", example = "1")
private Integer state;
@Schema(description = "设备类型", example = "10")
private Integer deviceType;
}