1、app消息数据查询重构
2、app消息已读未读方法重构 3、其余辅助功能添加
This commit is contained in:
@@ -36,8 +36,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -237,10 +239,15 @@ public class DataTaskServiceImpl implements IDataTaskService {
|
||||
alarmIds = data2.stream().map(CsEventPO::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<String> filteredData1 = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(data1)) {
|
||||
filteredData1 = filterTimeIntervals(data1, 6);
|
||||
}
|
||||
//只要有一个不为空,就需要统计
|
||||
if (CollUtil.isNotEmpty(data1) || CollUtil.isNotEmpty(alarmIds)) {
|
||||
if (CollUtil.isNotEmpty(filteredData1) || CollUtil.isNotEmpty(alarmIds)) {
|
||||
// 对中断时间数据进行过滤,只保留间隔超过 6 小时的时间段
|
||||
l0.add(item);
|
||||
l1.add(data1 != null ? Collections.singletonList(String.join(",", data1)) : null);
|
||||
l1.add(filteredData1 != null && !filteredData1.isEmpty() ? Collections.singletonList(String.join(",", filteredData1)) : null);
|
||||
l2.add(alarmIds);
|
||||
}
|
||||
});
|
||||
@@ -283,6 +290,64 @@ public class DataTaskServiceImpl implements IDataTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤时间间隔,只保留超过指定小时数的时间段
|
||||
*
|
||||
* @param timePeriods 时间段列表,格式如 ["2026-03-18 08:26:24 ~ 2026-03-18 08:27:45", "2026-03-18 08:29:46 ~ 2026-03-18 08:31:07"]
|
||||
* @param hours 最小间隔小时数
|
||||
* @return 过滤后的时间段列表
|
||||
*/
|
||||
private List<String> filterTimeIntervals(List<String> timePeriods, int hours) {
|
||||
if (CollUtil.isEmpty(timePeriods)) {
|
||||
return timePeriods;
|
||||
}
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
// 将所有时间段展开为独立的字符串
|
||||
for (String periodStr : timePeriods) {
|
||||
if (periodStr == null || periodStr.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 分割多个时间段(中文逗号分隔)
|
||||
String[] periods = periodStr.split(",");
|
||||
|
||||
for (String period : periods) {
|
||||
period = period.trim();
|
||||
if (period.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 解析时间段,格式:"2026-03-18 08:26:24 ~ 2026-03-18 08:27:45"
|
||||
String[] parts = period.split("~");
|
||||
if (parts.length != 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
String startTimeStr = parts[0].trim();
|
||||
String endTimeStr = parts[1].trim();
|
||||
|
||||
LocalDateTime startTime = LocalDateTime.parse(startTimeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
LocalDateTime endTime = LocalDateTime.parse(endTimeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
// 计算时间间隔(小时)
|
||||
long hoursBetween = ChronoUnit.HOURS.between(startTime, endTime);
|
||||
|
||||
// 如果间隔超过指定的小时数,则添加到结果中
|
||||
if (hoursBetween >= hours) {
|
||||
result.add(period);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("解析时间段失败:{}", period, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//获取设备最新的一条数据
|
||||
public List<PqsCommunicate> getRawDataLatest(String devId) {
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(PqsCommunicate.class);
|
||||
|
||||
Reference in New Issue
Block a user