From 5a66037725be4c9c26cb89f46bb88c260328dd33 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 29 Mar 2025 11:48:30 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E3=80=91IoT:=20=E9=80=9A=E8=BF=87=E4=BA=A7=E5=93=81=E6=A0=87?= =?UTF-8?q?=E8=AF=86=E5=92=8C=E8=AE=BE=E5=A4=87=E5=90=8D=E7=A7=B0=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E8=8E=B7=E5=8F=96=E8=AE=BE=E5=A4=87=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/device/IotDeviceController.java | 10 ++++++++- .../IotDeviceByProductKeyAndNamesReqVO.java | 22 +++++++++++++++++++ .../iot/dal/mysql/device/IotDeviceMapper.java | 9 +++++++- .../iot/service/device/IotDeviceService.java | 11 +++++++++- .../service/device/IotDeviceServiceImpl.java | 10 ++++++++- 5 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceByProductKeyAndNamesReqVO.java 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); + } + +}