Jelajahi Sumber

试车标准库导入校验更改,导入数据格式处理,试车检查添加导出和预览pdf

zhoudazhuang 6 bulan lalu
induk
melakukan
631bbab820

+ 20 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/dao/ZhcxCommissionCheckDetailTreeDao.java

@@ -6,6 +6,10 @@ import com.rongwei.bsentity.dto.commission.CopyDetailDto;
 import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+import java.util.Map;
 import org.apache.ibatis.annotations.Update;
 
 /**
@@ -79,6 +83,22 @@ public interface ZhcxCommissionCheckDetailTreeDao extends BaseMapper<ZhcxCommiss
             " ZHCX_COMMISSION_CHECK_DETAIL_TREE where BASEINFOID = #{sourcePid}")
     void copyByPid(CopyDetailDto copyDetail);
 
+    /**
+     * 查询检查内容树表
+     * @param map
+     * @return
+     */
+    @Select("SELECT\n" +
+            "\t*\n" +
+            "FROM\n" +
+            "\tZHCX_COMMISSION_CHECK_DETAIL_TREE\n" +
+            "WHERE\n" +
+            "\tBASEINFOID = #{checkId}\n" +
+            "\tAND DELETED = 0\n" +
+            "ORDER BY\n" +
+            "\tSORT ASC")
+    List<ZhcxCommissionCheckDetailTreeDo> listCheckDetailTreeData(Map map);
+
     @Update("UPDATE " +
             " ZHCX_COMMISSION_CHECK_DETAIL_TREE t1 " +
             "JOIN ZHCX_COMMISSION_CHECK_DETAIL_TREE t2 ON " +

+ 10 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxCommissionCheckDetailTreeService.java

@@ -4,6 +4,9 @@ import com.rongwei.bsentity.domain.ZhcxCommissionCheckDetailTreeDo;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.rongwei.bsentity.dto.commission.CopyDetailDto;
 
+import java.util.List;
+import java.util.Map;
+
 import java.util.List;
 
 /**
@@ -31,6 +34,13 @@ public interface ZhcxCommissionCheckDetailTreeService extends IService<ZhcxCommi
      */
     void copyByPid(CopyDetailDto copyDetail);
 
+    /**
+     * 查询检查
+     * @param map
+     * @return
+     */
+    List<ZhcxCommissionCheckDetailTreeDo> listCheckDetailTreeData(Map map);
+
     /**
      * 异步批量保存
      * @param resultTreeDo

+ 1 - 1
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxCommissionCheckService.java

@@ -46,7 +46,7 @@ public interface ZhcxCommissionCheckService extends IService<ZhcxCommissionCheck
      * @param response
      * @return
      */
-    int exportFile(Map<String, Object> map, HttpServletResponse response) throws Exception;
+    R exportFile(Map<String, Object> map, HttpServletResponse response) throws Exception;
 
     /**
      * 试车标准库导出

+ 8 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxCommissionCheckDetailTreeServiceImpl.java

@@ -11,6 +11,9 @@ import org.springframework.stereotype.Service;
 
 import java.util.List;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  *  服务实现类
@@ -51,4 +54,9 @@ public class ZhcxCommissionCheckDetailTreeServiceImpl extends ServiceImpl<ZhcxCo
     public void saveTreeBatch(List<ZhcxCommissionCheckDetailTreeDo> resultTreeDo) {
         this.saveBatch(resultTreeDo);
     }
+
+    @Override
+    public List<ZhcxCommissionCheckDetailTreeDo> listCheckDetailTreeData(Map map) {
+        return dao.listCheckDetailTreeData(map);
+    }
 }

+ 239 - 179
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxCommissionCheckServiceImpl.java

@@ -744,7 +744,7 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
      * @param response
      */
     @Override
-    public int exportFile(Map<String, Object> map, HttpServletResponse response) throws Exception {
+    public R exportFile(Map<String, Object> map, HttpServletResponse response) throws Exception {
         Object projectObj = map.get("projectId");
         Object machineNoObj = map.get("machineNo");
         Object exportObj = map.get("exportType");
@@ -771,6 +771,7 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
         formData.setMainDataList(mainDataList);
         indexDoc[0] = ExcelExportUtil.fillWordDataByMap(fileItemDo.getFullpath(), formData);
         List<ZhcxCommissionCheckDetailDo> list = zhcxCommissionCheckDetailDao.listData(map);
+        List<ZhcxCommissionCheckDetailTreeDo> checkTreeList = zhcxCommissionCheckDetailTreeService.listCheckDetailTreeData(map);
         Document doc = null;
         DocumentBuilder builder = null;
         ClassPathResource classPathResource = new ClassPathResource("template/检查内容明细模版.doc");
@@ -779,7 +780,7 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
             builder = new DocumentBuilder(doc);
         } catch (Exception e) {
             ExceptionUtils.printExceptionDetail(e,"空模板获取出现异常");
-            return 0;
+            return R.error("空模板获取出现异常");
         }
         //移动到页眉
         builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); // 主页眉
@@ -793,47 +794,121 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
             }
         }
         List<JSONObject> resultType = zhcxCommissionCheckDetailDao.getResultDictList();
