浙江报告与日志功能
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
package com.njcn.gather.result.service;
|
||||
|
||||
import com.njcn.gather.report.pojo.result.SingleTestResult;
|
||||
import com.njcn.gather.result.pojo.param.ResultParam;
|
||||
import com.njcn.gather.result.pojo.vo.FormContentVO;
|
||||
import com.njcn.gather.result.pojo.vo.ResultVO;
|
||||
import com.njcn.gather.result.pojo.vo.TreeDataVO;
|
||||
import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -75,4 +78,22 @@ public interface IResultService {
|
||||
* @param param
|
||||
*/
|
||||
void reCalculate(ResultParam.ChangeErrorSystemParam param);
|
||||
|
||||
/**
|
||||
* 获取某测试大项的检测项内容
|
||||
*
|
||||
* @param checkDataVOList 检测项脚本
|
||||
* @param planCode 计划编号
|
||||
* @param devId 被检设备id
|
||||
* @param lineNo 回路号
|
||||
* @param tableKeys 表格key
|
||||
*/
|
||||
SingleTestResult getFinalContent(List<PqScriptDtlDataVO> checkDataVOList, String planCode, String devId, Integer lineNo, List<String> tableKeys);
|
||||
|
||||
/**
|
||||
* 获取段落中指定的key对应的值
|
||||
* @param itemCode 测试大项code
|
||||
* @param pKeys 待填充的值
|
||||
*/
|
||||
Map<String, String> getParagraphKeysValue(String itemCode, List<String> pKeys);
|
||||
}
|
||||
|
||||
@@ -4,20 +4,30 @@ import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.text.StrPool;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.po.DevData;
|
||||
import com.njcn.gather.detection.pojo.vo.DetectionData;
|
||||
import com.njcn.gather.detection.service.impl.DetectionServiceImpl;
|
||||
import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.service.IAdPlanService;
|
||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||
import com.njcn.gather.report.pojo.constant.PowerConstant;
|
||||
import com.njcn.gather.report.pojo.enums.AffectEnum;
|
||||
import com.njcn.gather.report.pojo.enums.ItemReportKeyEnum;
|
||||
import com.njcn.gather.report.pojo.enums.PowerIndexEnum;
|
||||
import com.njcn.gather.report.pojo.result.SingleTestResult;
|
||||
import com.njcn.gather.result.pojo.enums.ResultUnitEnum;
|
||||
import com.njcn.gather.result.pojo.param.ResultParam;
|
||||
import com.njcn.gather.result.pojo.vo.FormContentVO;
|
||||
@@ -30,10 +40,12 @@ import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
||||
import com.njcn.gather.script.pojo.po.PqScriptCheckData;
|
||||
import com.njcn.gather.script.pojo.po.PqScriptDtls;
|
||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||
import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO;
|
||||
import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
||||
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.script.util.ScriptDtlsDesc;
|
||||
import com.njcn.gather.storage.mapper.TableGenMapper;
|
||||
import com.njcn.gather.storage.pojo.param.SingleNonHarmParam;
|
||||
import com.njcn.gather.storage.pojo.param.StorageParam;
|
||||
import com.njcn.gather.storage.pojo.po.AdBaseResult;
|
||||
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
|
||||
@@ -910,6 +922,528 @@ public class ResultServiceImpl implements IResultService {
|
||||
this.calculateResult(param.getPlanId(), param.getScriptId(), param.getCode(), param.getErrorSysId(), param.getDeviceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某测试大项的检测项内容,主要针对表格需要填充的值
|
||||
* 注:虽然测试项区是三相,他们的标准值可能不同,但是误差范围是一致的
|
||||
* 1、区分额定条件、单影响量条件、单影响量条件
|
||||
* 2、区分scriptIndex
|
||||
* 3、区分谐波次数(有必要的情况下)
|
||||
*
|
||||
* @param dtlDataVOList 检测项脚本
|
||||
* @param planCode 计划编号
|
||||
* @param devId 被检设备id
|
||||
* @param lineNo 回路号
|
||||
* @param tableKeys 表格key
|
||||
*/
|
||||
@Override
|
||||
public SingleTestResult getFinalContent(List<PqScriptDtlDataVO> dtlDataVOList, String planCode, String devId, Integer lineNo, List<String> tableKeys) {
|
||||
SingleTestResult singleTestResult = new SingleTestResult();
|
||||
Map<String/*subType影响量,额定或某单影响量*/, List<Map<String/*误差范围*/, List<Map<String/*填充key*/, String/*实际值*/>>>>> finalContent = new HashMap<>();
|
||||
if (CollUtil.isNotEmpty(dtlDataVOList)) {
|
||||
// 首先区分测试条件
|
||||
Map<String, List<PqScriptDtlDataVO>> subTypeMap = dtlDataVOList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptSubType));
|
||||
subTypeMap.forEach((subType, scriptDtlDataVOList) -> {
|
||||
AffectEnum affectEnum = AffectEnum.getByKey(subType);
|
||||
if (Objects.nonNull(affectEnum)) {
|
||||
String scriptCode = scriptDtlDataVOList.get(0).getScriptCode();
|
||||
String scriptId = scriptDtlDataVOList.get(0).getScriptId();
|
||||
PowerIndexEnum indexEnum = PowerIndexEnum.getByKey(scriptCode);
|
||||
if (Objects.nonNull(indexEnum)) {
|
||||
String affectName = affectEnum.getDesc().replaceAll("XX", indexEnum.getDesc());
|
||||
// 同一个影响量下,获取出子脚本信息
|
||||
List<Integer> indexList = scriptDtlDataVOList.stream().map(PqScriptDtlDataVO::getScriptIndex).distinct().collect(Collectors.toList());
|
||||
List<PqScriptCheckData> scriptCheckDataList = pqScriptCheckDataService.listCheckData(scriptId, indexList);
|
||||
List<String> valueTypeList = scriptCheckDataList.stream().map(PqScriptCheckData::getValueType).distinct().collect(Collectors.toList());
|
||||
// 查询检测结果,区分下表。
|
||||
if (PowerConstant.TIME.contains(scriptCode)) {
|
||||
// 谐波的测试项,肯定是三相的,可能会存在多次的,本处要填充的key全集为:time、standard、standardA、standardB、standardC、testA、testB、testC、errorA、errorB、errorC、result
|
||||
// 查询结果数据,经过上层处理谐波类此处的scriptIndex确保只有一个
|
||||
if (indexList.size() == 1 && valueTypeList.size() == 1) {
|
||||
// 获取谐波数据
|
||||
SingleNonHarmParam param = new SingleNonHarmParam(Integer.parseInt(planCode), devId, lineNo, valueTypeList.get(0), indexList.get(0));
|
||||
AdHarmonicResult singleResult = adHarmonicService.getSingleResult(param);
|
||||
// 注:如果ABC的标准值一致,则同步到standard中
|
||||
Map<Double, List<PqScriptCheckData>> checkDataHarmNumMap = scriptCheckDataList.stream().collect(Collectors.groupingBy(PqScriptCheckData::getHarmNum));
|
||||
List<Map<String, String>> keyFillMapList = new ArrayList<>();
|
||||
checkDataHarmNumMap.forEach((harmNum, dtlsList) -> {
|
||||
Map<String, String> keyFillMap = new HashMap<>();
|
||||
// 次数需要区分谐波&间谐波
|
||||
String time;
|
||||
if (harmNum % 1 == 0) {
|
||||
// 谐波,需要转为正数字符串
|
||||
time = String.valueOf(harmNum.intValue());
|
||||
} else {
|
||||
// 间谐波,保留小数位转为字符串
|
||||
time = String.format("%.1f", harmNum);
|
||||
}
|
||||
keyFillMap.put(ItemReportKeyEnum.TIME.getKey(), time);
|
||||
// 将间谐波次数取整1.5取2,2.5取3
|
||||
double timeDouble = Math.round(harmNum);
|
||||
int timeInt = (int) timeDouble;
|
||||
DetectionData tempA = getResultData(singleResult, timeInt, PowerConstant.PHASE_A);
|
||||
DetectionData tempB = getResultData(singleResult, timeInt, PowerConstant.PHASE_B);
|
||||
DetectionData tempC = getResultData(singleResult, timeInt, PowerConstant.PHASE_C);
|
||||
// 待填充Key
|
||||
String standard = "/", standardA = "/", standardB = "/", standardC = "/",
|
||||
testA = "/", testB = "/", testC = "/",
|
||||
errorA = "/", errorB = "/", errorC = "/",
|
||||
resultA = "/", resultB = "/", resultC = "/", result = "/",
|
||||
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_A.getKey(), standardA);
|
||||
keyFillMap.put(ItemReportKeyEnum.STANDARD_B.getKey(), standardB);
|
||||
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);
|
||||
errorScope = dealErrorScope(errorScope).concat(unit);
|
||||
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) {
|
||||
// 获取该三相的数据
|
||||
SingleNonHarmParam param = new SingleNonHarmParam(Integer.parseInt(planCode), devId, lineNo, valueTypeList, indexList);
|
||||
List<AdNonHarmonicResult> nonHarmList = adNonHarmonicService.queryByCondition(param);
|
||||
// 三相的数据通常包含:standard、standardA、standardB、standardC、testA、testB、testC、errorA、errorB、errorC、resultA、resultB、resultC、result、errorScope
|
||||
if (CollUtil.isNotEmpty(nonHarmList)) {
|
||||
List<Map<String, String>> keyFillMapList = new ArrayList<>();
|
||||
for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) {
|
||||
Map<String, String> keyFillMap = new HashMap<>(16);
|
||||
DetectionData tempA = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_A);
|
||||
DetectionData tempB = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_B);
|
||||
DetectionData tempC = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_C);
|
||||
// 待填充Key
|
||||
String standard = "/", standardA = "/", standardB = "/", standardC = "/",
|
||||
testA = "/", testB = "/", testC = "/",
|
||||
errorA = "/", errorB = "/", errorC = "/",
|
||||
resultA = "/", resultB = "/", resultC = "/", result = "/",
|
||||
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_A.getKey(), standardA);
|
||||
keyFillMap.put(ItemReportKeyEnum.STANDARD_B.getKey(), standardB);
|
||||
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);
|
||||
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("生成三相类表格数据失败,脚本配置不支持,请核实。");
|
||||
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 = "/",
|
||||
testMag = "/", testDur = "/",
|
||||
errorMag = "/", errorDur = "/",
|
||||
resultMag = "/", resultDur = "/", result,
|
||||
errorScope, errorScopeMag = "/", errorScopeDur = "/",
|
||||
unitMag = "", unitDur = "";
|
||||
Map<String, String> keyFillMap = new HashMap<>(16);
|
||||
for (AdNonHarmonicResult adNonHarmonicResult : nonHarmList) {
|
||||
DetectionData tempT = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_T);
|
||||
// 需要判断adNonHarmonicResult是特征幅值还是持续时间
|
||||
String adType = adNonHarmonicResult.getAdType();
|
||||
DictTree temp = dictTreeService.getById(adType);
|
||||
if (temp.getCode().equalsIgnoreCase("MAG")) {
|
||||
// 特征幅值
|
||||
if (Objects.nonNull(tempT) && PowerConstant.DATA_RANGE.contains(tempT.getIsData())) {
|
||||
standardMag = PubUtils.doubleRoundStr(4, tempT.getResultData());
|
||||
testMag = PubUtils.doubleRoundStr(4, tempT.getData());
|
||||
errorMag = PubUtils.doubleRoundStr(4, tempT.getErrorData().doubleValue());
|
||||
resultMag = tempT.getIsData() == 1 ? "合格" : "不合格";
|
||||
unitMag = tempT.getUnit();
|
||||
errorScopeMag = tempT.getRadius();
|
||||
}
|
||||
} else if (temp.getCode().equalsIgnoreCase("DUR")) {
|
||||
// 持续时间,需要注意时间单位处理,默认是秒
|
||||
String timeUnit = "s";
|
||||
for (String tableKey : tableKeys) {
|
||||
if (tableKey.contains(ItemReportKeyEnum.STANDARD_DUR.getKey())) {
|
||||
//截取单位
|
||||
String[] tempStr = tableKey.split(StrPool.UNDERLINE);
|
||||
if (tempStr.length > 1) {
|
||||
if (tempStr[1].equalsIgnoreCase("ms")) {
|
||||
timeUnit = "ms";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
standardDur = PubUtils.doubleRoundStr(4, tempT.getResultData());
|
||||
testDur = PubUtils.doubleRoundStr(4, tempT.getData());
|
||||
errorDur = PubUtils.doubleRoundStr(4, tempT.getErrorData().doubleValue());
|
||||
resultDur = tempT.getIsData() == 1 ? "合格" : "不合格";
|
||||
unitDur = tempT.getUnit();
|
||||
errorScopeDur = tempT.getRadius();
|
||||
if (timeUnit.equalsIgnoreCase("ms")) {
|
||||
// 如果是ms,上述的一些数据需要重新处理
|
||||
if (!standardDur.equalsIgnoreCase("/")) {
|
||||
standardDur = PubUtils.doubleRoundStr(4, Double.parseDouble(standardDur) * 1000);
|
||||
}
|
||||
if (!testDur.equalsIgnoreCase("/")) {
|
||||
testDur = PubUtils.doubleRoundStr(4, Double.parseDouble(testDur) * 1000);
|
||||
}
|
||||
if (!errorDur.equalsIgnoreCase("/")) {
|
||||
errorDur = PubUtils.doubleRoundStr(4, Double.parseDouble(errorDur) * 1000);
|
||||
}
|
||||
if(!errorScopeDur.equalsIgnoreCase("/")){
|
||||
if(errorScopeDur.contains("~")){
|
||||
String[] tempStr = errorScopeDur.split("~");
|
||||
errorScopeDur = PubUtils.doubleRoundStr(0, Double.parseDouble(tempStr[0]) * 1000).concat("~").concat(PubUtils.doubleRoundStr(0, Double.parseDouble(tempStr[1]) * 1000));
|
||||
}
|
||||
}
|
||||
unitDur = "ms";
|
||||
}
|
||||
}
|
||||
}
|
||||
errorScopeMag = dealErrorScope(errorScopeMag).concat(unitMag);
|
||||
errorScopeDur = dealErrorScope(errorScopeDur).concat(unitDur);
|
||||
|
||||
errorScope = "特征幅值:".concat(errorScopeMag).concat(StrPool.COMMA).concat("持续时间:").concat(errorScopeDur);
|
||||
keyFillMap.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope);
|
||||
// 标准值
|
||||
keyFillMap.put(ItemReportKeyEnum.STANDARD_MAG.getKey(), standardMag);
|
||||
keyFillMap.put(ItemReportKeyEnum.STANDARD_DUR.getKey(), standardDur);
|
||||
// 测试值
|
||||
keyFillMap.put(ItemReportKeyEnum.TEST_MAG.getKey(), testMag);
|
||||
keyFillMap.put(ItemReportKeyEnum.TEST_DUR.getKey(), testDur);
|
||||
// 误差
|
||||
keyFillMap.put(ItemReportKeyEnum.ERROR_MAG.getKey(), errorMag);
|
||||
keyFillMap.put(ItemReportKeyEnum.ERROR_DUR.getKey(), errorDur);
|
||||
// 结果
|
||||
keyFillMap.put(ItemReportKeyEnum.RESULT_MAG.getKey(), resultMag);
|
||||
keyFillMap.put(ItemReportKeyEnum.RESULT_DUR.getKey(), resultDur);
|
||||
// 综合结果
|
||||
result = resultMag;
|
||||
if (!resultDur.equals("/") && result.equals("合格")) {
|
||||
if (resultDur.equals("不合格")) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理下误差范围,如果正负数一致时调整为±的形式
|
||||
* 数据库中一般形式为:-0.1155~0.1155
|
||||
*
|
||||
* @param errorScope 误差范围
|
||||
*/
|
||||
private String dealErrorScope(String errorScope) {
|
||||
if (errorScope.contains("~")) {
|
||||
String[] split = errorScope.split("~");
|
||||
String begin = split[0];
|
||||
if (begin.contains(StrPool.DASHED)) {
|
||||
begin = begin.substring(1);
|
||||
}
|
||||
String end = split[1];
|
||||
if (end.equalsIgnoreCase(begin)) {
|
||||
return "±" + begin;
|
||||
}
|
||||
}
|
||||
return errorScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历所有的结果,是否存在不合格,但凡有一个不合格就返回false
|
||||
*
|
||||
* @param finalContent 最终结果
|
||||
*/
|
||||
private boolean judgeQualified(Map<String, List<Map<String, List<Map<String, String>>>>> finalContent) {
|
||||
List<String> results = finalContent.values().parallelStream()
|
||||
.flatMap(List::stream)
|
||||
.flatMap(m -> m.values().stream())
|
||||
.flatMap(List::stream)
|
||||
.filter(map -> map.containsKey(ItemReportKeyEnum.RESULT.getKey()))
|
||||
.map(map -> map.get(ItemReportKeyEnum.RESULT.getKey()))
|
||||
.collect(Collectors.toList());
|
||||
List<String> qualifiedList = results.stream().filter("不合格"::equals).collect(Collectors.toList());
|
||||
return CollUtil.isEmpty(qualifiedList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据谐波结果数据获取局的测试数据
|
||||
*
|
||||
* @param singleResult 谐波数据
|
||||
* @param timeInt 次数
|
||||
* @param phaseA 相别
|
||||
*/
|
||||
private DetectionData getResultData(Object singleResult, Integer timeInt, String phaseA) {
|
||||
String fieldName = phaseA.toLowerCase().concat("Value");
|
||||
if (Objects.nonNull(timeInt)) {
|
||||
fieldName = fieldName.concat(String.valueOf(timeInt));
|
||||
}
|
||||
String filedValue;
|
||||
try {
|
||||
filedValue = (String) ReflectUtil.getFieldValue(singleResult, fieldName);
|
||||
} catch (Exception exception) {
|
||||
throw new BusinessException("获取对象字段属性失败");
|
||||
}
|
||||
return JSONUtil.toBean(filedValue, DetectionData.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取段落中指定的key对应的值,目前主要为测试大项名称服务,通过code匹配
|
||||
*
|
||||
* @param itemCode 测试大项code
|
||||
* @param pKeys 待填充的值
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> getParagraphKeysValue(String itemCode, List<String> pKeys) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (CollUtil.isNotEmpty(pKeys)) {
|
||||
for (String pKey : pKeys) {
|
||||
ItemReportKeyEnum reportKeyEnum = ItemReportKeyEnum.getByKey(pKey);
|
||||
if (Objects.nonNull(reportKeyEnum)) {
|
||||
if (reportKeyEnum.getKey().equals(ItemReportKeyEnum.NAME.getKey())) {
|
||||
PowerIndexEnum indexEnum = PowerIndexEnum.getByKey(itemCode);
|
||||
if (Objects.nonNull(indexEnum)) {
|
||||
map.put(reportKeyEnum.getKey(), indexEnum.getDesc());
|
||||
} else {
|
||||
log.error("电能指标枚举未找到测试项");
|
||||
}
|
||||
} else if (reportKeyEnum.getKey().equals(ItemReportKeyEnum.NAME_DETAIL.getKey())) {
|
||||
PowerIndexEnum indexEnum = PowerIndexEnum.getByKey(itemCode);
|
||||
if (Objects.nonNull(indexEnum)) {
|
||||
map.put(reportKeyEnum.getKey(), indexEnum.getDesc().concat("测量准确度"));
|
||||
} else {
|
||||
log.error("电能指标枚举未找到测试项");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.error("段落枚举未找到占用符");
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private Integer conform(Set<Integer> numbers) {
|
||||
if (CollUtil.isNotEmpty(numbers)) {
|
||||
if (numbers.size() > 1) {
|
||||
|
||||
Reference in New Issue
Block a user