Commit e476dcb298082dabf0fc17eb75889797bddc91d5
1 parent
86658946
feat:【IoT 物联网】设备属性返回,从分页变成列表
Showing
6 changed files
with
24 additions
and
47 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDevicePropertyController.java
| @@ -3,10 +3,8 @@ package cn.iocoder.yudao.module.iot.controller.admin.device; | @@ -3,10 +3,8 @@ 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; | ||
| 7 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 8 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 9 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO; | 7 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryListReqVO; |
| 10 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; | 8 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; |
| 11 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | 9 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 12 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; | 10 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; |
| @@ -16,7 +14,6 @@ import cn.iocoder.yudao.module.iot.service.device.property.IotDevicePropertyServ | @@ -16,7 +14,6 @@ import cn.iocoder.yudao.module.iot.service.device.property.IotDevicePropertyServ | ||
| 16 | import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; | 14 | import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; |
| 17 | import io.swagger.v3.oas.annotations.Operation; | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 18 | import io.swagger.v3.oas.annotations.Parameter; | 16 | import io.swagger.v3.oas.annotations.Parameter; |
| 19 | -import io.swagger.v3.oas.annotations.Parameters; | ||
| 20 | import io.swagger.v3.oas.annotations.tags.Tag; | 17 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 21 | import jakarta.annotation.Resource; | 18 | import jakarta.annotation.Resource; |
| 22 | import jakarta.validation.Valid; | 19 | import jakarta.validation.Valid; |
| @@ -46,18 +43,12 @@ public class IotDevicePropertyController { | @@ -46,18 +43,12 @@ public class IotDevicePropertyController { | ||
| 46 | @Resource | 43 | @Resource |
| 47 | private IotDeviceService deviceService; | 44 | private IotDeviceService deviceService; |
| 48 | 45 | ||
| 49 | - @GetMapping("/latest") | 46 | + @GetMapping("/get-latest") |
| 50 | @Operation(summary = "获取设备属性最新属性") | 47 | @Operation(summary = "获取设备属性最新属性") |
| 51 | - @Parameters({ | ||
| 52 | - @Parameter(name = "deviceId", description = "设备编号", required = true), | ||
| 53 | - @Parameter(name = "identifier", description = "标识符"), | ||
| 54 | - @Parameter(name = "name", description = "名称") | ||
| 55 | - }) | 48 | + @Parameter(name = "deviceId", description = "设备编号", required = true) |
| 56 | @PreAuthorize("@ss.hasPermission('iot:device:property-query')") | 49 | @PreAuthorize("@ss.hasPermission('iot:device:property-query')") |
| 57 | public CommonResult<List<IotDevicePropertyRespVO>> getLatestDeviceProperties( | 50 | public CommonResult<List<IotDevicePropertyRespVO>> getLatestDeviceProperties( |
| 58 | - @RequestParam("deviceId") Long deviceId, | ||
| 59 | - @RequestParam(value = "identifier", required = false) String identifier, | ||
| 60 | - @RequestParam(value = "name", required = false) String name) { | 51 | + @RequestParam("deviceId") Long deviceId) { |
| 61 | Map<String, IotDevicePropertyDO> properties = devicePropertyService.getLatestDeviceProperties(deviceId); | 52 | Map<String, IotDevicePropertyDO> properties = devicePropertyService.getLatestDeviceProperties(deviceId); |
| 62 | 53 | ||
| 63 | // 拼接数据 | 54 | // 拼接数据 |
| @@ -70,12 +61,6 @@ public class IotDevicePropertyController { | @@ -70,12 +61,6 @@ public class IotDevicePropertyController { | ||
| 70 | if (thingModel == null || thingModel.getProperty() == null) { | 61 | if (thingModel == null || thingModel.getProperty() == null) { |
| 71 | return null; | 62 | return null; |
| 72 | } | 63 | } |
| 73 | - if (StrUtil.isNotEmpty(identifier) && !StrUtil.contains(thingModel.getIdentifier(), identifier)) { | ||
| 74 | - return null; | ||
| 75 | - } | ||
| 76 | - if (StrUtil.isNotEmpty(name) && !StrUtil.contains(thingModel.getName(), name)) { | ||
| 77 | - return null; | ||
| 78 | - } | ||
| 79 | // 构建对象 | 64 | // 构建对象 |
| 80 | IotDevicePropertyDO property = entry.getValue(); | 65 | IotDevicePropertyDO property = entry.getValue(); |
| 81 | return new IotDevicePropertyRespVO().setProperty(thingModel.getProperty()) | 66 | return new IotDevicePropertyRespVO().setProperty(thingModel.getProperty()) |
| @@ -83,13 +68,12 @@ public class IotDevicePropertyController { | @@ -83,13 +68,12 @@ public class IotDevicePropertyController { | ||
| 83 | })); | 68 | })); |
| 84 | } | 69 | } |
| 85 | 70 | ||
| 86 | - @GetMapping("/history-page") | ||
| 87 | - @Operation(summary = "获取设备属性历史数据") | 71 | + @GetMapping("/history-list") |
| 72 | + @Operation(summary = "获取设备属性历史数据列表") | ||
| 88 | @PreAuthorize("@ss.hasPermission('iot:device:property-query')") | 73 | @PreAuthorize("@ss.hasPermission('iot:device:property-query')") |
| 89 | - public CommonResult<PageResult<IotDevicePropertyRespVO>> getHistoryDevicePropertyPage( | ||
| 90 | - @Valid IotDevicePropertyHistoryPageReqVO pageReqVO) { | ||
| 91 | - Assert.notEmpty(pageReqVO.getIdentifier(), "标识符不能为空"); | ||
| 92 | - return success(devicePropertyService.getHistoryDevicePropertyPage(pageReqVO)); | 74 | + public CommonResult<List<IotDevicePropertyRespVO>> getHistoryDevicePropertyList( |
| 75 | + @Valid IotDevicePropertyHistoryListReqVO listReqVO) { | ||
| 76 | + return success(devicePropertyService.getHistoryDevicePropertyList(listReqVO)); | ||
| 93 | } | 77 | } |
| 94 | 78 | ||
| 95 | } | 79 | } |
| 96 | \ No newline at end of file | 80 | \ 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/IotDevicePropertyHistoryPageReqVO.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyHistoryListReqVO.java
| 1 | package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; | 1 | package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | import jakarta.validation.constraints.NotEmpty; | 4 | import jakarta.validation.constraints.NotEmpty; |
| 6 | import jakarta.validation.constraints.NotNull; | 5 | import jakarta.validation.constraints.NotNull; |
| @@ -12,9 +11,9 @@ import java.time.LocalDateTime; | @@ -12,9 +11,9 @@ import java.time.LocalDateTime; | ||
| 12 | 11 | ||
| 13 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | 12 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 14 | 13 | ||
| 15 | -@Schema(description = "管理后台 - IoT 设备属性历史分页 Request VO") | 14 | +@Schema(description = "管理后台 - IoT 设备属性历史列表 Request VO") |
| 16 | @Data | 15 | @Data |
| 17 | -public class IotDevicePropertyHistoryPageReqVO extends PageParam { | 16 | +public class IotDevicePropertyHistoryListReqVO { |
| 18 | 17 | ||
| 19 | @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") | 18 | @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") |
| 20 | @NotNull(message = "设备编号不能为空") | 19 | @NotNull(message = "设备编号不能为空") |
| @@ -29,4 +28,4 @@ public class IotDevicePropertyHistoryPageReqVO extends PageParam { | @@ -29,4 +28,4 @@ public class IotDevicePropertyHistoryPageReqVO extends PageParam { | ||
| 29 | @Size(min = 2, max = 2, message = "请选择时间范围") | 28 | @Size(min = 2, max = 2, message = "请选择时间范围") |
| 30 | private LocalDateTime[] times; | 29 | private LocalDateTime[] times; |
| 31 | 30 | ||
| 32 | -} | ||
| 33 | \ No newline at end of file | 31 | \ No newline at end of file |
| 32 | +} | ||
| 34 | \ No newline at end of file | 33 | \ No newline at end of file |
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.IotDevicePropertyHistoryPageReqVO; | 6 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryListReqVO; |
| 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; |
| @@ -84,7 +84,6 @@ public interface IotDevicePropertyMapper { | @@ -84,7 +84,6 @@ public interface IotDevicePropertyMapper { | ||
| 84 | @Param("properties") Map<String, Object> properties, | 84 | @Param("properties") Map<String, Object> properties, |
| 85 | @Param("reportTime") Long reportTime); | 85 | @Param("reportTime") Long reportTime); |
| 86 | 86 | ||
| 87 | - IPage<IotDevicePropertyRespVO> selectPageByHistory(IPage<?> page, | ||
| 88 | - @Param("reqVO") IotDevicePropertyHistoryPageReqVO reqVO); | 87 | + List<IotDevicePropertyRespVO> selectListByHistory(@Param("reqVO") IotDevicePropertyHistoryListReqVO reqVO); |
| 89 | 88 | ||
| 90 | } | 89 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDevicePropertyService.java
| 1 | package cn.iocoder.yudao.module.iot.service.device.property; | 1 | package cn.iocoder.yudao.module.iot.service.device.property; |
| 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.IotDevicePropertyHistoryPageReqVO; | 4 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryListReqVO; |
| 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.core.mq.message.IotDeviceMessage; | 6 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; | @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; | ||
| 9 | import jakarta.validation.Valid; | 9 | import jakarta.validation.Valid; |
| 10 | 10 | ||
| 11 | import java.time.LocalDateTime; | 11 | import java.time.LocalDateTime; |
| 12 | +import java.util.List; | ||
| 12 | import java.util.Map; | 13 | import java.util.Map; |
| 13 | import java.util.Set; | 14 | import java.util.Set; |
| 14 | 15 | ||
| @@ -47,10 +48,10 @@ public interface IotDevicePropertyService { | @@ -47,10 +48,10 @@ public interface IotDevicePropertyService { | ||
| 47 | /** | 48 | /** |
| 48 | * 获得设备属性历史数据 | 49 | * 获得设备属性历史数据 |
| 49 | * | 50 | * |
| 50 | - * @param pageReqVO 分页请求 | 51 | + * @param listReqVO 列表请求 |
| 51 | * @return 设备属性历史数据 | 52 | * @return 设备属性历史数据 |
| 52 | */ | 53 | */ |
| 53 | - PageResult<IotDevicePropertyRespVO> getHistoryDevicePropertyPage(@Valid IotDevicePropertyHistoryPageReqVO pageReqVO); | 54 | + List<IotDevicePropertyRespVO> getHistoryDevicePropertyList(@Valid IotDevicePropertyHistoryListReqVO listReqVO); |
| 54 | 55 | ||
| 55 | // ========== 设备时间相关操作 ========== | 56 | // ========== 设备时间相关操作 ========== |
| 56 | 57 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDevicePropertyServiceImpl.java
| @@ -4,8 +4,7 @@ import cn.hutool.core.collection.CollUtil; | @@ -4,8 +4,7 @@ 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.map.MapUtil; | 5 | 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; | ||
| 8 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO; | 7 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryListReqVO; |
| 9 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; | 8 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; |
| 10 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs; | 9 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs; |
| 11 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 10 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| @@ -22,8 +21,6 @@ import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum; | @@ -22,8 +21,6 @@ import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum; | ||
| 22 | import cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField; | 21 | import cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField; |
| 23 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; | 22 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; |
| 24 | import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; | 23 | import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; |
| 25 | -import com.baomidou.mybatisplus.core.metadata.IPage; | ||
| 26 | -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
| 27 | import jakarta.annotation.Resource; | 24 | import jakarta.annotation.Resource; |
| 28 | import lombok.extern.slf4j.Slf4j; | 25 | import lombok.extern.slf4j.Slf4j; |
| 29 | import org.springframework.scheduling.annotation.Async; | 26 | import org.springframework.scheduling.annotation.Async; |
| @@ -157,14 +154,12 @@ public class IotDevicePropertyServiceImpl implements IotDevicePropertyService { | @@ -157,14 +154,12 @@ public class IotDevicePropertyServiceImpl implements IotDevicePropertyService { | ||
| 157 | } | 154 | } |
| 158 | 155 | ||
| 159 | @Override | 156 | @Override |
| 160 | - public PageResult<IotDevicePropertyRespVO> getHistoryDevicePropertyPage(IotDevicePropertyHistoryPageReqVO pageReqVO) { | 157 | + public List<IotDevicePropertyRespVO> getHistoryDevicePropertyList(IotDevicePropertyHistoryListReqVO listReqVO) { |
| 161 | try { | 158 | try { |
| 162 | - IPage<IotDevicePropertyRespVO> page = devicePropertyMapper.selectPageByHistory( | ||
| 163 | - new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO); | ||
| 164 | - return new PageResult<>(page.getRecords(), page.getTotal()); | 159 | + return devicePropertyMapper.selectListByHistory(listReqVO); |
| 165 | } catch (Exception exception) { | 160 | } catch (Exception exception) { |
| 166 | if (exception.getMessage().contains("Table does not exist")) { | 161 | if (exception.getMessage().contains("Table does not exist")) { |
| 167 | - return PageResult.empty(); | 162 | + return Collections.emptyList(); |
| 168 | } | 163 | } |
| 169 | throw exception; | 164 | throw exception; |
| 170 | } | 165 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml
| @@ -66,15 +66,14 @@ | @@ -66,15 +66,14 @@ | ||
| 66 | DESCRIBE product_property_${productId} | 66 | DESCRIBE product_property_${productId} |
| 67 | </select> | 67 | </select> |
| 68 | 68 | ||
| 69 | - <!-- TODO @芋艿:这里查询有点问题 --> | ||
| 70 | - <select id="selectPageByHistory" | 69 | + <select id="selectListByHistory" |
| 71 | resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO"> | 70 | resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO"> |
| 72 | SELECT ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} AS `value`, ts AS update_time | 71 | SELECT ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} AS `value`, ts AS update_time |
| 73 | FROM device_property_${reqVO.deviceId} | 72 | FROM device_property_${reqVO.deviceId} |
| 74 | WHERE ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} IS NOT NULL | 73 | WHERE ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} IS NOT NULL |
| 75 | AND ts BETWEEN ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[0])} | 74 | AND ts BETWEEN ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[0])} |
| 76 | AND ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[1])} | 75 | AND ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[1])} |
| 77 | - ORDER BY ts DESC | 76 | + ORDER BY ts ASC |
| 78 | </select> | 77 | </select> |
| 79 | 78 | ||
| 80 | </mapper> | 79 | </mapper> |
| 81 | \ No newline at end of file | 80 | \ No newline at end of file |