-        if(list.isEmpty()){
-            return 1;
+        if(list.isEmpty()||checkTreeList.isEmpty()){
+            return R.error("该检查内容没有数据");
         }else {
-            //标题
-            Set<ZhcxCommissionCheckDetailDo> noSet = list.stream().filter(item -> ObjectUtil.isNotEmpty(item.getIstitle()) && "y".equals(item.getIstitle())).collect(Collectors.toSet());
+            //设置word导出目录
             Map<String, ZhcxCommissionCheckDetailWordVO> resMap = new HashMap<>();
-            for (ZhcxCommissionCheckDetailDo item : noSet) {
+            for (ZhcxCommissionCheckDetailTreeDo item : checkTreeList) {
                 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.setTitleContent(item.getName());
+                checkDetailWordVO.setLevel(item.getLevel());
                 checkDetailWordVO.setDetailList(new LinkedList<>());
-                resMap.put(item.getChapternopuls(),checkDetailWordVO);
+                if (!"-1".equals(item.getPid())){
+                    //目前标题最多到三级
+                    if (item.getLevel()==2){
+                        String oldPid = item.getPid();
+                        //树等级为二级处理章节号
+                        List<ZhcxCommissionCheckDetailTreeDo> parentList =  checkTreeList.stream().filter(info->info.getId().split("_")[0].equals(oldPid.split("_")[0])).collect(Collectors.toList());
+                        if (!parentList.isEmpty()){
+                            String parentTreeCode = parentList.get(0).getTreecode();
+                            if (StringUtils.isBlank(parentTreeCode)){
+                                return R.error(item.getName()+"该树的父节点的编码不能为空");
+                            }else {
+                                //设置二级树节点的章节号规则:取出一级树编码.号后面的放在二级编码的第一位
+                                int i = parentTreeCode.indexOf(".");
+                                if (i!= -1){
+                                    String key = parentTreeCode.substring(i+1);
+                                    String result = item.getTreecode().replaceAll(".*\\.", key+".");
+                                    checkDetailWordVO.setChapterno(result);
+                                }
+                            }
+                        }
+                    }else {
+                        String[] fullIds = item.getFullpid().split(",");
+                        if (fullIds.length>2){
+                            //树等级为三级处理章节号
+                            String oneLevelKey = "";
+                            //根据当前节点过滤出一级树的列表
+                            List<ZhcxCommissionCheckDetailTreeDo> oneLevelList =  checkTreeList.stream().filter(info->info.getId().split("_")[0].equals(fullIds[1])).collect(Collectors.toList());
+                            if (!oneLevelList.isEmpty()){
+                                //取出一级树节点编码
+                                String oneLevelTreeCode = oneLevelList.get(0).getTreecode();
+                                if (StringUtils.isBlank(oneLevelTreeCode)){
+                                    return R.error(item.getName()+"该树的一级节点的编码不能为空");
+                                }else {
+                                    String oldPid = item.getPid();
+                                    //设置三级树节点的章节号规则:取出一级树编码.号后面的加上二级树编码.号后面的再加上自身.号后面的数据
+                                    int i = oneLevelTreeCode.indexOf(".");
+                                    if (i!= -1){
+                                        oneLevelKey = oneLevelTreeCode.substring(i+1);
+                                        String twoLevelKey = "";
+                                        List<ZhcxCommissionCheckDetailTreeDo> parentList =  checkTreeList.stream().filter(info->info.getId().split("_")[0].equals(oldPid.split("_")[0])).collect(Collectors.toList());
+                                        if (!parentList.isEmpty()){
+                                            //取出父树节点编码
+                                            String parentTreeCode = parentList.get(0).getTreecode();
+                                            if (StringUtils.isBlank(parentTreeCode)){
+                                                return R.error(item.getName()+"该树的父节点的编码不能为空");
+                                            }
+                                            int j = parentTreeCode.indexOf(".");
+                                            if (j!= -1){
+                                                twoLevelKey = parentTreeCode.substring(j+1);
+                                            }
+                                        }
+                                        String result = item.getTreecode().replaceAll(".*\\.", oneLevelKey+"."+twoLevelKey+".");
+                                        checkDetailWordVO.setChapterno(result);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    String oldPid = item.getPid();
+                    String oldId = item.getId();
+                    resMap.put(oldPid.split("_")[0]+","+oldId.split("_")[0],checkDetailWordVO);
+                }else {
+                    String oldId = item.getId();
+                    //树等级为一级处理章节号
+                    if (StringUtils.isBlank(item.getTreecode())){
+                        return R.error(item.getName()+"树编码不能为空");
+                    }else {
+                        //设置一级树节点的章节号规则:去除.号前面的就行
+                        int i = item.getTreecode().indexOf(".");
+                        if (i!= -1){
+                            String key = item.getTreecode().substring(i+1);
+                            checkDetailWordVO.setChapterno(key);
+                        }
+                    }
+                    resMap.put(oldId.split("_")[0],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;
+            //子表数据
+            for (ZhcxCommissionCheckDetailDo item : list) {
+                String key = "";
+                String treeFullId = item.getTreefullid();
+                int fillIdLength = treeFullId.split(",").length;
+                int i = treeFullId.indexOf(",");
+                if (fillIdLength<=3){
+                    key = treeFullId.substring(i+1);
+                    if(!resMap.containsKey(key)){
+                        log.error("不能导出树表的id:{}的报告", treeFullId);
+                        log.error("不能导出树表的key:{}的报告", key);
+                        log.error("章节号有无误:{}的报告", item.getChapterno());
+                        return R.error(item.getChapterno()+"章节号有无误");
+                    }
+                }else {
+                    // 从第一个逗号之后开始找第二个逗号
+                    int j = treeFullId.indexOf(',', i + 1);
+                    key = treeFullId.substring(j+1);
+                    if(!resMap.containsKey(key)){
+                        log.error("不能导出树表的id:{}的报告", treeFullId);
+                        log.error("不能导出树表的key:{}的报告", key);
+                        log.error("章节号有无误:{}的报告", item.getChapterno());
+                        return R.error(item.getChapterno()+"章节号有无误");
+                    }
                 }
                 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()) {
@@ -846,67 +921,60 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
             });
             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);
+                if (res.getLevel()==1){
+                    buildTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_1, 15, true, res.getChapterno()+"."+res.getTitleContent(), null);
                 }else {
-                    buildText(builder, DEFAULT_FONT_NAME, titleType, 12, true,
-                            res.getChapterno()+res.getTitleContent(), null);
+                    if (res.getLevel()==2){
+                        buildTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_2, 15, true,res.getChapterno()+"."+res.getTitleContent(), null);
+                    }else {
+                        buildTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_3, 15, 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,
+                    buildTextContentTitle(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 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,
+                    buildTextContentTitle(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 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,
+                    buildTextContentTitle(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 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,
+                    buildTextContentTitle(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 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,
+                    buildTextContentTitle(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 12, true,
                             "备注", null);
                     builder.endRow();
+                    int count =0;
                     for (ZhcxCommissionCheckDetailDo detailWordVO:res.getDetailList()){
-                        // 插入表格的第一行
+                        count++;
                         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);
-
+                        // 设置样式
+                        buildTableTextContent(builder,40,9,DEFAULT_FONT_NAME,false, String.valueOf(count));
                         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())){
@@ -915,57 +983,46 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
                         if (StringUtils.isNotBlank(detailWordVO.getEntestcontent())){
                             entestcontent = detailWordVO.getEntestcontent();
                         }
-                        buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_7, 11, false,
-                                chtestcontent+entestcontent, null);
-
+                        buildTableTextContent(builder,170,9,DEFAULT_FONT_NAME,false,chtestcontent+entestcontent);
                         builder.insertCell();
-                        builder.getCellFormat().setWidth(120);
-                        builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
-                        builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                        String testaddress = "CX BASE长兴基地";
+                        String testaddress = "";
                         if (StringUtils.isNotBlank(detailWordVO.getTestaddress())){
                             // 10-> CX BASE长兴基地  20-> USER SITE码头现场
                             if(detailWordVO.getTestaddress().equals("20")){
                                 testaddress = "USER SITE码头现场";
                             }
+                            if(detailWordVO.getTestaddress().equals("10")){
+                                testaddress = "CX BASE长兴基地";
+                            }
                         }
-                        buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_7, 11, false,
-                                testaddress, null);
-
+                        buildTableTextContent(builder,120,9,DEFAULT_FONT_NAME,false,testaddress);
                         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);
+                        buildTableTextContent(builder,40,9,DEFAULT_FONT_NAME,false,testresult);
                         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);
+                        buildTableTextContent(builder,100,9,DEFAULT_FONT_NAME,false,detailWordVO.getTestnotes());
                         builder.endRow();
+                        // 设置行高为自适应
+                        builder.getRowFormat().setHeightRule(HeightRule.AUTO);
                     }
                     // 结束表格
                     builder.endTable();
                 }
             }
-            indexDoc[0].appendDocument(doc, ImportFormatMode.KEEP_DIFFERENT_STYLES);
+            // 创建模板A的副本
+            Document cloneDocA = indexDoc[0].deepClone();
+            // 在副本上合并文档B
+            cloneDocA.appendDocument(doc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
             if("export".equals(exportType)){
-                exportWord(indexDoc[0], response);
+                exportWord(cloneDocA, response);
             }else {
-                previewWord(indexDoc[0], response);
+                previewWord(cloneDocA, response);
             }
         }
-        return 3;
+        return R.ok();
     }
 
     private int sort1(List<String> parts1,List<String> parts2){
@@ -1134,6 +1191,29 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
         builder.writeln(content);
     }
 
+    /**
+     * 内容添加
+     *
+     * @param builder         文档对象
+     * @param width           表格宽度
+     * @param fontName        字体名称
+     * @param fontSize        字体大小
+     * @param isBold          是否加粗
+     * @param content         内容
+     * @throws Exception
+     */
+    private void buildTableTextContent(DocumentBuilder builder, double width, int fontSize, String fontName,
+                                       boolean isBold,String content) throws Exception {
+        builder.getCellFormat().setWidth(width);
+        builder.getFont().setSize(fontSize);
+        builder.getFont().setName(fontName);
+        builder.getFont().setBold(isBold);
+        if (StringUtils.isBlank(content)) {
+            content = "";
+        }
+        builder.write(content);
+    }
+
     /**
      * 内容添加
      *
@@ -1287,7 +1367,7 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
         if(list.isEmpty()||treeList.isEmpty()){
             return R.error("该模板没有数据");
         }else {
-            //标题
+            //设置word导出目录
             Map<String, ZhcxCommissionCheckDetailStandardWordVO> resMap = new HashMap<>();
             for (ZhcxCommissionCheckBaseInfoTreeDo item : treeList) {
                 ZhcxCommissionCheckDetailStandardWordVO checkDetailWordVO = new ZhcxCommissionCheckDetailStandardWordVO();
@@ -1297,44 +1377,71 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
                 if (!"-1".equals(item.getPid())){
                     //目前标题最多到三级
                     if (item.getLevel()==2){
+                        //树等级为二级处理章节号
                         List<ZhcxCommissionCheckBaseInfoTreeDo> parentList =  treeList.stream().filter(info->info.getId().equals(item.getPid())).collect(Collectors.toList());
                         if (!parentList.isEmpty()){
-                            int i = parentList.get(0).getTreecode().indexOf(".");
-                            if (i!= -1){
-                                String key = parentList.get(0).getTreecode().substring(i+1);
-                                String result = item.getTreecode().replaceAll(".*\\.", key+".");
-                                checkDetailWordVO.setChapterno(result);
+                            String parentTreeCode = parentList.get(0).getTreecode();
+                            if (StringUtils.isBlank(parentTreeCode)){
+                                return R.error(item.getName()+"该树的父节点的编码不能为空");
+                            }else {
+                                //设置二级树节点的章节号规则:取出一级树编码.号后面的放在二级编码的第一位
+                                int i = parentTreeCode.indexOf(".");
+                                if (i!= -1){
+                                    String key = parentTreeCode.substring(i+1);
+                                    String result = item.getTreecode().replaceAll(".*\\.", key+".");
+                                    checkDetailWordVO.setChapterno(result);
+                                }
                             }
                         }
                     }else {
                         String[] fullIds = item.getFullpid().split(",");
                         if (fullIds.length>2){
+                            //树等级为三级处理章节号
                             String oneLevelKey = "";
+                            //根据当前节点过滤出一级树的列表
                             List<ZhcxCommissionCheckBaseInfoTreeDo> oneLevelList =  treeList.stream().filter(info->info.getId().equals(fullIds[1])).collect(Collectors.toList());
                             if (!oneLevelList.isEmpty()){
-                                int i = oneLevelList.get(0).getTreecode().indexOf(".");
-                                if (i!= -1){
-                                    oneLevelKey = oneLevelList.get(0).getTreecode().substring(i+1);
-                                    String twoLevelKey = "";
-                                    List<ZhcxCommissionCheckBaseInfoTreeDo> parentList =  treeList.stream().filter(info->info.getId().equals(item.getPid())).collect(Collectors.toList());
-                                    if (!parentList.isEmpty()){
-                                        int j = parentList.get(0).getTreecode().indexOf(".");
-                                        if (j!= -1){
-                                            twoLevelKey = parentList.get(0).getTreecode().substring(j+1);
+                                //取出一级树节点编码
+                                String oneLevelTreeCode = oneLevelList.get(0).getTreecode();
+                                if (StringUtils.isBlank(oneLevelTreeCode)){
+                                    return R.error(item.getName()+"该树的一级节点的编码不能为空");
+                                }else {
+                                    //设置三级树节点的章节号规则:取出一级树编码.号后面的加上二级树编码.号后面的再加上自身.号后面的数据
+                                    int i = oneLevelTreeCode.indexOf(".");
+                                    if (i!= -1){
+                                        oneLevelKey = oneLevelTreeCode.substring(i+1);
+                                        String twoLevelKey = "";
+                                        List<ZhcxCommissionCheckBaseInfoTreeDo> parentList =  treeList.stream().filter(info->info.getId().equals(item.getPid())).collect(Collectors.toList());
+                                        if (!parentList.isEmpty()){
+                                            //取出父树节点编码
+                                            String parentTreeCode = parentList.get(0).getTreecode();
+                                            if (StringUtils.isBlank(parentTreeCode)){
+                                                return R.error(item.getName()+"该树的父节点的编码不能为空");
+                                            }
+                                            int j = parentTreeCode.indexOf(".");
+                                            if (j!= -1){
+                                                twoLevelKey = parentTreeCode.substring(j+1);
+                                            }
                                         }
+                                        String result = item.getTreecode().replaceAll(".*\\.", oneLevelKey+"."+twoLevelKey+".");
+                                        checkDetailWordVO.setChapterno(result);
                                     }
-                                    String result = item.getTreecode().replaceAll(".*\\.", oneLevelKey+"."+twoLevelKey+".");
-                                    checkDetailWordVO.setChapterno(result);
                                 }
                             }
                         }
                     }
                     resMap.put(item.getPid()+","+item.getId(),checkDetailWordVO);
                 }else {
-                    int i = item.getTreecode().indexOf(".");
-                    if (i!= -1){
-                        String key = item.getTreecode().substring(i+1);
-                        checkDetailWordVO.setChapterno(key);
+                    //树等级为一级处理章节号
+                    if (StringUtils.isBlank(item.getTreecode())){
+                        return R.error(item.getName()+"树编码不能为空");
+                    }else {
+                        //设置一级树节点的章节号规则:去除.号前面的就行
+                        int i = item.getTreecode().indexOf(".");
+                        if (i!= -1){
+                            String key = item.getTreecode().substring(i+1);
+                            checkDetailWordVO.setChapterno(key);
+                        }
                     }
                     resMap.put(item.getId(),checkDetailWordVO);
                 }
@@ -1436,78 +1543,29 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
                     for (ZhcxCommissionCheckBaseInfoDetailDo detailWordVO:res.getDetailList()){
                         // 插入表格的第一行
                         builder.insertCell();
-                        builder.getCellFormat().setWidth(30);
-                        builder.getFont().setSize(9);
-                        builder.getFont().setName(DEFAULT_FONT_NAME);
-                        builder.getFont().setBold(false);
-                        String chapterno = detailWordVO.getChapterno();
-                        if (StringUtils.isBlank(chapterno)) {
-                            chapterno = "";
-                        }
-                        builder.write(chapterno);
+                        buildTableTextContent(builder,30,9,DEFAULT_FONT_NAME,false,detailWordVO.getChapterno());
                         builder.insertCell();
-                        builder.getCellFormat().setWidth(40);
-                        builder.getFont().setSize(9);
-                        builder.getFont().setName(DEFAULT_FONT_NAME);
-                        builder.getFont().setBold(false);
-                        String classification = detailWordVO.getClassification();
-                        if (StringUtils.isBlank(classification)) {
-                            classification = "";
-                        }
-                        builder.write(classification);
+                        buildTableTextContent(builder,40,9,DEFAULT_FONT_NAME,false,detailWordVO.getClassification());
                         builder.insertCell();
-                        builder.getCellFormat().setWidth(40);
-                        builder.getFont().setSize(9);
-                        builder.getFont().setName(DEFAULT_FONT_NAME);
-                        builder.getFont().setBold(false);
-                        String classificationTwo = detailWordVO.getClassificationtwo();
-                        if (StringUtils.isBlank(classificationTwo)) {
-                            classificationTwo = "";
-                        }
-                        builder.write(classificationTwo);
+                        buildTableTextContent(builder,40,9,DEFAULT_FONT_NAME,false,detailWordVO.getClassificationtwo());
                         builder.insertCell();
-                        builder.getCellFormat().setWidth(60);
-                        builder.getFont().setSize(9);
-                        builder.getFont().setName(DEFAULT_FONT_NAME);
-                        builder.getFont().setBold(false);
-                        String chtestcontent = detailWordVO.getChtestcontent();
-                        if (StringUtils.isBlank(chtestcontent)) {
-                            chtestcontent = "";
-                        }
-                        builder.write(chtestcontent);
+                        buildTableTextContent(builder,60,9,DEFAULT_FONT_NAME,false,detailWordVO.getChtestcontent());
                         builder.insertCell();
-                        builder.getCellFormat().setWidth(60);
-                        builder.getFont().setSize(9);
-                        builder.getFont().setName(DEFAULT_FONT_NAME);
-                        builder.getFont().setBold(false);
-                        String entestcontent = detailWordVO.getEntestcontent();
-                        if (StringUtils.isBlank(entestcontent)) {
-                            entestcontent = "";
-                        }
-                        builder.write(entestcontent);
+                        buildTableTextContent(builder,60,9,DEFAULT_FONT_NAME,false,detailWordVO.getEntestcontent());
                         builder.insertCell();
-                        builder.getCellFormat().setWidth(60);
-                        builder.getFont().setSize(9);
-                        builder.getFont().setName(DEFAULT_FONT_NAME);
-                        builder.getFont().setBold(false);
-                        String testmethod = detailWordVO.getTestmethod();
-                        if (StringUtils.isBlank(testmethod)) {
-                            testmethod = "";
-                        }
-                        builder.write(testmethod);
+                        buildTableTextContent(builder,60,9,DEFAULT_FONT_NAME,false,detailWordVO.getTestmethod());
                         builder.insertCell();
-                        builder.getCellFormat().setWidth(60);
-                        String testaddress = "CX BASE长兴基地";
+                        String testAddress = "";
                         if (StringUtils.isNotBlank(detailWordVO.getTestaddress())){
                             // 10-> CX BASE长兴基地  20-> USER SITE码头现场
-                            if(detailWordVO.getTestaddress().equals("20")){
-                                testaddress = "USER SITE码头现场";
+                            if("20".equals(detailWordVO.getTestaddress())){
+                                testAddress = "USER SITE码头现场";
+                            }
+                            if ("10".equals(detailWordVO.getTestaddress())){
+                                testAddress = "CX BASE长兴基地";
                             }
                         }
-                        builder.getFont().setSize(9);
-                        builder.getFont().setName(DEFAULT_FONT_NAME);
-                        builder.getFont().setBold(false);
-                        builder.write(testaddress);
+                        buildTableTextContent(builder,60,9,DEFAULT_FONT_NAME,false,testAddress);
                         builder.endRow();
                         // 设置行高为自适应
                         builder.getRowFormat().setHeightRule(HeightRule.AUTO);
@@ -1516,11 +1574,6 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
                     builder.endTable();
                 }
             }
-            // 创建自定义样式
-            Style customStyle = indexDoc[0].getStyles().add(StyleType.PARAGRAPH, "CustomStyle");
-            customStyle.getFont().setName("宋体");
-            customStyle.getFont().setSize(12);
-//            doc.save("D:\\newestProject\\suzhou\\zhenghua_baoyan_new\\quality-inspection\\business-server\\src\\main\\resources\\template\\table.docx");
             // 创建模板A的副本
             Document cloneDocA = indexDoc[0].deepClone();
             // 在副本上合并文档B
@@ -1671,7 +1724,7 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
                 }else {
                     boolean hasSingleDot = number.matches(".*\\..*");
                     if ("是".equals(isTitle)&&hasSingleDot){
-                        number = number.replaceAll(".0","");
+                        number = number.replace(".0","");
                     }
                 }
                 boolean containChapterNos = chapterNos.contains(number);
@@ -1682,12 +1735,15 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
                 if (StringUtils.isBlank(oneLevelClass)) {
                     stringBuilder.append("一级分类必填");
                 }
-                if (StringUtils.isBlank(twoLevelClass)&&number.contains(".")) {
-                    stringBuilder.append("二级分类必填");
-                }
                 if (StringUtils.isBlank(isTitle)) {
                     stringBuilder.append("是否标题必填");
                 }
+                if ("否".equals(isTitle)&&StringUtils.isBlank(oneClassification)) {
+                    stringBuilder.append("模式1必填");
+                }
+                if ("否".equals(isTitle)&&StringUtils.isBlank(twoClassification)) {
+                    stringBuilder.append("模式2必填");
+                }
                 if (StringUtil.isNotBlank(stringBuilder)) {
                     allStrBuilder.append("第").append(i + 1).append("行").append(stringBuilder).append("<br>");
                 } else {
@@ -1704,6 +1760,10 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
                         importDetailVo.setOnelevelclassification(oneLevelClass);
                         importDetailVo.setSecondlevelclassification(twoLevelClass);
                         importDetailVo.setThreelevelclassification(threeLevelClass);
+                        //用于排序章节号
+                        if (!number.contains(".")){
+                            importDetailVo.setSerialNumber(Integer.parseInt(number));
+                        }
                         importDetailList.add(importDetailVo);
                     }else {
                         ZhcxCommissionCheckBaseInfoDetailDo detailDo = new ZhcxCommissionCheckBaseInfoDetailDo();
@@ -1735,7 +1795,7 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
                     return R.error("表格数据不能为空");
                 }
                 //根据导入数据的一级分类过滤出一级树并做好排序和去重
-                List<ImportCheckBaseInfoDetailVo> oneLevelTreeList = importDetailList.stream().filter(info->!info.getChapterno().contains(".")).sorted(Comparator.comparing(ImportCheckBaseInfoDetailVo::getChapterno)).collect(Collectors.toList());
+                List<ImportCheckBaseInfoDetailVo> oneLevelTreeList = importDetailList.stream().filter(info->!info.getChapterno().contains(".")).sorted(Comparator.comparing(ImportCheckBaseInfoDetailVo::getSerialNumber)).collect(Collectors.toList());
                 List<String> oneLevelClassList = oneLevelTreeList.stream().map(ImportCheckBaseInfoDetailVo::getOnelevelclassification).distinct().collect(Collectors.toList());
                 int i = 0;
                 for (String one:oneLevelClassList){
@@ -1798,7 +1858,7 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
         } catch (IOException e) {
             return R.error("文件流读取失败");
         }
-        return R.ok();
+        return R.ok("导入成功");
     }
 
     private void insertDetailData(List<ZhcxCommissionCheckBaseInfoTreeDo> treeList, List<ZhcxCommissionCheckBaseInfoDetailDo> detailList) {

+ 4 - 0
business-entity/src/main/java/com/rongwei/bsentity/vo/ImportCheckBaseInfoDetailVo.java

@@ -63,6 +63,10 @@ public class ImportCheckBaseInfoDetailVo extends BaseDo implements Serializable
      * 章节号
      */
     private String chapterno;
+    /**
+     * 编号
+     */
+    private Integer serialNumber;
     /**
      * 一级分类
      */

+ 5 - 0
business-entity/src/main/java/com/rongwei/bsentity/vo/ZhcxCommissionCheckDetailWordVO.java

@@ -45,6 +45,11 @@ public class ZhcxCommissionCheckDetailWordVO{
      */
     private String testnotes;
 
+    /**
+     * 等级
+     */
+    private Integer level;
+
     //子表数据
     private List<ZhcxCommissionCheckDetailDo> detailList;
 }

+ 16 - 14
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxCommissionCheckController.java

@@ -2,12 +2,12 @@ package com.rongwei.bsserver.controller;
 
 
 import com.rongwei.bscommon.sys.service.ZhcxCommissionCheckService;
+import com.rongwei.bscommon.sys.utils.ExceptionUtils;
 import com.rongwei.bsentity.dto.CheckDetailDTO;
 import com.rongwei.bsentity.dto.CommissionCheckDTO;
 import com.rongwei.bsentity.dto.commission.ImportProjectCheckDto;
 import com.rongwei.bscommon.sys.utils.FileCheckUtil;
 import com.rongwei.rwcommon.base.R;
-import com.rongwei.rwcommon.base.exception.CustomException;
 import com.rongwei.rwcommon.utils.StringUtils;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -71,26 +71,23 @@ public class ZhcxCommissionCheckController {
 
     @PostMapping("wordExport")
     @ApiOperation("试车检查报告word导出/预览")
-    public void wordExport(@RequestBody Map<String,Object> map, HttpServletResponse response) throws Exception {
-        int i = commissionCheckService.exportFile(map,response);
-        if(i == 0){
-            throw new CustomException("程序异常");
-        }else if(i == 1){
-            throw new CustomException("检查内容暂无数据");
-        }else {
-            if (i==2){
-                throw new CustomException("存在章节号错误数据");
-            }
+    public R wordExport(@RequestBody Map<String,Object> map, HttpServletResponse response) throws Exception {
+        try {
+            return commissionCheckService.exportFile(map,response);
+        } catch (Exception e) {
+            ExceptionUtils.printExceptionDetail(e,"试车报告导出异常");
+            return R.error("试车报告导出异常");
         }
     }
 
     @PostMapping("wordExportStandard")
-    @ApiOperation("试车标准库word导出/预览")
+    @ApiOperation("试车标准库word导出")
     public R wordExportStandard(@RequestBody Map<String,Object> map, HttpServletResponse response) throws Exception {
         try {
             return commissionCheckService.wordExportStandard(map,response);
         } catch (Exception e) {
-            return R.error("试车报告导出异常");
+            ExceptionUtils.printExceptionDetail(e,"试车报告标准库导出异常");
+            return R.error("试车报告标准库导出异常");
         }
     }
 
@@ -111,7 +108,12 @@ public class ZhcxCommissionCheckController {
         if (StringUtils.isNotBlank(errorMsg)){
             return R.error(errorMsg);
         }
-        return commissionCheckService.importStandard(file,mainId);
+        try {
+            return commissionCheckService.importStandard(file,mainId);
+        } catch (Exception e) {
+            ExceptionUtils.printExceptionDetail(e,"标准库导入异常");
+            return R.error("标准库导入异常");
+        }
     }
 }