优化部分代码
This commit is contained in:
@@ -13,6 +13,7 @@ public enum ItemReportKeyEnum {
|
||||
|
||||
NAME("name", "检测项,比如:频率"),
|
||||
NAME_DETAIL("nameDetail", "检测项详细,比如:频率测量准确度"),
|
||||
INFLUENCE("influence", "影响量的描述,比如额定工作条件、谐波对电压的影响等等"),
|
||||
ERROR_SCOPE("errorScope", "误差范围,注:在段落中时需加上(),表格中无需添加"),
|
||||
ERROR_SCOPE_MAG("errorScopeMag", "特征幅值:误差范围"),
|
||||
ERROR_SCOPE_DUR("errorScopeDur", "持续时间:误差范围"),
|
||||
|
||||
@@ -704,7 +704,6 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 如何处理结果性数据进文档,各省级平台的结果表格不一致,如何做到一致
|
||||
*
|
||||
@@ -801,7 +800,6 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理以回路为维度的数据项,书签占位符的方式
|
||||
*
|
||||
@@ -828,6 +826,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
todoInsertList.add(titleParagraph);
|
||||
// 依次处理大项文档内容
|
||||
Iterator<Map.Entry<String, List<PqScriptDtlDataVO>>> iterator = scriptMap.entrySet().iterator();
|
||||
String prefixCode = "";
|
||||
boolean first = true;
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, List<PqScriptDtlDataVO>> next = iterator.next();
|
||||
String scriptCode = next.getKey();
|
||||
@@ -853,18 +853,33 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
} else if (scriptResult.size() < lineNo) {
|
||||
needFill = true;
|
||||
}
|
||||
|
||||
// 控制指标名是否第一次,如果第一次就显示,不是则隐藏
|
||||
if (prefixCode.equalsIgnoreCase(scriptCode)) {
|
||||
first = false;
|
||||
} else {
|
||||
first = true;
|
||||
}
|
||||
prefixCode = scriptCode;
|
||||
if (PowerConstant.TIME.contains(scriptCode)) {
|
||||
// 谐波类,以scriptIndex区分
|
||||
Map<Integer, List<PqScriptDtlDataVO>> scriptIndexMap = dtlScriptItemList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptIndex));
|
||||
// 谐波类针对是否第一次还要额外做个处理,因为每个测点需要单独表示
|
||||
for (List<PqScriptDtlDataVO> scriptDtlDataItem : scriptIndexMap.values()) {
|
||||
singleTestResult = resultService.getFinalContent(scriptDtlDataItem, devReportParam.getPlanCode(), pqDevVO.getId(), lineNo, tableKeys);
|
||||
List<Object> tempList = fillContentInTemplate(singleTestResult.getDetail(), tempContent, factory, pKeyValueMap, tableKeys);
|
||||
List<Object> tempList;
|
||||
if (first) {
|
||||
tempList = fillContentInTemplate(singleTestResult.getDetail(), tempContent, factory, pKeyValueMap, tableKeys, first);
|
||||
first = false;
|
||||
} else {
|
||||
tempList = fillContentInTemplate(singleTestResult.getDetail(), tempContent, factory, pKeyValueMap, tableKeys, first);
|
||||
}
|
||||
todoInsertList.addAll(tempList);
|
||||
}
|
||||
} else {
|
||||
// 非谐波类
|
||||
singleTestResult = resultService.getFinalContent(dtlScriptItemList, devReportParam.getPlanCode(), pqDevVO.getId(), lineNo, tableKeys);
|
||||
List<Object> tempList = fillContentInTemplate(singleTestResult.getDetail(), tempContent, factory, pKeyValueMap, tableKeys);
|
||||
List<Object> tempList = fillContentInTemplate(singleTestResult.getDetail(), tempContent, factory, pKeyValueMap, tableKeys, first);
|
||||
todoInsertList.addAll(tempList);
|
||||
}
|
||||
if (Objects.nonNull(singleTestResult) && needFill) {
|
||||
@@ -886,22 +901,29 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
* 将查询的所有有效数据填充到集合中,待后续填充文档
|
||||
*/
|
||||
private List<Object> fillContentInTemplate(Map<String, List<Map<String, List<Map<String, String>>>>> finalContent, List<Docx4jUtil.HeadingContent> tempContent,
|
||||
ObjectFactory factory, Map<String, String> pKeyValueMap, List<String> tableKeys) {
|
||||
ObjectFactory factory, Map<String, String> pKeyValueMap, List<String> tableKeys, boolean first) {
|
||||
String influenceContent = "";
|
||||
|
||||
List<Object> todoInsertList = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(finalContent)) {
|
||||
Iterator<Map.Entry<String, List<Map<String, List<Map<String, String>>>>>> iterator1 = finalContent.entrySet().iterator();
|
||||
while (iterator1.hasNext()) {
|
||||
Map.Entry<String, List<Map<String, List<Map<String, String>>>>> next1 = iterator1.next();
|
||||
Iterator<Map.Entry<String, List<Map<String, List<Map<String, String>>>>>> allContentIterator = finalContent.entrySet().iterator();
|
||||
boolean nameFlag = false;
|
||||
while (allContentIterator.hasNext()) {
|
||||
boolean influenceFlag = false;
|
||||
// 以影响量分类的数据内容
|
||||
Map.Entry<String, List<Map<String, List<Map<String, String>>>>> contentMapEntry = allContentIterator.next();
|
||||
// 此处的key是影响量的文字描述
|
||||
String key = next1.getKey();
|
||||
List<Map<String, List<Map<String, String>>>> value = next1.getValue();
|
||||
for (Map<String, List<Map<String, String>>> stringListMap : value) {
|
||||
Iterator<Map.Entry<String, List<Map<String, String>>>> iterator2 = stringListMap.entrySet().iterator();
|
||||
while (iterator2.hasNext()) {
|
||||
Map.Entry<String, List<Map<String, String>>> next2 = iterator2.next();
|
||||
String influence = contentMapEntry.getKey();
|
||||
List<Map<String, List<Map<String, String>>>> contentByInfluence = contentMapEntry.getValue();
|
||||
for (Map<String, List<Map<String, String>>> stringListMap : contentByInfluence) {
|
||||
Iterator<Map.Entry<String, List<Map<String, String>>>> errorContentIterator = stringListMap.entrySet().iterator();
|
||||
while (errorContentIterator.hasNext()) {
|
||||
// 同一个影响量下的误差范围分类的数据内容
|
||||
Map.Entry<String, List<Map<String, String>>> errorContent = errorContentIterator.next();
|
||||
// 此处的key是误差范围
|
||||
String key1 = next2.getKey();
|
||||
List<Map<String, String>> value1 = next2.getValue();
|
||||
String errorContentKey = errorContent.getKey();
|
||||
// 待填充数据内容
|
||||
List<Map<String, String>> dataList = errorContent.getValue();
|
||||
// 填充模板内容
|
||||
if (CollUtil.isNotEmpty(tempContent)) {
|
||||
// 读取该表下模板里面的内容,并动态赋值渲染文档
|
||||
@@ -909,6 +931,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
for (Object object : headingContent.getSubContent()) {
|
||||
// 段落
|
||||
if (object instanceof P) {
|
||||
/* 如果是段落,目前的配置项无非就是:name、nameDetail、influence、errorScope、scriptDetail
|
||||
需要注意的是:
|
||||
1、如果name、nameDetail、influence独立存在时,仅赋值一次,避免重复出现;
|
||||
2、如果name、nameDetail、influence与其他配置项同时存在,通过 - 分隔,则每次都要输出
|
||||
*/
|
||||
P innerP = factory.createP();
|
||||
// 如果是段落,渲染段落内容
|
||||
P paragraph = (P) object;
|
||||
@@ -916,26 +943,57 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
RPr rPr = Docx4jUtil.getTcPrFromParagraph(paragraph);
|
||||
PPr pPr = paragraph.getPPr();
|
||||
String textFromP = Docx4jUtil.getTextFromP(paragraph);
|
||||
if (StrUtil.isNotBlank(textFromP)) {
|
||||
String text = "";
|
||||
if (textFromP.equalsIgnoreCase(ItemReportKeyEnum.SCRIPT_DETAIL.getKey())) {
|
||||
text = value1.get(0).get(ItemReportKeyEnum.SCRIPT_DETAIL.getKey());
|
||||
System.out.println(text);
|
||||
} else if (textFromP.startsWith(ItemReportKeyEnum.NAME.getKey())) {
|
||||
// 如果是段落内容,渲染段落内容
|
||||
String[] splitP = textFromP.split(StrPool.DASHED);
|
||||
for (String item : splitP) {
|
||||
if (StrUtil.isNotBlank(pKeyValueMap.get(item))) {
|
||||
text = text.concat(pKeyValueMap.get(item));
|
||||
} else if (item.equalsIgnoreCase(ItemReportKeyEnum.ERROR_SCOPE.getKey())) {
|
||||
text = text.concat("(").concat("最大允许误差:").concat(key1).concat(")");
|
||||
if (StrUtil.isNotBlank(textFromP)) {
|
||||
// 需要判断是否含有'-'
|
||||
if (textFromP.contains(ItemReportKeyEnum.NAME.getKey())
|
||||
|| textFromP.contains(ItemReportKeyEnum.NAME_DETAIL.getKey())
|
||||
|| textFromP.contains(ItemReportKeyEnum.INFLUENCE.getKey())) {
|
||||
if (textFromP.contains(StrPool.DASHED)) {
|
||||
String[] pArray = textFromP.split(StrPool.DASHED);
|
||||
for (String item : pArray) {
|
||||
text = text.concat(getValueFromDataMap(item, pKeyValueMap, errorContentKey, influence));
|
||||
}
|
||||
} else {
|
||||
// 调整标志位
|
||||
if (textFromP.contains(ItemReportKeyEnum.INFLUENCE.getKey()) && !influenceFlag) {
|
||||
if (!influenceContent.equalsIgnoreCase(influence)) {
|
||||
text = getValueFromDataMap(textFromP, pKeyValueMap, errorContentKey, influence);
|
||||
influenceFlag = true;
|
||||
influenceContent = influence;
|
||||
}
|
||||
} else {
|
||||
if (!nameFlag && first) {
|
||||
text = getValueFromDataMap(textFromP, pKeyValueMap, errorContentKey, influence);
|
||||
nameFlag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (textFromP.contains(ItemReportKeyEnum.SCRIPT_DETAIL.getKey())) {
|
||||
if (textFromP.contains(StrPool.DASHED)) {
|
||||
String[] pArray = textFromP.split(StrPool.DASHED);
|
||||
for (String item : pArray) {
|
||||
if (item.equalsIgnoreCase(ItemReportKeyEnum.SCRIPT_DETAIL.getKey())) {
|
||||
text = dataList.get(0).get(ItemReportKeyEnum.SCRIPT_DETAIL.getKey());
|
||||
} else {
|
||||
if (StrUtil.isBlank(text)) {
|
||||
text = "";
|
||||
}
|
||||
text = text.concat(getValueFromDataMap(item, pKeyValueMap, errorContentKey, influence));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
text = dataList.get(0).get(ItemReportKeyEnum.SCRIPT_DETAIL.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
// text为空,则不创建段落
|
||||
if (StrUtil.isNotBlank(text)) {
|
||||
Docx4jUtil.addPContent(factory, innerP, text, rPr, pPr);
|
||||
}
|
||||
//插入段落
|
||||
todoInsertList.add(innerP);
|
||||
}
|
||||
} else if (object instanceof JAXBElement) {
|
||||
// 表格需要注意深拷贝,避免修改了原对象
|
||||
JAXBElement<Tbl> temp = (JAXBElement<Tbl>) object;
|
||||
@@ -969,7 +1027,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
tcPr.setTcW(cellWidth);
|
||||
tbl.getContent().remove(existingRow);
|
||||
// 迭代增加行,需要填充的表格keys在tableKeys集合中
|
||||
for (Map<String, String> stringStringMap : value1) {
|
||||
for (Map<String, String> stringStringMap : dataList) {
|
||||
Tr newRow = Docx4jUtil.createCustomRow(factory, stringStringMap, tableKeys, trPr, tcPr, true);
|
||||
tbl.getContent().add(newRow);
|
||||
}
|
||||
@@ -992,6 +1050,26 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
return todoInsertList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据集合中获取对应key的值,误差范围需要做个特殊处理
|
||||
*
|
||||
* @param item key
|
||||
* @param pKeyValueMap 数据集合
|
||||
*/
|
||||
private String getValueFromDataMap(String item, Map<String, String> pKeyValueMap, String errorScope, String influence) {
|
||||
String value = "";
|
||||
if (item.equalsIgnoreCase(ItemReportKeyEnum.ERROR_SCOPE.getKey())) {
|
||||
value = "(最大允许误差:" + errorScope + ")";
|
||||
} else if (item.equalsIgnoreCase(ItemReportKeyEnum.INFLUENCE.getKey())) {
|
||||
value = influence;
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(pKeyValueMap.get(item))) {
|
||||
value = pKeyValueMap.get(item);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
private void updateDevAndPlanState(String devId, String planId) {
|
||||
// 将改设备的报告生成状态调整为已生成
|
||||
@@ -1403,7 +1481,6 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String devValue(String dataJson, double baseValue, Integer percent) {
|
||||
DetectionData tempA = JSONUtil.toBean(dataJson, DetectionData.class);
|
||||
if (Objects.nonNull(tempA) && Objects.nonNull(tempA.getData())) {
|
||||
|
||||
Reference in New Issue
Block a user