Commit d346a8d2ae2a8eb366ac15a765c68ad2bcb289d2
1 parent
72245b5b
feat:【IoT 物联网】完善设备消息的查询
Showing
13 changed files
with
136 additions
and
126 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceLogController.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceMessageController.java
| @@ -3,10 +3,10 @@ package cn.iocoder.yudao.module.iot.controller.admin.device; | @@ -3,10 +3,10 @@ package cn.iocoder.yudao.module.iot.controller.admin.device; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 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; | 6 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessageRespVO; |
| 7 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessagePageReqVO; | ||
| 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; | 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; |
| 9 | -import cn.iocoder.yudao.module.iot.service.device.property.IotDeviceLogService; | 9 | +import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService; |
| 10 | import io.swagger.v3.oas.annotations.Operation; | 10 | 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; |
| @@ -19,21 +19,21 @@ import org.springframework.web.bind.annotation.RestController; | @@ -19,21 +19,21 @@ import org.springframework.web.bind.annotation.RestController; | ||
| 19 | 19 | ||
| 20 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 20 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 21 | 21 | ||
| 22 | -@Tag(name = "管理后台 - IoT 设备日志") | 22 | +@Tag(name = "管理后台 - IoT 设备消息") |
| 23 | @RestController | 23 | @RestController |
| 24 | -@RequestMapping("/iot/device/log") | 24 | +@RequestMapping("/iot/device/message") |
| 25 | @Validated | 25 | @Validated |
| 26 | -public class IotDeviceLogController { | 26 | +public class IotDeviceMessageController { |
| 27 | 27 | ||
| 28 | @Resource | 28 | @Resource |
| 29 | - private IotDeviceLogService deviceLogService; | 29 | + private IotDeviceMessageService deviceMessageService; |
| 30 | 30 | ||
| 31 | @GetMapping("/page") | 31 | @GetMapping("/page") |
| 32 | - @Operation(summary = "获得设备日志分页") | ||
| 33 | - @PreAuthorize("@ss.hasPermission('iot:device:log-query')") | ||
| 34 | - public CommonResult<PageResult<IotDeviceLogRespVO>> getDeviceLogPage(@Valid IotDeviceLogPageReqVO pageReqVO) { | ||
| 35 | - PageResult<IotDeviceMessageDO> pageResult = deviceLogService.getDeviceLogPage(pageReqVO); | ||
| 36 | - return success(BeanUtils.toBean(pageResult, IotDeviceLogRespVO.class)); | 32 | + @Operation(summary = "获得设备消息分页") |
| 33 | + @PreAuthorize("@ss.hasPermission('iot:device:message-query')") | ||
| 34 | + public CommonResult<PageResult<IotDeviceMessageRespVO>> getDeviceLogPage(@Valid IotDeviceMessagePageReqVO pageReqVO) { | ||
| 35 | + PageResult<IotDeviceMessageDO> pageResult = deviceMessageService.getDeviceMessagePage(pageReqVO); | ||
| 36 | + return success(BeanUtils.toBean(pageResult, IotDeviceMessageRespVO.class)); | ||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | } | 39 | } |
| 40 | \ No newline at end of file | 40 | \ 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/IotDeviceLogPageReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | -import jakarta.validation.constraints.NotEmpty; | ||
| 6 | -import lombok.Data; | ||
| 7 | - | ||
| 8 | -@Schema(description = "管理后台 - IoT 设备日志分页查询 Request VO") | ||
| 9 | -@Data | ||
| 10 | -public class IotDeviceLogPageReqVO extends PageParam { | ||
| 11 | - | ||
| 12 | - // TODO @芋艿:【优先级:中】改成通过 deviceId 查询;然后转换下; | ||
| 13 | - @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "device123") | ||
| 14 | - @NotEmpty(message = "设备标识不能为空") | ||
| 15 | - private String deviceKey; | ||
| 16 | - | ||
| 17 | - @Schema(description = "消息类型", example = "property") | ||
| 18 | - private String type; // 参见 IotDeviceMessageTypeEnum 枚举,精准匹配 | ||
| 19 | - | ||
| 20 | - @Schema(description = "标识符", example = "temperature") | ||
| 21 | - private String identifier; // 参见 IotDeviceMessageIdentifierEnum 枚举,模糊匹配 | ||
| 22 | - | ||
| 23 | -} | ||
| 24 | \ No newline at end of file | 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/vo/data/IotDeviceLogRespVO.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | - | ||
| 6 | -import java.time.LocalDateTime; | ||
| 7 | - | ||
| 8 | -@Schema(description = "管理后台 - IoT 设备日志 Response VO") | ||
| 9 | -@Data | ||
| 10 | -public class IotDeviceLogRespVO { | ||
| 11 | - | ||
| 12 | - @Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 13 | - private String id; | ||
| 14 | - | ||
| 15 | - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "product123") | ||
| 16 | - private String productKey; | ||
| 17 | - | ||
| 18 | - @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "device123") | ||
| 19 | - private String deviceKey; | ||
| 20 | - | ||
| 21 | - @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "property") | ||
| 22 | - private String type; | ||
| 23 | - | ||
| 24 | - @Schema(description = "标识符", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature") | ||
| 25 | - private String identifier; | ||
| 26 | - | ||
| 27 | - @Schema(description = "日志内容", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 28 | - private String content; | ||
| 29 | - | ||
| 30 | - @Schema(description = "上报时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 31 | - private LocalDateTime reportTime; | ||
| 32 | - | ||
| 33 | - @Schema(description = "记录时间戳", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 34 | - private LocalDateTime ts; | ||
| 35 | - | ||
| 36 | -} | ||
| 37 | \ No newline at end of file | 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/vo/message/IotDeviceMessagePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.message; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 5 | +import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; | ||
| 6 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 7 | +import jakarta.validation.constraints.NotNull; | ||
| 8 | +import lombok.Data; | ||
| 9 | + | ||
| 10 | +@Schema(description = "管理后台 - IoT 设备消息分页查询 Request VO") | ||
| 11 | +@Data | ||
| 12 | +public class IotDeviceMessagePageReqVO extends PageParam { | ||
| 13 | + | ||
| 14 | + @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 15 | + @NotNull(message = "设备编号不能为空") | ||
| 16 | + private Long deviceId; | ||
| 17 | + | ||
| 18 | + @Schema(description = "消息类型", example = "property") | ||
| 19 | + @InEnum(IotDeviceMessageMethodEnum.class) | ||
| 20 | + private String method; | ||
| 21 | + | ||
| 22 | + @Schema(description = "是否上行", example = "true") | ||
| 23 | + private Boolean upstream; | ||
| 24 | + | ||
| 25 | +} | ||
| 0 | \ No newline at end of file | 26 | \ 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/message/IotDeviceMessageRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.message; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +import java.time.LocalDateTime; | ||
| 7 | + | ||
| 8 | +@Schema(description = "管理后台 - IoT 设备消息 Response VO") | ||
| 9 | +@Data | ||
| 10 | +public class IotDeviceMessageRespVO { | ||
| 11 | + | ||
| 12 | + @Schema(description = "消息编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 13 | + private String id; | ||
| 14 | + | ||
| 15 | + @Schema(description = "上报时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 16 | + private LocalDateTime reportTime; | ||
| 17 | + | ||
| 18 | + @Schema(description = "记录时间戳", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 19 | + private LocalDateTime ts; | ||
| 20 | + | ||
| 21 | + @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123") | ||
| 22 | + private Long deviceId; | ||
| 23 | + | ||
| 24 | + @Schema(description = "服务编号", example = "server_123") | ||
| 25 | + private String serverId; | ||
| 26 | + | ||
| 27 | + @Schema(description = "是否上行消息", example = "true", examples = "false") | ||
| 28 | + private Boolean upstream; | ||
| 29 | + | ||
| 30 | + @Schema(description = "是否回复消息", example = "false", examples = "true") | ||
| 31 | + private Boolean reply; | ||
| 32 | + | ||
| 33 | + // ========== codec(编解码)字段 ========== | ||
| 34 | + | ||
| 35 | + @Schema(description = "请求编号", example = "req_123") | ||
| 36 | + private String requestId; | ||
| 37 | + | ||
| 38 | + @Schema(description = "请求方法", requiredMode = Schema.RequiredMode.REQUIRED, example = "thing.property.report") | ||
| 39 | + private String method; | ||
| 40 | + | ||
| 41 | + @Schema(description = "请求参数") | ||
| 42 | + private Object params; | ||
| 43 | + | ||
| 44 | + @Schema(description = "响应结果") | ||
| 45 | + private Object data; | ||
| 46 | + | ||
| 47 | + @Schema(description = "响应错误码", example = "200") | ||
| 48 | + private Integer code; | ||
| 49 | + | ||
| 50 | + @Schema(description = "响应提示", example = "操作成功") | ||
| 51 | + private String msg; | ||
| 52 | + | ||
| 53 | +} | ||
| 0 | \ No newline at end of file | 54 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceMessageDO.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceMessageMapper.java
| 1 | package cn.iocoder.yudao.module.iot.dal.tdengine; | 1 | package cn.iocoder.yudao.module.iot.dal.tdengine; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; | 3 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessagePageReqVO; |
| 4 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; | 4 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; |
| 5 | import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS; | 5 | import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS; |
| 6 | import com.baomidou.mybatisplus.annotation.InterceptorIgnore; | 6 | import com.baomidou.mybatisplus.annotation.InterceptorIgnore; |
| @@ -47,7 +47,7 @@ public interface IotDeviceMessageMapper { | @@ -47,7 +47,7 @@ public interface IotDeviceMessageMapper { | ||
| 47 | * @return 设备消息列表 | 47 | * @return 设备消息列表 |
| 48 | */ | 48 | */ |
| 49 | IPage<IotDeviceMessageDO> selectPage(IPage<IotDeviceMessageDO> page, | 49 | IPage<IotDeviceMessageDO> selectPage(IPage<IotDeviceMessageDO> page, |
| 50 | - @Param("reqVO") IotDeviceLogPageReqVO reqVO); | 50 | + @Param("reqVO") IotDeviceMessagePageReqVO reqVO); |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
| 53 | * 统计设备消息数量 | 53 | * 统计设备消息数量 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/message/IotDeviceMessageService.java
| 1 | package cn.iocoder.yudao.module.iot.service.device.message; | 1 | package cn.iocoder.yudao.module.iot.service.device.message; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessagePageReqVO; | ||
| 3 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 5 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| 4 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; | ||
| 5 | 8 | ||
| 6 | /** | 9 | /** |
| 7 | * IoT 设备消息 Service 接口 | 10 | * IoT 设备消息 Service 接口 |
| @@ -46,4 +49,12 @@ public interface IotDeviceMessageService { | @@ -46,4 +49,12 @@ public interface IotDeviceMessageService { | ||
| 46 | */ | 49 | */ |
| 47 | void handleUpstreamDeviceMessage(IotDeviceMessage message, IotDeviceDO device); | 50 | void handleUpstreamDeviceMessage(IotDeviceMessage message, IotDeviceDO device); |
| 48 | 51 | ||
| 52 | + /** | ||
| 53 | + * 获得设备消息分页 | ||
| 54 | + * | ||
| 55 | + * @param pageReqVO 分页查询 | ||
| 56 | + * @return 设备消息分页 | ||
| 57 | + */ | ||
| 58 | + PageResult<IotDeviceMessageDO> getDeviceMessagePage(IotDeviceMessagePageReqVO pageReqVO); | ||
| 59 | + | ||
| 49 | } | 60 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/message/IotDeviceMessageServiceImpl.java
| @@ -3,8 +3,10 @@ package cn.iocoder.yudao.module.iot.service.device.message; | @@ -3,8 +3,10 @@ package cn.iocoder.yudao.module.iot.service.device.message; | ||
| 3 | import cn.hutool.core.util.StrUtil; | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | import cn.hutool.extra.spring.SpringUtil; | 4 | import cn.hutool.extra.spring.SpringUtil; |
| 5 | import cn.iocoder.yudao.framework.common.exception.ServiceException; | 5 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 7 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessagePageReqVO; | ||
| 8 | import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; | 10 | import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; |
| 9 | import cn.iocoder.yudao.module.iot.core.enums.IotDeviceStateEnum; | 11 | import cn.iocoder.yudao.module.iot.core.enums.IotDeviceStateEnum; |
| 10 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; | 12 | import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; |
| @@ -15,6 +17,8 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; | @@ -15,6 +17,8 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; | ||
| 15 | import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceMessageMapper; | 17 | import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceMessageMapper; |
| 16 | import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; | 18 | import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; |
| 17 | import cn.iocoder.yudao.module.iot.service.device.property.IotDevicePropertyService; | 19 | import cn.iocoder.yudao.module.iot.service.device.property.IotDevicePropertyService; |
| 20 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
| 21 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
| 18 | import com.google.common.base.Objects; | 22 | import com.google.common.base.Objects; |
| 19 | import jakarta.annotation.Resource; | 23 | import jakarta.annotation.Resource; |
| 20 | import lombok.extern.slf4j.Slf4j; | 24 | import lombok.extern.slf4j.Slf4j; |
| @@ -62,9 +66,10 @@ public class IotDeviceMessageServiceImpl implements IotDeviceMessageService { | @@ -62,9 +66,10 @@ public class IotDeviceMessageServiceImpl implements IotDeviceMessageService { | ||
| 62 | @Async | 66 | @Async |
| 63 | void createDeviceLogAsync(IotDeviceMessage message) { | 67 | void createDeviceLogAsync(IotDeviceMessage message) { |
| 64 | IotDeviceMessageDO messageDO = BeanUtils.toBean(message, IotDeviceMessageDO.class) | 68 | IotDeviceMessageDO messageDO = BeanUtils.toBean(message, IotDeviceMessageDO.class) |
| 65 | - .setUpstream(IotDeviceMessageUtils.isUpstreamMessage(message)); | 69 | + .setUpstream(IotDeviceMessageUtils.isUpstreamMessage(message)) |
| 70 | + .setReply(IotDeviceMessageUtils.isReplyMessage(message)); | ||
| 66 | if (message.getParams() != null) { | 71 | if (message.getParams() != null) { |
| 67 | - messageDO.setParams(JsonUtils.toJsonString(messageDO.getData())); | 72 | + messageDO.setParams(JsonUtils.toJsonString(messageDO.getParams())); |
| 68 | } | 73 | } |
| 69 | if (messageDO.getData() != null) { | 74 | if (messageDO.getData() != null) { |
| 70 | messageDO.setData(JsonUtils.toJsonString(messageDO.getData())); | 75 | messageDO.setData(JsonUtils.toJsonString(messageDO.getData())); |
| @@ -184,6 +189,20 @@ public class IotDeviceMessageServiceImpl implements IotDeviceMessageService { | @@ -184,6 +189,20 @@ public class IotDeviceMessageServiceImpl implements IotDeviceMessageService { | ||
| 184 | return null; | 189 | return null; |
| 185 | } | 190 | } |
| 186 | 191 | ||
| 192 | + @Override | ||
| 193 | + public PageResult<IotDeviceMessageDO> getDeviceMessagePage(IotDeviceMessagePageReqVO pageReqVO) { | ||
| 194 | + try { | ||
| 195 | + IPage<IotDeviceMessageDO> page = deviceLogMapper.selectPage( | ||
| 196 | + new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO); | ||
| 197 | + return new PageResult<>(page.getRecords(), page.getTotal()); | ||
| 198 | + } catch (Exception exception) { | ||
| 199 | + if (exception.getMessage().contains("Table does not exist")) { | ||
| 200 | + return PageResult.empty(); | ||
| 201 | + } | ||
| 202 | + throw exception; | ||
| 203 | + } | ||
| 204 | + } | ||
| 205 | + | ||
| 187 | private IotDeviceMessageServiceImpl getSelf() { | 206 | private IotDeviceMessageServiceImpl getSelf() { |
| 188 | return SpringUtil.getBean(getClass()); | 207 | return SpringUtil.getBean(getClass()); |
| 189 | } | 208 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDeviceLogService.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; | ||
| 4 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; | ||
| 5 | -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; | ||
| 6 | - | ||
| 7 | import javax.annotation.Nullable; | 3 | import javax.annotation.Nullable; |
| 8 | import java.time.LocalDateTime; | 4 | import java.time.LocalDateTime; |
| 9 | import java.util.List; | 5 | import java.util.List; |
| 10 | import java.util.Map; | 6 | import java.util.Map; |
| 11 | 7 | ||
| 12 | /** | 8 | /** |
| 13 | - * IoT 设备日志数据 Service 接口 | 9 | + * IoT 设备消息数据 Service 接口 |
| 14 | * | 10 | * |
| 15 | * @author alwayssuper | 11 | * @author alwayssuper |
| 16 | */ | 12 | */ |
| 17 | public interface IotDeviceLogService { | 13 | public interface IotDeviceLogService { |
| 18 | 14 | ||
| 19 | /** | 15 | /** |
| 20 | - * 获得设备日志分页 | ||
| 21 | - * | ||
| 22 | - * @param pageReqVO 分页查询 | ||
| 23 | - * @return 设备日志分页 | ||
| 24 | - */ | ||
| 25 | - PageResult<IotDeviceMessageDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO); | ||
| 26 | - | ||
| 27 | - /** | ||
| 28 | - * 获得设备日志数量 | 16 | + * 获得设备消息数量 |
| 29 | * | 17 | * |
| 30 | - * @param createTime 创建时间,如果为空,则统计所有日志数量 | ||
| 31 | - * @return 日志数量 | 18 | + * @param createTime 创建时间,如果为空,则统计所有消息数量 |
| 19 | + * @return 消息数量 | ||
| 32 | */ | 20 | */ |
| 33 | Long getDeviceLogCount(@Nullable LocalDateTime createTime); | 21 | Long getDeviceLogCount(@Nullable LocalDateTime createTime); |
| 34 | 22 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDeviceLogServiceImpl.java
| @@ -2,13 +2,7 @@ package cn.iocoder.yudao.module.iot.service.device.property; | @@ -2,13 +2,7 @@ package cn.iocoder.yudao.module.iot.service.device.property; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.date.LocalDateTimeUtil; | 3 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 4 | import cn.hutool.core.map.MapUtil; | 4 | import cn.hutool.core.map.MapUtil; |
| 5 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; | ||
| 8 | import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceMessageMapper; | 5 | import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceMessageMapper; |
| 9 | -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; | ||
| 10 | -import com.baomidou.mybatisplus.core.metadata.IPage; | ||
| 11 | -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
| 12 | import jakarta.annotation.Resource; | 6 | import jakarta.annotation.Resource; |
| 13 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
| 14 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
| @@ -31,26 +25,9 @@ import java.util.stream.Collectors; | @@ -31,26 +25,9 @@ import java.util.stream.Collectors; | ||
| 31 | public class IotDeviceLogServiceImpl implements IotDeviceLogService { | 25 | public class IotDeviceLogServiceImpl implements IotDeviceLogService { |
| 32 | 26 | ||
| 33 | @Resource | 27 | @Resource |
| 34 | - private IotDeviceService deviceService; | ||
| 35 | - | ||
| 36 | - @Resource | ||
| 37 | private IotDeviceMessageMapper deviceLogMapper; | 28 | private IotDeviceMessageMapper deviceLogMapper; |
| 38 | 29 | ||
| 39 | @Override | 30 | @Override |
| 40 | - public PageResult<IotDeviceMessageDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO) { | ||
| 41 | - try { | ||
| 42 | - IPage<IotDeviceMessageDO> page = deviceLogMapper.selectPage( | ||
| 43 | - new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO); | ||
| 44 | - return new PageResult<>(page.getRecords(), page.getTotal()); | ||
| 45 | - } catch (Exception exception) { | ||
| 46 | - if (exception.getMessage().contains("Table does not exist")) { | ||
| 47 | - return PageResult.empty(); | ||
| 48 | - } | ||
| 49 | - throw exception; | ||
| 50 | - } | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - @Override | ||
| 54 | public Long getDeviceLogCount(LocalDateTime createTime) { | 31 | public Long getDeviceLogCount(LocalDateTime createTime) { |
| 55 | return deviceLogMapper.selectCountByCreateTime(createTime != null ? LocalDateTimeUtil.toEpochMilli(createTime) : null); | 32 | return deviceLogMapper.selectCountByCreateTime(createTime != null ? LocalDateTimeUtil.toEpochMilli(createTime) : null); |
| 56 | } | 33 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceMessageMapper.xml
| @@ -55,12 +55,6 @@ | @@ -55,12 +55,6 @@ | ||
| 55 | <if test="reqVO.upstream != null"> | 55 | <if test="reqVO.upstream != null"> |
| 56 | AND upstream = #{reqVO.upstream} | 56 | AND upstream = #{reqVO.upstream} |
| 57 | </if> | 57 | </if> |
| 58 | - <if test="reqVO.startTime != null"> | ||
| 59 | - AND ts >= #{reqVO.startTime} | ||
| 60 | - </if> | ||
| 61 | - <if test="reqVO.endTime != null"> | ||
| 62 | - AND ts <= #{reqVO.endTime} | ||
| 63 | - </if> | ||
| 64 | </where> | 58 | </where> |
| 65 | ORDER BY ts DESC | 59 | ORDER BY ts DESC |
| 66 | </select> | 60 | </select> |
yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/enums/IotDeviceMessageMethodEnum.java
| @@ -19,18 +19,18 @@ public enum IotDeviceMessageMethodEnum implements ArrayValuable<String> { | @@ -19,18 +19,18 @@ public enum IotDeviceMessageMethodEnum implements ArrayValuable<String> { | ||
| 19 | 19 | ||
| 20 | // ========== 设备状态 ========== | 20 | // ========== 设备状态 ========== |
| 21 | 21 | ||
| 22 | - STATE_ONLINE("thing.state.online", true), | ||
| 23 | - STATE_OFFLINE("thing.state.offline", true), | 22 | + STATE_ONLINE("thing.state.online", "设备上线", true), |
| 23 | + STATE_OFFLINE("thing.state.offline", "设备下线", true), | ||
| 24 | 24 | ||
| 25 | // ========== 设备属性 ========== | 25 | // ========== 设备属性 ========== |
| 26 | // 可参考:https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services | 26 | // 可参考:https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services |
| 27 | 27 | ||
| 28 | - PROPERTY_POST("thing.property.post", true), | ||
| 29 | - PROPERTY_SET("thing.property.set", false), | 28 | + PROPERTY_POST("thing.property.post", "属性上报", true), |
| 29 | + PROPERTY_SET("thing.property.set", "属性设置", false), | ||
| 30 | 30 | ||
| 31 | // ========== 设备事件 ========== | 31 | // ========== 设备事件 ========== |
| 32 | 32 | ||
| 33 | - EVENT_POST("thing.event.post", true), | 33 | + EVENT_POST("thing.event.post", "事件上报", true), |
| 34 | 34 | ||
| 35 | ; | 35 | ; |
| 36 | 36 | ||
| @@ -44,6 +44,8 @@ public enum IotDeviceMessageMethodEnum implements ArrayValuable<String> { | @@ -44,6 +44,8 @@ public enum IotDeviceMessageMethodEnum implements ArrayValuable<String> { | ||
| 44 | 44 | ||
| 45 | private final String method; | 45 | private final String method; |
| 46 | 46 | ||
| 47 | + private final String name; | ||
| 48 | + | ||
| 47 | private final Boolean upstream; | 49 | private final Boolean upstream; |
| 48 | 50 | ||
| 49 | @Override | 51 | @Override |