소스 검색

【功能新增】IoT: 通过产品标识和设备名称列表获取设备列表

puhui999 7 달 전
부모
커밋
5a66037725

+ 9 - 1
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));
     }
 
-}
+    @GetMapping("/list-by-product-key-and-names")
+    @Operation(summary = "通过产品标识和设备名称列表获取设备")
+    @PreAuthorize("@ss.hasPermission('iot:device:query')")
+    public CommonResult<List<IotDeviceRespVO>> getDevicesByProductKeyAndNames(@Valid IotDeviceByProductKeyAndNamesReqVO reqVO) {
+        List<IotDeviceDO> devices = deviceService.getDevicesByProductKeyAndNames(reqVO.getProductKey(), reqVO.getDeviceNames());
+        return success(BeanUtils.toBean(devices, IotDeviceRespVO.class));
+    }
+
+}

+ 22 - 0
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<String> deviceNames;
+
+} 

+ 8 - 1
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<IotDeviceDO> {
                 .geIfPresent(IotDeviceDO::getCreateTime, createTime));
     }
 
+    default List<IotDeviceDO> selectByProductKeyAndDeviceNames(String productKey, Collection<String> deviceNames) {
+        return selectList(new LambdaQueryWrapperX<IotDeviceDO>()
+                .eq(IotDeviceDO::getProductKey, productKey)
+                .in(IotDeviceDO::getDeviceName, deviceNames));
+    }
+
     /**
      * 查询指定产品下各状态的设备数量
      *
@@ -93,4 +100,4 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
      */
     List<Map<String, Object>> selectDeviceCountGroupByState();
 
-}
+}

+ 10 - 1
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<Integer, Long> getDeviceCountMapByState();
 
-}
+    /**
+     * 通过产品标识和设备名称列表获取设备列表
+     *
+     * @param productKey  产品标识
+     * @param deviceNames 设备名称列表
+     * @return 设备列表
+     */
+    List<IotDeviceDO> getDevicesByProductKeyAndNames(String productKey, List<String> deviceNames);
+
+}

+ 9 - 1
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 {
         ));
     }
 
-}
+    @Override
+    public List<IotDeviceDO> getDevicesByProductKeyAndNames(String productKey, List<String> deviceNames) {
+        if (StrUtil.isBlank(productKey) || CollUtil.isEmpty(deviceNames)) {
+            return Collections.emptyList();
+        }
+        return deviceMapper.selectByProductKeyAndDeviceNames(productKey, deviceNames);
+    }
+
+}