diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java index 5dffa3509..fd2ac0176 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/report/service/impl/ParamsReportDetailEOServiceImpl.java @@ -726,16 +726,6 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl allRelevFileList = (List) allParamsInfoList.get(2).get("fileListAll"); - if (allRelevFileList != null && !allRelevFileList.isEmpty()) { - allRelevFileList = allRelevFileList.stream().distinct().collect(Collectors.toList()); - String exportFile = "导出文件"; - if (CutEnum.EN.getValue().equals(paramsReportDetailVO.getCut())) { - exportFile = "Export file"; - } - downLoadFileList(allRelevFileList,fileNowPath + File.separator + exportFile); - } // 拿取模板 String repFileName = fileName.replaceAll("/","_"); @@ -743,6 +733,35 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl> fileListAll = (List>) allParamsInfoList.get(2).get("fileListAll"); + + if (fileListAll != null && !fileListAll.isEmpty()) { + Map paramsAfterFilter = WordUtil.filterParams(wordMLPackage, params); + if (CollectionUtil.isNotEmpty(paramsAfterFilter)) { + List nioNumberList = paramsAfterFilter.keySet().stream().collect(Collectors.toList()); + List allRelevFileList = new ArrayList<>(); + for (Map fileMap : fileListAll) { + for (Map.Entry map : fileMap.entrySet()) { + String key = (String) map.getKey(); + List fileList = (List) map.getValue(); + if (nioNumberList.contains(key)) { + allRelevFileList.addAll(fileList); + } + } + } + if (CollectionUtil.isNotEmpty(allRelevFileList)) { + String exportFile = "导出文件"; + if (CutEnum.EN.getValue().equals(paramsReportDetailVO.getCut())) { + exportFile = "Export file"; + } + + downLoadFileList(allRelevFileList, fileNowPath + File.separator + exportFile); + } + } + } + // 替换占位符内容 WordUtil.replacePictureBatch(wordMLPackage, imgListAll); WordUtil.replaceVariable(wordMLPackage, params); @@ -837,29 +856,47 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl allRelevFileList = (List) allParamsInfoList.get(2).get("fileListAll"); - if (allRelevFileList != null && !allRelevFileList.isEmpty()) { - allRelevFileList = allRelevFileList.stream().distinct().collect(Collectors.toList()); - String exportFile = "导出文件"; - if (CutEnum.EN.getValue().equals(paramsReportDetailVO.getCut())) { - exportFile = "Export file"; - } - downLoadFileList(allRelevFileList,fileNowPath + File.separator + exportFile); - } - // 拿取模板 String repFileName = fileName.replaceAll("/","_"); wordOS = new FileOutputStream(fileNowPath + File.separator + repFileName); if (CosBootUtil.doesObjectExist(templateUrl)) { - InputStream wordTemplate = CosBootUtil.download(templateUrl); + InputStream exceltemplateForDocx4j = CosBootUtil.download(templateUrl); // com.qcloud.cos.utils.IOUtils.copy(wordTemplate, wordOS); + InputStream excelTemplateForPoi = CosBootUtil.download(templateUrl); + + SpreadsheetMLPackage pkg = SpreadsheetMLPackage.load(exceltemplateForDocx4j); + + //下载关联文件内容 + List> fileListAll = (List>) allParamsInfoList.get(2).get("fileListAll"); + + if (fileListAll != null && !fileListAll.isEmpty()) { + Map paramsAfterFilter = ExcelUtil.filterParams(pkg, params); + if (CollectionUtil.isNotEmpty(paramsAfterFilter)) { + List nioNumberList = paramsAfterFilter.keySet().stream().collect(Collectors.toList()); + List allRelevFileList = new ArrayList<>(); + for (Map fileMap : fileListAll) { + for (Map.Entry map : fileMap.entrySet()) { + String key = (String) map.getKey(); + List fileList = (List) map.getValue(); + if (nioNumberList.contains(key)) { + allRelevFileList.addAll(fileList); + } + } + } + if (CollectionUtil.isNotEmpty(allRelevFileList)) { + String exportFile = "导出文件"; + if (CutEnum.EN.getValue().equals(paramsReportDetailVO.getCut())) { + exportFile = "Export file"; + } + + downLoadFileList(allRelevFileList, fileNowPath + File.separator + exportFile); + } + } + } // 替换占位符内容 // docx4j方式 - InputStream excelTemplate = CosBootUtil.download(templateUrl); - SpreadsheetMLPackage pkg = SpreadsheetMLPackage.load(wordTemplate); - Workbook workbook = WorkbookFactory.create(excelTemplate); + Workbook workbook = WorkbookFactory.create(excelTemplateForPoi); ExcelUtil.replacePictureBatchPOI(workbook, pkg, imgListAll, params); ExcelUtil.variableReplace(pkg, params); pkg.save(wordOS); @@ -1092,7 +1129,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl resultMap = new HashMap<>(); List> imgListAll = new ArrayList<>(); // 存放图片信息 - List fileListAll = new ArrayList<>(); // 存放文件 + List> fileListAll = new ArrayList<>(); // 存放文件 String fileTypeStr = ".png,.PNG,.jfif,.JFIF,.pjpeg,.PJPEG,.jpeg,.JPEG,.pjp,.PJP,.jpg,.JPG"; // 查询配置列数据 for (Map record1 : dataList) { @@ -1125,13 +1162,16 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl fileMap = new HashMap<>(); + fileMap.put(nioNumber, ossFileList); + fileListAll.add(fileMap); } else { imgFileList.addAll(ossFileList); } } } } - fileListAll.addAll(fileList); StringBuilder configDataBuilder = new StringBuilder(); // 重新组合配置数据 if ((ControlTypeEnum.FILE.getValue().equals(controlType) diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/template/service/impl/ParamsInfoEOServiceImpl.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/template/service/impl/ParamsInfoEOServiceImpl.java index 176b3acdd..8316dee8e 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/template/service/impl/ParamsInfoEOServiceImpl.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/template/service/impl/ParamsInfoEOServiceImpl.java @@ -246,6 +246,39 @@ public class ParamsInfoEOServiceImpl extends ServiceImpl Long.parseLong("15")) { + if (CutEnum.CN.getValue().equals(cut)) { + throw new JeroBootException("编号不能超过15个字符"); + } else { + throw new JeroBootException("Number can not exceed 15 chars"); + } + } + } + + if (StringUtils.isNotBlank(paramsName)) { + if (paramsName.length() > Long.parseLong("100")) { + if (CutEnum.CN.getValue().equals(cut)) { + throw new JeroBootException("参数名称不能超过100个字符"); + } else { + throw new JeroBootException("Params Name can not exceed 100 chars"); + } + } + } + + } + /** * 通过id删除 * diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/ExcelUtil.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/ExcelUtil.java index 25cd437e8..544412b38 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/ExcelUtil.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/ExcelUtil.java @@ -1,5 +1,6 @@ package com.jero.modules.project.util; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; @@ -40,6 +41,7 @@ import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; @Slf4j public class ExcelUtil { @@ -70,6 +72,33 @@ public class ExcelUtil { System.out.println("mmmmmmm"); } + /** + * 过滤出需要导出的 + * @param pkg + * @param params + * @return + * @throws Exception + */ + public static Map filterParams(SpreadsheetMLPackage pkg, Map params) throws Exception { + JaxbSmlPart smlPart = (JaxbSmlPart)pkg.getParts().get(new PartName("/xl/sharedStrings.xml")); // 获取所有sheet中的文本 + String wmlTemplateString = getWmlTemplateString(smlPart); + List placeholderList = new ArrayList<>(); + getAllPlaceholderElementFromObject(wmlTemplateString, 0, placeholderList); // 获取文档中所有占位符 + + Map paramsAfterFilter = new HashMap<>(); + List textValueList = placeholderList.stream().distinct().collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(textValueList)) { + for (Map.Entry map : params.entrySet()) { + String value = "${" + map.getKey() + "}"; + if (textValueList.contains(value)) { + paramsAfterFilter.put(map.getKey(), map.getValue()); + } + } + } + + return paramsAfterFilter; + } + public static void setRowHeight(WorksheetPart worksheetPart, int rIndex, double height, int cIndex, String text) { SheetData sheetData = worksheetPart.getJaxbElement().getSheetData(); @@ -370,8 +399,8 @@ public class ExcelUtil { // This seems to be about 5% faster than the Scanner approach wmlTemplateString = IOUtils.toString(is, "UTF-8"); - List placeholderList = new ArrayList<>(); - getAllPlaceholderElementFromObject(wmlTemplateString, 0, placeholderList); +// List placeholderList = new ArrayList<>(); +// getAllPlaceholderElementFromObject(wmlTemplateString, 0, placeholderList); } } catch (Exception e) { log.error(e.getMessage(), e); @@ -381,18 +410,18 @@ public class ExcelUtil { } } - private static List getAllPlaceholderElementFromObject(String wmlTemplateString, int offset, List placeholderList) { + private static void getAllPlaceholderElementFromObject(String wmlTemplateString, int offset, List placeholderList) { int startKey = wmlTemplateString.indexOf("${", offset); if (startKey == -1) - return null; + return; else { int keyEnd = wmlTemplateString.indexOf('}', startKey); String placeHolder = wmlTemplateString.substring(startKey, keyEnd + 1); if (isPlaceholder(placeHolder)) { placeholderList.add(placeHolder); } - return getAllPlaceholderElementFromObject(wmlTemplateString, keyEnd + 1, placeholderList); + getAllPlaceholderElementFromObject(wmlTemplateString, keyEnd + 1, placeholderList); } } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/WordUtil.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/WordUtil.java index f6945d179..4d66e753e 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/WordUtil.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/util/WordUtil.java @@ -1,5 +1,6 @@ package com.jero.modules.project.util; +import cn.hutool.core.collection.CollectionUtil; import org.docx4j.Docx4J; import org.docx4j.TraversalUtil; import org.docx4j.XmlUtils; @@ -28,6 +29,7 @@ import java.io.OutputStream; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; public class WordUtil { private static final Logger log = LoggerFactory.getLogger(WordUtil.class); @@ -230,6 +232,34 @@ public class WordUtil { } + /** + * 过滤出需要导出的 + * @param wordMLPackage + * @param params + * @return + * @throws Exception + */ + public static Map filterParams(WordprocessingMLPackage wordMLPackage, Map params) throws Exception { + MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart(); + Docx4jUtils.cleanDocumentPart(mainDocumentPart); + Document wmlDoc = (Document)mainDocumentPart.getJaxbElement(); + Body body = wmlDoc.getBody(); + List textList = getAllPlaceholderElementFromObject(body); // 获取文档中所有占位符 + + Map paramsAfterFilter = new HashMap<>(); + List textValueList = textList.stream().map(Text::getValue).distinct().collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(textValueList)) { + for (Map.Entry map : params.entrySet()) { + String value = "${" + map.getKey() + "}"; + if (textValueList.contains(value)) { + paramsAfterFilter.put(map.getKey(), map.getValue()); + } + } + } + + return paramsAfterFilter; + } + /** * 发现docx文档包含占位符的文本节点 * 未解决问题:两个连着的相同占位符会识别成一个。如 原文:${key1}${key1}