feat(report): 更新数据库配置并完善检测报告功能

- 修改application.yml中的数据库连接URL从pqs910切换到pqs9100_jx
- 在BaseReportKeyEnum中新增装置名称和检测源名称枚举项
- 在PqReportServiceImpl中注入IAdPlanSourceService并实现检测源名称获取
- 添加装置名称到报告基础数据映射中
- 优化测量回路标题格式,统一显示回路编号
- 在ResultServiceImpl中增强表格数据生成逻辑,添加空数据检查和日志记录
- 修改数据填充方法返回布尔值以支持数据有效性验证
- 重构电压相位数据填充逻辑,提高数据处理准确性
- 增强异常处理机制,确保报告生成过程更加稳定可靠
This commit is contained in:
2026-06-29 19:12:23 +08:00
parent 1de66ce4dc
commit 88d3e00559
3 changed files with 109 additions and 57 deletions

View File

@@ -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","样品编号"),

View File

@@ -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<PqReportMapper, PqReport> 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<PqReportMapper, PqReport> i
WordprocessingMLPackage detailModelDocument = WordprocessingMLPackage.load(detailInputStream);
// 获取文档基础部分,并替换占位符
Map<String, String> baseModelDataMap = dealBaseModelData(pqDevVO, devType);
// 补充检测源名称:计划↔源走 ad_plan_source 中间表业务上单源datasourceId 是数据源类型枚举、不指向 pq_source
List<PqSource> 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<PqReportMapper, PqReport> 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<PqReportMapper, PqReport> i
List<Docx4jUtil.HeadingContent> 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;
}

View File

@@ -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<SimAndDigNonHarmonicResult> nonHarmList = simAndDigNonHarmonicService.queryByCondition(param);
if (CollUtil.isNotEmpty(nonHarmList)) {
if (CollUtil.isEmpty(nonHarmList)) {
log.warn("生成暂态类表格数据跳过结果表数据为空planCode={}, devId={}, lineNo={}, scriptCode={}, scriptIndex={}",
planCode, devId, lineNo, scriptCode, sort);
continue;
}
Map<String, String> keyFillMap = new HashMap<>(16);
fillVoltagePhaseData(nonHarmList, keyFillMap, tableKeys);
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<String, List<Map<String, String>>> 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<Double, List<PqScriptCheckData>> checkDataHarmNumMap = scriptCheckDataList.stream().collect(Collectors.groupingBy(PqScriptCheckData::getHarmNum));
List<Map<String, String>> 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);
if (fillThreePhaseData(singleResult, timeInt, keyFillMap, scriptCode)) {
keyFillMapList.add(keyFillMap);
}
});
if (CollUtil.isNotEmpty(keyFillMapList)) {
// 按次数排序
@@ -1522,13 +1537,18 @@ public class ResultServiceImpl implements IResultService {
// 获取该三相的数据
SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, Collections.singletonList(valueType), indexList);
List<SimAndDigNonHarmonicResult> nonHarmList = simAndDigNonHarmonicService.queryByCondition(param);
if (CollUtil.isNotEmpty(nonHarmList)) {
if (CollUtil.isEmpty(nonHarmList)) {
log.warn("生成三相类表格数据跳过结果表数据为空planCode={}, devId={}, lineNo={}, scriptCode={}, valueType={}, scriptIndexList={}",
planCode, devId, lineNo, scriptCode, valueType, indexList);
continue;
}
List<Map<String, String>> keyFillMapList = new ArrayList<>();
for (SimAndDigNonHarmonicResult SimAndDigNonHarmonicResult : nonHarmList) {
Map<String, String> keyFillMap = new HashMap<>(16);
fillThreePhaseData(SimAndDigNonHarmonicResult, null, keyFillMap, scriptCode);
if (fillThreePhaseData(SimAndDigNonHarmonicResult, null, keyFillMap, scriptCode)) {
keyFillMapList.add(keyFillMap);
}
}
if (CollUtil.isNotEmpty(keyFillMapList)) {
// 需要对所有的填充进行按误差范围分组
Map<String, List<Map<String, String>>> errorScoperMap = keyFillMapList.stream()
@@ -1542,18 +1562,19 @@ public class ResultServiceImpl implements IResultService {
// 最后赋值返回
finalContent.put(affectName, errorList);
}
} else {
log.error("生成三相类表格数据失败,结果表数据丢失,请核实。");
}
} else {
// 非三相且非暂态,通常只有一个数据,所以直接赋值即可
List<Map<String, String>> keyFillMapList = new ArrayList<>();
SingleNonHarmParam param = new SingleNonHarmParam(planCode, devId, lineNo, Collections.singletonList(valueType), indexList);
List<SimAndDigNonHarmonicResult> nonHarmList = simAndDigNonHarmonicService.queryByCondition(param);
if (CollUtil.isNotEmpty(nonHarmList)) {
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<String, String> keyFillMap = new HashMap<>(8);
fillTPhaseData(simAndDigNonHarmonicResult, null, keyFillMap);
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<String, String> keyFillMap, String scriptCode) {
private boolean fillThreePhaseData(Object singleResult, Integer timeInt, Map<String, String> 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,10 +1766,12 @@ public class ResultServiceImpl implements IResultService {
* @param timeInt 谐波类需要传指定次数
* @param keyFillMap 待填充的集合Map
*/
private void fillTPhaseData(Object singleResult, Integer timeInt, Map<String, String> keyFillMap) {
private boolean fillTPhaseData(Object singleResult, Integer timeInt, Map<String, String> keyFillMap) {
String standard = "/", test = "/", error = "/", result = "/", errorScope = "/", unit = "";
DetectionData tempT = getResultData(singleResult, timeInt, PowerConstant.PHASE_T);
if (Objects.nonNull(tempT)) {
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())) {
@@ -1752,13 +1780,13 @@ public class ResultServiceImpl implements IResultService {
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,21 +1796,25 @@ public class ResultServiceImpl implements IResultService {
* @param keyFillMap 待填充的集合Map
* @param tableKeys 模板表格中的key
*/
private void fillVoltagePhaseData(List<SimAndDigNonHarmonicResult> nonHarmList, Map<String, String> keyFillMap, List<String> tableKeys) {
private boolean fillVoltagePhaseData(List<SimAndDigNonHarmonicResult> nonHarmList, Map<String, String> keyFillMap, List<String> 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())) {
@@ -1791,7 +1823,6 @@ public class ResultServiceImpl implements IResultService {
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);
}