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

This commit is contained in:
puhui999 2025-03-29 11:48:30 +08:00
parent b3dcd7b133
commit 5a66037725
5 changed files with 58 additions and 4 deletions

View File

@ -185,4 +185,12 @@ public class IotDeviceController {
return success(deviceService.getMqttConnectionParams(deviceId)); 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));
}
}

View File

@ -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;
}

View File

@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.Mapper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -77,6 +78,12 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
.geIfPresent(IotDeviceDO::getCreateTime, createTime)); .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(); List<Map<String, Object>> selectDeviceCountGroupByState();
} }

View File

@ -219,4 +219,13 @@ public interface IotDeviceService {
*/ */
Map<Integer, Long> getDeviceCountMapByState(); Map<Integer, Long> getDeviceCountMapByState();
} /**
* 通过产品标识和设备名称列表获取设备列表
*
* @param productKey 产品标识
* @param deviceNames 设备名称列表
* @return 设备列表
*/
List<IotDeviceDO> getDevicesByProductKeyAndNames(String productKey, List<String> deviceNames);
}

View File

@ -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);
}
}