Commit 0b16f1678cc02aa5310e5820219a9ce16ea79ecd
1 parent
dfa03d24
【功能优化】Bpm:完善设备属性的历史值
Showing
13 changed files
with
82 additions
and
141 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceLogController.java
| @@ -11,6 +11,7 @@ import io.swagger.v3.oas.annotations.Operation; | @@ -11,6 +11,7 @@ import io.swagger.v3.oas.annotations.Operation; | ||
| 11 | import io.swagger.v3.oas.annotations.tags.Tag; | 11 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 12 | import jakarta.annotation.Resource; | 12 | import jakarta.annotation.Resource; |
| 13 | import jakarta.validation.Valid; | 13 | import jakarta.validation.Valid; |
| 14 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 14 | import org.springframework.validation.annotation.Validated; | 15 | import org.springframework.validation.annotation.Validated; |
| 15 | import org.springframework.web.bind.annotation.GetMapping; | 16 | import org.springframework.web.bind.annotation.GetMapping; |
| 16 | import org.springframework.web.bind.annotation.RequestMapping; | 17 | import org.springframework.web.bind.annotation.RequestMapping; |
| @@ -27,9 +28,9 @@ public class IotDeviceLogController { | @@ -27,9 +28,9 @@ public class IotDeviceLogController { | ||
| 27 | @Resource | 28 | @Resource |
| 28 | private IotDeviceLogService deviceLogService; | 29 | private IotDeviceLogService deviceLogService; |
| 29 | 30 | ||
| 30 | - // TODO:功能权限 | ||
| 31 | @GetMapping("/page") | 31 | @GetMapping("/page") |
| 32 | @Operation(summary = "获得设备日志分页") | 32 | @Operation(summary = "获得设备日志分页") |
| 33 | + @PreAuthorize("@ss.hasPermission('iot:device:log-query')") | ||
| 33 | public CommonResult<PageResult<IotDeviceLogRespVO>> getDeviceLogPage(@Valid IotDeviceLogPageReqVO pageReqVO) { | 34 | public CommonResult<PageResult<IotDeviceLogRespVO>> getDeviceLogPage(@Valid IotDeviceLogPageReqVO pageReqVO) { |
| 34 | PageResult<IotDeviceLogDO> pageResult = deviceLogService.getDeviceLogPage(pageReqVO); | 35 | PageResult<IotDeviceLogDO> pageResult = deviceLogService.getDeviceLogPage(pageReqVO); |
| 35 | return success(BeanUtils.toBean(pageResult, IotDeviceLogRespVO.class)); | 36 | return success(BeanUtils.toBean(pageResult, IotDeviceLogRespVO.class)); |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDevicePropertyController.java
| @@ -3,10 +3,11 @@ package cn.iocoder.yudao.module.iot.controller.admin.device; | @@ -3,10 +3,11 @@ package cn.iocoder.yudao.module.iot.controller.admin.device; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.date.LocalDateTimeUtil; | 4 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 5 | import cn.hutool.core.lang.Assert; | 5 | import cn.hutool.core.lang.Assert; |
| 6 | +import cn.hutool.core.util.StrUtil; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 9 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyPageReqVO; | 10 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO; |
| 10 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; | 11 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; |
| 11 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | 12 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 12 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; | 13 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; |
| @@ -15,12 +16,16 @@ import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; | @@ -15,12 +16,16 @@ import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; | ||
| 15 | import cn.iocoder.yudao.module.iot.service.device.data.IotDevicePropertyService; | 16 | import cn.iocoder.yudao.module.iot.service.device.data.IotDevicePropertyService; |
| 16 | import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; | 17 | import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; |
| 17 | import io.swagger.v3.oas.annotations.Operation; | 18 | import io.swagger.v3.oas.annotations.Operation; |
| 19 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 20 | +import io.swagger.v3.oas.annotations.Parameters; | ||
| 18 | import io.swagger.v3.oas.annotations.tags.Tag; | 21 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 19 | import jakarta.annotation.Resource; | 22 | import jakarta.annotation.Resource; |
| 20 | import jakarta.validation.Valid; | 23 | import jakarta.validation.Valid; |
| 24 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 21 | import org.springframework.validation.annotation.Validated; | 25 | import org.springframework.validation.annotation.Validated; |
| 22 | import org.springframework.web.bind.annotation.GetMapping; | 26 | import org.springframework.web.bind.annotation.GetMapping; |
| 23 | import org.springframework.web.bind.annotation.RequestMapping; | 27 | import org.springframework.web.bind.annotation.RequestMapping; |
| 28 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 24 | import org.springframework.web.bind.annotation.RestController; | 29 | import org.springframework.web.bind.annotation.RestController; |
| 25 | 30 | ||
| 26 | import java.util.List; | 31 | import java.util.List; |
| @@ -42,14 +47,22 @@ public class IotDevicePropertyController { | @@ -42,14 +47,22 @@ public class IotDevicePropertyController { | ||
| 42 | @Resource | 47 | @Resource |
| 43 | private IotDeviceService deviceService; | 48 | private IotDeviceService deviceService; |
| 44 | 49 | ||
| 45 | - // TODO @芋艿:权限 | ||
| 46 | @GetMapping("/latest") | 50 | @GetMapping("/latest") |
| 47 | @Operation(summary = "获取设备属性最新属性") | 51 | @Operation(summary = "获取设备属性最新属性") |
| 48 | - public CommonResult<List<IotDevicePropertyRespVO>> getLatestDeviceProperties(@Valid IotDevicePropertyPageReqVO pageReqVO) { | ||
| 49 | - Map<String, IotDevicePropertyDO> properties = devicePropertyService.getLatestDeviceProperties(pageReqVO); | 52 | + @Parameters({ |
| 53 | + @Parameter(name = "deviceId", description = "设备编号", required = true), | ||
| 54 | + @Parameter(name = "identifier", description = "标识符"), | ||
| 55 | + @Parameter(name = "name", description = "名称") | ||
| 56 | + }) | ||
| 57 | + @PreAuthorize("@ss.hasPermission('iot:device:property-query')") | ||
| 58 | + public CommonResult<List<IotDevicePropertyRespVO>> getLatestDeviceProperties( | ||
| 59 | + @RequestParam("deviceId") Long deviceId, | ||
| 60 | + @RequestParam(value = "identifier", required = false) String identifier, | ||
| 61 | + @RequestParam(value = "name", required = false) String name) { | ||
| 62 | + Map<String, IotDevicePropertyDO> properties = devicePropertyService.getLatestDeviceProperties(deviceId); | ||
| 50 | 63 | ||
| 51 | // 拼接数据 | 64 | // 拼接数据 |
| 52 | - IotDeviceDO device = deviceService.getDevice(pageReqVO.getDeviceId()); | 65 | + IotDeviceDO device = deviceService.getDevice(deviceId); |
| 53 | Assert.notNull(device, "设备不存在"); | 66 | Assert.notNull(device, "设备不存在"); |
| 54 | List<IotThingModelDO> thingModels = thingModelService.getThingModelListByProductId(device.getProductId()); | 67 | List<IotThingModelDO> thingModels = thingModelService.getThingModelListByProductId(device.getProductId()); |
| 55 | return success(convertList(properties.entrySet(), entry -> { | 68 | return success(convertList(properties.entrySet(), entry -> { |
| @@ -58,6 +71,13 @@ public class IotDevicePropertyController { | @@ -58,6 +71,13 @@ public class IotDevicePropertyController { | ||
| 58 | if (thingModel == null || thingModel.getProperty() == null) { | 71 | if (thingModel == null || thingModel.getProperty() == null) { |
| 59 | return null; | 72 | return null; |
| 60 | } | 73 | } |
| 74 | + if (StrUtil.isNotEmpty(identifier) && !StrUtil.contains(thingModel.getIdentifier(), identifier)) { | ||
| 75 | + return null; | ||
| 76 | + } | ||
| 77 | + if (StrUtil.isNotEmpty(name) && !StrUtil.contains(thingModel.getName(), name)) { | ||
| 78 | + return null; | ||
| 79 | + } | ||
| 80 | + // 构建对象 | ||
| 61 | IotDevicePropertyDO property = entry.getValue(); | 81 | IotDevicePropertyDO property = entry.getValue(); |
| 62 | return BeanUtils.toBean(thingModel, IotDevicePropertyRespVO.class) | 82 | return BeanUtils.toBean(thingModel, IotDevicePropertyRespVO.class) |
| 63 | .setDataType(thingModel.getProperty().getDataType()) | 83 | .setDataType(thingModel.getProperty().getDataType()) |
| @@ -66,11 +86,11 @@ public class IotDevicePropertyController { | @@ -66,11 +86,11 @@ public class IotDevicePropertyController { | ||
| 66 | })); | 86 | })); |
| 67 | } | 87 | } |
| 68 | 88 | ||
| 69 | - // TODO @芋艿:权限 | ||
| 70 | @GetMapping("/history-page") | 89 | @GetMapping("/history-page") |
| 71 | @Operation(summary = "获取设备属性历史数据") | 90 | @Operation(summary = "获取设备属性历史数据") |
| 91 | + @PreAuthorize("@ss.hasPermission('iot:device:property-query')") | ||
| 72 | public CommonResult<PageResult<IotDevicePropertyRespVO>> getHistoryDevicePropertyPage( | 92 | public CommonResult<PageResult<IotDevicePropertyRespVO>> getHistoryDevicePropertyPage( |
| 73 | - @Valid IotDevicePropertyPageReqVO pageReqVO) { | 93 | + @Valid IotDevicePropertyHistoryPageReqVO pageReqVO) { |
| 74 | Assert.notEmpty(pageReqVO.getIdentifier(), "标识符不能为空"); | 94 | Assert.notEmpty(pageReqVO.getIdentifier(), "标识符不能为空"); |
| 75 | return success(devicePropertyService.getHistoryDevicePropertyPage(pageReqVO)); | 95 | return success(devicePropertyService.getHistoryDevicePropertyPage(pageReqVO)); |
| 76 | } | 96 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyPageReqVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyHistoryPageReqVO.java
| @@ -2,12 +2,19 @@ package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; | @@ -2,12 +2,19 @@ package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | import io.swagger.v3.oas.annotations.media.Schema; | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | +import jakarta.validation.constraints.NotEmpty; | ||
| 5 | import jakarta.validation.constraints.NotNull; | 6 | import jakarta.validation.constraints.NotNull; |
| 7 | +import jakarta.validation.constraints.Size; | ||
| 6 | import lombok.Data; | 8 | import lombok.Data; |
| 9 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 7 | 10 | ||
| 8 | -@Schema(description = "管理后台 - IoT 设备属性 Request VO") | 11 | +import java.time.LocalDateTime; |
| 12 | + | ||
| 13 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 14 | + | ||
| 15 | +@Schema(description = "管理后台 - IoT 设备属性历史分页 Request VO") | ||
| 9 | @Data | 16 | @Data |
| 10 | -public class IotDevicePropertyPageReqVO extends PageParam { | 17 | +public class IotDevicePropertyHistoryPageReqVO extends PageParam { |
| 11 | 18 | ||
| 12 | @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") | 19 | @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") |
| 13 | @NotNull(message = "设备编号不能为空") | 20 | @NotNull(message = "设备编号不能为空") |
| @@ -17,9 +24,12 @@ public class IotDevicePropertyPageReqVO extends PageParam { | @@ -17,9 +24,12 @@ public class IotDevicePropertyPageReqVO extends PageParam { | ||
| 17 | private String deviceKey; // 非前端传递,后端自己查询设置 | 24 | private String deviceKey; // 非前端传递,后端自己查询设置 |
| 18 | 25 | ||
| 19 | @Schema(description = "属性标识符", requiredMode = Schema.RequiredMode.REQUIRED) | 26 | @Schema(description = "属性标识符", requiredMode = Schema.RequiredMode.REQUIRED) |
| 27 | + @NotEmpty(message = "属性标识符不能为空") | ||
| 20 | private String identifier; | 28 | private String identifier; |
| 21 | 29 | ||
| 22 | - @Schema(description = "属性名称", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 23 | - private String name; | 30 | + @Schema(description = "时间范围", requiredMode = Schema.RequiredMode.NOT_REQUIRED) |
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 32 | + @Size(min = 2, max = 2, message = "请选择时间范围") | ||
| 33 | + private LocalDateTime[] times; | ||
| 24 | 34 | ||
| 25 | } | 35 | } |
| 26 | \ No newline at end of file | 36 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyRespVO.java
| @@ -14,7 +14,7 @@ public class IotDevicePropertyRespVO { | @@ -14,7 +14,7 @@ public class IotDevicePropertyRespVO { | ||
| 14 | private Object value; | 14 | private Object value; |
| 15 | 15 | ||
| 16 | @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) | 16 | @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 17 | - private Long updateTime; | 17 | + private Long updateTime; // 由于从 TDengine 查询出来的是 Long 类型,所以这里也使用 Long 类型 |
| 18 | 18 | ||
| 19 | // ========== 基于 ThingModel 查询 ========== | 19 | // ========== 基于 ThingModel 查询 ========== |
| 20 | 20 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelProperty.java
| @@ -31,10 +31,7 @@ public class ThingModelProperty { | @@ -31,10 +31,7 @@ public class ThingModelProperty { | ||
| 31 | */ | 31 | */ |
| 32 | private String accessMode; | 32 | private String accessMode; |
| 33 | /** | 33 | /** |
| 34 | - * 是否是标准品类的必选服务。 | ||
| 35 | - * | ||
| 36 | - * - true:是 | ||
| 37 | - * - false:否 | 34 | + * 是否是标准品类的必选服务 |
| 38 | */ | 35 | */ |
| 39 | private Boolean required; | 36 | private Boolean required; |
| 40 | /** | 37 | /** |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/device/IotDeviceDataConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.convert.device; | ||
| 2 | - | ||
| 3 | -import org.mapstruct.Mapper; | ||
| 4 | -import org.mapstruct.factory.Mappers; | ||
| 5 | - | ||
| 6 | -// TODO 是否要删除? | ||
| 7 | -@Mapper | ||
| 8 | -public interface IotDeviceDataConvert { | ||
| 9 | - | ||
| 10 | - IotDeviceDataConvert INSTANCE = Mappers.getMapper(IotDeviceDataConvert.class); | ||
| 11 | - | ||
| 12 | -// default List<IotDeviceDataRespVO> convert(Map<String, Object> deviceData, IotDeviceDO device){ | ||
| 13 | -// List<IotDeviceDataRespVO> list = new ArrayList<>(); | ||
| 14 | -// deviceData.forEach((identifier, value) -> { | ||
| 15 | -//// ThingModelProperty property = ThingModelService.INSTANCE.getProperty(device.getProductId(), identifier); | ||
| 16 | -//// if (Objects.isNull(property)) { | ||
| 17 | -//// return; | ||
| 18 | -//// } | ||
| 19 | -// IotDeviceDataRespVO vo = new IotDeviceDataRespVO(); | ||
| 20 | -// vo.setDeviceId(device.getId()); | ||
| 21 | -// vo.setProductKey(device.getProductKey()); | ||
| 22 | -// vo.setDeviceName(device.getDeviceName()); | ||
| 23 | -// vo.setIdentifier(identifier); | ||
| 24 | -//// vo.setName(property.getName()); | ||
| 25 | -//// vo.setDataType(property.getDataType().getType()); | ||
| 26 | -// vo.setUpdateTime(device.getUpdateTime()); | ||
| 27 | -// vo.setValue(value.toString()); | ||
| 28 | -// list.add(vo); | ||
| 29 | -// }); | ||
| 30 | -// return list; | ||
| 31 | -// } | ||
| 32 | -} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/package-info.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDevicePropertyMapper.java
| @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.iot.dal.tdengine; | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.iot.dal.tdengine; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.ObjectUtil; | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 6 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyPageReqVO; | 6 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO; |
| 7 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; | 7 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; |
| 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 9 | import cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField; | 9 | import cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField; |
| @@ -85,6 +85,6 @@ public interface IotDevicePropertyMapper { | @@ -85,6 +85,6 @@ public interface IotDevicePropertyMapper { | ||
| 85 | @Param("reportTime") Long reportTime); | 85 | @Param("reportTime") Long reportTime); |
| 86 | 86 | ||
| 87 | IPage<IotDevicePropertyRespVO> selectPageByHistory(IPage<?> page, | 87 | IPage<IotDevicePropertyRespVO> selectPageByHistory(IPage<?> page, |
| 88 | - @Param("reqVO") IotDevicePropertyPageReqVO reqVO); | 88 | + @Param("reqVO") IotDevicePropertyHistoryPageReqVO reqVO); |
| 89 | 89 | ||
| 90 | } | 90 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java
| @@ -51,10 +51,16 @@ public class IotDeviceLogServiceImpl implements IotDeviceLogService { | @@ -51,10 +51,16 @@ public class IotDeviceLogServiceImpl implements IotDeviceLogService { | ||
| 51 | 51 | ||
| 52 | @Override | 52 | @Override |
| 53 | public PageResult<IotDeviceLogDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO) { | 53 | public PageResult<IotDeviceLogDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO) { |
| 54 | - // TODO @芋艿:增加一个表不存在的 try catch | ||
| 55 | - IPage<IotDeviceLogDO> page = deviceLogMapper.selectPage( | ||
| 56 | - new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO); | ||
| 57 | - return new PageResult<>(page.getRecords(), page.getTotal()); | 54 | + try { |
| 55 | + IPage<IotDeviceLogDO> page = deviceLogMapper.selectPage( | ||
| 56 | + new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO); | ||
| 57 | + return new PageResult<>(page.getRecords(), page.getTotal()); | ||
| 58 | + } catch (Exception exception) { | ||
| 59 | + if (exception.getMessage().contains("Table does not exist")) { | ||
| 60 | + return PageResult.empty(); | ||
| 61 | + } | ||
| 62 | + throw exception; | ||
| 63 | + } | ||
| 58 | } | 64 | } |
| 59 | 65 | ||
| 60 | } | 66 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyService.java
| 1 | package cn.iocoder.yudao.module.iot.service.device.data; | 1 | package cn.iocoder.yudao.module.iot.service.device.data; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyPageReqVO; | 4 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO; |
| 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; | 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; |
| 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; |
| 7 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; | 7 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; |
| @@ -36,7 +36,7 @@ public interface IotDevicePropertyService { | @@ -36,7 +36,7 @@ public interface IotDevicePropertyService { | ||
| 36 | * @param deviceId 设备编号 | 36 | * @param deviceId 设备编号 |
| 37 | * @return 设备属性最新数据 | 37 | * @return 设备属性最新数据 |
| 38 | */ | 38 | */ |
| 39 | - Map<String, IotDevicePropertyDO> getLatestDeviceProperties(@Valid IotDevicePropertyPageReqVO deviceId); | 39 | + Map<String, IotDevicePropertyDO> getLatestDeviceProperties(Long deviceId); |
| 40 | 40 | ||
| 41 | /** | 41 | /** |
| 42 | * 获得设备属性历史数据 | 42 | * 获得设备属性历史数据 |
| @@ -44,6 +44,6 @@ public interface IotDevicePropertyService { | @@ -44,6 +44,6 @@ public interface IotDevicePropertyService { | ||
| 44 | * @param pageReqVO 分页请求 | 44 | * @param pageReqVO 分页请求 |
| 45 | * @return 设备属性历史数据 | 45 | * @return 设备属性历史数据 |
| 46 | */ | 46 | */ |
| 47 | - PageResult<IotDevicePropertyRespVO> getHistoryDevicePropertyPage(@Valid IotDevicePropertyPageReqVO pageReqVO); | 47 | + PageResult<IotDevicePropertyRespVO> getHistoryDevicePropertyPage(@Valid IotDevicePropertyHistoryPageReqVO pageReqVO); |
| 48 | 48 | ||
| 49 | } | 49 | } |
| 50 | \ No newline at end of file | 50 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyServiceImpl.java
| @@ -6,7 +6,7 @@ import cn.hutool.core.map.MapUtil; | @@ -6,7 +6,7 @@ import cn.hutool.core.map.MapUtil; | ||
| 6 | import cn.hutool.core.util.StrUtil; | 6 | import cn.hutool.core.util.StrUtil; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; | 8 | import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; |
| 9 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyPageReqVO; | 9 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO; |
| 10 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; | 10 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; |
| 11 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs; | 11 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs; |
| 12 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | 12 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| @@ -25,7 +25,6 @@ import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; | @@ -25,7 +25,6 @@ import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; | ||
| 25 | import com.baomidou.mybatisplus.core.metadata.IPage; | 25 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 26 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 26 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| 27 | import jakarta.annotation.Resource; | 27 | import jakarta.annotation.Resource; |
| 28 | -import jakarta.validation.Valid; | ||
| 29 | import lombok.extern.slf4j.Slf4j; | 28 | import lombok.extern.slf4j.Slf4j; |
| 30 | import org.springframework.stereotype.Service; | 29 | import org.springframework.stereotype.Service; |
| 31 | 30 | ||
| @@ -146,33 +145,38 @@ public class IotDevicePropertyServiceImpl implements IotDevicePropertyService { | @@ -146,33 +145,38 @@ public class IotDevicePropertyServiceImpl implements IotDevicePropertyService { | ||
| 146 | 145 | ||
| 147 | // 3.1 保存设备属性【数据】 | 146 | // 3.1 保存设备属性【数据】 |
| 148 | devicePropertyMapper.insert(device, properties, | 147 | devicePropertyMapper.insert(device, properties, |
| 149 | - LocalDateTimeUtil.toEpochMilli(message.getReportTime())); // TODO @芋艿:后续要看看,查询的时候,能不能用 LocalDateTime | 148 | + LocalDateTimeUtil.toEpochMilli(message.getReportTime())); |
| 150 | 149 | ||
| 151 | // 3.2 保存设备属性【日志】 | 150 | // 3.2 保存设备属性【日志】 |
| 152 | deviceDataRedisDAO.set(message.getDeviceKey(), convertMap(properties.entrySet(), Map.Entry::getKey, | 151 | deviceDataRedisDAO.set(message.getDeviceKey(), convertMap(properties.entrySet(), Map.Entry::getKey, |
| 153 | entry -> IotDevicePropertyDO.builder().value(entry.getValue()).updateTime(message.getReportTime()).build())); | 152 | entry -> IotDevicePropertyDO.builder().value(entry.getValue()).updateTime(message.getReportTime()).build())); |
| 154 | } | 153 | } |
| 155 | 154 | ||
| 156 | - // TODO @芋艿:需要在优化下,根据 name 之类的过滤 | ||
| 157 | @Override | 155 | @Override |
| 158 | - public Map<String, IotDevicePropertyDO> getLatestDeviceProperties(@Valid IotDevicePropertyPageReqVO pageReqVO) { | 156 | + public Map<String, IotDevicePropertyDO> getLatestDeviceProperties(Long deviceId) { |
| 159 | // 获取设备信息 | 157 | // 获取设备信息 |
| 160 | - IotDeviceDO device = deviceService.validateDeviceExists(pageReqVO.getDeviceId()); | 158 | + IotDeviceDO device = deviceService.validateDeviceExists(deviceId); |
| 161 | 159 | ||
| 162 | // 获得设备属性 | 160 | // 获得设备属性 |
| 163 | return deviceDataRedisDAO.get(device.getDeviceKey()); | 161 | return deviceDataRedisDAO.get(device.getDeviceKey()); |
| 164 | } | 162 | } |
| 165 | 163 | ||
| 166 | @Override | 164 | @Override |
| 167 | - public PageResult<IotDevicePropertyRespVO> getHistoryDevicePropertyPage(IotDevicePropertyPageReqVO pageReqVO) { | 165 | + public PageResult<IotDevicePropertyRespVO> getHistoryDevicePropertyPage(IotDevicePropertyHistoryPageReqVO pageReqVO) { |
| 168 | // 获取设备信息 | 166 | // 获取设备信息 |
| 169 | IotDeviceDO device = deviceService.validateDeviceExists(pageReqVO.getDeviceId()); | 167 | IotDeviceDO device = deviceService.validateDeviceExists(pageReqVO.getDeviceId()); |
| 170 | pageReqVO.setDeviceKey(device.getDeviceKey()); | 168 | pageReqVO.setDeviceKey(device.getDeviceKey()); |
| 171 | 169 | ||
| 172 | - // TODO @芋艿:增加一个表不存在的 try catch | ||
| 173 | - IPage<IotDevicePropertyRespVO> page = devicePropertyMapper.selectPageByHistory( | ||
| 174 | - new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO); | ||
| 175 | - return new PageResult<>(page.getRecords(), page.getTotal()); | 170 | + try { |
| 171 | + IPage<IotDevicePropertyRespVO> page = devicePropertyMapper.selectPageByHistory( | ||
| 172 | + new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO); | ||
| 173 | + return new PageResult<>(page.getRecords(), page.getTotal()); | ||
| 174 | + } catch (Exception exception) { | ||
| 175 | + if (exception.getMessage().contains("Table does not exist")) { | ||
| 176 | + return PageResult.empty(); | ||
| 177 | + } | ||
| 178 | + throw exception; | ||
| 179 | + } | ||
| 176 | } | 180 | } |
| 177 | 181 | ||
| 178 | } | 182 | } |
| 179 | \ No newline at end of file | 183 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/util/IotTdDatabaseUtils.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.util; | ||
| 2 | - | ||
| 3 | -import cn.hutool.core.lang.Assert; | ||
| 4 | -import cn.hutool.core.util.StrUtil; | ||
| 5 | -import cn.iocoder.yudao.module.iot.enums.IotConstants; | ||
| 6 | -import cn.iocoder.yudao.module.iot.enums.product.IotProductDeviceTypeEnum; | ||
| 7 | - | ||
| 8 | -// TODO @芋艿:可能要思索下,有没更好的处理方式 | ||
| 9 | -// TODO @芋艿:怎么改成无状态 | ||
| 10 | -/** | ||
| 11 | - * TD 数据库工具类 | ||
| 12 | - * | ||
| 13 | - * @author AlwaysSuper | ||
| 14 | - */ | ||
| 15 | -public class IotTdDatabaseUtils { | ||
| 16 | - | ||
| 17 | - /** | ||
| 18 | - * 获取数据库名称 | ||
| 19 | - */ | ||
| 20 | - public static String getDatabaseName(String url) { | ||
| 21 | -// TODO @alwayssuper:StrUtil.subAfter("/") | ||
| 22 | - return StrUtil.subAfter(url, "/", true); | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | - /** | ||
| 26 | - * 获取产品超级表表名 | ||
| 27 | - * | ||
| 28 | - * @param deviceType 设备类型 | ||
| 29 | - * @param productKey 产品 Key | ||
| 30 | - * @return 产品超级表表名 | ||
| 31 | - */ | ||
| 32 | - public static String getProductSuperTableName(Integer deviceType, String productKey) { | ||
| 33 | - Assert.notNull(deviceType, "deviceType 不能为空"); | ||
| 34 | - if (IotProductDeviceTypeEnum.GATEWAY_SUB.getType().equals(deviceType)) { | ||
| 35 | - return String.format(IotConstants.GATEWAY_SUB_STABLE_NAME_FORMAT, productKey).toLowerCase(); | ||
| 36 | - } | ||
| 37 | - if (IotProductDeviceTypeEnum.GATEWAY.getType().equals(deviceType)) { | ||
| 38 | - return String.format(IotConstants.GATEWAY_STABLE_NAME_FORMAT, productKey).toLowerCase(); | ||
| 39 | - } | ||
| 40 | - if (IotProductDeviceTypeEnum.DIRECT.getType().equals(deviceType)){ | ||
| 41 | - return String.format(IotConstants.DEVICE_STABLE_NAME_FORMAT, productKey).toLowerCase(); | ||
| 42 | - } | ||
| 43 | - throw new IllegalArgumentException("deviceType 不正确"); | ||
| 44 | - } | ||
| 45 | - | ||
| 46 | - /** | ||
| 47 | - * 获取物模型日志超级表表名 | ||
| 48 | - * | ||
| 49 | - * @param productKey 产品 Key | ||
| 50 | - * @return 物模型日志超级表表名 | ||
| 51 | - * | ||
| 52 | - */ | ||
| 53 | - public static String getThingModelMessageSuperTableName(String productKey) { | ||
| 54 | - return "thing_model_message_" + productKey.toLowerCase(); | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - /** | ||
| 58 | - * 获取物模型日志设备表名 | ||
| 59 | - * | ||
| 60 | - * @param productKey 产品 Key | ||
| 61 | - * @param deviceName 设备名称 | ||
| 62 | - * @return 物模型日志设备表名 | ||
| 63 | - */ | ||
| 64 | - public static String getThingModelMessageDeviceTableName(String productKey, String deviceName) { | ||
| 65 | - return String.format(IotConstants.THING_MODEL_MESSAGE_TABLE_NAME_FORMAT, | ||
| 66 | - productKey.toLowerCase(), deviceName.toLowerCase()); | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | -} |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml
| @@ -66,11 +66,12 @@ | @@ -66,11 +66,12 @@ | ||
| 66 | DESCRIBE product_property_${productKey} | 66 | DESCRIBE product_property_${productKey} |
| 67 | </select> | 67 | </select> |
| 68 | 68 | ||
| 69 | - <!-- TODO 芋艿:缺少时间范围 AND ts BETWEEN #{reqVO.startTime} AND #{reqVO.endTime} --> | ||
| 70 | <select id="selectPageByHistory" resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO"> | 69 | <select id="selectPageByHistory" resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO"> |
| 71 | - SELECT ${reqVO.identifier} AS `value`, report_time AS update_time | ||
| 72 | - FROM device_property_${reqVO.deviceKey} | 70 | + SELECT ${reqVO.identifier} AS `value`, ts AS update_time |
| 71 | + FROM device_property_${reqVO.deviceKey}1 | ||
| 73 | WHERE ${reqVO.identifier} IS NOT NULL | 72 | WHERE ${reqVO.identifier} IS NOT NULL |
| 73 | + AND ts BETWEEN ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[0])} | ||
| 74 | + AND ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[1])} | ||
| 74 | ORDER BY ts DESC | 75 | ORDER BY ts DESC |
| 75 | </select> | 76 | </select> |
| 76 | 77 |