|
@@ -1072,4 +1072,214 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
|
|
|
//改动目录的相关内容都得更新目录域
|
|
|
doc.updateFields();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int exportFile2(Map<String, Object> map, HttpServletResponse response) throws Exception{
|
|
|
+ SysFileItemDo fileItemDo = sysFileItemService.getById("d1b3271ce2ec45c2915f2dbcd819f45a");
|
|
|
+ final Document[] indexDoc = {WordHelpUtils.getDoc(fileItemDo.getFullpath())};
|
|
|
+ FormData formData = new FormData();
|
|
|
+ List<Map<String,Object>> mainDataList = new ArrayList<>();
|
|
|
+ Map<String,Object> mainMap = new HashMap<>(16);
|
|
|
+ mainMap.put("projectNames","XXX");
|
|
|
+ mainMap.put("projectCode","XXX");
|
|
|
+ mainMap.put("projectName","XXX");
|
|
|
+ mainMap.put("currentDate",DateUtils.format(new Date()));
|
|
|
+ mainMap.put("machineNo","XXX");
|
|
|
+ mainDataList.add(mainMap);
|
|
|
+ formData.setMainDataList(mainDataList);
|
|
|
+ indexDoc[0] = ExcelExportUtil.fillWordDataByMap(fileItemDo.getFullpath(), formData);
|
|
|
+ List<ZhcxCommissionCheckDetailDo> list = zhcxCommissionCheckDetailDao.listData(map);
|
|
|
+ Document doc = null;
|
|
|
+ DocumentBuilder builder = null;
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("template/检查内容明细模版.doc");
|
|
|
+ try {
|
|
|
+ doc = new Document(classPathResource.getInputStream());
|
|
|
+ builder = new DocumentBuilder(doc);
|
|
|
+ } catch (Exception e) {
|
|
|
+ ExceptionUtils.printExceptionDetail(e,"空模板获取出现异常");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ //移动到页眉
|
|
|
+ builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); // 主页眉
|
|
|
+ // 如果有多个页眉,可以选择HeaderFooterType.HEADER_FIRST, HeaderFooterType.HEADER_EVEN等
|
|
|
+ for (com.aspose.words.Field field : doc.getRange().getFields()) {
|
|
|
+ if ("«projectName»".equals(field.getResult())) { // 替换FieldName为你的字段名称
|
|
|
+ // 在这里操作field对象
|
|
|
+ builder.moveToField(field, true);
|
|
|
+ builder.write("XXX");
|
|
|
+ field.setResult("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<JSONObject> resultType = zhcxCommissionCheckDetailDao.getResultDictList();
|
|
|
+ if(list.isEmpty()){
|
|
|
+ return 1;
|
|
|
+ }else {
|
|
|
+ //标题
|
|
|
+ Set<ZhcxCommissionCheckDetailDo> noSet = list.stream().filter(item -> ObjectUtil.isNotEmpty(item.getIstitle()) && "y".equals(item.getIstitle())).collect(Collectors.toSet());
|
|
|
+ Map<String, ZhcxCommissionCheckDetailWordVO> resMap = new HashMap<>();
|
|
|
+ for (ZhcxCommissionCheckDetailDo item : noSet) {
|
|
|
+ ZhcxCommissionCheckDetailWordVO checkDetailWordVO = new ZhcxCommissionCheckDetailWordVO();
|
|
|
+ checkDetailWordVO.setChapterno(item.getChapternopuls());
|
|
|
+ String chtitle = "";
|
|
|
+ String entitle = "";
|
|
|
+ if (StringUtils.isNotBlank(item.getChtitle())){
|
|
|
+ chtitle = item.getChtitle();
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(item.getEntitle())){
|
|
|
+ entitle = item.getEntitle();
|
|
|
+ }
|
|
|
+ checkDetailWordVO.setTitleContent(chtitle+entitle);
|
|
|
+ checkDetailWordVO.setDetailList(new LinkedList<>());
|
|
|
+ resMap.put(item.getChapternopuls(),checkDetailWordVO);
|
|
|
+ }
|
|
|
+ //非标题
|
|
|
+ List<ZhcxCommissionCheckDetailDo> detailLists = list.stream().filter(item -> !(ObjectUtil.isNotEmpty(item.getIstitle()) && "y".equals(item.getIstitle()))).collect(Collectors.toList());
|
|
|
+ for (ZhcxCommissionCheckDetailDo item : detailLists) {
|
|
|
+ String chapternopuls = item.getChapternopuls();
|
|
|
+ int i = chapternopuls.lastIndexOf(".");
|
|
|
+ String key = chapternopuls.substring(0, i);
|
|
|
+ if(!resMap.containsKey(key)){
|
|
|
+ log.error("不能导出错误的章节号:{}的报告", chapternopuls);
|
|
|
+ log.error("不能导出错误的章节号key:{}的报告", key);
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+ ZhcxCommissionCheckDetailWordVO checkDetailWordVO = resMap.get(key);
|
|
|
+ List<ZhcxCommissionCheckDetailDo> detailList = checkDetailWordVO.getDetailList();
|
|
|
+ detailList.add(item);
|
|
|
+ detailList.sort((a,b)->{
|
|
|
+ LinkedList<String> a1 = new LinkedList<>(Arrays.asList(a.getChapternopuls().split("\\.")));
|
|
|
+ LinkedList<String> b1 = new LinkedList<>(Arrays.asList(b.getChapternopuls().split("\\.")));
|
|
|
+ return sort1(a1,b1);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ List<ZhcxCommissionCheckDetailWordVO> resList = new LinkedList<>();
|
|
|
+ for (String s : resMap.keySet()) {
|
|
|
+ resList.add(resMap.get(s));
|
|
|
+ }
|
|
|
+ resList.sort((a,b)->{
|
|
|
+ LinkedList<String> a1 = new LinkedList<>(Arrays.asList(a.getChapterno().split("\\.")));
|
|
|
+ LinkedList<String> b1 = new LinkedList<>(Arrays.asList(b.getChapterno().split("\\.")));
|
|
|
+ return sort1(a1,b1);
|
|
|
+ });
|
|
|
+ builder.moveToDocumentStart();
|
|
|
+ for (ZhcxCommissionCheckDetailWordVO res : resList) {
|
|
|
+ int titleType = res.getChapterno().split("\\.").length;
|
|
|
+ if (titleType==1){
|
|
|
+ buildText(builder, DEFAULT_FONT_NAME, titleType, 12, true,
|
|
|
+ res.getChapterno()+"."+res.getTitleContent(), null);
|
|
|
+ }else {
|
|
|
+ buildText(builder, DEFAULT_FONT_NAME, titleType, 12, true,
|
|
|
+ res.getChapterno()+res.getTitleContent(), null);
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(res.getDetailList())){
|
|
|
+ builder.getFont().setSize(15);
|
|
|
+ // 插入表头
|
|
|
+ builder.insertCell();
|
|
|
+ builder.getCellFormat().setWidth(40);
|
|
|
+ builder.getRowFormat().setHeight(20);
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
|
|
|
+ builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
|
|
|
+ buildTextContentTitle(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_6, 12, true,
|
|
|
+ "NO.", null);
|
|
|
+ builder.insertCell();
|
|
|
+ builder.getCellFormat().setWidth(170);
|
|
|
+ builder.getRowFormat().setHeight(20);
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
|
|
|
+ builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
|
|
|
+ buildTextContentTitle(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_6, 12, true,
|
|
|
+ "检查项目", null);
|
|
|
+ builder.insertCell();
|
|
|
+ builder.getCellFormat().setWidth(120);
|
|
|
+ builder.getRowFormat().setHeight(20);
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
|
|
|
+ builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
|
|
|
+ buildTextContentTitle(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_6, 12, true,
|
|
|
+ "测试地点", null);
|
|
|
+ builder.insertCell();
|
|
|
+ builder.getCellFormat().setWidth(40);
|
|
|
+ builder.getRowFormat().setHeight(20);
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
|
|
|
+ builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
|
|
|
+ buildTextContentTitle(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_6, 12, true,
|
|
|
+ "结果", null);
|
|
|
+ builder.insertCell();
|
|
|
+ builder.getCellFormat().setWidth(100);
|
|
|
+ builder.getRowFormat().setHeight(20);
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
|
|
|
+ builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
|
|
|
+ buildTextContentTitle(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_6, 12, true,
|
|
|
+ "备注", null);
|
|
|
+ builder.endRow();
|
|
|
+ for (ZhcxCommissionCheckDetailDo detailWordVO:res.getDetailList()){
|
|
|
+ // 插入表格的第一行
|
|
|
+ builder.insertCell();
|
|
|
+ builder.getCellFormat().setWidth(40);
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
|
|
|
+ builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
|
|
|
+ // 取的应该是新的章节号 detailWordVO.getChapterno
|
|
|
+ buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_7, 11, false,
|
|
|
+ detailWordVO.getChapternopuls(), null);
|
|
|
+
|
|
|
+ builder.insertCell();
|
|
|
+ builder.getCellFormat().setWidth(170);
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
|
|
|
+ builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
|
|
|
+ String chtestcontent = "";
|
|
|
+ String entestcontent = "";
|
|
|
+ if (StringUtils.isNotBlank(detailWordVO.getChtestcontent())){
|
|
|
+ chtestcontent = detailWordVO.getChtestcontent();
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(detailWordVO.getEntestcontent())){
|
|
|
+ entestcontent = detailWordVO.getEntestcontent();
|
|
|
+ }
|
|
|
+ buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_7, 11, false,
|
|
|
+ chtestcontent+entestcontent, null);
|
|
|
+
|
|
|
+ builder.insertCell();
|
|
|
+ builder.getCellFormat().setWidth(120);
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
|
|
|
+ builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
|
|
|
+ String testaddress = "CX BASE长兴基地";
|
|
|
+ if (StringUtils.isNotBlank(detailWordVO.getTestaddress())){
|
|
|
+ // 10-> CX BASE长兴基地 20-> USER SITE码头现场
|
|
|
+ if(detailWordVO.getTestaddress().equals("20")){
|
|
|
+ testaddress = "USER SITE码头现场";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_7, 11, false,
|
|
|
+ testaddress, null);
|
|
|
+
|
|
|
+ builder.insertCell();
|
|
|
+ builder.getCellFormat().setWidth(40);
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
|
|
|
+ builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
|
|
|
+ String testresult = "";
|
|
|
+ if (StringUtils.isNotBlank(detailWordVO.getTestresult())){
|
|
|
+ testresult = resultType.stream().filter(dictDo -> detailWordVO.getTestresult().contains(dictDo.getString("VALUE"))).findFirst().get().getString("NAME").toString();
|
|
|
+ }
|
|
|
+ buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_7, 11, false,
|
|
|
+ testresult, null);
|
|
|
+ builder.insertCell();
|
|
|
+ builder.getCellFormat().setWidth(100);
|
|
|
+ builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
|
|
|
+ builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
|
|
|
+ String testnotes = "";
|
|
|
+ if (StringUtils.isNotBlank(detailWordVO.getTestnotes())){
|
|
|
+ testnotes = detailWordVO.getTestnotes();
|
|
|
+ }
|
|
|
+ buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_7, 11, false,
|
|
|
+ testnotes, null);
|
|
|
+ builder.endRow();
|
|
|
+ }
|
|
|
+ // 结束表格
|
|
|
+ builder.endTable();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ indexDoc[0].appendDocument(doc, ImportFormatMode.KEEP_DIFFERENT_STYLES);
|
|
|
+ // 导出world
|
|
|
+ exportWord(indexDoc[0], response);
|
|
|
+ }
|
|
|
+ return 3;
|
|
|
+ }
|
|
|
}
|