diff --git a/detection/src/main/java/com/njcn/gather/report/pojo/enums/BaseReportKeyEnum.java b/detection/src/main/java/com/njcn/gather/report/pojo/enums/BaseReportKeyEnum.java index e63ac024..c027b54b 100644 --- a/detection/src/main/java/com/njcn/gather/report/pojo/enums/BaseReportKeyEnum.java +++ b/detection/src/main/java/com/njcn/gather/report/pojo/enums/BaseReportKeyEnum.java @@ -17,9 +17,11 @@ public enum BaseReportKeyEnum { DEV_TYPE("devType","设备型号、规格"), DEV_CODE("createId","装置编号"), + DEV_NAME("devName","装置名称"), POWER("power","工作电源"), DEV_CURR("devCurr","额定电流"), DEV_VOLT("devVolt","额定电压"), + SOURCE_NAME("sourceName","检测源名称"), COUNT("count","通道数"), MANUFACTURER("manufacturer","设备厂家、制造厂商"), SAMPLE_ID("sampleId","样品编号"), diff --git a/detection/src/main/java/com/njcn/gather/report/service/impl/PqReportServiceImpl.java b/detection/src/main/java/com/njcn/gather/report/service/impl/PqReportServiceImpl.java index cd877acc..b47ea913 100644 --- a/detection/src/main/java/com/njcn/gather/report/service/impl/PqReportServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/report/service/impl/PqReportServiceImpl.java @@ -47,6 +47,7 @@ import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum; import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlanTestConfig; import com.njcn.gather.plan.service.IAdPlanService; +import com.njcn.gather.plan.service.IAdPlanSourceService; import com.njcn.gather.plan.service.IAdPlanTestConfigService; import com.njcn.gather.pojo.enums.DetectionResponseEnum; import com.njcn.gather.report.mapper.PqReportMapper; @@ -62,6 +63,7 @@ import com.njcn.gather.report.service.IPqReportService; import com.njcn.gather.result.service.IResultService; import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO; import com.njcn.gather.script.service.IPqScriptDtlsService; +import com.njcn.gather.source.pojo.po.PqSource; import com.njcn.gather.storage.pojo.param.SingleNonHarmParam; import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult; import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult; @@ -185,6 +187,7 @@ public class PqReportServiceImpl extends ServiceImpl i private final IPqDevSubService iPqDevSubService; private final IDictDataService dictDataService; private final IAdPlanService adPlanService; + private final IAdPlanSourceService adPlanSourceService; private final IPqScriptDtlsService pqScriptDtlsService; private final SimAndDigNonHarmonicService adNonHarmonicService; private final SimAndDigHarmonicService adHarmonicService; @@ -913,6 +916,10 @@ public class PqReportServiceImpl extends ServiceImpl i WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream); // 获取文档基础部分,并替换占位符 Map baseModelDataMap = dealBaseModelData(pqDevVO, devType); + // 补充检测源名称:计划↔源走 ad_plan_source 中间表(业务上单源),datasourceId 是数据源类型枚举、不指向 pq_source + List planSources = adPlanSourceService.listPqSourceByPlanId(plan.getId()); + baseModelDataMap.put(BaseReportKeyEnum.SOURCE_NAME.getKey(), + CollUtil.isNotEmpty(planSources) ? planSources.get(0).getName() : StrUtil.EMPTY); InputStream wordFinishInputStream = wordReportService.replacePlaceholders(baseInputStream, baseModelDataMap); WordprocessingMLPackage baseModelDocument = WordprocessingMLPackage.load(wordFinishInputStream); MainDocumentPart baseDocumentPart = baseModelDocument.getMainDocumentPart(); @@ -2123,6 +2130,7 @@ public class PqReportServiceImpl extends ServiceImpl i } // 装置编码 baseModelMap.put(BaseReportKeyEnum.DEV_CODE.getKey(), pqDevVO.getCreateId()); + baseModelMap.put(BaseReportKeyEnum.DEV_NAME.getKey(), StrUtil.isBlank(pqDevVO.getName()) ? StrPool.TAB : pqDevVO.getName()); // 工作电源 baseModelMap.put(BaseReportKeyEnum.POWER.getKey(), devType.getPower()); // 额定电流 @@ -2581,13 +2589,14 @@ public class PqReportServiceImpl extends ServiceImpl i List headingContents = contentMap.get(PowerIndexEnum.LINE_TITLE.getKey()); int lineNo = currentLine + 1; // 如果contentMap中有指定内容,创建大纲级别为2的标题 + // 回路标题恒带回路号(单回路也显示"测量回路1"),与结论表头"测量回路N"保持一致 if (CollUtil.isNotEmpty(headingContents)) { - return Docx4jUtil.createTitle(factory, 2, totalLine > 1 ? lineNo + ".测量回路" + lineNo : lineNo + ".测量回路", + return Docx4jUtil.createTitle(factory, 2, lineNo + ".测量回路" + lineNo, "SimSun", 30, true); } // 没有模板配置时,创建默认样式段落 P titleParagraph = factory.createP(); - Docx4jUtil.createTitle(factory, titleParagraph, totalLine > 1 ? "测量回路" + lineNo : "测量回路", + Docx4jUtil.createTitle(factory, titleParagraph, "测量回路" + lineNo, 28, true); return titleParagraph; } diff --git a/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java b/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java index 4208d021..e795ce9d 100644 --- a/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java @@ -1454,12 +1454,21 @@ public class ResultServiceImpl implements IResultService { for (Integer sort : indexList) { SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, valueTypeList, Collections.singletonList(sort)); List nonHarmList = simAndDigNonHarmonicService.queryByCondition(param); - if (CollUtil.isNotEmpty(nonHarmList)) { - Map keyFillMap = new HashMap<>(16); - fillVoltagePhaseData(nonHarmList, keyFillMap, tableKeys); + if (CollUtil.isEmpty(nonHarmList)) { + log.warn("生成暂态类表格数据跳过,结果表数据为空,planCode={}, devId={}, lineNo={}, scriptCode={}, scriptIndex={}", + planCode, devId, lineNo, scriptCode, sort); + continue; + } + Map keyFillMap = new HashMap<>(16); + if (fillVoltagePhaseData(nonHarmList, keyFillMap, tableKeys)) { keyFillMapList.add(keyFillMap); } } + if (CollUtil.isEmpty(keyFillMapList)) { + log.warn("生成暂态类表格数据跳过,当前脚本无可填充结果,planCode={}, devId={}, lineNo={}, scriptCode={}, scriptIndexList={}", + planCode, devId, lineNo, scriptCode, indexList); + return; + } // 需要对所有填充进行按误差范围分组 Map>> errorScoperMap = keyFillMapList.stream() .collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()))); @@ -1479,6 +1488,11 @@ public class ResultServiceImpl implements IResultService { // 获取谐波数据 SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, valueType, indexList.get(0)); SimAndDigHarmonicResult singleResult = simAndDigHarmonicService.getSingleResult(param); + if (Objects.isNull(singleResult)) { + log.warn("生成谐波类表格数据跳过,结果表数据为空,planCode={}, devId={}, lineNo={}, scriptCode={}, valueType={}, scriptIndex={}", + planCode, devId, lineNo, scriptCode, valueType, indexList.get(0)); + continue; + } // 注:如果ABC的标准值一致,则同步到standard中 Map> checkDataHarmNumMap = scriptCheckDataList.stream().collect(Collectors.groupingBy(PqScriptCheckData::getHarmNum)); List> keyFillMapList = new ArrayList<>(); @@ -1498,8 +1512,9 @@ public class ResultServiceImpl implements IResultService { double timeDouble = Math.round(harmNum); int timeInt = (int) timeDouble; // 填充结果数据 - fillThreePhaseData(singleResult, timeInt, keyFillMap, scriptCode); - keyFillMapList.add(keyFillMap); + if (fillThreePhaseData(singleResult, timeInt, keyFillMap, scriptCode)) { + keyFillMapList.add(keyFillMap); + } }); if (CollUtil.isNotEmpty(keyFillMapList)) { // 按次数排序 @@ -1522,38 +1537,44 @@ public class ResultServiceImpl implements IResultService { // 获取该三相的数据 SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, Collections.singletonList(valueType), indexList); List nonHarmList = simAndDigNonHarmonicService.queryByCondition(param); - if (CollUtil.isNotEmpty(nonHarmList)) { - List> keyFillMapList = new ArrayList<>(); - for (SimAndDigNonHarmonicResult SimAndDigNonHarmonicResult : nonHarmList) { - Map keyFillMap = new HashMap<>(16); - fillThreePhaseData(SimAndDigNonHarmonicResult, null, keyFillMap, scriptCode); + if (CollUtil.isEmpty(nonHarmList)) { + log.warn("生成三相类表格数据跳过,结果表数据为空,planCode={}, devId={}, lineNo={}, scriptCode={}, valueType={}, scriptIndexList={}", + planCode, devId, lineNo, scriptCode, valueType, indexList); + continue; + } + List> keyFillMapList = new ArrayList<>(); + for (SimAndDigNonHarmonicResult SimAndDigNonHarmonicResult : nonHarmList) { + Map keyFillMap = new HashMap<>(16); + if (fillThreePhaseData(SimAndDigNonHarmonicResult, null, keyFillMap, scriptCode)) { keyFillMapList.add(keyFillMap); } - if (CollUtil.isNotEmpty(keyFillMapList)) { - // 需要对所有的填充进行按误差范围分组 - Map>> errorScoperMap = keyFillMapList.stream() - .collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()))); - // 分组后,还需要针对标准值进行一个升序 - errorScoperMap.forEach((errorScope, maps) -> { - PubUtils.sortByDoubleValue(maps, ItemReportKeyEnum.STANDARD.getKey()); - }); - List>>> errorList = new ArrayList<>(); - errorList.add(errorScoperMap); - // 最后赋值返回 - finalContent.put(affectName, errorList); - } - } else { - log.error("生成三相类表格数据失败,结果表数据丢失,请核实。"); + } + if (CollUtil.isNotEmpty(keyFillMapList)) { + // 需要对所有的填充进行按误差范围分组 + Map>> errorScoperMap = keyFillMapList.stream() + .collect(Collectors.groupingBy(map -> map.get(ItemReportKeyEnum.ERROR_SCOPE.getKey()))); + // 分组后,还需要针对标准值进行一个升序 + errorScoperMap.forEach((errorScope, maps) -> { + PubUtils.sortByDoubleValue(maps, ItemReportKeyEnum.STANDARD.getKey()); + }); + List>>> errorList = new ArrayList<>(); + errorList.add(errorScoperMap); + // 最后赋值返回 + finalContent.put(affectName, errorList); } } else { // 非三相且非暂态,通常只有一个数据,所以直接赋值即可 List> keyFillMapList = new ArrayList<>(); SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, Collections.singletonList(valueType), indexList); List nonHarmList = simAndDigNonHarmonicService.queryByCondition(param); - if (CollUtil.isNotEmpty(nonHarmList)) { - for (SimAndDigNonHarmonicResult simAndDigNonHarmonicResult : nonHarmList) { - Map keyFillMap = new HashMap<>(8); - fillTPhaseData(simAndDigNonHarmonicResult, null, keyFillMap); + if (CollUtil.isEmpty(nonHarmList)) { + log.warn("生成T相类表格数据跳过,结果表数据为空,planCode={}, devId={}, lineNo={}, scriptCode={}, valueType={}, scriptIndexList={}", + planCode, devId, lineNo, scriptCode, valueType, indexList); + continue; + } + for (SimAndDigNonHarmonicResult simAndDigNonHarmonicResult : nonHarmList) { + Map keyFillMap = new HashMap<>(8); + if (fillTPhaseData(simAndDigNonHarmonicResult, null, keyFillMap)) { keyFillMapList.add(keyFillMap); } } @@ -1597,10 +1618,14 @@ public class ResultServiceImpl implements IResultService { * @param timeInt 谐波类需要传指定次数 * @param keyFillMap 待填充的集合Map */ - private void fillThreePhaseData(Object singleResult, Integer timeInt, Map keyFillMap, String scriptCode) { + private boolean fillThreePhaseData(Object singleResult, Integer timeInt, Map keyFillMap, String scriptCode) { +// boolean isCurrentI = "I".equalsIgnoreCase(scriptCode); DetectionData tempA = getResultData(singleResult, timeInt, PowerConstant.PHASE_A); DetectionData tempB = getResultData(singleResult, timeInt, PowerConstant.PHASE_B); DetectionData tempC = getResultData(singleResult, timeInt, PowerConstant.PHASE_C); + if (Objects.isNull(tempA) && Objects.isNull(tempB) && Objects.isNull(tempC)) { + return false; + } // 待填充Key String standard = "/", standardA = "/", standardB = "/", standardC = "/", testA = "/", testB = "/", testC = "/", @@ -1654,11 +1679,11 @@ public class ResultServiceImpl implements IResultService { } } // 浙江脚本特殊处理 - if (scriptCode.equalsIgnoreCase("I")) { - resultA = "/"; - resultB = "/"; - resultC = "/"; - } +// if (isCurrentI) { +// resultA = "/"; +// resultB = "/"; +// resultC = "/"; +// } if (standardA.equals(standardB) && standardA.equals(standardC)) { standard = standardA; } @@ -1690,6 +1715,7 @@ public class ResultServiceImpl implements IResultService { keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result); errorScope = dealErrorScope(errorScope).concat(unit); keyFillMap.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope); + return true; } /** @@ -1740,25 +1766,27 @@ public class ResultServiceImpl implements IResultService { * @param timeInt 谐波类需要传指定次数 * @param keyFillMap 待填充的集合Map */ - private void fillTPhaseData(Object singleResult, Integer timeInt, Map keyFillMap) { + private boolean fillTPhaseData(Object singleResult, Integer timeInt, Map keyFillMap) { String standard = "/", test = "/", error = "/", result = "/", errorScope = "/", unit = ""; DetectionData tempT = getResultData(singleResult, timeInt, PowerConstant.PHASE_T); - if (Objects.nonNull(tempT)) { - standard = PubUtils.doubleRoundStr(4, tempT.getResultData()) == null ? "/" : PubUtils.doubleRoundStr(4, tempT.getResultData()); - test = PubUtils.doubleRoundStr(4, tempT.getData()) == null ? "/" : PubUtils.doubleRoundStr(4, tempT.getData()); - if (Objects.nonNull(tempT.getErrorData())) { - error = PubUtils.doubleRoundStr(4, tempT.getErrorData().doubleValue()); - } - result = tempT.getIsData() == 1 ? "合格" : tempT.getIsData() == 2 ? "不合格" : "/"; - unit = tempT.getUnit() == null ? "" : tempT.getUnit(); - errorScope = tempT.getRadius() == null ? "/" : tempT.getRadius(); + if (Objects.isNull(tempT)) { + return false; } + standard = PubUtils.doubleRoundStr(4, tempT.getResultData()) == null ? "/" : PubUtils.doubleRoundStr(4, tempT.getResultData()); + test = PubUtils.doubleRoundStr(4, tempT.getData()) == null ? "/" : PubUtils.doubleRoundStr(4, tempT.getData()); + if (Objects.nonNull(tempT.getErrorData())) { + error = PubUtils.doubleRoundStr(4, tempT.getErrorData().doubleValue()); + } + result = tempT.getIsData() == 1 ? "合格" : tempT.getIsData() == 2 ? "不合格" : "/"; + unit = tempT.getUnit() == null ? "" : tempT.getUnit(); + errorScope = tempT.getRadius() == null ? "/" : 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); + return true; } /** @@ -1768,30 +1796,33 @@ public class ResultServiceImpl implements IResultService { * @param keyFillMap 待填充的集合Map * @param tableKeys 模板表格中的key */ - private void fillVoltagePhaseData(List nonHarmList, Map keyFillMap, List tableKeys) { + private boolean fillVoltagePhaseData(List nonHarmList, Map keyFillMap, List tableKeys) { String standardMag = "/", standardDur = "/", testMag = "/", testDur = "/", errorMag = "/", errorDur = "/", resultMag = "/", resultDur = "/", result, errorScope, errorScopeMag = "/", errorScopeDur = "/", unitMag = "", unitDur = ""; + boolean hasData = false; for (SimAndDigNonHarmonicResult adNonHarmonicResult : nonHarmList) { DetectionData tempT = getResultData(adNonHarmonicResult, null, PowerConstant.PHASE_T); + if (Objects.isNull(tempT)) { + continue; + } + hasData = true; // 需要判断adNonHarmonicResult是特征幅值还是持续时间 String adType = adNonHarmonicResult.getAdType(); DictTree temp = dictTreeService.getById(adType); if (temp.getCode().equalsIgnoreCase("MAG")) { // 特征幅值 - if (Objects.nonNull(tempT)) { - standardMag = PubUtils.doubleRoundStr(4, tempT.getResultData()) == null ? "/" : PubUtils.doubleRoundStr(4, tempT.getResultData()); - testMag = PubUtils.doubleRoundStr(4, tempT.getData()) == null ? "/" : PubUtils.doubleRoundStr(4, tempT.getData()); - if (Objects.nonNull(tempT.getErrorData())) { - errorMag = PubUtils.doubleRoundStr(4, tempT.getErrorData().doubleValue()); - } - resultMag = tempT.getIsData() == 1 ? "合格" : tempT.getIsData() == 2 ? "不合格" : "/"; - unitMag = tempT.getUnit(); - errorScopeMag = tempT.getRadius(); + standardMag = PubUtils.doubleRoundStr(4, tempT.getResultData()) == null ? "/" : PubUtils.doubleRoundStr(4, tempT.getResultData()); + testMag = PubUtils.doubleRoundStr(4, tempT.getData()) == null ? "/" : PubUtils.doubleRoundStr(4, tempT.getData()); + if (Objects.nonNull(tempT.getErrorData())) { + errorMag = PubUtils.doubleRoundStr(4, tempT.getErrorData().doubleValue()); } + resultMag = tempT.getIsData() == 1 ? "合格" : tempT.getIsData() == 2 ? "不合格" : "/"; + unitMag = tempT.getUnit(); + errorScopeMag = tempT.getRadius(); } else if (temp.getCode().equalsIgnoreCase("DUR")) { // 持续时间,需要注意时间单位处理,默认是秒 String timeUnit = "s"; @@ -1846,6 +1877,9 @@ public class ResultServiceImpl implements IResultService { } } } + if (!hasData) { + return false; + } errorScopeMag = dealErrorScope(errorScopeMag).concat(StrUtil.isBlank(unitMag) ? "" : unitMag); errorScopeDur = dealErrorScope(errorScopeDur).concat(StrUtil.isBlank(unitDur) ? "" : unitDur); @@ -1871,6 +1905,7 @@ public class ResultServiceImpl implements IResultService { } } keyFillMap.put(ItemReportKeyEnum.RESULT.getKey(), result); + return true; } @@ -1923,6 +1958,9 @@ public class ResultServiceImpl implements IResultService { * @param phaseA 相别 */ private DetectionData getResultData(Object singleResult, Integer timeInt, String phaseA) { + if (Objects.isNull(singleResult)) { + return null; + } String fieldName = phaseA.toLowerCase().concat("Value"); if (Objects.nonNull(timeInt)) { fieldName = fieldName.concat(String.valueOf(timeInt)); @@ -1933,6 +1971,9 @@ public class ResultServiceImpl implements IResultService { } catch (Exception exception) { throw new BusinessException("获取对象字段属性失败"); } + if (StrUtil.isBlank(filedValue)) { + return null; + } return JSONUtil.toBean(filedValue, DetectionData.class); }