优化部分代码

This commit is contained in:
2025-04-14 18:38:08 +08:00
parent 92b0640f9c
commit 1a28d25026
4 changed files with 364 additions and 378 deletions

View File

@@ -21,7 +21,7 @@ public interface PowerConstant {
/** /**
* T相指标 * T相指标
*/ */
List<String> T_PHASE = Arrays.asList("VOLTAGE", "IMBV", "IMBA"); List<String> T_PHASE = Arrays.asList("VOLTAGE", "IMBV", "IMBA", "FREQ");
/** /**
@@ -32,7 +32,7 @@ public interface PowerConstant {
/** /**
* 没有次数的指标 * 没有次数的指标
*/ */
List<String> NO_TIME = Arrays.asList("V", "I", "P", "VOLTAGE", "IMBV", "IMBA", "F"); List<String> NO_TIME = Arrays.asList("V", "I", "P", "VOLTAGE", "IMBV", "IMBA", "F", "FREQ");
/** /**
* 有数据范围 * 有数据范围

View File

@@ -15,7 +15,7 @@ public enum AffectEnum {
BASE("base", "额定工作条件下的检测"), BASE("base", "额定工作条件下的检测"),
VOL("vol", "电压对XX测量的影响"), VOL("vol", "电压对XX测量的影响"),
FREQ("freq", "频率对XX测量的影响"), FREQ("freq", "频率对XX测量的影响"),
HARM("single", "谐波对XX测量的影响"); HARM("harm", "谐波对XX测量的影响");
private String key; private String key;

View File

@@ -72,6 +72,8 @@ import org.docx4j.jaxb.Context;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage; import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart; import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.wml.*; import org.docx4j.wml.*;
import org.docx4j.wml.CTTblLayoutType;
import org.docx4j.wml.STTblLayoutType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@@ -85,6 +87,7 @@ import javax.xml.bind.JAXBElement;
import java.io.*; import java.io.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@@ -604,6 +607,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
// 确保目录存在 // 确保目录存在
ensureDirectoryExists(dirPath); ensureDirectoryExists(dirPath);
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX))); baseModelDocument.save(new File(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX)));
this.updateDevAndPlanState(devReportParam.getDevId(), devReportParam.getPlanId());
} catch (Exception e) { } catch (Exception e) {
log.error(ReportResponseEnum.GENERATE_REPORT_ERROR.getMessage(), e); log.error(ReportResponseEnum.GENERATE_REPORT_ERROR.getMessage(), e);
throw new BusinessException(ReportResponseEnum.GENERATE_REPORT_ERROR); throw new BusinessException(ReportResponseEnum.GENERATE_REPORT_ERROR);
@@ -809,7 +814,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
ObjectFactory factory = new ObjectFactory(); ObjectFactory factory = new ObjectFactory();
// 读取该计划的检测大项组装数据内容 // 读取该计划的检测大项组装数据内容
List<PqScriptDtlDataVO> pqScriptDtlsList = pqScriptDtlsService.getScriptDtlsDataList(devReportParam.getScriptId()); List<PqScriptDtlDataVO> pqScriptDtlsList = pqScriptDtlsService.getScriptDtlsDataList(devReportParam.getScriptId());
Map<String, List<PqScriptDtlDataVO>> scriptMap = pqScriptDtlsList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptCode)); Map<String, List<PqScriptDtlDataVO>> scriptMap = pqScriptDtlsList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptCode, LinkedHashMap::new, Collectors.toList()));
List<Object> allContent = detailModelDocument.getContent(); List<Object> allContent = detailModelDocument.getContent();
List<Docx4jUtil.HeadingContent> headingContents = Docx4jUtil.extractHeading5Contents(allContent); List<Docx4jUtil.HeadingContent> headingContents = Docx4jUtil.extractHeading5Contents(allContent);
Map<String, List<Docx4jUtil.HeadingContent>> contentMap = headingContents.stream().collect(Collectors.groupingBy(Docx4jUtil.HeadingContent::getHeadingText, Collectors.toList())); Map<String, List<Docx4jUtil.HeadingContent>> contentMap = headingContents.stream().collect(Collectors.groupingBy(Docx4jUtil.HeadingContent::getHeadingText, Collectors.toList()));
@@ -825,7 +830,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map.Entry<String, List<PqScriptDtlDataVO>> next = iterator.next(); Map.Entry<String, List<PqScriptDtlDataVO>> next = iterator.next();
String scriptCode = next.getKey(); String scriptCode = next.getKey();
List<PqScriptDtlDataVO> checkckItemList = next.getValue(); List<PqScriptDtlDataVO> dtlScriptItemList = next.getValue();
List<Docx4jUtil.HeadingContent> tempContent = contentMap.get(scriptCode); List<Docx4jUtil.HeadingContent> tempContent = contentMap.get(scriptCode);
// 获取需要填充keys索引0对应的段落key索引1对应的表格key // 获取需要填充keys索引0对应的段落key索引1对应的表格key
List<List<String>> keys = Docx4jUtil.getFillKeys(tempContent); List<List<String>> keys = Docx4jUtil.getFillKeys(tempContent);
@@ -849,14 +854,14 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
} }
if (PowerConstant.TIME.contains(scriptCode)) { if (PowerConstant.TIME.contains(scriptCode)) {
// 谐波类以scriptIndex区分 // 谐波类以scriptIndex区分
Map<Integer, List<PqScriptDtlDataVO>> scriptIndexMap = checkckItemList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptIndex)); Map<Integer, List<PqScriptDtlDataVO>> scriptIndexMap = dtlScriptItemList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptIndex));
for (List<PqScriptDtlDataVO> scriptDtlDataItem : scriptIndexMap.values()) { for (List<PqScriptDtlDataVO> scriptDtlDataItem : scriptIndexMap.values()) {
singleTestResult = resultService.getFinalContent(scriptDtlDataItem, devReportParam.getPlanCode(), pqDevVO.getId(), lineNo, tableKeys); singleTestResult = resultService.getFinalContent(scriptDtlDataItem, devReportParam.getPlanCode(), pqDevVO.getId(), lineNo, tableKeys);
position = fillContentInTemplate(singleTestResult.getDetail(), position, tempContent, factory, pKeyValueMap, tableKeys, paragraphs); position = fillContentInTemplate(singleTestResult.getDetail(), position, tempContent, factory, pKeyValueMap, tableKeys, paragraphs);
} }
} else { } else {
// 非谐波类 // 非谐波类
singleTestResult = resultService.getFinalContent(checkckItemList, devReportParam.getPlanCode(), pqDevVO.getId(), lineNo, tableKeys); singleTestResult = resultService.getFinalContent(dtlScriptItemList, devReportParam.getPlanCode(), pqDevVO.getId(), lineNo, tableKeys);
position = fillContentInTemplate(singleTestResult.getDetail(), position, tempContent, factory, pKeyValueMap, tableKeys, paragraphs); position = fillContentInTemplate(singleTestResult.getDetail(), position, tempContent, factory, pKeyValueMap, tableKeys, paragraphs);
} }
if (Objects.nonNull(singleTestResult) && needFill) { if (Objects.nonNull(singleTestResult) && needFill) {
@@ -942,13 +947,16 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
List<Object> rows = tbl.getContent(); List<Object> rows = tbl.getContent();
boolean isRow = Docx4jUtil.judgeTableCross(rows.get(0)); boolean isRow = Docx4jUtil.judgeTableCross(rows.get(0));
if (isRow) { if (isRow) {
// 删除最后一行这行用来填模板key的无需展示
// 获取现有行的样式 // 获取现有行的样式
Tr existingRow = (Tr) tbl.getContent().get(rows.size() - 1); Tr existingRow = (Tr) tbl.getContent().get(rows.size() - 1);
// 获取现有样式 // 获取现有样式
TrPr trPr = existingRow.getTrPr(); TrPr trPr = existingRow.getTrPr();
JAXBElement<Tc> element = (JAXBElement<Tc>) existingRow.getContent().get(0); JAXBElement<Tc> element = (JAXBElement<Tc>) existingRow.getContent().get(0);
TcPr tcPr = element.getValue().getTcPr(); TcPr tcPr = element.getValue().getTcPr();
TblWidth cellWidth = factory.createTblWidth();
cellWidth.setType("dxa");
cellWidth.setW(BigInteger.valueOf(5000/tableKeys.size()));
tcPr.setTcW(cellWidth);
tbl.getContent().remove(existingRow); tbl.getContent().remove(existingRow);
// 迭代增加行,需要填充的表格keys在tableKeys集合中 // 迭代增加行,需要填充的表格keys在tableKeys集合中
for (Map<String, String> stringStringMap : value1) { for (Map<String, String> stringStringMap : value1) {
@@ -958,14 +966,16 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
} else { } else {
// 纵向表格暂不考虑 // 纵向表格暂不考虑
} }
// 插入段落 // 插入段落,处理下样式
paragraphs.add(position++, copiedTableElement); paragraphs.add(position++, copiedTableElement);
} }
} }
// 全部渲染完毕后,添加几个换行 // 全部渲染完毕后,添加几个换行
P p = factory.createP(); P p = factory.createP();
Docx4jUtil.addBr(factory, p, 2); Docx4jUtil.addBr(factory, p, 1);
paragraphs.add(position++, p); paragraphs.add(position++, p);
} }

View File

@@ -517,6 +517,8 @@ public class ResultServiceImpl implements IResultService {
case VOLTAGE_MAG: case VOLTAGE_MAG:
case VOLTAGE_DUR: case VOLTAGE_DUR:
break; break;
default:
break;
} }
} }
@@ -596,6 +598,8 @@ public class ResultServiceImpl implements IResultService {
case VOLTAGE_MAG: case VOLTAGE_MAG:
case VOLTAGE_DUR: case VOLTAGE_DUR:
break; break;
default:
break;
} }
} }
@@ -687,6 +691,8 @@ public class ResultServiceImpl implements IResultService {
case VOLTAGE_MAG: case VOLTAGE_MAG:
case VOLTAGE_DUR: case VOLTAGE_DUR:
break; break;
default:
break;
} }
} }
@@ -782,6 +788,8 @@ public class ResultServiceImpl implements IResultService {
List<PqScriptDtls> dip = dtls.stream().filter(x -> "Dip".equals(x.getValueType())).collect(Collectors.toList()); List<PqScriptDtls> dip = dtls.stream().filter(x -> "Dip".equals(x.getValueType())).collect(Collectors.toList());
dtlType.setScriptTypeName("频率=" + dipf.get(0).getValue() + ResultUnitEnum.FREQ.getUnit() + ",特征幅值=" + dip.get(0).getTransValue().intValue() + "%Un持续时间=" + dip.get(0).getRetainTime().intValue() + "周波"); dtlType.setScriptTypeName("频率=" + dipf.get(0).getValue() + ResultUnitEnum.FREQ.getUnit() + ",特征幅值=" + dip.get(0).getTransValue().intValue() + "%Un持续时间=" + dip.get(0).getRetainTime().intValue() + "周波");
break; break;
default:
break;
} }
} }
@@ -954,13 +962,37 @@ public class ResultServiceImpl implements IResultService {
List<Integer> indexList = scriptDtlDataVOList.stream().map(PqScriptDtlDataVO::getScriptIndex).distinct().collect(Collectors.toList()); List<Integer> indexList = scriptDtlDataVOList.stream().map(PqScriptDtlDataVO::getScriptIndex).distinct().collect(Collectors.toList());
List<PqScriptCheckData> scriptCheckDataList = pqScriptCheckDataService.listCheckData(scriptId, indexList); List<PqScriptCheckData> scriptCheckDataList = pqScriptCheckDataService.listCheckData(scriptId, indexList);
List<String> valueTypeList = scriptCheckDataList.stream().map(PqScriptCheckData::getValueType).distinct().collect(Collectors.toList()); List<String> valueTypeList = scriptCheckDataList.stream().map(PqScriptCheckData::getValueType).distinct().collect(Collectors.toList());
// 查询检测结果,区分下表。 // 稍作区分暂态的脚本同一个scriptIndex可以有两个指标其余脚本每个checkData的valueType对应一个指标结果
if (PowerConstant.VOLTAGE.equalsIgnoreCase(scriptCode)) {
// 暂态的valueType通常只有2个一个特征幅值一个持续时间
List<Map<String, String>> keyFillMapList = new ArrayList<>();
for (Integer sort : indexList) {
SingleNonHarmParam param = new SingleNonHarmParam(Integer.parseInt(planCode), devId, lineNo, valueTypeList, Collections.singletonList(sort));
List<AdNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
if (CollUtil.isNotEmpty(nonHarmList)) {
Map<String, String> keyFillMap = new HashMap<>(16);
fillVoltagePhaseData(nonHarmList, keyFillMap, tableKeys);
keyFillMapList.add(keyFillMap);
}
}
// 需要对所有填充进行按误差范围分组
Map<String, List<Map<String, String>>> errorScoperMap = keyFillMapList.stream()
.collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey())));
// 分组后,还需要针对特征幅值标准值进行一个升序
errorScoperMap.forEach((errorScope, maps) -> {
PubUtils.sortByDoubleValue(maps, ItemReportKeyEnum.STANDARD_MAG.getKey());
});
List<Map<String, List<Map<String, String>>>> errorList = new ArrayList<>();
errorList.add(errorScoperMap);
// 最后赋值返回
finalContent.put(affectName, errorList);
} else {
for (String valueType : valueTypeList) {
if (PowerConstant.TIME.contains(scriptCode)) { if (PowerConstant.TIME.contains(scriptCode)) {
// 谐波的测试项肯定是三相的可能会存在多次的本处要填充的key全集为time、standard、standardA、standardB、standardC、testA、testB、testC、errorA、errorB、errorC、result
// 查询结果数据经过上层处理谐波类此处的scriptIndex确保只有一个 // 查询结果数据经过上层处理谐波类此处的scriptIndex确保只有一个
if (indexList.size() == 1 && valueTypeList.size() == 1) { if (indexList.size() == 1) {
// 获取谐波数据 // 获取谐波数据
SingleNonHarmParam param = new SingleNonHarmParam(Integer.parseInt(planCode), devId, lineNo, valueTypeList.get(0), indexList.get(0)); SingleNonHarmParam param = new SingleNonHarmParam(Integer.parseInt(planCode), devId, lineNo, valueType, indexList.get(0));
AdHarmonicResult singleResult = adHarmonicService.getSingleResult(param); AdHarmonicResult singleResult = adHarmonicService.getSingleResult(param);
// 注如果ABC的标准值一致则同步到standard中 // 注如果ABC的标准值一致则同步到standard中
Map<Double, List<PqScriptCheckData>> checkDataHarmNumMap = scriptCheckDataList.stream().collect(Collectors.groupingBy(PqScriptCheckData::getHarmNum)); Map<Double, List<PqScriptCheckData>> checkDataHarmNumMap = scriptCheckDataList.stream().collect(Collectors.groupingBy(PqScriptCheckData::getHarmNum));
@@ -980,6 +1012,113 @@ public class ResultServiceImpl implements IResultService {
// 将间谐波次数取整1.5取22.5取3 // 将间谐波次数取整1.5取22.5取3
double timeDouble = Math.round(harmNum); double timeDouble = Math.round(harmNum);
int timeInt = (int) timeDouble; int timeInt = (int) timeDouble;
// 填充结果数据
fillThreePhaseData(singleResult, timeInt, keyFillMap);
if(!keyFillMap.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()).equals("/")){
keyFillMapList.add(keyFillMap);
}
});
if(CollUtil.isNotEmpty(keyFillMapList)){
// 按次数排序
PubUtils.sortByDoubleValue(keyFillMapList, ItemReportKeyEnum.TIME.getKey());
// 取出任意一次谐波数据的误差范围作为key
String titleScope = keyFillMapList.get(0).get(ItemReportKeyEnum.ERROR_SCOPE.getKey());
Map<String, List<Map<String, String>>> errorScoperMap = new HashMap<>();
errorScoperMap.put(titleScope, keyFillMapList);
List<Map<String, List<Map<String, String>>>> errorScoperMapList = new ArrayList<>();
errorScoperMapList.add(errorScoperMap);
finalContent.put(affectName, errorScoperMapList);
}
} else {
log.error("生成谐波类表格数据失败,脚本配置不支持,请核实。");
throw new BusinessException("生成谐波类表格数据失败,脚本配置不支持,请核实。");
}
} else {
// 非谐波的需要区分是否为ABC相还是T相
if (PowerConstant.THREE_PHASE.contains(scriptCode)) {
// 获取该三相的数据
SingleNonHarmParam param = new SingleNonHarmParam(Integer.parseInt(planCode), devId, lineNo, Collections.singletonList(valueType), indexList);
List<AdNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
if (CollUtil.isNotEmpty(nonHarmList)) {
List<Map<String, String>> keyFillMapList = new ArrayList<>();
for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) {
Map<String, String> keyFillMap = new HashMap<>(16);
fillThreePhaseData(adNonHarmonicResult, null, keyFillMap);
if(!keyFillMap.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()).equals("/")){
keyFillMapList.add(keyFillMap);
}
}
if(CollUtil.isNotEmpty(keyFillMapList)){
// 需要对所有的填充进行按误差范围分组
Map<String, List<Map<String, String>>> errorScoperMap = keyFillMapList.stream()
.collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey())));
// 分组后,还需要针对标准值进行一个升序
errorScoperMap.forEach((errorScope, maps) -> {
PubUtils.sortByDoubleValue(maps, ItemReportKeyEnum.STANDARD.getKey());
});
List<Map<String, List<Map<String, String>>>> errorList = new ArrayList<>();
errorList.add(errorScoperMap);
// 最后赋值返回
finalContent.put(affectName, errorList);
}
} else {
log.error("生成三相类表格数据失败,结果表数据丢失,请核实。");
}
} else {
// 非三相且非暂态,通常只有一个数据,所以直接赋值即可
List<Map<String, String>> keyFillMapList = new ArrayList<>();
SingleNonHarmParam param = new SingleNonHarmParam(Integer.parseInt(planCode), devId, lineNo, Collections.singletonList(valueType), indexList);
List<AdNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
if (CollUtil.isNotEmpty(nonHarmList)) {
for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) {
Map<String, String> keyFillMap = new HashMap<>(8);
fillTPhaseData(adNonHarmonicResult, null, keyFillMap);
if(!keyFillMap.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()).equals("/")){
keyFillMapList.add(keyFillMap);
}
}
}
if(CollUtil.isNotEmpty(keyFillMapList)){
// 需要对所有填充进行按误差范围分组
Map<String, List<Map<String, String>>> errorScoperMap = keyFillMapList.stream()
.collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey())));
// 分组后,还需要针对特征幅值标准值进行一个升序
errorScoperMap.forEach((errorScope, maps) -> {
PubUtils.sortByDoubleValue(maps, ItemReportKeyEnum.STANDARD.getKey());
});
List<Map<String, List<Map<String, String>>>> errorList = new ArrayList<>();
errorList.add(errorScoperMap);
// 最后赋值返回
finalContent.put(affectName, errorList);
}
}
}
}
}
} else {
log.error("未找到合适的脚本信息");
}
} else {
log.error("未找到合适的测量条件");
}
});
}
// 返回之前做下总结性判断
singleTestResult.setQualified(judgeQualified(finalContent));
singleTestResult.setDetail(finalContent);
return singleTestResult;
}
/**
* 三相的相关数据处理
* 包含:谐波、间谐波、电压、电流、功率、闪变
*
* @param singleResult 可能是谐波类,也有可能是电压电流,需要区分下结果
* @param timeInt 谐波类需要传指定次数
* @param keyFillMap 待填充的集合Map
*/
private void fillThreePhaseData(Object singleResult, Integer timeInt, Map<String, String> keyFillMap) {
DetectionData tempA = getResultData(singleResult, timeInt, PowerConstant.PHASE_A); DetectionData tempA = getResultData(singleResult, timeInt, PowerConstant.PHASE_A);
DetectionData tempB = getResultData(singleResult, timeInt, PowerConstant.PHASE_B); DetectionData tempB = getResultData(singleResult, timeInt, PowerConstant.PHASE_B);
DetectionData tempC = getResultData(singleResult, timeInt, PowerConstant.PHASE_C); DetectionData tempC = getResultData(singleResult, timeInt, PowerConstant.PHASE_C);
@@ -1057,146 +1196,50 @@ public class ResultServiceImpl implements IResultService {
keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result); keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result);
errorScope = dealErrorScope(errorScope).concat(unit); errorScope = dealErrorScope(errorScope).concat(unit);
keyFillMap.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope); keyFillMap.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope);
keyFillMapList.add(keyFillMap);
});
// 按次数排序
PubUtils.sortByDoubleValue(keyFillMapList, ItemReportKeyEnum.TIME.getKey());
// 取出任意一次谐波数据的误差范围作为key
String titleScope = keyFillMapList.get(0).get(ItemReportKeyEnum.ERROR_SCOPE.getKey());
Map<String, List<Map<String, String>>> errorScoperMap = new HashMap<>();
errorScoperMap.put(titleScope, keyFillMapList);
List<Map<String, List<Map<String, String>>>> errorScoperMapList = new ArrayList<>();
errorScoperMapList.add(errorScoperMap);
finalContent.put(affectName, errorScoperMapList);
} else {
log.error("生成谐波类表格数据失败,脚本配置不支持,请核实。");
throw new BusinessException("生成谐波类表格数据失败,脚本配置不支持,请核实。");
} }
} else {
// 非谐波的需要区分是否为ABC相还是T相
if (PowerConstant.THREE_PHASE.contains(scriptCode)) { /**
if (valueTypeList.size() == 1) { * T相的相关数据处理非暂态数据
// 获取该三相的数据 * 包含:三相电压/电流不平衡度、频率,其中三相电压/电流实际ABC中存了正序/负序/零序电压
SingleNonHarmParam param = new SingleNonHarmParam(Integer.parseInt(planCode), devId, lineNo, valueTypeList, indexList); *
List<AdNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param); * @param singleResult 可能是谐波类,也有可能是电压电流,需要区分下结果
// 三相的数据通常包含standard、standardA、standardB、standardC、testA、testB、testC、errorA、errorB、errorC、resultA、resultB、resultC、result、errorScope * @param timeInt 谐波类需要传指定次数
if (CollUtil.isNotEmpty(nonHarmList)) { * @param keyFillMap 待填充的集合Map
List<Map<String, String>> keyFillMapList = new ArrayList<>(); */
for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) { private void fillTPhaseData(Object singleResult, Integer timeInt, Map<String, String> keyFillMap) {
Map<String, String> keyFillMap = new HashMap<>(16); String standard = "/", test = "/", error = "/", result = "/", errorScope = "/", unit = "";
DetectionData tempA = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_A); DetectionData tempT = getResultData(singleResult, timeInt, PowerConstant.PHASE_T);
DetectionData tempB = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_B); if (Objects.nonNull(tempT) && PowerConstant.DATA_RANGE.contains(tempT.getIsData())) {
DetectionData tempC = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_C); standard = PubUtils.doubleRoundStr(4, tempT.getResultData());
// 待填充Key test = PubUtils.doubleRoundStr(4, tempT.getData());
String standard = "/", standardA = "/", standardB = "/", standardC = "/", error = PubUtils.doubleRoundStr(4, tempT.getErrorData().doubleValue());
testA = "/", testB = "/", testC = "/", result = tempT.getIsData() == 1 ? "合格" : "不合格";
errorA = "/", errorB = "/", errorC = "/", unit = tempT.getUnit();
resultA = "/", resultB = "/", resultC = "/", result = "/", errorScope = tempT.getRadius();
errorScope = "/", unit = "";
if (Objects.nonNull(tempA) && (PowerConstant.DATA_RANGE.contains(tempA.getIsData()))) {
standardA = PubUtils.doubleRoundStr(4, tempA.getResultData());
testA = PubUtils.doubleRoundStr(4, tempA.getData());
errorA = PubUtils.doubleRoundStr(4, tempA.getErrorData().doubleValue());
resultA = tempA.getIsData() == 1 ? "合格" : "不合格";
errorScope = tempA.getRadius();
unit = tempA.getUnit();
standard = PubUtils.doubleRoundStr(4, tempA.getResultData());
} }
if (Objects.nonNull(tempB) && (PowerConstant.DATA_RANGE.contains(tempB.getIsData()))) {
standardB = PubUtils.doubleRoundStr(4, tempB.getResultData());
testB = PubUtils.doubleRoundStr(4, tempB.getData());
errorB = PubUtils.doubleRoundStr(4, tempB.getErrorData().doubleValue());
resultB = tempB.getIsData() == 1 ? "合格" : "不合格";
if (errorScope.equals("/")) {
errorScope = tempB.getRadius();
}
if (StrUtil.isBlank(unit)) {
unit = tempB.getUnit();
}
if (standard.equals("/")) {
standard = PubUtils.doubleRoundStr(4, tempB.getResultData());
}
}
if (Objects.nonNull(tempC) && (PowerConstant.DATA_RANGE.contains(tempC.getIsData()))) {
standardC = PubUtils.doubleRoundStr(4, tempC.getResultData());
testC = PubUtils.doubleRoundStr(4, tempC.getData());
errorC = PubUtils.doubleRoundStr(4, tempC.getErrorData().doubleValue());
resultC = tempC.getIsData() == 1 ? "合格" : "不合格";
if (errorScope.equals("/")) {
errorScope = tempC.getRadius();
}
if (StrUtil.isBlank(unit)) {
unit = tempC.getUnit();
}
if (standard.equals("/")) {
standard = PubUtils.doubleRoundStr(4, tempC.getResultData());
}
}
if (standardA.equals(standardB) && standardA.equals(standardC)) {
standard = standardA;
}
// 标准值
keyFillMap.put(ItemReportKeyEnum.STANDARD.getKey(), standard); keyFillMap.put(ItemReportKeyEnum.STANDARD.getKey(), standard);
keyFillMap.put(ItemReportKeyEnum.STANDARD_A.getKey(), standardA); keyFillMap.put(ItemReportKeyEnum.TEST.getKey(), test);
keyFillMap.put(ItemReportKeyEnum.STANDARD_B.getKey(), standardB); keyFillMap.put(ItemReportKeyEnum.ERROR.getKey(), error);
keyFillMap.put(ItemReportKeyEnum.STANDARD_C.getKey(), standardC);
// 测试值
keyFillMap.put(ItemReportKeyEnum.TEST_A.getKey(), testA);
keyFillMap.put(ItemReportKeyEnum.TEST_B.getKey(), testB);
keyFillMap.put(ItemReportKeyEnum.TEST_C.getKey(), testC);
// 误差值
keyFillMap.put(ItemReportKeyEnum.ERROR_A.getKey(), errorA);
keyFillMap.put(ItemReportKeyEnum.ERROR_B.getKey(), errorB);
keyFillMap.put(ItemReportKeyEnum.ERROR_C.getKey(), errorC);
// 结果
keyFillMap.put(ItemReportKeyEnum.RESULT_A.getKey(), resultA);
keyFillMap.put(ItemReportKeyEnum.RESULT_B.getKey(), resultB);
keyFillMap.put(ItemReportKeyEnum.RESULT_C.getKey(), resultC);
if (resultA.equals("不合格") || resultB.equals("不合格") || resultC.equals("不合格")) {
result = "不合格";
} else if (!resultA.equals("/") || !resultB.equals("/") || !resultC.equals("/")) {
result = "合格";
}
keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result); keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result);
errorScope = dealErrorScope(errorScope).concat(unit); errorScope = dealErrorScope(errorScope).concat(unit);
keyFillMap.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope); keyFillMap.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope);
keyFillMapList.add(keyFillMap);
} }
// 需要对所有的填充进行按误差范围分组
Map<String, List<Map<String, String>>> errorScoperMap = keyFillMapList.stream() /**
.collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()))); * 针对暂态的数据填充
// 分组后,还需要针对标准值进行一个升序 *
errorScoperMap.forEach((errorScope, maps) -> { * @param nonHarmList 暂态的结果集
PubUtils.sortByDoubleValue(maps, ItemReportKeyEnum.STANDARD.getKey()); * @param keyFillMap 待填充的集合Map
}); * @param tableKeys 模板表格中的key
List<Map<String, List<Map<String, String>>>> errorList = new ArrayList<>(); */
errorList.add(errorScoperMap); private void fillVoltagePhaseData(List<AdNonHarmonicResult> nonHarmList, Map<String, String> keyFillMap, List<String> tableKeys) {
// 最后赋值返回
finalContent.put(affectName, errorList);
} else {
log.error("生成三相类表格数据失败,结果表数据丢失,请核实。");
}
} else {
log.error("生成三相类表格数据失败,脚本配置不支持,请核实。");
throw new BusinessException("生成三相类表格数据失败,脚本配置不支持,请核实。");
}
} else {
// 非三相的还需要特殊处理下暂态的
if (PowerConstant.VOLTAGE.equalsIgnoreCase(scriptCode)) {
// 暂态的valueType通常只有2个一个特征幅值一个持续时间
List<Map<String, String>> keyFillMapList = new ArrayList<>();
for (Integer sort : indexList) {
SingleNonHarmParam param = new SingleNonHarmParam(Integer.parseInt(planCode), devId, lineNo, valueTypeList, Collections.singletonList(sort));
List<AdNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
// 暂态的数据通常包含standardMag、standardDur、testMag、testDur、errorMag、errorDur、resultMag、resultDur、result、errorScope、errorScopeMag、errorScopeDur
if (CollUtil.isNotEmpty(nonHarmList)) {
String standardMag = "/", standardDur = "/", String standardMag = "/", standardDur = "/",
testMag = "/", testDur = "/", testMag = "/", testDur = "/",
errorMag = "/", errorDur = "/", errorMag = "/", errorDur = "/",
resultMag = "/", resultDur = "/", result, resultMag = "/", resultDur = "/", result,
errorScope, errorScopeMag = "/", errorScopeDur = "/", errorScope, errorScopeMag = "/", errorScopeDur = "/",
unitMag = "", unitDur = ""; unitMag = "", unitDur = "";
Map<String, String> keyFillMap = new HashMap<>(16);
for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) { for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) {
DetectionData tempT = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_T); DetectionData tempT = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_T);
// 需要判断adNonHarmonicResult是特征幅值还是持续时间 // 需要判断adNonHarmonicResult是特征幅值还是持续时间
@@ -1243,8 +1286,8 @@ public class ResultServiceImpl implements IResultService {
if (!errorDur.equalsIgnoreCase("/")) { if (!errorDur.equalsIgnoreCase("/")) {
errorDur = PubUtils.doubleRoundStr(4, Double.parseDouble(errorDur) * 1000); errorDur = PubUtils.doubleRoundStr(4, Double.parseDouble(errorDur) * 1000);
} }
if(!errorScopeDur.equalsIgnoreCase("/")){ if (!errorScopeDur.equalsIgnoreCase("/")) {
if(errorScopeDur.contains("~")){ if (errorScopeDur.contains("~")) {
String[] tempStr = errorScopeDur.split("~"); String[] tempStr = errorScopeDur.split("~");
errorScopeDur = PubUtils.doubleRoundStr(0, Double.parseDouble(tempStr[0]) * 1000).concat("~").concat(PubUtils.doubleRoundStr(0, Double.parseDouble(tempStr[1]) * 1000)); errorScopeDur = PubUtils.doubleRoundStr(0, Double.parseDouble(tempStr[0]) * 1000).concat("~").concat(PubUtils.doubleRoundStr(0, Double.parseDouble(tempStr[1]) * 1000));
} }
@@ -1278,75 +1321,8 @@ public class ResultServiceImpl implements IResultService {
} }
} }
keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result); keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result);
keyFillMapList.add(keyFillMap);
}
}
// 需要对所有填充进行按误差范围分组
Map<String, List<Map<String, String>>> errorScoperMap = keyFillMapList.stream()
.collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey())));
// 分组后,还需要针对特征幅值标准值进行一个升序
errorScoperMap.forEach((errorScope, maps) -> {
PubUtils.sortByDoubleValue(maps, ItemReportKeyEnum.STANDARD_MAG.getKey());
});
List<Map<String, List<Map<String, String>>>> errorList = new ArrayList<>();
errorList.add(errorScoperMap);
// 最后赋值返回
finalContent.put(affectName, errorList);
} else {
// 非三相且非暂态,通常只有一个数据,所以直接赋值即可
List<Map<String, String>> keyFillMapList = new ArrayList<>();
SingleNonHarmParam param = new SingleNonHarmParam(Integer.parseInt(planCode), devId, lineNo, valueTypeList, indexList);
List<AdNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
if (CollUtil.isNotEmpty(nonHarmList)) {
for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) {
String standard = "/", test = "/", error = "/", result = "/", errorScope = "/",unit = "";
Map<String, String> keyFillMap = new HashMap<>(8);
DetectionData tempT = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_T);
if (Objects.nonNull(tempT) && PowerConstant.DATA_RANGE.contains(tempT.getIsData())) {
standard = PubUtils.doubleRoundStr(4, tempT.getResultData());
test = PubUtils.doubleRoundStr(4, tempT.getData());
error = PubUtils.doubleRoundStr(4, tempT.getErrorData().doubleValue());
result = tempT.getIsData() == 1 ? "合格" : "不合格";
unit = tempT.getUnit();
errorScope = tempT.getRadius();
}
keyFillMap.put(ItemReportKeyEnum.STANDARD.getKey(), standard);
keyFillMap.put(ItemReportKeyEnum.TEST.getKey(), test);
keyFillMap.put(ItemReportKeyEnum.ERROR.getKey(), error);
keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result);
errorScope = dealErrorScope(errorScope).concat(unit);
keyFillMap.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope);
keyFillMapList.add(keyFillMap);
}
}
// 需要对所有填充进行按误差范围分组
Map<String, List<Map<String, String>>> errorScoperMap = keyFillMapList.stream()
.collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey())));
// 分组后,还需要针对特征幅值标准值进行一个升序
errorScoperMap.forEach((errorScope, maps) -> {
PubUtils.sortByDoubleValue(maps, ItemReportKeyEnum.STANDARD.getKey());
});
List<Map<String, List<Map<String, String>>>> errorList = new ArrayList<>();
errorList.add(errorScoperMap);
// 最后赋值返回
finalContent.put(affectName, errorList);
}
}
}
} else {
log.error("未找到合适的脚本信息");
}
} else {
log.error("未找到合适的测量条件");
}
});
} }
// 返回之前做下总结性判断
singleTestResult.setQualified(judgeQualified(finalContent));
singleTestResult.setDetail(finalContent);
return singleTestResult;
}
/** /**
* 处理下误差范围,如果正负数一致时调整为±的形式 * 处理下误差范围,如果正负数一致时调整为±的形式