feat: 新功能开发,监测历史记录。微信和物联网平台,模块搭建。
This commit is contained in:
@@ -29,9 +29,13 @@ public interface IDeviceSensorDataService {
|
||||
public void batchInsertDeviceSensorData(List<DeviceSensorData> dataList);
|
||||
|
||||
/**
|
||||
* 查询数据
|
||||
* 查询历史数据列表
|
||||
*
|
||||
* @return 影响行数
|
||||
* @param serialNum 设备序列号
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param intervalType 间隔类型:1-原始数据,2-10分钟,3-30分钟,4-1小时,5-3小时,6-6小时
|
||||
* @return 设备传感器数据列表
|
||||
*/
|
||||
public List<DeviceSensorData> getHistoryDataList(String serialNum, Long deviceId, String mobilePhone, int deviceType, String startTime, String endTime);
|
||||
public List<DeviceSensorData> getHistoryDataList(String serialNum, String startTime, String endTime, Integer intervalType);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
package com.intc.tdengine.service.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.intc.tdengine.domain.DeviceSensorData;
|
||||
import com.intc.tdengine.mapper.DeviceSensorDataMapper;
|
||||
import com.intc.tdengine.service.IDeviceSensorDataService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@DS("taos") // 指定使用 taos 数据源(TDengine)
|
||||
public class DeviceSensorDataService implements IDeviceSensorDataService {
|
||||
@Resource
|
||||
private DeviceSensorDataMapper deviceSensorDataMapper;
|
||||
@@ -37,18 +42,69 @@ public class DeviceSensorDataService implements IDeviceSensorDataService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据
|
||||
* 查询历史数据列表
|
||||
*
|
||||
* @return 影响行数
|
||||
* @param serialNum 设备序列号
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param intervalType 间隔类型:1-原始数据,2-10分钟,3-30分钟,4-1小时,5-3小时,6-6小时
|
||||
* @return 设备传感器数据列表
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceSensorData> getHistoryDataList(String serialNum,Long deviceId, String mobilePhone, int deviceType,String startTime, String endTime) {
|
||||
List<DeviceSensorData> list=new ArrayList<>();
|
||||
public List<DeviceSensorData> getHistoryDataList(String serialNum, String startTime, String endTime, Integer intervalType) {
|
||||
List<DeviceSensorData> list = new ArrayList<>();
|
||||
try {
|
||||
list=deviceSensorDataMapper.getHistoryDataList(serialNum,deviceId,mobilePhone,deviceType,startTime,endTime);
|
||||
}catch (Exception e){
|
||||
|
||||
// 默认为原始数据
|
||||
if (intervalType == null) {
|
||||
intervalType = 1;
|
||||
}
|
||||
|
||||
// 验证intervalType参数
|
||||
if (intervalType < 1 || intervalType > 6) {
|
||||
log.error("无效的intervalType参数: {}, 使用默认值1", intervalType);
|
||||
intervalType = 1;
|
||||
}
|
||||
|
||||
// 处理时间格式
|
||||
if (startTime != null && !startTime.contains(" ")) {
|
||||
startTime = startTime + " 00:00:00";
|
||||
}
|
||||
if (endTime != null && !endTime.contains(" ")) {
|
||||
endTime = endTime + " 23:59:59";
|
||||
}
|
||||
|
||||
String intervalDesc = getIntervalDesc(intervalType);
|
||||
log.info("查询TDengine历史数据: serialNum={}, startTime={}, endTime={}, intervalType={} ({})",
|
||||
serialNum, startTime, endTime, intervalType, intervalDesc);
|
||||
|
||||
list = deviceSensorDataMapper.getHistoryDataList(serialNum, startTime, endTime, intervalType);
|
||||
|
||||
log.info("查询到 {} 条历史数据 ({})", list.size(), intervalDesc);
|
||||
} catch (Exception e) {
|
||||
log.error("查询TDengine历史数据失败", e);
|
||||
// 打印完整异常链
|
||||
Throwable cause = e;
|
||||
int level = 0;
|
||||
while (cause != null && level < 10) {
|
||||
log.error("异常层级 {}: {}", level++, cause.getClass().getName() + ": " + cause.getMessage());
|
||||
cause = cause.getCause();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取间隔类型描述
|
||||
*/
|
||||
private String getIntervalDesc(Integer intervalType) {
|
||||
switch (intervalType) {
|
||||
case 1: return "原始数据";
|
||||
case 2: return "10分钟间隔";
|
||||
case 3: return "30分钟间隔";
|
||||
case 4: return "1小时间隔";
|
||||
case 5: return "3小时间隔";
|
||||
case 6: return "6小时间隔";
|
||||
default: return "未知";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user