异常数据功能重写
This commit is contained in:
@@ -52,6 +52,8 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -266,9 +268,6 @@ public class PqDataVerifyBakServiceImpl extends ServiceImpl<PqDataVerifyBakMappe
|
||||
}
|
||||
List<PqDataVerifyBak> dataVerifyList = this.list(lambdaQueryWrapper);
|
||||
|
||||
|
||||
|
||||
|
||||
for (PqDataVerifyBak pqDataVerifyBak : dataVerifyList) {
|
||||
Set<String> set = new HashSet<>();
|
||||
try (InputStream fileStream = fileStorageUtil.getFileStream(pqDataVerifyBak.getPath())) {
|
||||
@@ -278,45 +277,42 @@ public class PqDataVerifyBakServiceImpl extends ServiceImpl<PqDataVerifyBakMappe
|
||||
if (StrUtil.isNotBlank(monitorBaseParam.getTargetKey())) {
|
||||
if (targetJson.containsKey(monitorBaseParam.getTargetKey())) {
|
||||
JSONArray innerJson = targetJson.getJSONArray(monitorBaseParam.getTargetKey());
|
||||
JSONObject jsonObjectTem = (JSONObject) innerJson.get(0);
|
||||
for(Object oJson : innerJson){
|
||||
JSONObject jsonObjectTem = (JSONObject) oJson;
|
||||
JSONArray list = jsonObjectTem.getJSONArray("list");
|
||||
list.forEach(listItem -> {
|
||||
JSONObject object = (JSONObject) listItem;
|
||||
JSONArray timeArr = object.getJSONArray("time");
|
||||
timeArr.forEach(timeJson -> set.add((String) timeJson));
|
||||
});
|
||||
DetailAbnormalVO detailAbnormalVO = new DetailAbnormalVO();
|
||||
LineDevGetDTO lineDevGetDTO = lineDetailMap.get(pqDataVerifyBak.getLineId());
|
||||
detailAbnormalVO.setTimeSum((long) lineDevGetDTO.getTimeInterval() * set.size());
|
||||
detailAbnormalVO.setDate(pqDataVerifyBak.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN)));
|
||||
detailAbnormalVO.setMonitorName(lineDevGetDTO.getPointName());
|
||||
detailAbnormalVO.setMonitorId(lineDevGetDTO.getPointId());
|
||||
detailAbnormalVO.setTargetKey(monitorBaseParam.getTargetKey());
|
||||
result.add(detailAbnormalVO);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rangeMap.forEach((rangeKey, val) -> {
|
||||
if (targetJson.containsKey(rangeKey)) {
|
||||
JSONArray innerJson = targetJson.getJSONArray(rangeKey);
|
||||
JSONObject jsonObjectTem = (JSONObject) innerJson.get(0);
|
||||
for(Object oJson : innerJson){
|
||||
JSONObject jsonObjectTem = (JSONObject) oJson;
|
||||
JSONArray list = jsonObjectTem.getJSONArray("list");
|
||||
list.forEach(listItem -> {
|
||||
JSONObject object = (JSONObject) listItem;
|
||||
JSONArray timeArr = object.getJSONArray("time");
|
||||
timeArr.forEach(timeJson -> set.add((String) timeJson));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
DetailAbnormalVO detailAbnormalVO = new DetailAbnormalVO();
|
||||
LineDevGetDTO lineDevGetDTO = lineDetailMap.get(pqDataVerifyBak.getLineId());
|
||||
detailAbnormalVO.setTimeSum((long) lineDevGetDTO.getTimeInterval() * set.size());
|
||||
detailAbnormalVO.setDate(pqDataVerifyBak.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN)));
|
||||
detailAbnormalVO.setMonitorName(lineDevGetDTO.getPointName());
|
||||
detailAbnormalVO.setMonitorId(lineDevGetDTO.getPointId());
|
||||
detailAbnormalVO.setTargetKey(rangeKey);
|
||||
detailAbnormalVO.setTargetKey("");
|
||||
result.add(detailAbnormalVO);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("数据异常");
|
||||
}
|
||||
@@ -362,17 +358,42 @@ public class PqDataVerifyBakServiceImpl extends ServiceImpl<PqDataVerifyBakMappe
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("数据异常");
|
||||
}
|
||||
// 排序实现
|
||||
result = result.stream()
|
||||
.sorted(Comparator.comparing(DetailAbnormalVO.DetailAbnormalInnerVO::getTime)
|
||||
.thenComparing(vo -> extractHarmonicOrder(vo.getTargetName()))
|
||||
.thenComparing(DetailAbnormalVO.DetailAbnormalInnerVO::getTargetName))
|
||||
.collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static final Pattern HARMONIC_PATTERN = Pattern.compile("(\\d+)次谐波");
|
||||
|
||||
// 提取谐波次数的方法
|
||||
private static int extractHarmonicOrder(String targetName) {
|
||||
if (StrUtil.isBlank(targetName)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Matcher matcher = HARMONIC_PATTERN.matcher(targetName);
|
||||
if (matcher.find()) {
|
||||
try {
|
||||
return Integer.parseInt(matcher.group(1));
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("无法从targetName中提取谐波次数: {}", targetName);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void resultDeal(Map<String, PqReasonableRangeDto> dtoMap, String targetKey, JSONObject targetJson, List<DetailAbnormalVO.DetailAbnormalInnerVO> result) {
|
||||
PqReasonableRangeDto pqReasonableRangeDto = dtoMap.get(targetKey);
|
||||
JSONArray innerJson = targetJson.getJSONArray(targetKey);
|
||||
JSONObject jsonObjectTem = (JSONObject) innerJson.get(0);
|
||||
innerJson.forEach(oo-> {
|
||||
JSONObject jsonObjectTem = (JSONObject) oo;
|
||||
String targetName = jsonObjectTem.get("targetName").toString();
|
||||
JSONArray list = jsonObjectTem.getJSONArray("list");
|
||||
|
||||
List<DetailAbnormalVO.DetailLimitInnerVO> temList = new ArrayList<>();
|
||||
list.forEach(listItem -> {
|
||||
JSONObject object = (JSONObject) listItem;
|
||||
@@ -391,7 +412,6 @@ public class PqDataVerifyBakServiceImpl extends ServiceImpl<PqDataVerifyBakMappe
|
||||
temList.add(temData);
|
||||
}
|
||||
});
|
||||
|
||||
Map<String, List<DetailAbnormalVO.DetailLimitInnerVO>> listMap = temList.stream().collect(Collectors.groupingBy(DetailAbnormalVO.DetailLimitInnerVO::getTime, TreeMap::new, Collectors.toList()));
|
||||
listMap.forEach((time, timeList) -> {
|
||||
Map<String, List<DetailAbnormalVO.DetailLimitInnerVO>> indexMap = timeList.stream().collect(Collectors.groupingBy(DetailAbnormalVO.DetailLimitInnerVO::getTargetKey));
|
||||
@@ -431,7 +451,7 @@ public class PqDataVerifyBakServiceImpl extends ServiceImpl<PqDataVerifyBakMappe
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user