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