[功能添加]:物模型日志表查询与创建 模拟设备基础逻辑
This commit is contained in:
parent
0249ca9929
commit
6aad4545a8
|
@ -4,11 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataRespVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.*;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotTimeDataRespVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO;
|
||||
import cn.iocoder.yudao.module.iot.service.device.IotDeviceLogDataService;
|
||||
import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
@ -36,6 +34,9 @@ public class IotDeviceDataController {
|
|||
@Resource
|
||||
private IotDeviceLogDataService iotDeviceLogDataService;
|
||||
|
||||
@Resource
|
||||
private IotDeviceLogDataService deviceLogDataService;
|
||||
|
||||
// TODO @浩浩:这里的 /latest-list,包括方法名。
|
||||
@GetMapping("/latest")
|
||||
@Operation(summary = "获取设备属性最新数据")
|
||||
|
@ -51,7 +52,7 @@ public class IotDeviceDataController {
|
|||
PageResult<Map<String, Object>> list = deviceDataService.getHistoryDeviceProperties(deviceDataReqVO);
|
||||
return success(BeanUtils.toBean(list, IotTimeDataRespVO.class));
|
||||
}
|
||||
|
||||
// TODO:数据权限
|
||||
@PostMapping("/simulator")
|
||||
@Operation(summary = "模拟设备")
|
||||
public CommonResult<Boolean> simulatorDevice(@Valid @RequestBody IotDeviceDataSimulatorSaveReqVO simulatorReqVO) {
|
||||
|
@ -59,5 +60,12 @@ public class IotDeviceDataController {
|
|||
iotDeviceLogDataService.createDeviceLog(simulatorReqVO);
|
||||
return success(true);
|
||||
}
|
||||
// TODO:数据权限
|
||||
@GetMapping("/log/page")
|
||||
@Operation(summary = "获得设备日志分页")
|
||||
public CommonResult<PageResult<IotDeviceLogRespVO>> getDeviceLogPage(@Valid IotDeviceLogPageReqVO pageReqVO) {
|
||||
PageResult<IotDeviceLogDO> pageResult = deviceLogDataService.getDeviceLogPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, IotDeviceLogRespVO.class));
|
||||
}
|
||||
|
||||
}
|
|
@ -3,9 +3,12 @@ package cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData;
|
|||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - IoT 模拟设备数据 Request VO")
|
||||
@Data
|
||||
public class IotDeviceDataSimulatorSaveReqVO {
|
||||
|
@ -34,6 +37,6 @@ public class IotDeviceDataSimulatorSaveReqVO {
|
|||
private String content;
|
||||
|
||||
@Schema(description = "上报时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime reportTime;
|
||||
private Long reportTime;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - IoT 设备日志分页查询 Request VO")
|
||||
@Data
|
||||
public class IotDeviceLogPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "device123")
|
||||
@NotEmpty(message = "设备标识不能为空")
|
||||
private String deviceKey;
|
||||
|
||||
@Schema(description = "消息类型", example = "property")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "标识符", example = "temperature")
|
||||
private String subType;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData;
|
||||
|
||||
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 subType;
|
||||
|
||||
@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;
|
||||
}
|
|
@ -1,11 +1,15 @@
|
|||
package cn.iocoder.yudao.module.iot.dal.tdengine;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO;
|
||||
import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS;
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* IOT 设备日志数据 Mapper 接口
|
||||
*
|
||||
|
@ -23,8 +27,12 @@ public interface IotDeviceLogDataMapper {
|
|||
*/
|
||||
void createDeviceLogSTable();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建设备日志子表
|
||||
*
|
||||
* @param deviceKey 设备标识
|
||||
*/
|
||||
void createDeviceLogTable(@Param("deviceKey") String deviceKey);
|
||||
|
||||
/**
|
||||
* 插入设备日志数据
|
||||
|
@ -34,4 +42,20 @@ public interface IotDeviceLogDataMapper {
|
|||
* @param log 设备日志数据
|
||||
*/
|
||||
void insert(@Param("log") IotDeviceLogDO log);
|
||||
|
||||
/**
|
||||
* 获得设备日志分页
|
||||
*
|
||||
* @param reqVO 分页查询条件
|
||||
* @return 设备日志列表
|
||||
*/
|
||||
List<IotDeviceLogDO> selectPage(@Param("reqVO") IotDeviceLogPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得设备日志总数
|
||||
*
|
||||
* @param reqVO 查询条件
|
||||
* @return 日志总数
|
||||
*/
|
||||
Long selectCount(@Param("reqVO") IotDeviceLogPageReqVO reqVO);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package cn.iocoder.yudao.module.iot.service.device;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO;
|
||||
|
||||
|
||||
/**
|
||||
* IoT 设备日志数据 Service 接口
|
||||
|
@ -25,4 +29,12 @@ public interface IotDeviceLogDataService {
|
|||
*/
|
||||
void createDeviceLog(IotDeviceDataSimulatorSaveReqVO simulatorReqVO);
|
||||
|
||||
/**
|
||||
* 获得设备日志分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 设备日志分页
|
||||
*/
|
||||
PageResult<IotDeviceLogDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package cn.iocoder.yudao.module.iot.service.device;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogDataMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -12,6 +14,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* IoT 设备日志数据 Service 实现了
|
||||
|
@ -49,19 +52,17 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{
|
|||
long currentTime = System.currentTimeMillis();
|
||||
// 2.1 设置时序时间为当前时间
|
||||
iotDeviceLogDO.setTs(currentTime);
|
||||
|
||||
// 2.2 处理上报时间
|
||||
if (simulatorReqVO.getReportTime() != null) {
|
||||
// 将 LocalDateTime 转换为时间戳
|
||||
iotDeviceLogDO.setReportTime(
|
||||
simulatorReqVO.getReportTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
|
||||
);
|
||||
} else {
|
||||
// 如果没有上报时间,使用当前时间
|
||||
iotDeviceLogDO.setReportTime(currentTime);
|
||||
}
|
||||
|
||||
|
||||
// 3. 插入数据
|
||||
iotDeviceLogDataMapper.insert(iotDeviceLogDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<IotDeviceLogDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO) {
|
||||
// 查询数据
|
||||
List<IotDeviceLogDO> list = iotDeviceLogDataMapper.selectPage(pageReqVO);
|
||||
Long total = iotDeviceLogDataMapper.selectCount(pageReqVO);
|
||||
// 构造分页结果
|
||||
return new PageResult<>(list, total);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,4 +41,38 @@
|
|||
)
|
||||
</insert>
|
||||
|
||||
<select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
|
||||
SELECT ts, id, device_key, product_key, type, subType, content, report_time
|
||||
FROM device_log_${reqVO.deviceKey}
|
||||
<where>
|
||||
<if test="reqVO.type != null and reqVO.type != ''">
|
||||
AND type = #{reqVO.type}
|
||||
</if>
|
||||
<if test="reqVO.subType != null and reqVO.subType != ''">
|
||||
AND subType = #{reqVO.subType}
|
||||
</if>
|
||||
<if test="reqVO.createTime != null">
|
||||
AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY ts DESC
|
||||
LIMIT #{reqVO.pageSize} OFFSET #{reqVO.pageNo}
|
||||
</select>
|
||||
|
||||
<select id="selectCount" resultType="Long">
|
||||
SELECT COUNT(*)
|
||||
FROM device_log_${reqVO.deviceKey}
|
||||
<where>
|
||||
<if test="reqVO.type != null and reqVO.type != ''">
|
||||
AND type = #{reqVO.type}
|
||||
</if>
|
||||
<if test="reqVO.subType != null and reqVO.subType != ''">
|
||||
AND subType = #{reqVO.subType}
|
||||
</if>
|
||||
<if test="reqVO.createTime != null">
|
||||
AND ts BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue