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 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 5 | 5 | import cn.hutool.core.lang.Assert; |
| 6 | -import cn.hutool.core.util.StrUtil; | |
| 7 | 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 | 8 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; |
| 11 | 9 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 12 | 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 | 14 | import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; |
| 17 | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 18 | 16 | import io.swagger.v3.oas.annotations.Parameter; |
| 19 | -import io.swagger.v3.oas.annotations.Parameters; | |
| 20 | 17 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 21 | 18 | import jakarta.annotation.Resource; |
| 22 | 19 | import jakarta.validation.Valid; |
| ... | ... | @@ -46,18 +43,12 @@ public class IotDevicePropertyController { |
| 46 | 43 | @Resource |
| 47 | 44 | private IotDeviceService deviceService; |
| 48 | 45 | |
| 49 | - @GetMapping("/latest") | |
| 46 | + @GetMapping("/get-latest") | |
| 50 | 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 | 49 | @PreAuthorize("@ss.hasPermission('iot:device:property-query')") |
| 57 | 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 | 52 | Map<String, IotDevicePropertyDO> properties = devicePropertyService.getLatestDeviceProperties(deviceId); |
| 62 | 53 | |
| 63 | 54 | // 拼接数据 |
| ... | ... | @@ -70,12 +61,6 @@ public class IotDevicePropertyController { |
| 70 | 61 | if (thingModel == null || thingModel.getProperty() == null) { |
| 71 | 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 | 65 | IotDevicePropertyDO property = entry.getValue(); |
| 81 | 66 | return new IotDevicePropertyRespVO().setProperty(thingModel.getProperty()) |
| ... | ... | @@ -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 | 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 | 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 | 1 | package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 4 | import jakarta.validation.constraints.NotEmpty; |
| 6 | 5 | import jakarta.validation.constraints.NotNull; |
| ... | ... | @@ -12,9 +11,9 @@ import java.time.LocalDateTime; |
| 12 | 11 | |
| 13 | 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 | 15 | @Data |
| 17 | -public class IotDevicePropertyHistoryPageReqVO extends PageParam { | |
| 16 | +public class IotDevicePropertyHistoryListReqVO { | |
| 18 | 17 | |
| 19 | 18 | @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") |
| 20 | 19 | @NotNull(message = "设备编号不能为空") |
| ... | ... | @@ -29,4 +28,4 @@ public class IotDevicePropertyHistoryPageReqVO extends PageParam { |
| 29 | 28 | @Size(min = 2, max = 2, message = "请选择时间范围") |
| 30 | 29 | private LocalDateTime[] times; |
| 31 | 30 | |
| 32 | -} | |
| 33 | 31 | \ No newline at end of file |
| 32 | +} | |
| 34 | 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 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | 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 | 7 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; |
| 8 | 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 9 | 9 | import cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField; |
| ... | ... | @@ -84,7 +84,6 @@ public interface IotDevicePropertyMapper { |
| 84 | 84 | @Param("properties") Map<String, Object> properties, |
| 85 | 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 | 1 | package cn.iocoder.yudao.module.iot.service.device.property; |
| 2 | 2 | |
| 3 | 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 | 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; |
| 6 | 6 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 7 | 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 | 9 | import jakarta.validation.Valid; |
| 10 | 10 | |
| 11 | 11 | import java.time.LocalDateTime; |
| 12 | +import java.util.List; | |
| 12 | 13 | import java.util.Map; |
| 13 | 14 | import java.util.Set; |
| 14 | 15 | |
| ... | ... | @@ -47,10 +48,10 @@ public interface IotDevicePropertyService { |
| 47 | 48 | /** |
| 48 | 49 | * 获得设备属性历史数据 |
| 49 | 50 | * |
| 50 | - * @param pageReqVO 分页请求 | |
| 51 | + * @param listReqVO 列表请求 | |
| 51 | 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 | 4 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 5 | 5 | import cn.hutool.core.map.MapUtil; |
| 6 | 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 | 8 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; |
| 10 | 9 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs; |
| 11 | 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 | 21 | import cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField; |
| 23 | 22 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; |
| 24 | 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 | 24 | import jakarta.annotation.Resource; |
| 28 | 25 | import lombok.extern.slf4j.Slf4j; |
| 29 | 26 | import org.springframework.scheduling.annotation.Async; |
| ... | ... | @@ -157,14 +154,12 @@ public class IotDevicePropertyServiceImpl implements IotDevicePropertyService { |
| 157 | 154 | } |
| 158 | 155 | |
| 159 | 156 | @Override |
| 160 | - public PageResult<IotDevicePropertyRespVO> getHistoryDevicePropertyPage(IotDevicePropertyHistoryPageReqVO pageReqVO) { | |
| 157 | + public List<IotDevicePropertyRespVO> getHistoryDevicePropertyList(IotDevicePropertyHistoryListReqVO listReqVO) { | |
| 161 | 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 | 160 | } catch (Exception exception) { |
| 166 | 161 | if (exception.getMessage().contains("Table does not exist")) { |
| 167 | - return PageResult.empty(); | |
| 162 | + return Collections.emptyList(); | |
| 168 | 163 | } |
| 169 | 164 | throw exception; |
| 170 | 165 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml
| ... | ... | @@ -66,15 +66,14 @@ |
| 66 | 66 | DESCRIBE product_property_${productId} |
| 67 | 67 | </select> |
| 68 | 68 | |
| 69 | - <!-- TODO @芋艿:这里查询有点问题 --> | |
| 70 | - <select id="selectPageByHistory" | |
| 69 | + <select id="selectListByHistory" | |
| 71 | 70 | resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO"> |
| 72 | 71 | SELECT ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} AS `value`, ts AS update_time |
| 73 | 72 | FROM device_property_${reqVO.deviceId} |
| 74 | 73 | WHERE ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} IS NOT NULL |
| 75 | 74 | AND ts BETWEEN ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[0])} |
| 76 | 75 | AND ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[1])} |
| 77 | - ORDER BY ts DESC | |
| 76 | + ORDER BY ts ASC | |
| 78 | 77 | </select> |
| 79 | 78 | |
| 80 | 79 | </mapper> |
| 81 | 80 | \ No newline at end of file | ... | ... |