Commit 8c9044867047f265ba8b17ff94e1d1fc3f3fd62a
1 parent
6071afea
【功能优化】Bpm:完善最新数据的接口
Showing
16 changed files
with
120 additions
and
138 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceDataController.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.controller.admin.device; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO; | |
| 7 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataRespVO; | |
| 8 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotTimeDataRespVO; | |
| 9 | -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; | |
| 10 | -import cn.iocoder.yudao.module.iot.service.device.data.IotDevicePropertyService; | |
| 11 | -import io.swagger.v3.oas.annotations.Operation; | |
| 12 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 13 | -import jakarta.annotation.Resource; | |
| 14 | -import jakarta.validation.Valid; | |
| 15 | -import org.springframework.validation.annotation.Validated; | |
| 16 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 17 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 18 | -import org.springframework.web.bind.annotation.RestController; | |
| 19 | - | |
| 20 | -import java.util.List; | |
| 21 | -import java.util.Map; | |
| 22 | - | |
| 23 | -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 24 | - | |
| 25 | -@Tag(name = "管理后台 - IoT 设备数据") | |
| 26 | -@RestController | |
| 27 | -@RequestMapping("/iot/device/data") | |
| 28 | -@Validated | |
| 29 | -public class IotDeviceDataController { | |
| 30 | - | |
| 31 | - @Resource | |
| 32 | - private IotDevicePropertyService deviceDataService; | |
| 33 | - | |
| 34 | - // TODO @浩浩:这里的 /latest-list,包括方法名。 | |
| 35 | - @GetMapping("/latest") | |
| 36 | - @Operation(summary = "获取设备属性最新数据") | |
| 37 | - public CommonResult<List<IotDeviceDataRespVO>> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO deviceDataReqVO) { | |
| 38 | - List<IotDevicePropertyDO> list = deviceDataService.getLatestDeviceProperties(deviceDataReqVO); | |
| 39 | - return success(BeanUtils.toBean(list, IotDeviceDataRespVO.class)); | |
| 40 | - } | |
| 41 | - | |
| 42 | - // TODO @浩浩:这里的 /history-page 包括方法名。 | |
| 43 | - @GetMapping("/history") | |
| 44 | - @Operation(summary = "获取设备属性历史数据") | |
| 45 | - public CommonResult<PageResult<IotTimeDataRespVO>> getHistoryDeviceProperties(@Valid IotDeviceDataPageReqVO deviceDataReqVO) { | |
| 46 | - PageResult<Map<String, Object>> list = deviceDataService.getHistoryDeviceProperties(deviceDataReqVO); | |
| 47 | - return success(BeanUtils.toBean(list, IotTimeDataRespVO.class)); | |
| 48 | - } | |
| 49 | - | |
| 50 | -} | |
| 51 | 0 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceLogController.java
| ... | ... | @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.iot.controller.admin.device; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO; | |
| 7 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogRespVO; | |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogRespVO; | |
| 8 | 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; |
| 9 | 9 | import cn.iocoder.yudao.module.iot.service.device.data.IotDeviceLogService; |
| 10 | 10 | import io.swagger.v3.oas.annotations.Operation; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDevicePropertyController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.device; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.lang.Assert; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 8 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceDataPageReqVO; | |
| 9 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceDataRespVO; | |
| 10 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotTimeDataRespVO; | |
| 11 | +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.thingmodel.IotThingModelDO; | |
| 14 | +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.thingmodel.IotThingModelService; | |
| 17 | +import io.swagger.v3.oas.annotations.Operation; | |
| 18 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 19 | +import jakarta.annotation.Resource; | |
| 20 | +import jakarta.validation.Valid; | |
| 21 | +import org.springframework.validation.annotation.Validated; | |
| 22 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 23 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 24 | +import org.springframework.web.bind.annotation.RestController; | |
| 25 | + | |
| 26 | +import java.util.List; | |
| 27 | +import java.util.Map; | |
| 28 | + | |
| 29 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 30 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 31 | + | |
| 32 | +@Tag(name = "管理后台 - IoT 设备属性") | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/iot/device/property") | |
| 35 | +@Validated | |
| 36 | +public class IotDevicePropertyController { | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private IotDevicePropertyService devicePropertyService; | |
| 40 | + @Resource | |
| 41 | + private IotThingModelService thingModelService; | |
| 42 | + @Resource | |
| 43 | + private IotDeviceService deviceService; | |
| 44 | + | |
| 45 | + @GetMapping("/latest") | |
| 46 | + @Operation(summary = "获取设备属性最新属性") | |
| 47 | + public CommonResult<List<IotDeviceDataRespVO>> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO pageReqVO) { | |
| 48 | + Map<String, IotDevicePropertyDO> properties = devicePropertyService.getLatestDeviceProperties(pageReqVO); | |
| 49 | + | |
| 50 | + // 拼接数据 | |
| 51 | + IotDeviceDO device = deviceService.getDevice(pageReqVO.getDeviceId()); | |
| 52 | + Assert.notNull(device, "设备不存在"); | |
| 53 | + List<IotThingModelDO> thingModels = thingModelService.getThingModelListByProductId(device.getProductId()); | |
| 54 | + return success(convertList(properties.entrySet(), entry -> { | |
| 55 | + IotThingModelDO thingModel = CollUtil.findOne(thingModels, | |
| 56 | + item -> item.getIdentifier().equals(entry.getKey())); | |
| 57 | + if (thingModel == null || thingModel.getProperty() == null) { | |
| 58 | + return null; | |
| 59 | + } | |
| 60 | + IotDevicePropertyDO property = entry.getValue(); | |
| 61 | + return BeanUtils.toBean(thingModel, IotDeviceDataRespVO.class) | |
| 62 | + .setDataType(thingModel.getProperty().getDataType()) | |
| 63 | + .setValue(property.getValue()).setUpdateTime(property.getUpdateTime()); | |
| 64 | + })); | |
| 65 | + } | |
| 66 | + | |
| 67 | + // TODO @浩浩:这里的 /history-page 包括方法名。 | |
| 68 | + @GetMapping("/history") | |
| 69 | + @Operation(summary = "获取设备属性历史数据") | |
| 70 | + public CommonResult<PageResult<IotTimeDataRespVO>> getHistoryDeviceProperties(@Valid IotDeviceDataPageReqVO pageReqVO) { | |
| 71 | + PageResult<Map<String, Object>> list = devicePropertyService.getHistoryDeviceProperties(pageReqVO); | |
| 72 | + return success(BeanUtils.toBean(list, IotTimeDataRespVO.class)); | |
| 73 | + } | |
| 74 | + | |
| 75 | +} | |
| 0 | 76 | \ 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/deviceData/IotDeviceDataPageReqVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceDataPageReqVO.java
| 1 | -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData; | |
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | -import jakarta.validation.constraints.Size; | |
| 5 | +import jakarta.validation.constraints.NotNull; | |
| 6 | 6 | import lombok.Data; |
| 7 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | - | |
| 9 | -import java.time.LocalDateTime; | |
| 10 | - | |
| 11 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 12 | 7 | |
| 13 | 8 | @Schema(description = "管理后台 - IoT 设备数据 Request VO") |
| 14 | 9 | @Data |
| 15 | 10 | public class IotDeviceDataPageReqVO extends PageParam { |
| 16 | 11 | |
| 17 | 12 | @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") |
| 13 | + @NotNull(message = "设备编号不能为空") | |
| 18 | 14 | private Long deviceId; |
| 19 | 15 | |
| 20 | 16 | @Schema(description = "属性标识符", requiredMode = Schema.RequiredMode.REQUIRED) |
| ... | ... | @@ -23,9 +19,4 @@ public class IotDeviceDataPageReqVO extends PageParam { |
| 23 | 19 | @Schema(description = "属性名称", requiredMode = Schema.RequiredMode.REQUIRED) |
| 24 | 20 | private String name; |
| 25 | 21 | |
| 26 | - @Schema(description = "时间范围", requiredMode = Schema.RequiredMode.NOT_REQUIRED) | |
| 27 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 28 | - @Size(min = 2, max = 2, message = "请选择时间范围") | |
| 29 | - private LocalDateTime[] times; | |
| 30 | - | |
| 31 | 22 | } |
| 32 | 23 | \ 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/deviceData/IotDeviceDataRespVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceDataRespVO.java
| 1 | -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData; | |
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; | |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | |
| 6 | 6 | import java.time.LocalDateTime; |
| 7 | 7 | |
| 8 | -@Schema(description = "管理后台 - IoT 设备数据 Response VO") | |
| 8 | +@Schema(description = "管理后台 - IoT 设备属性 Response VO") | |
| 9 | 9 | @Data |
| 10 | 10 | public class IotDeviceDataRespVO { |
| 11 | 11 | |
| 12 | - @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") | |
| 13 | - private Long deviceId; | |
| 12 | + @Schema(description = "属性标识符", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 13 | + private String identifier; | |
| 14 | 14 | |
| 15 | - @Schema(description = "物模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816") | |
| 16 | - private Long thingModelId; | |
| 15 | + @Schema(description = "最新值", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 16 | + private Object value; | |
| 17 | 17 | |
| 18 | - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 19 | - private String productKey; | |
| 18 | + @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 19 | + private LocalDateTime updateTime; | |
| 20 | 20 | |
| 21 | - @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") | |
| 22 | - private String deviceName; | |
| 21 | + // ========== 基于 ThingModel 查询 ========== | |
| 23 | 22 | |
| 24 | - @Schema(description = "属性标识符", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 25 | - private String identifier; | |
| 23 | +// @Schema(description = "物模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816") | |
| 24 | +// private Long thingModelId; | |
| 26 | 25 | |
| 27 | 26 | @Schema(description = "属性名称", requiredMode = Schema.RequiredMode.REQUIRED) |
| 28 | 27 | private String name; |
| ... | ... | @@ -30,10 +29,4 @@ public class IotDeviceDataRespVO { |
| 30 | 29 | @Schema(description = "数据类型", requiredMode = Schema.RequiredMode.REQUIRED) |
| 31 | 30 | private String dataType; |
| 32 | 31 | |
| 33 | - @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 34 | - private LocalDateTime updateTime; | |
| 35 | - | |
| 36 | - @Schema(description = "最新值", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 37 | - private String value; | |
| 38 | - | |
| 39 | 32 | } |
| 40 | 33 | \ 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/deviceData/IotDeviceLogPageReqVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceLogPageReqVO.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceLogRespVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceLogRespVO.java
| 1 | -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData; | |
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; | |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| ... | ... | @@ -22,7 +22,7 @@ public class IotDeviceLogRespVO { |
| 22 | 22 | private String type; |
| 23 | 23 | |
| 24 | 24 | @Schema(description = "标识符", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature") |
| 25 | - private String subType; | |
| 25 | + private String identifier; | |
| 26 | 26 | |
| 27 | 27 | @Schema(description = "日志内容", requiredMode = Schema.RequiredMode.REQUIRED) |
| 28 | 28 | private String content; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotTimeDataRespVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotTimeDataRespVO.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/device/DevicePropertyRedisDAO.java
| ... | ... | @@ -28,8 +28,9 @@ public class DevicePropertyRedisDAO { |
| 28 | 28 | if (CollUtil.isEmpty(entries)) { |
| 29 | 29 | return Collections.emptyMap(); |
| 30 | 30 | } |
| 31 | - return convertMap(entries.values(), key -> (String) key, | |
| 32 | - value -> JsonUtils.parseObject((String) value, IotDevicePropertyDO.class)); | |
| 31 | + return convertMap(entries.entrySet(), | |
| 32 | + entry -> (String) entry.getKey(), | |
| 33 | + entry -> JsonUtils.parseObject((String) entry.getValue(), IotDevicePropertyDO.class)); | |
| 33 | 34 | } |
| 34 | 35 | |
| 35 | 36 | public void set(String deviceKey, Map<String, IotDevicePropertyDO> properties) { | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.dal.tdengine; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO; | |
| 3 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; | |
| 4 | 4 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; |
| 5 | 5 | import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS; |
| 6 | 6 | import com.baomidou.mybatisplus.annotation.InterceptorIgnore; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java
| ... | ... | @@ -60,6 +60,14 @@ public interface IotDeviceService { |
| 60 | 60 | void deleteDeviceList(Collection<Long> ids); |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | + * 校验设备是否存在 | |
| 64 | + * | |
| 65 | + * @param id 设备 ID | |
| 66 | + * @return 设备对象 | |
| 67 | + */ | |
| 68 | + IotDeviceDO validateDeviceExists(Long id); | |
| 69 | + | |
| 70 | + /** | |
| 63 | 71 | * 获得设备 |
| 64 | 72 | * |
| 65 | 73 | * @param id 编号 |
| ... | ... | @@ -67,7 +75,6 @@ public interface IotDeviceService { |
| 67 | 75 | */ |
| 68 | 76 | IotDeviceDO getDevice(Long id); |
| 69 | 77 | |
| 70 | - | |
| 71 | 78 | /** |
| 72 | 79 | * 根据设备 key 获得设备 |
| 73 | 80 | * | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java
| ... | ... | @@ -187,13 +187,8 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 187 | 187 | deleteDeviceCache(devices); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - /** | |
| 191 | - * 校验设备是否存在 | |
| 192 | - * | |
| 193 | - * @param id 设备 ID | |
| 194 | - * @return 设备对象 | |
| 195 | - */ | |
| 196 | - private IotDeviceDO validateDeviceExists(Long id) { | |
| 190 | + @Override | |
| 191 | + public IotDeviceDO validateDeviceExists(Long id) { | |
| 197 | 192 | IotDeviceDO device = deviceMapper.selectById(id); |
| 198 | 193 | if (device == null) { |
| 199 | 194 | throw exception(DEVICE_NOT_EXISTS); | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogService.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.service.device.data; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO; | |
| 4 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; | |
| 5 | 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; |
| 6 | 6 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; |
| 7 | 7 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java
| ... | ... | @@ -5,7 +5,7 @@ import cn.hutool.core.util.StrUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; | |
| 9 | 9 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; |
| 10 | 10 | import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogMapper; |
| 11 | 11 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyService.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.service.device.data; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO; | |
| 4 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceDataPageReqVO; | |
| 5 | 5 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; |
| 6 | 6 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; |
| 7 | 7 | import jakarta.validation.Valid; |
| 8 | 8 | |
| 9 | -import java.util.List; | |
| 10 | 9 | import java.util.Map; |
| 11 | 10 | |
| 12 | 11 | /** |
| ... | ... | @@ -36,7 +35,7 @@ public interface IotDevicePropertyService { |
| 36 | 35 | * @param deviceId 设备编号 |
| 37 | 36 | * @return 设备属性最新数据 |
| 38 | 37 | */ |
| 39 | - List<IotDevicePropertyDO> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO deviceId); | |
| 38 | + Map<String, IotDevicePropertyDO> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO deviceId); | |
| 40 | 39 | |
| 41 | 40 | /** |
| 42 | 41 | * 获得设备属性历史数据 | ... | ... |
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 | 6 | import cn.hutool.core.util.StrUtil; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | 8 | import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; |
| 9 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO; | |
| 9 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceDataPageReqVO; | |
| 10 | 10 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs; |
| 11 | 11 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 12 | 12 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; |
| ... | ... | @@ -151,41 +151,12 @@ public class IotDevicePropertyServiceImpl implements IotDevicePropertyService { |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | @Override |
| 154 | - public List<IotDevicePropertyDO> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO deviceDataReqVO) { | |
| 155 | -// List<IotDevicePropertyDO> list = new ArrayList<>(); | |
| 156 | -// // 1. 获取设备信息 | |
| 157 | -// IotDeviceDO device = deviceService.getDevice(deviceDataReqVO.getDeviceId()); | |
| 158 | -// // 2. 获取设备属性最新数据 | |
| 159 | -// List<IotThingModelDO> thingModelList = thingModelService.getProductThingModelListByProductKey(device.getProductKey()); | |
| 160 | -// thingModelList = filterList(thingModelList, thingModel -> IotThingModelTypeEnum.PROPERTY.getType() | |
| 161 | -// .equals(thingModel.getType())); | |
| 162 | -// | |
| 163 | -// // 3. 过滤标识符和属性名称 | |
| 164 | -// if (deviceDataReqVO.getIdentifier() != null) { | |
| 165 | -// thingModelList = filterList(thingModelList, thingModel -> thingModel.getIdentifier() | |
| 166 | -// .toLowerCase().contains(deviceDataReqVO.getIdentifier().toLowerCase())); | |
| 167 | -// } | |
| 168 | -// if (deviceDataReqVO.getName() != null) { | |
| 169 | -// thingModelList = filterList(thingModelList, thingModel -> thingModel.getName() | |
| 170 | -// .toLowerCase().contains(deviceDataReqVO.getName().toLowerCase())); | |
| 171 | -// } | |
| 172 | -// // 4. 获取设备属性最新数据 | |
| 173 | -// thingModelList.forEach(thingModel -> { | |
| 174 | -// IotDevicePropertyDO deviceData = deviceDataRedisDAO.get(device.getProductKey(), device.getDeviceName(), thingModel.getIdentifier()); | |
| 175 | -// if (deviceData == null) { | |
| 176 | -// deviceData = new IotDevicePropertyDO(); | |
| 177 | -// deviceData.setProductKey(device.getProductKey()); | |
| 178 | -// deviceData.setDeviceName(device.getDeviceName()); | |
| 179 | -// deviceData.setIdentifier(thingModel.getIdentifier()); | |
| 180 | -// deviceData.setDeviceId(deviceDataReqVO.getDeviceId()); | |
| 181 | -// deviceData.setThingModelId(thingModel.getId()); | |
| 182 | -// deviceData.setName(thingModel.getName()); | |
| 183 | -// deviceData.setDataType(thingModel.getProperty().getDataType()); | |
| 184 | -// } | |
| 185 | -// list.add(deviceData); | |
| 186 | -// }); | |
| 187 | -// return list; | |
| 188 | - return null; // TODO 芋艿:晚点实现 | |
| 154 | + public Map<String, IotDevicePropertyDO> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO pageReqVO) { | |
| 155 | + // 获取设备信息 | |
| 156 | + IotDeviceDO device = deviceService.validateDeviceExists(pageReqVO.getDeviceId()); | |
| 157 | + | |
| 158 | + // 获得设备属性 | |
| 159 | + return deviceDataRedisDAO.get(device.getDeviceKey()); | |
| 189 | 160 | } |
| 190 | 161 | |
| 191 | 162 | @Override | ... | ... |