修改自定义报表适配分钟/统计数据查询

This commit is contained in:
cdf
2026-05-14 17:05:43 +08:00
parent eff784e94e
commit 23d87aecc8
3 changed files with 423 additions and 173 deletions

View File

@@ -36,6 +36,9 @@ public class ReportSearchParam {
//目前用于区分不同系统资源null默认 1.无线系统配合cs-device
private Integer resourceType;
//区分统计数据还是分钟数据null默认统计数据 0.统计数据 1.分钟数据
private Integer isStatisticData;
//浙江无线报表特殊标识 null为通用报表 1.浙江无线报表
private Integer customType;

View File

@@ -7,7 +7,7 @@ import lombok.Data;
/**
* pqs
*
* 装置数据单位配置类
* @author cdf
* @date 2026/1/17
*/

View File

@@ -27,6 +27,7 @@ import com.njcn.harmonic.pojo.param.ReportSearchParam;
import com.njcn.harmonic.pojo.po.ExcelRptTemp;
import com.njcn.influx.constant.InfluxDbSqlConstant;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.influx.utils.InfluxDbUtils;
import com.njcn.oss.constant.OssPath;
import com.njcn.oss.enums.OssResponseEnum;
import com.njcn.oss.utils.FileStorageUtil;
@@ -44,7 +45,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.stereotype.Service;
import javax.annotation.PreDestroy;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
@@ -72,6 +73,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
private final EpdFeignClient epdFeignClient;
private final FileStorageUtil fileStorageUtil;
private final DicDataFeignClient dicDataFeignClient;
private final InfluxDbUtils influxDbUtils;
private final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
private final String CELL_DATA = "celldata";
@@ -90,7 +92,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
}};
@Override
public void getCustomReport(ReportSearchParam reportSearchParam,Map<String,String> newMap,DeviceUnitCommDTO deviceUnitCommDTO, HttpServletResponse response) {
public void getCustomReport(ReportSearchParam reportSearchParam, Map<String, String> newMap, DeviceUnitCommDTO deviceUnitCommDTO, HttpServletResponse response) {
TimeInterval timeInterval = new TimeInterval();
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(reportSearchParam.getTempId());
if (Objects.isNull(excelRptTemp)) {
@@ -98,7 +100,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
}
if (Objects.isNull(reportSearchParam.getCustomType())) {
//通用报表
analyzeReport(reportSearchParam, excelRptTemp, newMap,deviceUnitCommDTO,response);
analyzeReport(reportSearchParam, excelRptTemp, newMap, deviceUnitCommDTO, response);
log.info("报表执行时间{}秒", timeInterval.intervalSecond());
}
@@ -106,7 +108,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
@Override
public String saveStableEventReport(ReportSearchParam reportSearchParam, Map<String, String> newMap, DeviceUnitCommDTO deviceUnitCommDTO) {
String filePath = "";
String filePath = "";
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(reportSearchParam.getTempId());
if (Objects.isNull(excelRptTemp)) {
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_ACTIVE);
@@ -118,7 +120,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
return filePath;
}
private String analyzeReport2(ReportSearchParam reportSearchParam, ExcelRptTemp excelRptTemp,Map<String,String> newMap,DeviceUnitCommDTO deviceUnitCommDTO) {
private String analyzeReport2(ReportSearchParam reportSearchParam, ExcelRptTemp excelRptTemp, Map<String, String> newMap, DeviceUnitCommDTO deviceUnitCommDTO) {
Map<String, Object> dataMap = new HashMap<>();
//定义一个线程集合
List<Future<?>> futures = new ArrayList<>();
@@ -133,23 +135,23 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
jsonArray = new JSONArray(new JSONTokener(fileStream, new JSONConfig()));
parseTemplate(jsonArray, reportTemplateDTOList, reportLimitList, terminalList);
} catch (Exception e) {
if(e instanceof BusinessException){
if (e instanceof BusinessException) {
throw new BusinessException(e.getMessage());
}else {
} else {
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
}
}
//查询不分相别的指标
DictData dictData = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.EPD.getCode(), DicDataTypeEnum.CS_DATA_TYPE.getCode()).getData();
if(Objects.isNull(dictData)){
throw new BusinessException(CommonResponseEnum.FAIL,"字典类型模板缺少!");
if (Objects.isNull(dictData)) {
throw new BusinessException(CommonResponseEnum.FAIL, "字典类型模板缺少!");
}
DictData epdDic = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.EPD.getCode(),DicDataTypeEnum.CS_DATA_TYPE.getCode()).getData();
List<EleEpdPqd> eleEpdPqdList= epdFeignClient.dictMarkByDataType(epdDic.getId()).getData();
DictData epdDic = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.EPD.getCode(), DicDataTypeEnum.CS_DATA_TYPE.getCode()).getData();
List<EleEpdPqd> eleEpdPqdList = epdFeignClient.dictMarkByDataType(epdDic.getId()).getData();
Map<String, String> tMap = new HashMap<>();
eleEpdPqdList.forEach(item->{
eleEpdPqdList.forEach(item -> {
String phase;
if (Objects.isNull(PHASE_MAPPING.get(item.getPhase()))) {
phase = item.getPhase();
@@ -165,8 +167,8 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
}
});
eleEpdPqdList = eleEpdPqdList.stream().filter(it->"T".equals(it.getPhase())||"M".equals(it.getPhase())).collect(Collectors.toList());
List<String> noPhaseList = eleEpdPqdList.stream().filter(it->StrUtil.isNotBlank(it.getOtherName())).map(it->it.getOtherName().toUpperCase()).collect(Collectors.toList());
eleEpdPqdList = eleEpdPqdList.stream().filter(it -> "T".equals(it.getPhase()) || "M".equals(it.getPhase())).collect(Collectors.toList());
List<String> noPhaseList = eleEpdPqdList.stream().filter(it -> StrUtil.isNotBlank(it.getOtherName())).map(it -> it.getOtherName().toUpperCase()).collect(Collectors.toList());
//处理指标是否合格
reportLimitList = new LinkedHashSet<>(reportLimitList).stream().sorted(Comparator.comparing(ReportTemplateDTO::getItemName)).collect(Collectors.toList());
@@ -194,18 +196,18 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
phaseMap.forEach((phaseKey, phaseVal) -> {
StringBuilder sql = new StringBuilder(InfluxDbSqlConstant.SELECT);
if (InfluxDbSqlConstant.MAX.equalsIgnoreCase(valueTypeKey)) {
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),phaseVal, sql, endList, InfluxDbSqlConstant.MAX, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap,noPhaseList);
assSqlByMysql(tMap, newMap.get("LEVEL"), newMap.get("PT"), newMap.get("CT"), phaseVal, sql, endList, InfluxDbSqlConstant.MAX, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, noPhaseList);
} else if (InfluxDbSqlConstant.MIN.equalsIgnoreCase(valueTypeKey)) {
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),phaseVal, sql, endList, InfluxDbSqlConstant.MIN, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap,noPhaseList);
assSqlByMysql(tMap, newMap.get("LEVEL"), newMap.get("PT"), newMap.get("CT"), phaseVal, sql, endList, InfluxDbSqlConstant.MIN, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, noPhaseList);
} else if (InfluxDbSqlConstant.AVG_WEB.equalsIgnoreCase(valueTypeKey)) {
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),phaseVal, sql, endList, InfluxDbSqlConstant.AVG_WEB, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap,noPhaseList);
assSqlByMysql(tMap, newMap.get("LEVEL"), newMap.get("PT"), newMap.get("CT"), phaseVal, sql, endList, InfluxDbSqlConstant.AVG_WEB, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, noPhaseList);
} else if (InfluxDbSqlConstant.CP95.equalsIgnoreCase(valueTypeKey)) {
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),phaseVal, sql, endList, InfluxDbSqlConstant.CP95, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap,noPhaseList);
assSqlByMysql(tMap, newMap.get("LEVEL"), newMap.get("PT"), newMap.get("CT"), phaseVal, sql, endList, InfluxDbSqlConstant.CP95, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, noPhaseList);
}
});
});
}finally {
} finally {
DynamicDataSourceContextHolder.poll();
}
}));
@@ -217,53 +219,53 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
future.get(); // 这会阻塞直到任务完成或抛出异常
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
log.error("自定义报表多线程查询流程出错!错误信息{}",e.getMessage());
log.error("自定义报表多线程查询流程出错!错误信息{}", e.getMessage());
}
}
//处理指标最终判定合格还是不合格
dealTargetResult(assNoPassMap, limitTargetMapX, endList);
}
resultAssemble2(endList,reportSearchParam,newMap,deviceUnitCommDTO,jsonArray,dataMap);
resultAssemble2(endList, reportSearchParam, newMap, deviceUnitCommDTO, jsonArray, dataMap);
//存储自定义报表
return saveReport(jsonArray,dataMap);
return saveReport(jsonArray, dataMap);
}
public void resultAssemble2(List<ReportTemplateDTO> endList, ReportSearchParam reportSearchParam, Map<String, String> finalTerminalMap, DeviceUnitCommDTO deviceUnitCommDTO, JSONArray jsonArray,Map<String, Object> dataMap) {
public void resultAssemble2(List<ReportTemplateDTO> endList, ReportSearchParam reportSearchParam, Map<String, String> finalTerminalMap, DeviceUnitCommDTO deviceUnitCommDTO, JSONArray jsonArray, Map<String, Object> dataMap) {
if (CollUtil.isNotEmpty(endList)) {
Map<String, String> unit = this.unitMap(deviceUnitCommDTO);
Map<String, List<ReportTemplateDTO>> assMap = (Map)endList.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getItemName));
Map<String, List<ReportTemplateDTO>> assMap = (Map) endList.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getItemName));
jsonArray.forEach((item) -> {
JSONObject jsonObject = (JSONObject)item;
JSONArray itemArr = (JSONArray)jsonObject.get("celldata");
JSONObject jsonObject = (JSONObject) item;
JSONArray itemArr = (JSONArray) jsonObject.get("celldata");
itemArr.forEach((it) -> {
if (Objects.nonNull(it) && !"null".equals(it.toString())) {
JSONObject data = (JSONObject)it;
JSONObject son = (JSONObject)data.get("v");
JSONObject data = (JSONObject) it;
JSONObject son = (JSONObject) data.get("v");
if (son.containsKey("v")) {
String v = son.getStr("v");
String tem;
List rDto;
if (v.charAt(0) == '$' && v.contains("#")) {
tem = "";
rDto = (List)assMap.get(v.replace("$", "").toUpperCase());
rDto = (List) assMap.get(v.replace("$", "").toUpperCase());
if (Objects.nonNull(rDto)) {
tem = ((ReportTemplateDTO)rDto.get(0)).getValue();
tem = ((ReportTemplateDTO) rDto.get(0)).getValue();
if (StringUtils.isBlank(tem)) {
tem = "/";
}
son.set("v", tem);
dataMap.put(v, tem);
if (Objects.nonNull(((ReportTemplateDTO)rDto.get(0)).getOverLimitFlag()) && ((ReportTemplateDTO)rDto.get(0)).getOverLimitFlag() == 1) {
if (Objects.nonNull(((ReportTemplateDTO) rDto.get(0)).getOverLimitFlag()) && ((ReportTemplateDTO) rDto.get(0)).getOverLimitFlag() == 1) {
son.set("fc", "#990000");
}
}
} else if (v.charAt(0) == '%' && v.contains("#")) {
tem = "";
rDto = (List)assMap.get(v.replace("%", "").toUpperCase());
rDto = (List) assMap.get(v.replace("%", "").toUpperCase());
if (Objects.nonNull(rDto)) {
tem = ((ReportTemplateDTO)rDto.get(0)).getValue();
tem = ((ReportTemplateDTO) rDto.get(0)).getValue();
if (StringUtils.isBlank(tem)) {
tem = "/";
}
@@ -292,7 +294,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
}
} else {
son.set("v", finalTerminalMap.getOrDefault(tem, "/"));
dataMap.put(v, finalTerminalMap.getOrDefault(tem, "/"));
dataMap.put(v, finalTerminalMap.getOrDefault(tem, "/"));
}
}
}
@@ -310,9 +312,8 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
}
private String saveReport(JSONArray jsonArray, Map<String, Object> dataMap) {
String filePath = "";
String filePath = "";
Workbook workbook = new XSSFWorkbook();
for (int i = 0; i < jsonArray.size(); i++) {
@@ -412,21 +413,21 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
style.setFont(font);
style.setWrapText(true);
if (Objects.equals(cell.getStringCellValue(),"非谐波统计报表")
|| Objects.equals(cell.getStringCellValue(),"谐波电压统计报表")
|| Objects.equals(cell.getStringCellValue(),"谐波电流统计报表")) {
if (Objects.equals(cell.getStringCellValue(), "非谐波统计报表")
|| Objects.equals(cell.getStringCellValue(), "谐波电压统计报表")
|| Objects.equals(cell.getStringCellValue(), "谐波电流统计报表")) {
font.setFontHeightInPoints((short) 18);
font.setBold(true);
}
if (Objects.equals(cell.getStringCellValue(),"有效值")
|| Objects.equals(cell.getStringCellValue(),"功率")
|| Objects.equals(cell.getStringCellValue(),"电压闪变")
|| Objects.equals(cell.getStringCellValue(),"畸变率")
|| Objects.equals(cell.getStringCellValue(),"电压偏差")
|| Objects.equals(cell.getStringCellValue(),"频率")
|| Objects.equals(cell.getStringCellValue(),"三相不平衡度")
|| Objects.equals(cell.getStringCellValue(),"谐波电压含有率")
|| Objects.equals(cell.getStringCellValue(),"谐波电流幅值")) {
if (Objects.equals(cell.getStringCellValue(), "有效值")
|| Objects.equals(cell.getStringCellValue(), "功率")
|| Objects.equals(cell.getStringCellValue(), "电压闪变")
|| Objects.equals(cell.getStringCellValue(), "畸变率")
|| Objects.equals(cell.getStringCellValue(), "电压偏差")
|| Objects.equals(cell.getStringCellValue(), "频率")
|| Objects.equals(cell.getStringCellValue(), "三相不平衡度")
|| Objects.equals(cell.getStringCellValue(), "谐波电压含有率")
|| Objects.equals(cell.getStringCellValue(), "谐波电流幅值")) {
font.setFontHeightInPoints((short) 15);
font.setBold(true);
}
@@ -558,126 +559,126 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
}
/**
* 处理
*
* @author cdf
* @date 2023/10/8
*/
* 处理
*
* @author cdf
* @date 2023/10/8
*/
private void analyzeReport(ReportSearchParam reportSearchParam, ExcelRptTemp excelRptTemp,Map<String,String> newMap,DeviceUnitCommDTO deviceUnitCommDTO, HttpServletResponse response) {
//定义一个线程集合
List<Future<?>> futures = new ArrayList<>();
//指标
List<ReportTemplateDTO> reportTemplateDTOList = new ArrayList<>();
//限值
List<ReportTemplateDTO> reportLimitList = new ArrayList<>();
//台账
List<ReportTemplateDTO> terminalList = new ArrayList<>();
JSONArray jsonArray;
try (InputStream fileStream = fileStorageUtil.getFileStream(excelRptTemp.getContent())) {
jsonArray = new JSONArray(new JSONTokener(fileStream, new JSONConfig()));
parseTemplate(jsonArray, reportTemplateDTOList, reportLimitList, terminalList);
} catch (Exception e) {
if(e instanceof BusinessException){
throw new BusinessException(e.getMessage());
}else {
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
}
private void analyzeReport(ReportSearchParam reportSearchParam, ExcelRptTemp excelRptTemp, Map<String, String> newMap, DeviceUnitCommDTO deviceUnitCommDTO, HttpServletResponse response) {
//定义一个线程集合
List<Future<?>> futures = new ArrayList<>();
//指标
List<ReportTemplateDTO> reportTemplateDTOList = new ArrayList<>();
//限值
List<ReportTemplateDTO> reportLimitList = new ArrayList<>();
//台账
List<ReportTemplateDTO> terminalList = new ArrayList<>();
JSONArray jsonArray;
try (InputStream fileStream = fileStorageUtil.getFileStream(excelRptTemp.getContent())) {
jsonArray = new JSONArray(new JSONTokener(fileStream, new JSONConfig()));
parseTemplate(jsonArray, reportTemplateDTOList, reportLimitList, terminalList);
} catch (Exception e) {
if (e instanceof BusinessException) {
throw new BusinessException(e.getMessage());
} else {
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
}
//查询不分相别的指标
DictData dictData = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.EPD.getCode(), DicDataTypeEnum.CS_DATA_TYPE.getCode()).getData();
if(Objects.isNull(dictData)){
throw new BusinessException(CommonResponseEnum.FAIL,"字典类型模板缺少!");
}
//查询不分相别的指标
DictData dictData = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.EPD.getCode(), DicDataTypeEnum.CS_DATA_TYPE.getCode()).getData();
if (Objects.isNull(dictData)) {
throw new BusinessException(CommonResponseEnum.FAIL, "字典类型模板缺少!");
}
List<EleEpdPqd> eleEpdPqdList = epdFeignClient.dictMarkByDataType(dictData.getId()).getData();
Map<String, String> tableMap = eleEpdPqdList.stream().collect(Collectors.toMap(EleEpdPqd::getResourcesId, EleEpdPqd::getClassId, (oldValue, newValue) -> oldValue));
Map<String, String> tMap = new HashMap<>();
eleEpdPqdList.forEach(item -> {
String phase;
if (Objects.isNull(PHASE_MAPPING.get(item.getPhase()))) {
phase = item.getPhase();
} else {
phase = PHASE_MAPPING.get(item.getPhase());
}
DictData epdDic = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.EPD.getCode(),DicDataTypeEnum.CS_DATA_TYPE.getCode()).getData();
List<EleEpdPqd> eleEpdPqdList= epdFeignClient.dictMarkByDataType(epdDic.getId()).getData();
Map<String, String> tMap = new HashMap<>();
eleEpdPqdList.forEach(item->{
String phase;
if (Objects.isNull(PHASE_MAPPING.get(item.getPhase()))) {
phase = item.getPhase();
} else {
phase = PHASE_MAPPING.get(item.getPhase());
if (ObjectUtils.isNotNull(item.getHarmStart()) && ObjectUtils.isNotNull(item.getHarmEnd())) {
for (int i = item.getHarmStart(); i <= item.getHarmEnd() + 1; i++) {
tMap.put((item.getOtherName() + "_" + i + phase + item.getResourcesId()).toUpperCase(), item.getPrimaryFormula());
}
if (ObjectUtils.isNotNull(item.getHarmStart()) && ObjectUtils.isNotNull(item.getHarmEnd())) {
for (int i = item.getHarmStart(); i <= item.getHarmEnd() + 1; i++) {
tMap.put((item.getOtherName() + "_" + i + phase + item.getResourcesId()).toUpperCase(), item.getPrimaryFormula());
}
} else {
tMap.put((item.getOtherName() + phase + item.getResourcesId()).toUpperCase(), item.getPrimaryFormula());
}
});
} else {
tMap.put((item.getOtherName() + phase + item.getResourcesId()).toUpperCase(), item.getPrimaryFormula());
}
});
eleEpdPqdList = eleEpdPqdList.stream().filter(it->"T".equals(it.getPhase())||"M".equals(it.getPhase())).collect(Collectors.toList());
List<String> noPhaseList = eleEpdPqdList.stream().filter(it->StrUtil.isNotBlank(it.getOtherName())).map(it->it.getOtherName().toUpperCase()).collect(Collectors.toList());
eleEpdPqdList = eleEpdPqdList.stream().filter(it -> "M".equals(it.getPhase())).collect(Collectors.toList());
List<String> noPhaseList = eleEpdPqdList.stream().filter(it -> StrUtil.isNotBlank(it.getOtherName())).map(it -> it.getOtherName().toUpperCase()).collect(Collectors.toList());
//处理指标是否合格
reportLimitList = new LinkedHashSet<>(reportLimitList).stream().sorted(Comparator.comparing(ReportTemplateDTO::getItemName)).collect(Collectors.toList());
Map<String, Float> limitMap = overLimitDeal(reportLimitList, reportSearchParam);
//存放限值指标的map
Map<String, ReportTemplateDTO> limitTargetMapX = reportLimitList.stream().collect(Collectors.toMap(ReportTemplateDTO::getItemName, Function.identity()));
//处理指标是否合格
reportLimitList = new LinkedHashSet<>(reportLimitList).stream().sorted(Comparator.comparing(ReportTemplateDTO::getItemName)).collect(Collectors.toList());
Map<String, Float> limitMap = overLimitDeal(reportLimitList, reportSearchParam);
//存放限值指标的map
Map<String, ReportTemplateDTO> limitTargetMapX = reportLimitList.stream().collect(Collectors.toMap(ReportTemplateDTO::getItemName, Function.identity()));
List<ReportTemplateDTO> endList = new CopyOnWriteArrayList<>();
if (CollUtil.isNotEmpty(reportTemplateDTOList)) {
//开始组织sql
reportTemplateDTOList = new LinkedHashSet<>(reportTemplateDTOList).stream().sorted(Comparator.comparing(ReportTemplateDTO::getItemName)).collect(Collectors.toList());
Map<String, List<ReportTemplateDTO>> classMap = reportTemplateDTOList.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getResourceId));
//定义存放越限指标的map
Map<String, ReportTemplateDTO> assNoPassMap = new HashMap<>();
classMap.forEach((classKey, templateValue) -> {
Map<String, List<ReportTemplateDTO>> valueTypeMap = templateValue.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getStatMethod));
//每张表开启一个独立线程查询
futures.add(executorService.submit(() -> {
DynamicDataSourceContextHolder.push("sjzx");
//avg.max,min,cp95
try {
List<ReportTemplateDTO> endList = new CopyOnWriteArrayList<>();
if (CollUtil.isNotEmpty(reportTemplateDTOList)) {
//开始组织sql
reportTemplateDTOList = new LinkedHashSet<>(reportTemplateDTOList).stream().sorted(Comparator.comparing(ReportTemplateDTO::getItemName)).collect(Collectors.toList());
Map<String, List<ReportTemplateDTO>> classMap = reportTemplateDTOList.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getResourceId));
//定义存放越限指标的map
Map<String, ReportTemplateDTO> assNoPassMap = new HashMap<>();
classMap.forEach((classKey, templateValue) -> {
Map<String, List<ReportTemplateDTO>> valueTypeMap = templateValue.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getStatMethod));
//每张表开启一个独立线程查询
futures.add(executorService.submit(() -> {
DynamicDataSourceContextHolder.push("sjzx");
//avg.max,min,cp95
try {
valueTypeMap.forEach((valueTypeKey, valueTypeVal) -> {
//相别分组
Map<String, List<ReportTemplateDTO>> phaseMap = valueTypeVal.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getPhase));
phaseMap.forEach((phaseKey, phaseVal) -> {
StringBuilder sql = new StringBuilder(InfluxDbSqlConstant.SELECT);
if (InfluxDbSqlConstant.MAX.equalsIgnoreCase(valueTypeKey)) {
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),phaseVal, sql, endList, InfluxDbSqlConstant.MAX, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap,noPhaseList);
assembleSqlAndQuery(tMap, newMap.get("LEVEL"), newMap.get("PT"), newMap.get("CT"), phaseVal, sql, endList, InfluxDbSqlConstant.MAX, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, noPhaseList, tableMap);
} else if (InfluxDbSqlConstant.MIN.equalsIgnoreCase(valueTypeKey)) {
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),phaseVal, sql, endList, InfluxDbSqlConstant.MIN, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap,noPhaseList);
assembleSqlAndQuery(tMap, newMap.get("LEVEL"), newMap.get("PT"), newMap.get("CT"), phaseVal, sql, endList, InfluxDbSqlConstant.MIN, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, noPhaseList, tableMap);
} else if (InfluxDbSqlConstant.AVG_WEB.equalsIgnoreCase(valueTypeKey)) {
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),phaseVal, sql, endList, InfluxDbSqlConstant.AVG_WEB, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap,noPhaseList);
assembleSqlAndQuery(tMap, newMap.get("LEVEL"), newMap.get("PT"), newMap.get("CT"), phaseVal, sql, endList, InfluxDbSqlConstant.AVG_WEB, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, noPhaseList,tableMap);
} else if (InfluxDbSqlConstant.CP95.equalsIgnoreCase(valueTypeKey)) {
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),phaseVal, sql, endList, InfluxDbSqlConstant.CP95, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap,noPhaseList);
assembleSqlAndQuery(tMap, newMap.get("LEVEL"), newMap.get("PT"), newMap.get("CT"), phaseVal, sql, endList, InfluxDbSqlConstant.CP95, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, noPhaseList,tableMap);
}
});
});
}finally {
} finally {
DynamicDataSourceContextHolder.poll();
}
}));
});
// 等待所有任务完成
for (Future<?> future : futures) {
try {
future.get(); // 这会阻塞直到任务完成或抛出异常
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
log.error("自定义报表多线程查询流程出错!错误信息{}",e.getMessage());
}
}));
});
// 等待所有任务完成
for (Future<?> future : futures) {
try {
future.get(); // 这会阻塞直到任务完成或抛出异常
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
log.error("自定义报表多线程查询流程出错!错误信息{}", e.getMessage());
}
//处理指标最终判定合格还是不合格
dealTargetResult(assNoPassMap, limitTargetMapX, endList);
}
resultAssemble(endList,reportSearchParam,newMap,deviceUnitCommDTO,jsonArray);
//导出自定义报表
downReport(jsonArray, response);
}
//处理指标最终判定合格还是不合格
dealTargetResult(assNoPassMap, limitTargetMapX, endList);
}
resultAssemble(endList, reportSearchParam, newMap, deviceUnitCommDTO, jsonArray);
//导出自定义报表
downReport(jsonArray, response);
}
/**
* 解析模板
*
* @author cdf
* @date 2023/10/20
*/
@@ -780,7 +781,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
for (ReportTemplateDTO item : reportLimitList) {
if (limitMap.containsKey(item.getTemplateName())) {
if(item.getTemplateName().equalsIgnoreCase(VOLTAGE_DEV)){
if (item.getTemplateName().equalsIgnoreCase(VOLTAGE_DEV)) {
item.setLowValue(limitMap.get(UVOLTAGE_DEV).toString());
}
item.setValue(limitMap.get(item.getTemplateName()).toString());
@@ -815,6 +816,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
/**
* 对多测点数据进行计算求出一组数据
*
* @param method
* @param allList
* @return
@@ -884,7 +886,6 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
}
/**
* 处理指标超标结论
*/
@@ -897,13 +898,13 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
}
String expend = "";
if(Objects.nonNull(val.getLowValue())){
expend = val.getLowValue()+",";
if (Objects.nonNull(val.getLowValue())) {
expend = val.getLowValue() + ",";
}
if (val.getOverLimitFlag() == 1) {
val.setValue("不合格 (" + expend+val.getValue() + ")");
val.setValue("不合格 (" + expend + val.getValue() + ")");
} else {
val.setValue("合格 (" + expend+val.getValue() + ")");
val.setValue("合格 (" + expend + val.getValue() + ")");
}
endList.add(val);
});
@@ -935,15 +936,15 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
return ratio;
}
public String appendData(Map<String,String> tMap,String name, double pt, double ct) {
public String appendData(Map<String, String> tMap, String name, double pt, double ct) {
String result;
String format = tMap.get(name);
if (Objects.equals(format, "*PT")) {
result = "*"+pt+"/1000";
result = "*" + pt + "/1000";
} else if (Objects.equals(format, "*CT")) {
result = "*"+ct;
result = "*" + ct;
} else if (Objects.equals(format, "*PT*CT")) {
result = "*"+pt+"*"+ct+"/1000";
result = "*" + pt + "*" + ct + "/1000";
} else {
result = "";
}
@@ -958,7 +959,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
* @param assNoPassMap 用于存储不合格的指标
* @date 2023/10/20
*/
private void assSqlByMysql(Map<String,String> tMap, String dataLevel, String pt, String ct, List<ReportTemplateDTO> data, StringBuilder sql, List<ReportTemplateDTO> endList, String method, ReportSearchParam reportSearchParam, Map<String, ReportTemplateDTO> limitMap, Map<String, Float> overLimitMap, Map<String, ReportTemplateDTO> assNoPassMap,List<String> noPhaseList) {
private void assSqlByMysql(Map<String, String> tMap, String dataLevel, String pt, String ct, List<ReportTemplateDTO> data, StringBuilder sql, List<ReportTemplateDTO> endList, String method, ReportSearchParam reportSearchParam, Map<String, ReportTemplateDTO> limitMap, Map<String, Float> overLimitMap, Map<String, ReportTemplateDTO> assNoPassMap, List<String> noPhaseList) {
//sql拼接示例select MAX(IHA2) as IHA2 from power_quality_data where Phase = 'A' and LineId='1324564568' and Stat_Method='max' tz('Asia/Shanghai')
if (InfluxDbSqlConstant.CP95.equals(method)) {
for (int i = 0; i < data.size(); i++) {
@@ -967,17 +968,17 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName())
.append(InfluxDbSqlConstant.RBK)
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName()+data.get(i).getPhase()+data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName() + data.get(i).getPhase() + data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(InfluxDbSqlConstant.AS)
.append("\""+data.get(i).getItemName()+"\"");
.append("\"" + data.get(i).getItemName() + "\"");
} else {
sql.append(InfluxDbSqlConstant.MAX)
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName())
.append(InfluxDbSqlConstant.RBK)
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName()+data.get(i).getPhase()+data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName() + data.get(i).getPhase() + data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(InfluxDbSqlConstant.AS)
.append("\""+data.get(i).getItemName()+"\"").append(StrUtil.COMMA);
.append("\"" + data.get(i).getItemName() + "\"").append(StrUtil.COMMA);
}
}
} else {
@@ -987,17 +988,17 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName())
.append(InfluxDbSqlConstant.RBK)
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName()+data.get(i).getPhase()+data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName() + data.get(i).getPhase() + data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(InfluxDbSqlConstant.AS)
.append("\""+data.get(i).getItemName()+"\"");
.append("\"" + data.get(i).getItemName() + "\"");
} else {
sql.append(method)
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName())
.append(InfluxDbSqlConstant.RBK)
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName()+data.get(i).getPhase()+data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName() + data.get(i).getPhase() + data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(InfluxDbSqlConstant.AS)
.append("\""+data.get(i).getItemName()+"\"").append(StrUtil.COMMA);
.append("\"" + data.get(i).getItemName() + "\"").append(StrUtil.COMMA);
}
}
@@ -1035,9 +1036,6 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
//频率和频率偏差仅统计T相
if (noPhaseList.contains(data.get(0).getTemplateName())) {
if(data.get(0).getTemplateName().equalsIgnoreCase("v_unbalance")){
System.out.println(44);
}
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDBTableConstant.PHASIC_TYPE)
.append(InfluxDbSqlConstant.EQ)
@@ -1050,9 +1048,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.GE).append(InfluxDbSqlConstant.QM).append(reportSearchParam.getStartTime()).append(InfluxDbSqlConstant.START_TIME).append(InfluxDbSqlConstant.QM)
.append(InfluxDbSqlConstant.AND)
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.LT).append(InfluxDbSqlConstant.QM).append(reportSearchParam.getEndTime()).append(InfluxDbSqlConstant.END_TIME).append(InfluxDbSqlConstant.QM);
System.out.println(sql);
List<Map<String, Object>> mapList = SqlRunner.DEFAULT.selectList(sql.toString());
if (CollUtil.isEmpty(mapList) || Objects.isNull(mapList.get(0))) {
data = data.stream().peek(item -> item.setValue("/")).collect(Collectors.toList());
@@ -1066,16 +1062,16 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
if (overLimitMap.containsKey(item.getLimitName())) {
Float tagVal = overLimitMap.get(item.getLimitName());
if(item.getLimitName().equalsIgnoreCase(UVOLTAGE_DEV)){
if (item.getLimitName().equalsIgnoreCase(UVOLTAGE_DEV)) {
//对电压偏差特殊处理
Float tagVal_U = overLimitMap.get(UVOLTAGE_DEV);
if (v > tagVal || v<tagVal_U) {
if (v > tagVal || v < tagVal_U) {
item.setOverLimitFlag(1);
} else {
item.setOverLimitFlag(0);
}
}else {
} else {
if (v > tagVal) {
item.setOverLimitFlag(1);
} else {
@@ -1091,18 +1087,18 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
ReportTemplateDTO tem = limitMap.get(key);
double limitVal = Double.parseDouble(tem.getValue());
if(VOLTAGE_DEV.equalsIgnoreCase(tem.getLimitName())){
if (VOLTAGE_DEV.equalsIgnoreCase(tem.getLimitName())) {
//针对电压偏差特殊处理
double limitLowVal = Double.parseDouble(tem.getLowValue());
if (v > limitVal || v<limitLowVal) {
if (v > limitVal || v < limitLowVal) {
tem.setOverLimitFlag(1);
assNoPassMap.put(key, tem);
} else if (!assNoPassMap.containsKey(key)) {
tem.setOverLimitFlag(0);
assNoPassMap.put(key, tem);
}
}else {
} else {
//其他指标
if (v > limitVal) {
tem.setOverLimitFlag(1);
@@ -1123,6 +1119,251 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
}
private void assembleSqlAndQuery(Map<String, String> tMap, String dataLevel, String pt, String ct,
List<ReportTemplateDTO> data, StringBuilder sql,
List<ReportTemplateDTO> endList, String method,
ReportSearchParam reportSearchParam,
Map<String, ReportTemplateDTO> limitMap,
Map<String, Float> overLimitMap,
Map<String, ReportTemplateDTO> assNoPassMap,
List<String> noPhaseList,
Map<String, String> tableMap) {
// sql拼接示例select MAX(IHA2) as IHA2 from power_quality_data where Phase = 'A' and LineId='1324564568' and Stat_Method='max' tz('Asia/Shanghai')
// 处理CP95或PERCENTILE特殊情况
boolean isCp95 = InfluxDbSqlConstant.CP95.equals(method);
boolean isAvg = InfluxDbSqlConstant.AVG_WEB.equals(method);
String aggregateFunc;
// 执行查询
List<Map<String, Object>> mapList = new ArrayList<>();
if (Objects.isNull(reportSearchParam.getIsStatisticData()) || reportSearchParam.getIsStatisticData() == 0) {
aggregateFunc = isCp95 ? InfluxDbSqlConstant.MAX : method;
for (int i = 0; i < data.size(); i++) {
sql.append(aggregateFunc)
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName())
.append(InfluxDbSqlConstant.RBK)
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName() + data.get(i).getPhase() + data.get(0).getResourceId(), getData(pt), getData(ct)) : "");
if (i == data.size() - 1) {
sql.append(InfluxDbSqlConstant.AS).append("\"").append(data.get(i).getItemName()).append("\"");
} else {
sql.append(InfluxDbSqlConstant.AS).append("\"").append(data.get(i).getItemName()).append("\"").append(StrUtil.COMMA);
}
}
//拼接表名
sql.append(StrPool.C_SPACE).append(InfluxDbSqlConstant.FROM).append(data.get(0).getResourceId());
sql.append(InfluxDbSqlConstant.WHERE)
.append(InfluxDBTableConstant.LINE_ID)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDbSqlConstant.QM)
.append(reportSearchParam.getLineId())
.append(InfluxDbSqlConstant.QM);
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDBTableConstant.VALUE_TYPE)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDbSqlConstant.QM)
.append(data.get(0).getStatMethod())
.append(InfluxDbSqlConstant.QM);
//相别特殊处理
if (noPhaseList.contains(data.get(0).getTemplateName())) {
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDBTableConstant.PHASIC_TYPE)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDbSqlConstant.QM)
.append(InfluxDBTableConstant.PHASE_TYPE_T)
.append(InfluxDbSqlConstant.QM);
}else {
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDBTableConstant.PHASIC_TYPE)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDbSqlConstant.QM)
.append(data.get(0).getPhase())
.append(InfluxDbSqlConstant.QM);
}
//时间范围处理
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.GE).append(InfluxDbSqlConstant.QM).append(reportSearchParam.getStartTime()).append(InfluxDbSqlConstant.START_TIME).append(InfluxDbSqlConstant.QM)
.append(InfluxDbSqlConstant.AND)
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.LT).append(InfluxDbSqlConstant.QM).append(reportSearchParam.getEndTime()).append(InfluxDbSqlConstant.END_TIME).append(InfluxDbSqlConstant.QM);
System.out.println(sql);
mapList = SqlRunner.DEFAULT.selectList(sql.toString());
} else if (reportSearchParam.getIsStatisticData() == 1) {
//查分钟数据
if (isCp95) {
// InfluxDB的PERCENTILE特殊处理
for (int i = 0; i < data.size(); i++) {
sql.append(method)
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName().toLowerCase())
.append(InfluxDbSqlConstant.NUM_95)
.append(InfluxDbSqlConstant.RBK)
.append(InfluxDbSqlConstant.AS).append(InfluxDbSqlConstant.DQM)
.append(data.get(i).getItemName()).append(InfluxDbSqlConstant.DQM);
if (i != data.size() - 1) {
sql.append(StrUtil.COMMA);
}
}
} else {
aggregateFunc = isAvg ? InfluxDbSqlConstant.AVG:method;
for (int i = 0; i < data.size(); i++) {
sql.append(aggregateFunc)
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName().toLowerCase())
.append(InfluxDbSqlConstant.RBK)
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName() + data.get(i).getPhase() + data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(InfluxDbSqlConstant.AS).append("\"").append(data.get(i).getItemName()).append("\"");
if (i != data.size() - 1) {
sql.append(StrUtil.COMMA);
}
}
}
// 拼接表名
sql.append(StrPool.C_SPACE).append(InfluxDbSqlConstant.FROM).append(StrPool.C_SPACE);
if (Objects.nonNull(reportSearchParam.getResourceType()) && reportSearchParam.getResourceType() == 1) {
sql.append(data.get(0).getClassId().replace("data", "day"));
} else {
sql.append(tableMap.get(data.get(0).getResourceId().toLowerCase()).toLowerCase());
}
// 拼接WHERE条件
sql.append(InfluxDbSqlConstant.WHERE)
.append(InfluxDBTableConstant.LINE_ID)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDbSqlConstant.QM)
.append(reportSearchParam.getLineId())
.append(InfluxDbSqlConstant.QM);
// InfluxDB特殊处理data_flicker、data_fluc、data_plt 无 value_type
String classTable = tableMap.get(data.get(0).getResourceId().toLowerCase());
if (!InfluxDBTableConstant.DATA_FLICKER.equals(classTable)
&& !InfluxDBTableConstant.DATA_FLUC.equals(classTable)
&& !InfluxDBTableConstant.DATA_PLT.equals(classTable)) {
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDBTableConstant.VALUE_TYPE)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDbSqlConstant.QM)
.append(data.get(0).getStatMethod())
.append(InfluxDbSqlConstant.QM);
}
// 相别特殊处理
if (!noPhaseList.contains(data.get(0).getPhase())) {
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDBTableConstant.PHASIC_TYPE)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDbSqlConstant.QM)
.append(data.get(0).getPhase())
.append(InfluxDbSqlConstant.QM);
}
// 时间范围处理
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.GE)
.append(InfluxDbSqlConstant.QM).append(reportSearchParam.getStartTime())
.append(InfluxDbSqlConstant.QM)
.append(InfluxDbSqlConstant.AND)
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.LT)
.append(InfluxDbSqlConstant.QM).append(reportSearchParam.getEndTime())
.append(InfluxDbSqlConstant.QM);
// InfluxDB需要添加时区
sql.append(InfluxDbSqlConstant.TZ);
System.out.println(sql);
mapList = influxDbUtils.getMapResult(sql.toString());
}
// 处理查询结果
fetchData(mapList, data, limitMap, overLimitMap, assNoPassMap, endList);
}
public void fetchData(List<Map<String, Object>> mapList,
List<ReportTemplateDTO> data, Map<String,
ReportTemplateDTO> limitMap,
Map<String, Float> overLimitMap,
Map<String, ReportTemplateDTO> assNoPassMap,
List<ReportTemplateDTO> endList) {
// 处理查询结果
if (CollUtil.isEmpty(mapList)) {
data = data.stream().peek(item -> item.setValue("/")).collect(Collectors.toList());
} else {
// 兼容达梦数据库方法
Map<String, Object> map = convertKeysToUpperCase(mapList.get(0));
for (ReportTemplateDTO item : data) {
if (map.containsKey(item.getItemName())) {
double v = Double.parseDouble(map.get(item.getItemName()).toString());
item.setValue(String.format("%.3f", v));
// 处理overLimitMap越限判断
if (overLimitMap != null && overLimitMap.containsKey(item.getLimitName())) {
Float tagVal = overLimitMap.get(item.getLimitName());
if (item.getLimitName() != null && item.getLimitName().equalsIgnoreCase(UVOLTAGE_DEV)) {
// 对电压偏差特殊处理
Float tagVal_U = overLimitMap.get(UVOLTAGE_DEV);
if (v > tagVal || v < tagVal_U) {
item.setOverLimitFlag(1);
} else {
item.setOverLimitFlag(0);
}
} else {
if (v > tagVal) {
item.setOverLimitFlag(1);
} else {
item.setOverLimitFlag(0);
}
}
}
// 判断是否越限limitMap处理
if (limitMap != null && !limitMap.isEmpty()) {
String key = item.getLimitName() + STR_ONE + item.getStatMethod() + "#PQ_OVERLIMIT";
if (limitMap.containsKey(key)) {
ReportTemplateDTO tem = limitMap.get(key);
double limitVal = Double.parseDouble(tem.getValue());
if (VOLTAGE_DEV.equalsIgnoreCase(tem.getLimitName())) {
// 针对电压偏差特殊处理
double limitLowVal = Double.parseDouble(tem.getLowValue());
if (v > limitVal || v < limitLowVal) {
tem.setOverLimitFlag(1);
if (assNoPassMap != null) {
assNoPassMap.put(key, tem);
}
} else if (assNoPassMap != null && !assNoPassMap.containsKey(key)) {
tem.setOverLimitFlag(0);
assNoPassMap.put(key, tem);
}
} else {
// 其他指标
if (v > limitVal) {
tem.setOverLimitFlag(1);
if (assNoPassMap != null) {
assNoPassMap.put(key, tem);
}
} else if (assNoPassMap != null && !assNoPassMap.containsKey(key)) {
tem.setOverLimitFlag(0);
assNoPassMap.put(key, tem);
}
}
}
}
} else {
item.setValue("/");
}
}
}
if (endList != null) {
endList.addAll(data);
}
}
/**
* 数据单位信息
*/
@@ -1179,10 +1420,11 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
/**
* 处理最终结果
*
* @author cdf
* @date 2026/1/16
*/
public void resultAssemble(List<ReportTemplateDTO> endList,ReportSearchParam reportSearchParam,Map<String,String> finalTerminalMap,DeviceUnitCommDTO deviceUnitCommDTO,JSONArray jsonArray){
public void resultAssemble(List<ReportTemplateDTO> endList, ReportSearchParam reportSearchParam, Map<String, String> finalTerminalMap, DeviceUnitCommDTO deviceUnitCommDTO, JSONArray jsonArray) {
if (CollUtil.isNotEmpty(endList)) {
//数据单位信息
Map<String, String> unit = unitMap(deviceUnitCommDTO);
@@ -1233,7 +1475,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
} else if (v.charAt(0) == '&') {
//结论
String tem = v.replace(STR_THREE, "").toUpperCase();
if (finalTerminalMap.size()>0) {
if (finalTerminalMap.size() > 0) {
if ("STATIS_TIME".equals(tem)) {
//如何时间是大于当前时间则用当前时间
String localTime = InfluxDbSqlConstant.END_TIME;
@@ -1267,7 +1509,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
/**
* map key转大写
*/
public <V> Map<String, V> convertKeysToUpperCase(Map<String, V> originalMap) {
public <V> Map<String, V> convertKeysToUpperCase(Map<String, V> originalMap) {
Map<String, V> newMap = new HashMap<>();
for (Map.Entry<String, V> entry : originalMap.entrySet()) {
newMap.put(entry.getKey().toUpperCase(), entry.getValue());
@@ -1275,4 +1517,9 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
return newMap;
}
// 5. 添加线程池销毁方法
@PreDestroy
public void destroy() {
executorService.shutdown();
}
}