|
@@ -3,10 +3,11 @@ package cn.iocoder.yudao.module.iot.controller.admin.device;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
-import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO;
|
|
|
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO;
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO;
|
|
@@ -15,12 +16,16 @@ import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
|
|
|
import cn.iocoder.yudao.module.iot.service.device.data.IotDevicePropertyService;
|
|
|
import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
+import io.swagger.v3.oas.annotations.Parameters;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import jakarta.validation.Valid;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.List;
|
|
@@ -42,14 +47,22 @@ public class IotDevicePropertyController {
|
|
|
@Resource
|
|
|
private IotDeviceService deviceService;
|
|
|
|
|
|
- // TODO @芋艿:权限
|
|
|
@GetMapping("/latest")
|
|
|
@Operation(summary = "获取设备属性最新属性")
|
|
|
- public CommonResult<List<IotDevicePropertyRespVO>> getLatestDeviceProperties(@Valid IotDevicePropertyPageReqVO pageReqVO) {
|
|
|
- Map<String, IotDevicePropertyDO> properties = devicePropertyService.getLatestDeviceProperties(pageReqVO);
|
|
|
+ @Parameters({
|
|
|
+ @Parameter(name = "deviceId", description = "设备编号", required = true),
|
|
|
+ @Parameter(name = "identifier", description = "标识符"),
|
|
|
+ @Parameter(name = "name", description = "名称")
|
|
|
+ })
|
|
|
+ @PreAuthorize("@ss.hasPermission('iot:device:property-query')")
|
|
|
+ public CommonResult<List<IotDevicePropertyRespVO>> getLatestDeviceProperties(
|
|
|
+ @RequestParam("deviceId") Long deviceId,
|
|
|
+ @RequestParam(value = "identifier", required = false) String identifier,
|
|
|
+ @RequestParam(value = "name", required = false) String name) {
|
|
|
+ Map<String, IotDevicePropertyDO> properties = devicePropertyService.getLatestDeviceProperties(deviceId);
|
|
|
|
|
|
// 拼接数据
|
|
|
- IotDeviceDO device = deviceService.getDevice(pageReqVO.getDeviceId());
|
|
|
+ IotDeviceDO device = deviceService.getDevice(deviceId);
|
|
|
Assert.notNull(device, "设备不存在");
|
|
|
List<IotThingModelDO> thingModels = thingModelService.getThingModelListByProductId(device.getProductId());
|
|
|
return success(convertList(properties.entrySet(), entry -> {
|
|
@@ -58,6 +71,13 @@ public class IotDevicePropertyController {
|
|
|
if (thingModel == null || thingModel.getProperty() == null) {
|
|
|
return null;
|
|
|
}
|
|
|
+ if (StrUtil.isNotEmpty(identifier) && !StrUtil.contains(thingModel.getIdentifier(), identifier)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotEmpty(name) && !StrUtil.contains(thingModel.getName(), name)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 构建对象
|
|
|
IotDevicePropertyDO property = entry.getValue();
|
|
|
return BeanUtils.toBean(thingModel, IotDevicePropertyRespVO.class)
|
|
|
.setDataType(thingModel.getProperty().getDataType())
|
|
@@ -66,11 +86,11 @@ public class IotDevicePropertyController {
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
- // TODO @芋艿:权限
|
|
|
@GetMapping("/history-page")
|
|
|
@Operation(summary = "获取设备属性历史数据")
|
|
|
+ @PreAuthorize("@ss.hasPermission('iot:device:property-query')")
|
|
|
public CommonResult<PageResult<IotDevicePropertyRespVO>> getHistoryDevicePropertyPage(
|
|
|
- @Valid IotDevicePropertyPageReqVO pageReqVO) {
|
|
|
+ @Valid IotDevicePropertyHistoryPageReqVO pageReqVO) {
|
|
|
Assert.notEmpty(pageReqVO.getIdentifier(), "标识符不能为空");
|
|
|
return success(devicePropertyService.getHistoryDevicePropertyPage(pageReqVO));
|
|
|
}
|