Commit 5a66037725be4c9c26cb89f46bb88c260328dd33
1 parent
b3dcd7b1
【功能新增】IoT: 通过产品标识和设备名称列表获取设备列表
Showing
5 changed files
with
58 additions
and
4 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java
| ... | ... | @@ -185,4 +185,12 @@ public class IotDeviceController { |
| 185 | 185 | return success(deviceService.getMqttConnectionParams(deviceId)); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | -} | |
| 189 | 188 | \ No newline at end of file |
| 189 | + @GetMapping("/list-by-product-key-and-names") | |
| 190 | + @Operation(summary = "通过产品标识和设备名称列表获取设备") | |
| 191 | + @PreAuthorize("@ss.hasPermission('iot:device:query')") | |
| 192 | + public CommonResult<List<IotDeviceRespVO>> getDevicesByProductKeyAndNames(@Valid IotDeviceByProductKeyAndNamesReqVO reqVO) { | |
| 193 | + List<IotDeviceDO> devices = deviceService.getDevicesByProductKeyAndNames(reqVO.getProductKey(), reqVO.getDeviceNames()); | |
| 194 | + return success(BeanUtils.toBean(devices, IotDeviceRespVO.class)); | |
| 195 | + } | |
| 196 | + | |
| 197 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceByProductKeyAndNamesReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotBlank; | |
| 5 | +import jakarta.validation.constraints.NotEmpty; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +@Schema(description = "管理后台 - 通过产品标识和设备名称列表获取设备 Request VO") | |
| 11 | +@Data | |
| 12 | +public class IotDeviceByProductKeyAndNamesReqVO { | |
| 13 | + | |
| 14 | + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1de24640dfe") | |
| 15 | + @NotBlank(message = "产品标识不能为空") | |
| 16 | + private String productKey; | |
| 17 | + | |
| 18 | + @Schema(description = "设备名称列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "device001,device002") | |
| 19 | + @NotEmpty(message = "设备名称列表不能为空") | |
| 20 | + private List<String> deviceNames; | |
| 21 | + | |
| 22 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java
| ... | ... | @@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.Mapper; |
| 11 | 11 | |
| 12 | 12 | import javax.annotation.Nullable; |
| 13 | 13 | import java.time.LocalDateTime; |
| 14 | +import java.util.Collection; | |
| 14 | 15 | import java.util.List; |
| 15 | 16 | import java.util.Map; |
| 16 | 17 | |
| ... | ... | @@ -77,6 +78,12 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> { |
| 77 | 78 | .geIfPresent(IotDeviceDO::getCreateTime, createTime)); |
| 78 | 79 | } |
| 79 | 80 | |
| 81 | + default List<IotDeviceDO> selectByProductKeyAndDeviceNames(String productKey, Collection<String> deviceNames) { | |
| 82 | + return selectList(new LambdaQueryWrapperX<IotDeviceDO>() | |
| 83 | + .eq(IotDeviceDO::getProductKey, productKey) | |
| 84 | + .in(IotDeviceDO::getDeviceName, deviceNames)); | |
| 85 | + } | |
| 86 | + | |
| 80 | 87 | /** |
| 81 | 88 | * 查询指定产品下各状态的设备数量 |
| 82 | 89 | * |
| ... | ... | @@ -93,4 +100,4 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> { |
| 93 | 100 | */ |
| 94 | 101 | List<Map<String, Object>> selectDeviceCountGroupByState(); |
| 95 | 102 | |
| 96 | -} | |
| 97 | 103 | \ No newline at end of file |
| 104 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java
| ... | ... | @@ -219,4 +219,13 @@ public interface IotDeviceService { |
| 219 | 219 | */ |
| 220 | 220 | Map<Integer, Long> getDeviceCountMapByState(); |
| 221 | 221 | |
| 222 | -} | |
| 223 | 222 | \ No newline at end of file |
| 223 | + /** | |
| 224 | + * 通过产品标识和设备名称列表获取设备列表 | |
| 225 | + * | |
| 226 | + * @param productKey 产品标识 | |
| 227 | + * @param deviceNames 设备名称列表 | |
| 228 | + * @return 设备列表 | |
| 229 | + */ | |
| 230 | + List<IotDeviceDO> getDevicesByProductKeyAndNames(String productKey, List<String> deviceNames); | |
| 231 | + | |
| 232 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java
| ... | ... | @@ -451,4 +451,12 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 451 | 451 | )); |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | -} | |
| 455 | 454 | \ No newline at end of file |
| 455 | + @Override | |
| 456 | + public List<IotDeviceDO> getDevicesByProductKeyAndNames(String productKey, List<String> deviceNames) { | |
| 457 | + if (StrUtil.isBlank(productKey) || CollUtil.isEmpty(deviceNames)) { | |
| 458 | + return Collections.emptyList(); | |
| 459 | + } | |
| 460 | + return deviceMapper.selectByProductKeyAndDeviceNames(productKey, deviceNames); | |
| 461 | + } | |
| 462 | + | |
| 463 | +} | ... | ... |