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