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 17f26bb0..72256b5f 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 @@ -25,7 +25,6 @@ import com.njcn.gather.device.pojo.enums.DevReportStateEnum; import com.njcn.gather.device.pojo.po.PqDev; import com.njcn.gather.device.pojo.vo.PqDevVO; import com.njcn.gather.device.service.IPqDevService; -import com.njcn.gather.err.service.IPqErrSysDtlsService; import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum; import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.service.IAdPlanService; @@ -39,47 +38,33 @@ import com.njcn.gather.report.pojo.param.ReportParam; import com.njcn.gather.report.pojo.po.CellEntity; import com.njcn.gather.report.pojo.po.PqReport; import com.njcn.gather.report.pojo.result.SingleTestResult; -import com.njcn.gather.report.pojo.vo.Bookmark; import com.njcn.gather.report.pojo.vo.PqReportVO; import com.njcn.gather.report.service.IPqReportService; import com.njcn.gather.report.utils.BookmarkUtil; import com.njcn.gather.report.utils.Docx4jUtil; import com.njcn.gather.report.utils.WordUtil; import com.njcn.gather.result.service.IResultService; -import com.njcn.gather.script.pojo.po.PqScriptCheckData; -import com.njcn.gather.script.pojo.po.PqScriptDtls; 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.storage.pojo.param.SingleNonHarmParam; -import com.njcn.gather.storage.pojo.po.AdBaseResult; import com.njcn.gather.storage.pojo.po.AdHarmonicResult; import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult; -import com.njcn.gather.storage.pojo.vo.RawResultDataVO; import com.njcn.gather.storage.service.AdHarmonicService; import com.njcn.gather.storage.service.AdNonHarmonicService; import com.njcn.gather.system.cfg.pojo.enums.SceneEnum; import com.njcn.gather.system.cfg.service.ISysTestConfigService; import com.njcn.gather.system.dictionary.pojo.po.DictData; -import com.njcn.gather.system.dictionary.pojo.po.DictTree; import com.njcn.gather.system.dictionary.service.IDictDataService; -import com.njcn.gather.system.dictionary.service.IDictTreeService; -import com.njcn.gather.system.pojo.enums.DicDataEnum; import com.njcn.gather.type.pojo.po.DevType; import com.njcn.gather.type.service.IDevTypeService; -import com.njcn.gather.user.user.service.ISysUserService; import com.njcn.web.factory.PageFactory; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.poi.xwpf.usermodel.*; -import org.docx4j.TraversalUtil; -import org.docx4j.finders.RangeFinder; import org.docx4j.jaxb.Context; import org.docx4j.openpackaging.packages.WordprocessingMLPackage; import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart; import org.docx4j.wml.*; -import org.docx4j.wml.CTBookmark; -import org.docx4j.wml.Document; import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; @@ -100,7 +85,6 @@ import java.nio.file.Paths; import java.util.*; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * @author makejava @@ -111,17 +95,12 @@ import java.util.stream.Stream; @RequiredArgsConstructor public class PqReportServiceImpl extends ServiceImpl implements IPqReportService { - private static final int TWIPS_PER_INCH = 1440; - @Value("${report.template:D:\\template}") private String templatePath; @Value("${report.reportDir:D:\\report}") private String reportPath; - private final String RED = "FF0000"; - private final String BLACK = "000000"; - private final IPqDevService iPqDevService; private final PqDevMapper pqDevMapper; @@ -131,22 +110,14 @@ public class PqReportServiceImpl extends ServiceImpl i private final IPqScriptDtlsService pqScriptDtlsService; - private final IPqScriptCheckDataService pqScriptCheckDataService; - private final AdNonHarmonicService adNonHarmonicService; private final AdHarmonicService adHarmonicService; private final IDevTypeService devTypeService; - private final IDictTreeService dictTreeService; - - private final IPqErrSysDtlsService pqErrSysDtlsService; - private final IResultService resultService; - private final ISysUserService sysUserService; - private final ISysTestConfigService sysTestConfigService; private final long FILE_SIZE_LIMIT = 5 * 1024 * 1024; @@ -205,7 +176,7 @@ public class PqReportServiceImpl extends ServiceImpl i } @Override - @Transactional + @Transactional(rollbackFor = {Exception.class}) public boolean add(ReportParam reportParam) { this.checkPattern(reportParam); this.checkRepeat(reportParam, false); @@ -230,7 +201,7 @@ public class PqReportServiceImpl extends ServiceImpl i } @Override - @Transactional + @Transactional(rollbackFor = {Exception.class}) public boolean update(ReportParam.UpdateParam reportParam) { this.checkPattern(reportParam); this.checkRepeat(reportParam, true); @@ -692,7 +663,7 @@ public class PqReportServiceImpl extends ServiceImpl i dealDataLine(baseDocumentPart, devReportParam, pqDevVO, resultMap); } bookmarkInfo = BookmarkUtil.getBookmarkInfo(BookmarkEnum.TEST_RESULT_DEV.getKey(), bookmarks); - todoInsertList = dealTestResultLine(baseDocumentPart, detailDocumentPart, devReportParam, resultMap, DocAnchorEnum.TEST_RESULT_DEV); + todoInsertList = dealTestResultLine(devReportParam, resultMap, DocAnchorEnum.TEST_RESULT_DEV); if (Objects.nonNull(bookmarkInfo) && CollectionUtil.isNotEmpty(todoInsertList)) { BookmarkUtil.insertElement(bookmarkInfo, todoInsertList); BookmarkUtil.removeBookmark(bookmarkInfo); @@ -704,7 +675,7 @@ public class PqReportServiceImpl extends ServiceImpl i dealDataLine(baseDocumentPart, devReportParam, pqDevVO, resultMap); } bookmarkInfo = BookmarkUtil.getBookmarkInfo(BookmarkEnum.TEST_RESULT_LINE.getKey(), bookmarks); - todoInsertList = dealTestResultLine(baseDocumentPart, detailDocumentPart, devReportParam, resultMap, DocAnchorEnum.TEST_RESULT_LINE); + todoInsertList = dealTestResultLine(devReportParam, resultMap, DocAnchorEnum.TEST_RESULT_LINE); if (Objects.nonNull(bookmarkInfo) && CollectionUtil.isNotEmpty(todoInsertList)) { BookmarkUtil.insertElement(bookmarkInfo, todoInsertList); BookmarkUtil.removeBookmark(bookmarkInfo); @@ -716,7 +687,7 @@ public class PqReportServiceImpl extends ServiceImpl i dealDataLine(baseDocumentPart, devReportParam, pqDevVO, resultMap); } bookmarkInfo = BookmarkUtil.getBookmarkInfo(BookmarkEnum.TEST_RESULT_LINE.getKey(), bookmarks); - todoInsertList = dealTestResultLine(baseDocumentPart, detailDocumentPart, devReportParam, resultMap, DocAnchorEnum.TEST_RESULT_DETAIL); + todoInsertList = dealTestResultLine(devReportParam, resultMap, DocAnchorEnum.TEST_RESULT_DETAIL); if (Objects.nonNull(bookmarkInfo) && CollectionUtil.isNotEmpty(todoInsertList)) { BookmarkUtil.insertElement(bookmarkInfo, todoInsertList); BookmarkUtil.removeBookmark(bookmarkInfo); @@ -733,197 +704,13 @@ public class PqReportServiceImpl extends ServiceImpl i } - /** - * 通用基础信息文档里可能会存在的书签锚点 - * 1、目录信息 - * 2、准确度测试详情 - * 3、测试结果页 - * 上述3个锚点位置不固定,可能结果页在通用信息中间,也有可能在文档最末端。 - * 注:当存在目录信息时,目录最后生成。 - * - * @param baseDocumentPart 通用信息文档 - * @param detailDocumentPart 数据项模板文档 - * @param devReportParam 测试报告参数 - * @param pqDevVO 被检设备 - */ - private void dealDataModelScattered(MainDocumentPart baseDocumentPart, MainDocumentPart detailDocumentPart, DevReportParam devReportParam, PqDevVO pqDevVO) { - // 查找 base 文档中所有以#{开始的书签所在的段落,并收集整理 - List baseContent = baseDocumentPart.getContent(); - List bookmarks = new ArrayList<>(); - for (int i = 0; i < baseContent.size(); i++) { - Object obj = baseContent.get(i); - if (obj instanceof P) { - P p = (P) obj; - String text = Docx4jUtil.getTextFromP(p).trim(); - if (text.startsWith(ReportConstant.BOOKMARK_START)) { - Bookmark bookmark = new Bookmark(i, DocAnchorEnum.getByKey(text)); - bookmarks.add(bookmark); - } - } - } - if (CollUtil.isNotEmpty(bookmarks)) { - /* - * 从结构上分析,处理的顺序: - * 1、数据项 - * 2、结果信息 - * 3、目录信息 - * 所以要先先获取的书签进行操作排序 - * */ - Collections.sort(bookmarks); - // 定义个结果,以便存在结果信息的书签 - Map> resultMap = new HashMap<>(); - // 书签在文档的位置 - int position; - for (int i = 0; i < bookmarks.size(); i++) { - Bookmark bookmark = bookmarks.get(i); - if (i == 0) { - position = bookmark.getIndex(); - } else { - // 经过处理后,原本的书签位置,已经被处理,所以需要重新获取 - position = Docx4jUtil.getParagraphPosition(baseDocumentPart, bookmark.getDocAnchorEnum()); - } - switch (bookmark.getDocAnchorEnum()) { - case DATA_LINE: - dealDataLine(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO, position, resultMap); - break; - case DATA_SCRIPT: - break; - case TEST_RESULT_DEV: - // 判断是否已经处理过数据了,有了结论性的描述 - if (CollUtil.isEmpty(resultMap)) { - dealDataLine(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO, position, resultMap); - } - dealTestResultLine(baseDocumentPart, detailDocumentPart, position, resultMap, DocAnchorEnum.TEST_RESULT_DEV); - break; - case TEST_RESULT_LINE: - // 判断是否已经处理过数据了,有了结论性的描述 - if (CollUtil.isEmpty(resultMap)) { - dealDataLine(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO, position, resultMap); - } - dealTestResultLine(baseDocumentPart, detailDocumentPart, position, resultMap, DocAnchorEnum.TEST_RESULT_LINE); - break; - case TEST_RESULT_DETAIL: - // 判断是否已经处理过数据了,有了结论性的描述 - if (CollUtil.isEmpty(resultMap)) { - dealDataLine(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO, position, resultMap); - } - dealTestResultLine(baseDocumentPart, detailDocumentPart, position, resultMap, DocAnchorEnum.TEST_RESULT_DETAIL); - break; - case CATALOG: - break; - default: - break; - } - } - } - - } - /** * 如何处理结果性数据进文档,各省级平台的结果表格不一致,如何做到一致 * - * @param baseDocumentPart 基础模板文档 - * @param detailDocumentPart 数据模板文档 - * @param position 书签在基础文档的位置 * @param resultMap 各测试项的结果 */ - private void dealTestResultLine(MainDocumentPart baseDocumentPart, MainDocumentPart detailDocumentPart, int position, Map> resultMap, DocAnchorEnum docAnchorEnum) { - // 先判断数据有没有,如果没有,则不处理 - if (CollUtil.isEmpty(resultMap.get(PowerIndexEnum.UNKNOWN.getKey()))) { - List paragraphs = baseDocumentPart.getContent(); - ObjectFactory factory = Context.getWmlObjectFactory(); - // 结论 - P newParagraph = factory.createP(); - Docx4jUtil.createTitle(factory, newParagraph, "检测结论", 24, true); - //插入段落 - paragraphs.add(position++, newParagraph); - // 源文档的内容 - // 创建表格(示例为3列,列数可任意调整) - Tbl table = factory.createTbl(); - List> tempResultList = new ArrayList<>(resultMap.values()); - int lineNum = tempResultList.get(0).size(); - // 处理表头 - List title = new ArrayList<>(); - title.add("检测项目"); - switch (docAnchorEnum) { - case TEST_RESULT_DEV: - title.add("结论"); - break; - case TEST_RESULT_LINE: - for (int i = 1; i < lineNum + 1; i++) { - title.add("测量回路" + i); - } - break; - case TEST_RESULT_DETAIL: - for (int i = 1; i < lineNum + 1; i++) { - title.add("测量回路" + i); - } - title.add("结论"); - break; - default: - break; - } - List centerFlag = new ArrayList<>(); - centerFlag.add(0); - Tr titleRow = Docx4jUtil.createCustomRow(factory, title, "Arial", "宋体", 21, true, centerFlag); - - table.getContent().add(titleRow); - // 处理业务数据 - resultMap.forEach((key, value) -> { - List cellValues = new ArrayList<>(); - PowerIndexEnum indexEnum = PowerIndexEnum.getByKey(key); - if (indexEnum != null) { - cellValues.add(indexEnum.getDesc().concat("测量准确度")); - } else { - cellValues.add(PowerIndexEnum.UNKNOWN.getDesc().concat("测量准确度")); - } - // 判断是否有不合格的 - List totalValue = value.stream().filter(item -> !item).collect(Collectors.toList()); - String total = !totalValue.isEmpty() ? "不合格" : "合格"; - switch (docAnchorEnum) { - case TEST_RESULT_DEV: - cellValues.add(total); - break; - case TEST_RESULT_LINE: - for (int i = 0; i < value.size(); i++) { - cellValues.add(value.get(i) ? "合格" : "不合格"); - } - break; - case TEST_RESULT_DETAIL: - for (int i = 0; i < value.size(); i++) { - cellValues.add(value.get(i) ? "合格" : "不合格"); - } - cellValues.add(total); - break; - default: - break; - } - Tr tempRow = Docx4jUtil.createCustomRow(factory, cellValues, "Arial", "宋体", 21, false, centerFlag); - table.getContent().add(tempRow); - }); - TblPr tblPr = Docx4jUtil.getTblPr(factory); - table.setTblPr(tblPr); - paragraphs.add(position++, table); - // 标签的位置,以便清空原标签 - if (position >= 0 && position < paragraphs.size()) { - paragraphs.remove(position); - } else { - System.out.println("指定的索引超出范围"); - } - } - - - } - - /** - * 如何处理结果性数据进文档,各省级平台的结果表格不一致,如何做到一致 - * - * @param baseDocumentPart 基础模板文档 - * @param detailDocumentPart 数据模板文档 - * @param resultMap 各测试项的结果 - */ - private List dealTestResultLine(MainDocumentPart baseDocumentPart, MainDocumentPart detailDocumentPart, DevReportParam devReportParam, Map> resultMap, DocAnchorEnum docAnchorEnum) { + private List dealTestResultLine(DevReportParam devReportParam, Map> resultMap, DocAnchorEnum docAnchorEnum) { List todoInsertList = new ArrayList<>(); // 先判断数据有没有,如果没有,则不处理 if (CollUtil.isEmpty(resultMap.get(PowerIndexEnum.UNKNOWN.getKey()))) { @@ -1014,93 +801,6 @@ public class PqReportServiceImpl extends ServiceImpl i } - /** - * 处理以回路为维度的数据项 - * - * @param baseModelDocument 基础模板 - * @param detailModelDocument 数据项模板 - * @param devReportParam 测试报告参数 - * @param pqDevVO 被检设备 - * @param position 待处理书签的位置 - */ - private void dealDataLine(MainDocumentPart baseModelDocument, MainDocumentPart detailModelDocument, DevReportParam devReportParam, PqDevVO pqDevVO, int position, Map> resultMap) { - // 源文档的内容 - List paragraphs = baseModelDocument.getContent(); - // 以回路维度处理数据项 - Integer devChns = pqDevVO.getDevChns(); - ObjectFactory factory = new ObjectFactory(); - // 读取该计划的检测大项组装数据内容 - List pqScriptDtlsList = pqScriptDtlsService.getScriptDtlsDataList(devReportParam.getScriptId()); - Map> scriptMap = pqScriptDtlsList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptCode, LinkedHashMap::new, Collectors.toList())); - List allContent = detailModelDocument.getContent(); - List headingContents = Docx4jUtil.extractHeading5Contents(allContent); - Map> contentMap = headingContents.stream().collect(Collectors.groupingBy(Docx4jUtil.HeadingContent::getHeadingText, Collectors.toList())); - for (int i = 0; i < devChns; i++) { - // 回路标题 - P newParagraph = factory.createP(); - Integer lineNo = i + 1; - Docx4jUtil.createTitle(factory, newParagraph, "测量回路" + lineNo, 28, true); - //插入段落 - paragraphs.add(position++, newParagraph); - // 依次处理大项文档内容 - Iterator>> iterator = scriptMap.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry> next = iterator.next(); - String scriptCode = next.getKey(); - List dtlScriptItemList = next.getValue(); - List tempContent = contentMap.get(scriptCode); - // 获取需要填充keys,索引0对应的段落key,索引1对应的表格key - List> keys = Docx4jUtil.getFillKeys(tempContent); - // 段落keys值赋值 - List pKeys = keys.get(0); - Map pKeyValueMap = resultService.getParagraphKeysValue(scriptCode, pKeys); - List tableKeys = keys.get(1); - /* tableKeys值赋值,注:由于谐波类检测数据与非谐波检测类数据的区别,此处要做区分 - * 1、谐波类每个scriptIndex对应一个Excel表格 - * 2、非谐波类则是一个误差范围对应一个Excel表格 - */ - SingleTestResult singleTestResult = null; - // 根据code找到名称 - List scriptResult = resultMap.get(scriptCode); - boolean needFill = false; - if (CollUtil.isEmpty(scriptResult)) { - scriptResult = new ArrayList<>(); - needFill = true; - } else if (scriptResult.size() < lineNo) { - needFill = true; - } - if (PowerConstant.TIME.contains(scriptCode)) { - // 谐波类,以scriptIndex区分 - Map> scriptIndexMap = dtlScriptItemList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptIndex)); - for (List scriptDtlDataItem : scriptIndexMap.values()) { - singleTestResult = resultService.getFinalContent(scriptDtlDataItem, devReportParam.getPlanCode(), pqDevVO.getId(), lineNo, tableKeys); - position = fillContentInTemplate(singleTestResult.getDetail(), position, tempContent, factory, pKeyValueMap, tableKeys, paragraphs); - } - } else { - // 非谐波类 - singleTestResult = resultService.getFinalContent(dtlScriptItemList, devReportParam.getPlanCode(), pqDevVO.getId(), lineNo, tableKeys); - position = fillContentInTemplate(singleTestResult.getDetail(), position, tempContent, factory, pKeyValueMap, tableKeys, paragraphs); - } - if (Objects.nonNull(singleTestResult) && needFill) { - singleTestResult.setScriptCode(scriptCode); - scriptResult.add(singleTestResult.isQualified()); - resultMap.put(scriptCode, scriptResult); - } - } - } - // 如果经过一顿处理后,结果性数据集合还是空,塞个特殊数据进去,避免嵌套循环 - if (CollUtil.isEmpty(resultMap)) { - resultMap.put(PowerIndexEnum.UNKNOWN.getKey(), Collections.singletonList(false)); - } - // 标签的位置,以便清空原标签 - if (position >= 0 && position < paragraphs.size()) { - paragraphs.remove(position); - } else { - System.out.println("指定的索引超出范围"); - } - - } - /** * 处理以回路为维度的数据项,书签占位符的方式 @@ -1182,109 +882,6 @@ public class PqReportServiceImpl extends ServiceImpl i } - /** - * 将查询的所有有效数据填充到模板中 - */ - private int fillContentInTemplate(Map>>>> finalContent, int position, List tempContent, - ObjectFactory factory, Map pKeyValueMap, List tableKeys, List paragraphs) { - if (CollUtil.isNotEmpty(finalContent)) { - Iterator>>>>> iterator1 = finalContent.entrySet().iterator(); - while (iterator1.hasNext()) { - Map.Entry>>>> next1 = iterator1.next(); - // 此处的key是影响量的文字描述 - String key = next1.getKey(); - List>>> value = next1.getValue(); - for (Map>> stringListMap : value) { - Iterator>>> iterator2 = stringListMap.entrySet().iterator(); - while (iterator2.hasNext()) { - Map.Entry>> next2 = iterator2.next(); - // 此处的key是误差范围 - String key1 = next2.getKey(); - List> value1 = next2.getValue(); - // 填充模板内容 - if (CollUtil.isNotEmpty(tempContent)) { - // 读取该表下模板里面的内容,并动态赋值渲染文档 - Docx4jUtil.HeadingContent headingContent = tempContent.get(0); - for (Object object : headingContent.getSubContent()) { - // 段落 - if (object instanceof P) { - P innerP = factory.createP(); - // 如果是段落,渲染段落内容 - P paragraph = (P) object; - // 获取该段落的样式 - 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()); - } 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(")"); - } - } - } - Docx4jUtil.addPContent(factory, innerP, text, rPr,pPr); - } - //插入段落 - paragraphs.add(position++, innerP); - } else if (object instanceof JAXBElement) { - // 表格需要注意深拷贝,避免修改了原对象 - JAXBElement temp = (JAXBElement) object; - JAXBElement copiedTableElement; - try { - copiedTableElement = Docx4jUtil.deepCopyTbl(temp); - } catch (Exception e) { - throw new RuntimeException(e); - } - // 解析表格并插入对应数据,最关键的是得知道表格是横向还是纵向以及表头占了几行 - Tbl tbl = copiedTableElement.getValue(); - // 获取表格的行 - List rows = tbl.getContent(); - boolean isRow = Docx4jUtil.judgeTableCross(rows.get(0)); - if (isRow) { - // 获取现有行的样式 - Tr existingRow = (Tr) tbl.getContent().get(rows.size() - 1); - // 获取现有样式 - TrPr trPr = existingRow.getTrPr(); - JAXBElement element = (JAXBElement) existingRow.getContent().get(0); - TcPr tcPr = element.getValue().getTcPr(); - TblWidth cellWidth = factory.createTblWidth(); - cellWidth.setType("dxa"); - cellWidth.setW(BigInteger.valueOf(5000 / tableKeys.size())); - tcPr.setTcW(cellWidth); - tbl.getContent().remove(existingRow); - // 迭代增加行,需要填充的表格keys在tableKeys集合中 - for (Map stringStringMap : value1) { - Tr newRow = Docx4jUtil.createCustomRow(factory, stringStringMap, tableKeys, trPr, tcPr, true); - tbl.getContent().add(newRow); - } - } else { - // 纵向表格暂不考虑 - } - // 插入段落,处理下样式 - paragraphs.add(position++, copiedTableElement); - } - } - // 全部渲染完毕后,添加几个换行 - P p = factory.createP(); -// Docx4jUtil.addBr(factory, p, 1); -// paragraphs.add(position++, p); - - } - } - } - } - } - return position; - } - /** * 将查询的所有有效数据填充到集合中,待后续填充文档 */ @@ -1561,7 +1158,7 @@ public class PqReportServiceImpl extends ServiceImpl i // 实验室温度 baseModelMap.put(prefix + BaseReportKeyEnum.TEMPERATURE.getKey() + suffix, Objects.isNull(pqDevVO.getTemperature()) ? StrPool.TAB : pqDevVO.getTemperature().toString()); // 实验室湿度 - baseModelMap.put(prefix + BaseReportKeyEnum.TEMPERATURE.getKey() + suffix, Objects.isNull(pqDevVO.getTemperature()) ? StrPool.TAB : pqDevVO.getTemperature().toString()); + baseModelMap.put(prefix + BaseReportKeyEnum.HUMIDITY.getKey() + suffix, Objects.isNull(pqDevVO.getHumidity()) ? StrPool.TAB : pqDevVO.getHumidity().toString()); // 样品编号 baseModelMap.put(prefix + BaseReportKeyEnum.SAMPLE_ID.getKey() + suffix, StrUtil.isEmpty(pqDevVO.getSampleId()) ? StrPool.TAB : pqDevVO.getSampleId()); @@ -1805,617 +1402,7 @@ public class PqReportServiceImpl extends ServiceImpl i return allMarkList.stream().sorted(Comparator.comparing(String::toString)).collect(Collectors.toList()); } - private void dealDataModelZJ(XWPFDocument baseModelDocument, DevReportParam devReportParam, PqDevVO pqDevVO) { - List nonHarmonicResultList = adNonHarmonicService.get(devReportParam.getScriptId(), null, devReportParam.getDevId(), "-1", devReportParam.getPlanCode()); - List harmonicResultList = adHarmonicService.get(devReportParam.getScriptId(), null, devReportParam.getDevId(), "-1", devReportParam.getPlanCode()); - if (CollectionUtil.isEmpty(nonHarmonicResultList) && CollectionUtil.isEmpty(harmonicResultList)) { - throw new BusinessException(ReportResponseEnum.NO_CHECK_DATA); - } - List allBaseResultList = Stream.concat(nonHarmonicResultList.stream(), harmonicResultList.stream()) - .sorted(Comparator.comparing(AdBaseResult::getSort)).collect(Collectors.toList()); - LinkedHashMap> chnResultMap = allBaseResultList.stream().sorted(Comparator.comparing(AdBaseResult::getSort)) - .collect(Collectors.groupingBy( - (obj) -> obj.getMonitorId().substring(obj.getMonitorId().lastIndexOf("_") + 1), - LinkedHashMap::new, - Collectors.toList())); - - for (int i = 1; i <= pqDevVO.getDevChns(); i++) { - XWPFParagraph paragraph = baseModelDocument.createParagraph(); - paragraph.setAlignment(ParagraphAlignment.LEFT); - XWPFRun run = paragraph.createRun(); - run.setFontFamily("宋体"); - run.setBold(true); - run.setFontSize(14); - run.setText("测量回路" + i); - - List chnResultList = chnResultMap.get(String.valueOf(i)); - -// // 排除电压相角、电压偏差、电流相角 -// list1 = list1.stream().filter(obj -> !"e8bbfaad7a3fa343d3c46d345fb45fa3".equals(obj.getAdType())) -// .filter(obj -> !"148faabd2630aaac0b70be8609075f69".equals(obj.getAdType())) -// .filter(obj -> !"fdffc6b5dfdc8751b9fde9b599b8ea51".equals(obj.getAdType())).collect(Collectors.toList()); - - - Map> checkMap = this.getCheckMap(chnResultList); - for (String key : checkMap.keySet()) { - Set indexSet = checkMap.get(key); - generateTitleAndTableZJ(baseModelDocument, String.valueOf(i), key, devReportParam, indexSet); - } - } - - - //generateNonHarmABCTableHeaderZJ(baseModelDocument); - XWPFTable table = baseModelDocument.getTables().get(2); - for (int i = 1; i <= 3; i++) { - XWPFTableRow row = table.createRow(); - for (int j = 0; j < 8; j++) { - row.getCell(j).setText("1.00"); - row.getCell(j).setWidth("12.5%"); - row.getCell(j).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); - row.getCell(j).getParagraphs().get(0).setAlignment(ParagraphAlignment.CENTER); - if (j == 0) { - row.getCell(j).setWidth("15.0%"); - } - if (j == 7) { - row.getCell(j).setWidth("10.0%"); - } - } - } - } - - /** - * 获取map。 key为 检测大项code_大项ID ,value为检测大项下的所有index。 - * - * @param list - */ - private Map> getCheckMap(List list) { - Map> checkMap = new LinkedHashMap<>(); - for (int i = 0; i < list.size(); i++) { - AdBaseResult adBaseResult = list.get(i); - DictTree dictTree = dictTreeService.getById(adBaseResult.getAdType()); - DictTree parentDictTree = dictTreeService.getById(dictTree.getPid()); - if (ObjectUtil.isNotNull(parentDictTree)) { - String key = parentDictTree.getCode(); - checkMap.putIfAbsent(key + "_" + parentDictTree.getId(), new TreeSet<>()); - checkMap.get(key + "_" + parentDictTree.getId()).add(adBaseResult.getSort()); - } - } - return checkMap; - } - - - /** - * 浙江电科院版-动态生成标题和表格 - * - * @param baseModelDocument - * @param devNum - * @param key - * @param devReportParam - * @param indexSet - */ - private void generateTitleAndTableZJ(XWPFDocument baseModelDocument, String devNum, String key, DevReportParam devReportParam, Set indexSet) { - boolean isHarm = key.contains(DicDataEnum.HV.getCode()) || key.contains(DicDataEnum.HI.getCode()) || key.contains(DicDataEnum.HSV.getCode()) || key.contains(DicDataEnum.HSV.getCode()); - Map> radiusMap = getRadiusMap(devNum, key, devReportParam, indexSet, isHarm); - - for (String radius : radiusMap.keySet()) { - XWPFParagraph paragraph = baseModelDocument.createParagraph(); - paragraph.setAlignment(ParagraphAlignment.LEFT); - XWPFRun run = paragraph.createRun(); - run.setFontFamily("宋体"); - run.setBold(true); - run.setFontSize(12); - String s = key.split("_")[0]; - String msg = DicDataEnum.getMessageByCode(s); - if (isHarm) { - run.setText(msg + "测量准确度(最大允许误差:±" + radius.split("_")[1] + ")"); - } else { - run.setText(msg + "测量准确度(最大允许误差:±" + radius + ")"); - } - DicDataEnum enumByCode = DicDataEnum.getEnumByCode(key.split("_")[0]); - XWPFTable table = generateTableHeaderZJ(baseModelDocument, enumByCode); - - paragraph = baseModelDocument.createParagraph(); - // 生成表体 - generateTableBodyZJ(table, radiusMap.get(radius), enumByCode); - } - } - - - /** - * 获取同一个检测大项下不同的误差范围,及其检测结果 - * - * @param devNum - * @param key - * @param devReportParam - * @param indexSet - * @return - */ - private Map> getRadiusMap(String devNum, String key, DevReportParam devReportParam, Set indexSet, boolean isHarm) { - Map> raiusMap = new LinkedHashMap<>(); -// ResultParam param = new ResultParam(); -// param.setScriptId(devReportParam.getScriptId()); -// param.setDevId(devReportParam.getDevId()); -// param.setDevNum(devNum); -// param.setCode(devReportParam.getPlanCode()); -// String[] split = key.split("_"); -// param.setScriptType(split[1]); -// for (Integer index : indexSet) { -// param.setIndex(index); -// ResultVO resultVO = resultService.resultDataForReport(param); -// Map> resultData = resultVO.getResultData(); -// if (CollectionUtil.isNotEmpty(resultData)) { -// if (DicDataEnum.V.getCode().equals(split[0]) || DicDataEnum.I.getCode().equals(split[0])) { -// // 排除电压相角、电压偏差、电流相角 -// resultData.remove("电压相角"); -// resultData.remove("电压偏差"); -// resultData.remove("电流相角"); -// } -// resultData.values().stream().findFirst().ifPresent(obj -> { -// String radius = obj.getRadius(); -// String unit = obj.getUnit(); -// if (StrUtil.isNotBlank(radius)) { -// if (isHarm) { -// raiusMap.put(index + "_" + radius.split("~")[1] + unit, resultData.values().stream().collect(Collectors.toList())); -// } else { -// raiusMap.put(radius.split("~")[1] + unit, resultData.values().stream().collect(Collectors.toList())); -// } -// } -// }); -// } -// } - return raiusMap; - } - - /** - * 浙江电科院版-生成表格头部 - * - * @param doc - * @param checkItem 区分不同的表头 - * @return 生成的表格 - */ - private XWPFTable generateTableHeaderZJ(XWPFDocument doc, DicDataEnum checkItem) { - List> rows = new ArrayList<>(); - List row = null; - switch (checkItem) { - case FREQ: // 用于 频率 - row = new ArrayList<>(); - row.add(new CellEntity("给定值(HZ)", "25.0%", 1, 1, BLACK)); - row.add(new CellEntity("测试值(HZ)", "25.0%", 1, 1, BLACK)); - row.add(new CellEntity("误差(HZ)", "25.0%", 1, 1, BLACK)); - row.add(new CellEntity("结论", "25.0%", 1, 1, BLACK)); - rows.add(row); - break; - case V: // 用于 电压 - row = new ArrayList<>(); - row.add(new CellEntity("给定值(V)", "15.0%", 2, 1, BLACK)); - row.add(new CellEntity("测试值(V)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("误差(%)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("结论", "10.0%", 2, 1, BLACK)); - rows.add(row); - - row = new ArrayList<>(); - row.add(new CellEntity("", "15.0%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "10.0%", 1, 1, BLACK)); - rows.add(row); - break; - case I: // 用于 电流 - row = new ArrayList<>(); - row.add(new CellEntity("给定值(A)", "15.0%", 2, 1, BLACK)); - row.add(new CellEntity("测试值(A)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("误差(%)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("结论", "10.0%", 2, 1, BLACK)); - rows.add(row); - - row = new ArrayList<>(); - row.add(new CellEntity("", "15.0%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "10.0%", 1, 1, BLACK)); - rows.add(row); - break; - case IMBV:// 用于 负序电压不平衡度、负序电流不平衡度 - case IMBA: - row = new ArrayList<>(); - row.add(new CellEntity("给定值(%)", "25.0%", 1, 1, BLACK)); - row.add(new CellEntity("测试值(%)", "25.0%", 1, 1, BLACK)); - row.add(new CellEntity("误差(%)", "25.0%", 1, 1, BLACK)); - row.add(new CellEntity("结论", "25.0%", 1, 1, BLACK)); - rows.add(row); - break; - case F: // 用于 短时闪变 - row = new ArrayList<>(); - row.add(new CellEntity("给定值", "15.0%", 2, 1, BLACK)); - row.add(new CellEntity("测试值", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("误差(%)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("结论", "10.0%", 2, 1, BLACK)); - rows.add(row); - - row = new ArrayList<>(); - row.add(new CellEntity("", "15.0%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "10.0%", 1, 1, BLACK)); - rows.add(row); - break; - case HV: // 用于 谐波电压 - row = new ArrayList<>(); - row.add(new CellEntity("谐波次数", "7.0%", 2, 1, BLACK)); - row.add(new CellEntity("谐波电压给定值(%)", "10.0%", 2, 1, BLACK)); - row.add(new CellEntity("测试值(%)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("误差(%)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("结论", "8.0%", 2, 1, BLACK)); - rows.add(row); - - row = new ArrayList<>(); - row.add(new CellEntity("", "7.0%", 1, 1, BLACK)); - row.add(new CellEntity("", "10.0%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "8.0%", 1, 1, BLACK)); - rows.add(row); - break; - case HI: // 用于 谐波电流 - row = new ArrayList<>(); - row.add(new CellEntity("谐波次数", "8.0%", 2, 1, BLACK)); - row.add(new CellEntity("谐波电流给定值(A)", "10.0%", 2, 1, BLACK)); - row.add(new CellEntity("测试值(A)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("误差(%)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("结论", "7.0%", 2, 1, BLACK)); - rows.add(row); - - row = new ArrayList<>(); - row.add(new CellEntity("", "8.0%", 1, 1, BLACK)); - row.add(new CellEntity("", "10.0%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "7.0%", 1, 1, BLACK)); - rows.add(row); - break; - case HSV: // 用于 间谐波电压 - row = new ArrayList<>(); - row.add(new CellEntity("间谐波次数", "8.0%", 2, 1, BLACK)); - row.add(new CellEntity("间谐波电压给定值(%)", "10.0%", 2, 1, BLACK)); - row.add(new CellEntity("测试值(%)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("误差(%)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("结论", "7.0%", 2, 1, BLACK)); - rows.add(row); - - row = new ArrayList<>(); - row.add(new CellEntity("", "8.0%", 1, 1, BLACK)); - row.add(new CellEntity("", "10.0%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "7.0%", 1, 1, BLACK)); - rows.add(row); - break; - case HSI: // 用于 间谐波电流 - row = new ArrayList<>(); - row.add(new CellEntity("间谐波次数", "8.0%", 2, 1, BLACK)); - row.add(new CellEntity("间谐波电流给定值(A)", "10.0%", 2, 1, BLACK)); - row.add(new CellEntity("测试值(A)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("误差(%)", "12.5%", 1, 3, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("结论", "7.0%", 2, 1, BLACK)); - rows.add(row); - - row = new ArrayList<>(); - row.add(new CellEntity("", "8.0%", 1, 1, BLACK)); - row.add(new CellEntity("", "10.0%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L1", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L2", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("L3", "12.5%", 1, 1, BLACK)); - row.add(new CellEntity("", "7.0%", 1, 1, BLACK)); - rows.add(row); - break; - case VOLTAGE: // 用于 电压暂降、暂升及短时中断 - row = new ArrayList<>(); - row.add(new CellEntity("给定值", "16.0%", 1, 2, BLACK)); - row.add(new CellEntity("", "16.0%", 1, 1, BLACK)); - row.add(new CellEntity("测试值", "16.0%", 1, 2, BLACK)); - row.add(new CellEntity("", "16.0%", 1, 1, BLACK)); - row.add(new CellEntity("误差", "16.0%", 1, 2, BLACK)); - row.add(new CellEntity("", "16.0%", 1, 1, BLACK)); - rows.add(row); - - row = new ArrayList<>(); - row.add(new CellEntity("特征幅值(%)", "16.0%", 1, 1, BLACK)); - row.add(new CellEntity("持续时间(ms)", "16.0%", 1, 1, BLACK)); - row.add(new CellEntity("特征幅值(%)", "16.0%", 1, 1, BLACK)); - row.add(new CellEntity("持续时间(ms)", "16.0%", 1, 1, BLACK)); - row.add(new CellEntity("特征幅值(%)", "16.0%", 1, 1, BLACK)); - row.add(new CellEntity("持续时间(ms)", "16.0%", 1, 1, BLACK)); - rows.add(row); - break; - default: - break; - } - - - return generateTable(doc, rows, true); - } - - /** - * 根据数据生成表体部分 - * - * @param table - * @param rawResultDataVOS - * @param enumByCode - * @return - */ - private XWPFTable generateTableBodyZJ(XWPFTable table, List rawResultDataVOS, DicDataEnum enumByCode) { - // 组装数据 - getTableBodyDataZJ(rawResultDataVOS, enumByCode); - return table; - } - - /** - * 动态生成表格 - * - * @param doc - * @param rows 表头数据 - * @param isHeader 是否是表头 - * @return 生成的表格 - */ - private XWPFTable generateTable(XWPFDocument doc, List> rows, boolean isHeader) { - XWPFTable table = doc.createTable(rows.size(), rows.get(0).size()); - table.setTableAlignment(TableRowAlign.CENTER); - table.setWidth("100%"); - - CTTblGrid grid = table.getCTTbl().addNewTblGrid(); - for (int i = 0; i < rows.get(0).size(); i++) { - grid.addNewGridCol(); - } - for (int i = 0; i < rows.size(); i++) { - XWPFTableRow row = table.getRow(i); - row.setHeight((int) (1 / 2.54 * TWIPS_PER_INCH)); - - for (int j = 0; j < rows.get(i).size(); j++) { - CellEntity cellEntity = rows.get(i).get(j); - row.getCell(j).setWidth(cellEntity.getWidth()); - if (isHeader) { - setCommonCellStyle(row.getCell(j), cellEntity, true); - } else { - setCommonCellStyle(row.getCell(j), cellEntity, false); - } - - if (cellEntity.getColSpan() > 1) { - mergeCellsHorizontal(table, i, j, j + cellEntity.getColSpan() - 1); - } - if (cellEntity.getRowSpan() > 1) { - mergeCellsVertically(table, j, i, i + cellEntity.getRowSpan() - 1); - } - } - } - return table; - } - - /** - * 获取表体数据 - * - * @param resultDataVOList - * @param checkItem - * @return - */ - private List> getTableBodyDataZJ(List resultDataVOList, DicDataEnum checkItem) { - List> rows = new ArrayList<>(); - List row = null; - switch (checkItem) { - case FREQ: - for (RawResultDataVO resultDataVO : resultDataVOList) { - row = new ArrayList<>(); - RawResultDataVO.DetectionData dataT = resultDataVO.getDataT(); - row.add(new CellEntity(dataT.getResultData() + "", "25.0%", 1, 1, BLACK)); - row.add(new CellEntity(dataT.getData() + "", "25.0%", 1, 1, BLACK)); - row.add(new CellEntity(dataT.getRadius() + "", "25.0%", 1, 1, BLACK)); - row.add(new CellEntity(getResultStr(resultDataVO.getIsData()) + "", "25.0%", 1, 1, resultDataVO.getIsData() == 1 ? BLACK : RED)); - rows.add(row); - } - break; - default: - break; - } - return rows; - } - - public CTTcPr getTcPr(XWPFTableCell cell) { - return cell.getCTTc().isSetTcPr() ? cell.getCTTc().getTcPr() : cell.getCTTc().addNewTcPr(); - } - - /** - * word单元格列合并(合并列) - * - * @param table - * @param row - * @param fromCol - * @param toCol - */ - public void mergeCellsHorizontal(XWPFTable table, int row, int fromCol, int toCol) { - for (int colIndex = fromCol; colIndex <= toCol; colIndex++) { - XWPFTableCell cell = table.getRow(row).getCell(colIndex); - CTTcPr tcPr = getTcPr(cell); - CTHMerge hMerge = tcPr.addNewHMerge(); - if (colIndex == fromCol) { - hMerge.setVal(STMerge.RESTART); - } else { - hMerge.setVal(STMerge.CONTINUE); - } - } - } - - /** - * word单元格行合并(合并行) - * - * @param table - * @param col - * @param fromRow - * @param toRow - */ - public void mergeCellsVertically(XWPFTable table, int col, int fromRow, int toRow) { - for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) { - XWPFTableCell cell = table.getRow(rowIndex).getCell(col); - CTTcPr tcPr = getTcPr(cell); - CTVMerge vMerge = tcPr.addNewVMerge(); - if (rowIndex == fromRow) { - vMerge.setVal(STMerge.RESTART); - } else { - vMerge.setVal(STMerge.CONTINUE); - } - } - } - - public void setCommonCellStyle(XWPFTableCell cell, CellEntity cellEntity, boolean isBold) { - cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); - XWPFParagraph xwpfParagraph = cell.getParagraphs().get(0); - xwpfParagraph.setAlignment(ParagraphAlignment.CENTER); - List runs = xwpfParagraph.getRuns(); - XWPFRun run = null; - if (runs.isEmpty()) { - run = xwpfParagraph.createRun(); - } else { - run = runs.get(0); - } - run.setText(cellEntity.getCellValue()); - run.setBold(isBold); - run.setFontSize(10); - String text = run.getText(0); - if (StrUtil.isNotBlank(text) && Pattern.matches("^[A-Za-z0-9]+$", text)) { - run.setFontFamily("Arial"); - } else { - run.setFontFamily("宋体"); - } - } - - private void specialDealVoltage(Map dataModelMap, String symbol) { - String value = dataModelMap.get(symbol); - if (Objects.nonNull(value) && !value.equals("/")) { - Double valueDouble = Double.valueOf(value); - double result = ((valueDouble - 57.74) / 57.74) * 100; - dataModelMap.put(symbol, doubleRound(4, result)); - } - } - - /** - * 填充谐波Map数据 - */ - private void fillMapValueHarm(SingleNonHarmParam singleNonHarmParam, Map dataModelMap, String aSymbol, String bSymbol, String cSymbol, double baseValue, int percent) { - AdHarmonicResult adHarmonicResult = adHarmonicService.getSingleResult(singleNonHarmParam); - if (Objects.nonNull(adHarmonicResult)) { - - // 要处理 2 5 7 11 23 35 43 50 - // 基波 - String aBase = devValue(adHarmonicResult.getAValue1(), 1, 1); - String bBase = devValue(adHarmonicResult.getBValue1(), 1, 1); - String cBase = devValue(adHarmonicResult.getCValue1(), 1, 1); - dataModelMap.put("${" + aSymbol + "1}", aBase); - dataModelMap.put("${" + bSymbol + "1}", bBase); - dataModelMap.put("${" + cSymbol + "1}", cBase); - double aBaseValue = baseValue; - double bBaseValue = baseValue; - double cBaseValue = baseValue; - - if (!aBase.equals(StrPool.SLASH)) { - aBaseValue = Double.parseDouble(aBase); - } - if (!bBase.equals(StrPool.SLASH)) { - bBaseValue = Double.parseDouble(bBase); - } - if (!cBase.equals(StrPool.SLASH)) { - cBaseValue = Double.parseDouble(cBase); - } - - dataModelMap.put("${" + aSymbol + "2}", devValue(adHarmonicResult.getAValue2(), aBaseValue, percent)); - dataModelMap.put("${" + bSymbol + "2}", devValue(adHarmonicResult.getBValue2(), bBaseValue, percent)); - dataModelMap.put("${" + cSymbol + "2}", devValue(adHarmonicResult.getCValue2(), cBaseValue, percent)); - - - dataModelMap.put("${" + aSymbol + "5}", devValue(adHarmonicResult.getAValue5(), aBaseValue, percent)); - dataModelMap.put("${" + bSymbol + "5}", devValue(adHarmonicResult.getBValue5(), bBaseValue, percent)); - dataModelMap.put("${" + cSymbol + "5}", devValue(adHarmonicResult.getCValue5(), cBaseValue, percent)); - - dataModelMap.put("${" + aSymbol + "7}", devValue(adHarmonicResult.getAValue7(), aBaseValue, percent)); - dataModelMap.put("${" + bSymbol + "7}", devValue(adHarmonicResult.getBValue7(), bBaseValue, percent)); - dataModelMap.put("${" + cSymbol + "7}", devValue(adHarmonicResult.getCValue7(), cBaseValue, percent)); - - dataModelMap.put("${" + aSymbol + "11}", devValue(adHarmonicResult.getAValue11(), aBaseValue, percent)); - dataModelMap.put("${" + bSymbol + "11}", devValue(adHarmonicResult.getBValue11(), bBaseValue, percent)); - dataModelMap.put("${" + cSymbol + "11}", devValue(adHarmonicResult.getCValue11(), cBaseValue, percent)); - - dataModelMap.put("${" + aSymbol + "23}", devValue(adHarmonicResult.getAValue23(), aBaseValue, percent)); - dataModelMap.put("${" + bSymbol + "23}", devValue(adHarmonicResult.getBValue23(), bBaseValue, percent)); - dataModelMap.put("${" + cSymbol + "23}", devValue(adHarmonicResult.getCValue23(), cBaseValue, percent)); - - dataModelMap.put("${" + aSymbol + "35}", devValue(adHarmonicResult.getAValue35(), aBaseValue, percent)); - dataModelMap.put("${" + bSymbol + "35}", devValue(adHarmonicResult.getBValue35(), bBaseValue, percent)); - dataModelMap.put("${" + cSymbol + "35}", devValue(adHarmonicResult.getCValue35(), cBaseValue, percent)); - - dataModelMap.put("${" + aSymbol + "43}", devValue(adHarmonicResult.getAValue43(), aBaseValue, percent)); - dataModelMap.put("${" + bSymbol + "43}", devValue(adHarmonicResult.getBValue43(), bBaseValue, percent)); - dataModelMap.put("${" + cSymbol + "43}", devValue(adHarmonicResult.getCValue43(), cBaseValue, percent)); - - dataModelMap.put("${" + aSymbol + "50}", devValue(adHarmonicResult.getAValue50(), aBaseValue, percent)); - dataModelMap.put("${" + bSymbol + "50}", devValue(adHarmonicResult.getBValue50(), bBaseValue, percent)); - dataModelMap.put("${" + cSymbol + "50}", devValue(adHarmonicResult.getCValue50(), cBaseValue, percent)); - - - } - } private String devValue(String dataJson, double baseValue, Integer percent) { DetectionData tempA = JSONUtil.toBean(dataJson, DetectionData.class); @@ -2426,64 +1413,6 @@ public class PqReportServiceImpl extends ServiceImpl i } - /** - * 填充非谐波Map数据,ABC三相 - */ - private void fillMapValue(SingleNonHarmParam singleNonHarmParam, Map dataModelMap, String aSymbol, String bSymbol, String cSymbol) { - AdNonHarmonicResult adNonHarmonicResult = adNonHarmonicService.getSingleResult(singleNonHarmParam); - if (Objects.nonNull(adNonHarmonicResult)) { - dataModelMap.put("${".concat(aSymbol).concat("}"), devValue(adNonHarmonicResult.getAValue(), 1, 1)); - dataModelMap.put("${".concat(bSymbol).concat("}"), devValue(adNonHarmonicResult.getBValue(), 1, 1)); - dataModelMap.put("${".concat(cSymbol).concat("}"), devValue(adNonHarmonicResult.getCValue(), 1, 1)); - } - } - - /** - * 填充非谐波Map数据,T相 - */ - private void fillMapValueT(SingleNonHarmParam singleNonHarmParam, Map dataModelMap, String tSymbol) { - AdNonHarmonicResult adNonHarmonicResult = adNonHarmonicService.getSingleResult(singleNonHarmParam); - if (Objects.nonNull(adNonHarmonicResult)) { - dataModelMap.put("${".concat(tSymbol).concat("}"), devValue(adNonHarmonicResult.getTValue(), 1, 1)); - } - } - - - private String getPqScriptCheckDataByScriptId(String scriptId, Integer index, Integer errFlag, List phase) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - // todo... 不参与比较的数据没有了 - queryWrapper.eq(PqScriptCheckData::getScriptId, scriptId) - .eq(PqScriptCheckData::getEnable, DataStateEnum.ENABLE.getCode()) - .in(PqScriptCheckData::getPhase, phase) - .eq(PqScriptCheckData::getScriptIndex, index); - List list = pqScriptCheckDataService.list(queryWrapper); - if (CollectionUtil.isNotEmpty(list)) { - return list.get(0).getValueType(); - } - return null; - } - - - /** - * 获取测试小项的index - * 注:测试项下发的ABCT的index均是一样的 - */ - private Integer getTestItemIndex(String scriptId, String sourceScriptId, String subType, String valueType, Integer value) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(PqScriptDtls::getScriptId, scriptId) - .eq(PqScriptDtls::getScriptType, sourceScriptId) - .eq(PqScriptDtls::getScriptSubType, subType) - .eq(PqScriptDtls::getValueType, valueType) - .in(PqScriptDtls::getPhase, Arrays.asList("A", "B", "C")) - .eq(PqScriptDtls::getValue, value); - List pqScriptDtls = pqScriptDtlsService.list(queryWrapper); - if (CollectionUtil.isNotEmpty(pqScriptDtls)) { - return pqScriptDtls.get(0).getScriptIndex(); - } - return null; - } - - /** * 根据参数返回double的四舍五入值 * @@ -2530,104 +1459,5 @@ public class PqReportServiceImpl extends ServiceImpl i } } - private String getResultStr(Integer isData) { - if (isData == 1) { - return "合格"; - } - if (isData == 2) { - return "不合格"; - } - return "/"; - } - -// @Override -// public Map getMap(DevReportParam devReportParam) { -// HashMap resultMap = new HashMap<>(); -// List adNonHarmonicResultList = adNonHarmonicService.listAll(devReportParam.getScriptId(), "result_" + devReportParam.getPlanCode(), devReportParam.getDevId()); -// List adHarmonicResultList = adHarmonicService.listAll(devReportParam.getScriptId(), "result_" + devReportParam.getPlanCode(), devReportParam.getDevId()); -// -// Map> monitorIdMap1 = adNonHarmonicResultList.stream() -// .sorted(Comparator.comparing(AdNonHarmonicResult::getMonitorId)) -// .collect(Collectors.groupingBy(AdNonHarmonicResult::getMonitorId, LinkedHashMap::new, Collectors.toList())); -// Map> monitorIdMap2 = adHarmonicResultList.stream() -// .sorted(Comparator.comparing(AdHarmonicResult::getMonitorId)) -// .collect(Collectors.groupingBy(AdHarmonicResult::getMonitorId, LinkedHashMap::new, Collectors.toList())); -// -// String[] monitorIds = monitorIdMap1.keySet().stream().map(String::valueOf).toArray(String[]::new); -// -// monitorIdMap1.get(monitorIds[0]).stream().forEach(adNonHarmonicResult -> { -// DictTree dictTree = dictTreeService.getById(adNonHarmonicResult.getAdType()); -// -// DetectionData detectionDataA = JSON.parseObject(adNonHarmonicResult.getAValue(), DetectionData.class); -// DetectionData detectionDataB = JSON.parseObject(adNonHarmonicResult.getBValue(), DetectionData.class); -// DetectionData detectionDataC = JSON.parseObject(adNonHarmonicResult.getCValue(), DetectionData.class); -// -// DetectionData detectionDataT = JSON.parseObject(adNonHarmonicResult.getTValue(), DetectionData.class); -// // 标准值 -// Double standardValue = null; -// if (ObjectUtil.isNotNull(detectionDataT)) { -// standardValue = detectionDataT.getResultData(); -// -// resultMap.putIfAbsent(dictTree.getCode() + "_" + standardValue + "_T_Standard", detectionDataT.getResultData()); -// resultMap.putIfAbsent(dictTree.getCode() + "_" + standardValue + "_T_Test", detectionDataT.getData()); -// } else { -// standardValue = detectionDataA.getResultData(); -// -// resultMap.putIfAbsent(dictTree.getCode() + "_" + standardValue + "_A_Standard", detectionDataA.getResultData()); -// resultMap.putIfAbsent(dictTree.getCode() + "_" + standardValue + "_A_Test", detectionDataA.getData()); -// -// resultMap.putIfAbsent(dictTree.getCode() + "_" + standardValue + "_B_Standard", detectionDataB.getResultData()); -// resultMap.putIfAbsent(dictTree.getCode() + "_" + standardValue + "_B_Test", detectionDataB.getData()); -// -// resultMap.putIfAbsent(dictTree.getCode() + "_" + standardValue + "_C_Standard", detectionDataC.getResultData()); -// resultMap.putIfAbsent(dictTree.getCode() + "_" + standardValue + "_C_Test", detectionDataC.getData()); -// } -// resultMap.putIfAbsent(dictTree.getCode() + "_" + standardValue + "_Result", getResultStr(adNonHarmonicResult.getResultFlag())); -// }); -// -// monitorIdMap2.get(monitorIds[0]).stream().forEach(adHarmonicResult -> { -// DictTree dictTree = dictTreeService.getById(adHarmonicResult.getAdType()); -// -// for (int i = 2; i <= 50; i++) { -// try { -// Field fieldA = adHarmonicResult.getClass().getDeclaredField("aValue" + i); -// fieldA.setAccessible(true); -// Object a = fieldA.get(adHarmonicResult); -// -// Field fieldB = adHarmonicResult.getClass().getDeclaredField("bValue" + i); -// fieldB.setAccessible(true); -// Object b = fieldB.get(adHarmonicResult); -// -// Field fieldC = adHarmonicResult.getClass().getDeclaredField("cValue" + i); -// fieldC.setAccessible(true); -// Object c = fieldC.get(adHarmonicResult); -// -// List isDataList = new ArrayList<>(); -// if (ObjectUtil.isNotNull(a) && ObjectUtil.isNotNull(b) && ObjectUtil.isNotNull(c)) { -// DetectionData detectionData = JSON.parseObject(a.toString(), DetectionData.class); -// resultMap.putIfAbsent(dictTree.getCode() + "_" + detectionData.getResultData() + "_" + i + "_A_Standard", detectionData.getResultData()); -// resultMap.putIfAbsent(dictTree.getCode() + "_" + detectionData.getResultData() + "_" + i + "_A_Test", detectionData.getData()); -// isDataList.add(detectionData.getIsData()); -// -// detectionData = JSON.parseObject(b.toString(), DetectionData.class); -// resultMap.putIfAbsent(dictTree.getCode() + "_" + detectionData.getResultData() + "_" + i + "_B_Standard", detectionData.getResultData()); -// resultMap.putIfAbsent(dictTree.getCode() + "_" + detectionData.getResultData() + "_" + i + "_B_Test", detectionData.getData()); -// isDataList.add(detectionData.getIsData()); -// -// detectionData = JSON.parseObject(c.toString(), DetectionData.class); -// resultMap.putIfAbsent(dictTree.getCode() + "_" + detectionData.getResultData() + "_" + i + "_C_Standard", detectionData.getResultData()); -// resultMap.putIfAbsent(dictTree.getCode() + "_" + detectionData.getResultData() + "_" + i + "_C_Test", detectionData.getData()); -// isDataList.add(detectionData.getIsData()); -// } -// -// resultMap.putIfAbsent(dictTree.getCode() + "_" + i + "_Result", getResultStr(isDataList.stream().allMatch(data -> data == 1) ? 1 : (isDataList.stream().anyMatch(data -> data == 2) ? 2 : 4))); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// } -// }); -// -// return resultMap; -// } } 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 5f0f0b39..04913022 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 @@ -1363,8 +1363,8 @@ public class ResultServiceImpl implements IResultService { } } } - errorScopeMag = dealErrorScope(errorScopeMag).concat(unitMag); - errorScopeDur = dealErrorScope(errorScopeDur).concat(unitDur); + errorScopeMag = dealErrorScope(errorScopeMag).concat(StrUtil.isBlank(unitMag) ? "" : unitMag); + errorScopeDur = dealErrorScope(errorScopeDur).concat(StrUtil.isBlank(unitDur) ? "" : unitDur); errorScope = "特征幅值:".concat(errorScopeMag).concat(StrPool.COMMA).concat("持续时间:").concat(errorScopeDur); keyFillMap.put(ItemReportKeyEnum.ERROR_SCOPE.getKey(), errorScope); @@ -1398,6 +1398,9 @@ public class ResultServiceImpl implements IResultService { * @param errorScope 误差范围 */ private String dealErrorScope(String errorScope) { + if (StrUtil.isBlank(errorScope)) { + return "/"; + } if (errorScope.contains("~")) { String[] split = errorScope.split("~"); String begin = split[0];