diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java index 08fc244b15..ecc4726e7b 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java +++ b/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 { return success(deviceService.getMqttConnectionParams(deviceId)); } -} \ No newline at end of file + @GetMapping("/list-by-product-key-and-names") + @Operation(summary = "通过产品标识和设备名称列表获取设备") + @PreAuthorize("@ss.hasPermission('iot:device:query')") + public CommonResult> getDevicesByProductKeyAndNames(@Valid IotDeviceByProductKeyAndNamesReqVO reqVO) { + List devices = deviceService.getDevicesByProductKeyAndNames(reqVO.getProductKey(), reqVO.getDeviceNames()); + return success(BeanUtils.toBean(devices, IotDeviceRespVO.class)); + } + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceByProductKeyAndNamesReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceByProductKeyAndNamesReqVO.java new file mode 100644 index 0000000000..e617cad935 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceByProductKeyAndNamesReqVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import lombok.Data; + +import java.util.List; + +@Schema(description = "管理后台 - 通过产品标识和设备名称列表获取设备 Request VO") +@Data +public class IotDeviceByProductKeyAndNamesReqVO { + + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1de24640dfe") + @NotBlank(message = "产品标识不能为空") + private String productKey; + + @Schema(description = "设备名称列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "device001,device002") + @NotEmpty(message = "设备名称列表不能为空") + private List deviceNames; + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java index babbf29e7d..785af92551 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java +++ b/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; import javax.annotation.Nullable; import java.time.LocalDateTime; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -77,6 +78,12 @@ public interface IotDeviceMapper extends BaseMapperX { .geIfPresent(IotDeviceDO::getCreateTime, createTime)); } + default List selectByProductKeyAndDeviceNames(String productKey, Collection deviceNames) { + return selectList(new LambdaQueryWrapperX() + .eq(IotDeviceDO::getProductKey, productKey) + .in(IotDeviceDO::getDeviceName, deviceNames)); + } + /** * 查询指定产品下各状态的设备数量 * @@ -93,4 +100,4 @@ public interface IotDeviceMapper extends BaseMapperX { */ List> selectDeviceCountGroupByState(); -} \ No newline at end of file +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java index 1dda3f333c..11a0767bcd 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java +++ b/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 { */ Map getDeviceCountMapByState(); -} \ No newline at end of file + /** + * 通过产品标识和设备名称列表获取设备列表 + * + * @param productKey 产品标识 + * @param deviceNames 设备名称列表 + * @return 设备列表 + */ + List getDevicesByProductKeyAndNames(String productKey, List deviceNames); + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java index 989f10a095..785e376eb7 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java +++ b/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 { )); } -} \ No newline at end of file + @Override + public List getDevicesByProductKeyAndNames(String productKey, List deviceNames) { + if (StrUtil.isBlank(productKey) || CollUtil.isEmpty(deviceNames)) { + return Collections.emptyList(); + } + return deviceMapper.selectByProductKeyAndDeviceNames(productKey, deviceNames); + } + +}