Explorar el Código

试车标准库导出报告样式优化,标准库导入初版代码提交

zhoudazhuang hace 7 meses
padre
commit
b1f7d3c4ba

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

@@ -70,4 +70,12 @@ public interface ZhcxCommissionCheckService extends IService<ZhcxCommissionCheck
      * @param file
      */
     void saveImportCheckDetail(ImportProjectCheckDto importDto, MultipartFile file);
+
+    /**
+     * 标准库导入
+     * @param file
+     * @param mainId
+     * @return
+     */
+    R importStandard(MultipartFile file,String mainId);
 }

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

@@ -13,6 +13,7 @@ import com.rongwei.bscommon.sys.feign.CXCommonFeginClient;
 import com.rongwei.bscommon.sys.service.*;
 import com.rongwei.bscommon.sys.utils.ExceptionUtils;
 import com.rongwei.bscommon.sys.utils.ImportCommissionHelp;
+import com.rongwei.bscommon.sys.utils.ImportExcelUtils;
 import com.rongwei.bsentity.domain.*;
 import com.rongwei.bscommon.sys.dao.ZhcxCommissionCheckDao;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -25,6 +26,7 @@ import com.rongwei.bsentity.dto.commission.ImportProjectCheckBO;
 import com.rongwei.bsentity.dto.commission.ImportProjectCheckDto;
 import com.rongwei.bsentity.dto.commission.ParseDocBO;
 import com.rongwei.bsentity.vo.FormDataCheckVO;
+import com.rongwei.bsentity.vo.ImportCheckBaseInfoDetailVo;
 import com.rongwei.bsentity.vo.ZhcxCommissionCheckDetailStandardWordVO;
 import com.rongwei.bsentity.vo.ZhcxCommissionCheckDetailWordVO;
 import com.rongwei.rwadmincommon.system.domain.SysDictDo;
@@ -39,7 +41,11 @@ import com.rongwei.rwcommoncomponent.excel.utils.WordHelpUtils;
 import com.rongwei.rwcommoncomponent.excel.vo.FormData;
 import com.rongwei.rwcommoncomponent.file.service.SysFileItemService;
 import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
+import jodd.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
@@ -50,7 +56,9 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.PostConstruct;
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.lang.reflect.Field;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -108,6 +116,9 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
     @Autowired
     private ZhcxCommissionCheckBaseInfoTreeDao zhcxCommissionCheckBaseInfoTreeDao;
 
+    @Autowired
+    private ZhcxCommissionCheckBaseInfoDetailService zhcxCommissionCheckBaseInfoDetailService;
+
     @Autowired
     private ExcelUtils excelUtils;
 
@@ -1086,6 +1097,43 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
         builder.writeln(content);
     }
 
+    /**
+     * 内容添加
+     *
+     * @param builder         文档对象
+     * @param fontName        字体名称
+     * @param styleIdentifier 设置样式  正文 标题1 标题2 StyleIdentifier.HEADING_1
+     * @param fontSize        字体大小
+     * @param isBold          是否加粗
+     * @param content         内容
+     * @param prefixContent   内容前缀 此处用来做首行缩进
+     * @throws Exception
+     */
+    private void buildTableTitleContent(DocumentBuilder builder, String fontName, int styleIdentifier, int fontSize,
+                                   boolean isBold, String content, String prefixContent) throws Exception {
+        // 设置字体
+        builder.getFont().setName(fontName);
+        // 是否倾斜
+        builder.getFont().setItalic(false);
+        // 设置字体大小
+        builder.getFont().setSize(fontSize);
+        // 是否加粗
+        builder.getFont().setBold(isBold);
+        // 设置对齐方式
+        builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
+        // 设置样式
+        builder.getParagraphFormat().setStyleIdentifier(styleIdentifier);
+        // 设置前缀 此处作为 首行缩进
+        if (prefixContent != null) {
+            builder.write(prefixContent);
+        }
+        if (StringUtils.isBlank(content)) {
+            content = "";
+        }
+        // 添加正文内容
+        builder.writeln(content);
+    }
+
     /**
      * 内容添加
      *
@@ -1295,111 +1343,123 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
             builder.moveToDocumentStart();
             for (ZhcxCommissionCheckDetailStandardWordVO res : resList) {
                 if (res.getLevel()==1){
-                    buildTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_1, 15, false, res.getChapterno()+"."+res.getTitleContent(), null);
+                    buildTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_1, 15, true, res.getChapterno()+"."+res.getTitleContent(), null);
                 }else {
                     if (res.getLevel()==2){
-                        buildTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.HEADING_2, 15, false,res.getChapterno()+"."+res.getTitleContent(), null);
+                        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, false, res.getChapterno()+"."+res.getTitleContent(), null);
+                        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(30);
                     builder.getRowFormat().setHeight(20);
                     builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
                     builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                    builder.getFont().setSize(9);
-                    builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
-                    builder.writeln("NO.");
+                    buildTableTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, true,"NO.", null);
                     builder.insertCell();
                     builder.getCellFormat().setWidth(40);
                     builder.getRowFormat().setHeight(20);
                     builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
                     builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                    builder.getFont().setSize(9);
-                    builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
-                    builder.writeln("模式1");
+                    buildTableTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, true,"模式1", null);
                     builder.insertCell();
                     builder.getCellFormat().setWidth(40);
                     builder.getRowFormat().setHeight(20);
-                    builder.getFont().setSize(9);
                     builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
                     builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                    builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
-                    builder.writeln("模式2");
+                    buildTableTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, true,"模式2", null);
                     builder.insertCell();
                     builder.getCellFormat().setWidth(60);
                     builder.getRowFormat().setHeight(20);
-                    builder.getFont().setSize(9);
                     builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
                     builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                    builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
-                    builder.writeln("测试内容中文");
+                    buildTableTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, true,"测试内容中文", null);
                     builder.insertCell();
                     builder.getCellFormat().setWidth(60);
                     builder.getRowFormat().setHeight(20);
-                    builder.getFont().setSize(9);
                     builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
                     builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                    builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
-                    builder.writeln("测试内容英文");
+                    buildTableTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, true,"测试内容英文", null);
                     builder.insertCell();
                     builder.getCellFormat().setWidth(60);
                     builder.getRowFormat().setHeight(20);
-                    builder.getFont().setSize(9);
                     builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
                     builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                    builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
-                    builder.writeln("标准测试方法");
+                    buildTableTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, true,"标准测试方法", null);
                     builder.insertCell();
                     builder.getCellFormat().setWidth(60);
                     builder.getRowFormat().setHeight(20);
-                    builder.getFont().setSize(9);
                     builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);//设置HeightRule
                     builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                    builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
-                    builder.writeln("测试地点");
+                    buildTableTitleContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, true,"测试地点", null);
                     builder.endRow();
                     for (ZhcxCommissionCheckBaseInfoDetailDo detailWordVO:res.getDetailList()){
                         // 插入表格的第一行
                         builder.insertCell();
                         builder.getCellFormat().setWidth(30);
-                        builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
-                        builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                        String chapterno = detailWordVO.getChapterno()+"";
-                        buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, false,chapterno, null);
+                        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);
                         builder.insertCell();
                         builder.getCellFormat().setWidth(40);
-                        builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
-                        builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                        buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, false,detailWordVO.getClassification(), null);
+                        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);
                         builder.insertCell();
                         builder.getCellFormat().setWidth(40);
-                        builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
-                        builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                        buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, false,detailWordVO.getClassificationtwo(), null);
+                        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);
                         builder.insertCell();
                         builder.getCellFormat().setWidth(60);
-                        builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
-                        builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                        buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, false, detailWordVO.getChtestcontent(), null);
+                        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);
                         builder.insertCell();
                         builder.getCellFormat().setWidth(60);
-                        builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
-                        builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                        buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, false, detailWordVO.getEntestcontent(), null);
+                        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);
                         builder.insertCell();
                         builder.getCellFormat().setWidth(60);
-                        builder.getRowFormat().setHeightRule(HeightRule.AUTO);//设置HeightRule
-                        builder.getCellFormat().setOrientation(TextOrientation.HORIZONTAL);
-                        buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, false, detailWordVO.getTestmethod(), null);
+                        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);
                         builder.insertCell();
                         builder.getCellFormat().setWidth(60);
-                        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码头现场
@@ -1407,8 +1467,13 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
                                 testaddress = "USER SITE码头现场";
                             }
                         }
-                        buildTextContent(builder, DEFAULT_FONT_NAME, StyleIdentifier.NORMAL, 9, false, testaddress, null);
+                        builder.getFont().setSize(9);
+                        builder.getFont().setName(DEFAULT_FONT_NAME);
+                        builder.getFont().setBold(false);
+                        builder.write(testaddress);
                         builder.endRow();
+                        // 设置行高为自适应
+                        builder.getRowFormat().setHeightRule(HeightRule.AUTO);
                     }
                     // 结束表格
                     builder.endTable();
@@ -1418,7 +1483,7 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
             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
@@ -1529,4 +1594,186 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
             throw new CustomException("文件获取失败");
         }
     }
+
+    @Override
+    public R importStandard(MultipartFile file, String mainId) {
+        try {
+            StringBuilder allStrBuilder = new StringBuilder();
+            Sheet sheet = null;
+            try {
+                sheet = new XSSFWorkbook(file.getInputStream()).getSheetAt(0);
+                int lastRowNum = sheet.getLastRowNum();
+                List<ZhcxCommissionCheckBaseInfoTreeDo> treeList = new ArrayList<>();
+                List<ZhcxCommissionCheckBaseInfoDetailDo> detailList = new ArrayList<>();
+                List<ImportCheckBaseInfoDetailVo> importDetailList = new ArrayList<>();
+                List<String> chapterNos = new ArrayList<>();
+                for (int i = 1; i <= lastRowNum; i++) {
+                    StringBuilder stringBuilder = new StringBuilder();
+                    ImportCheckBaseInfoDetailVo importDetailVo = new ImportCheckBaseInfoDetailVo();
+                    ZhcxCommissionCheckBaseInfoDetailDo detailDo = new ZhcxCommissionCheckBaseInfoDetailDo();
+                    Row row = sheet.getRow(i);
+                    if (ImportExcelUtils.isRowEmpty(row)) {
+                        continue;
+                    }
+                    String number = row.getCell(0) == null ? "" : row.getCell(0).toString().trim();
+                    String oneLevelClass = row.getCell(1) == null ? "" : row.getCell(1).toString().trim();
+                    String twoLevelClass = row.getCell(2) == null ? "" : row.getCell(2).toString().trim();
+                    String threeLevelClass = row.getCell(3) == null ? "" : row.getCell(3).toString().trim();
+                    String oneClassification = row.getCell(4) == null ? "" : row.getCell(4).toString().trim();
+                    String twoClassification = row.getCell(5) == null ? "" : row.getCell(5).toString().trim();
+                    String threeClassification = row.getCell(6) == null ? "" : row.getCell(6).toString().trim();
+                    String zhContent = row.getCell(7) == null ? "" : row.getCell(7).toString().trim();
+                    String ehContent = row.getCell(8) == null ? "" : row.getCell(8).toString().trim();
+                    String testMethod = row.getCell(9) == null ? "" : row.getCell(9).toString().trim();
+                    String testAddress = row.getCell(10) == null ? "" : row.getCell(10).toString().trim();
+                    String testTime = row.getCell(11) == null ? "" : row.getCell(11).toString().trim();
+                    String status = row.getCell(12) == null ? "" : row.getCell(12).toString().trim();
+                    String isTitle = row.getCell(13) == null ? "" : row.getCell(13).toString().trim();
+                    if (StringUtils.isBlank(number)) {
+                        stringBuilder.append("章节号必填");
+                    }
+                    if (StringUtils.isBlank(oneLevelClass)) {
+                        stringBuilder.append("一级分类必填");
+                    }
+                    if (StringUtils.isBlank(twoLevelClass)) {
+                        stringBuilder.append("二级分类必填");
+                    }
+                    if (StringUtils.isBlank(isTitle)) {
+                        stringBuilder.append("是否标题必填");
+                    }
+                    boolean containChapterNos = chapterNos.contains(number);
+                    if (StringUtils.isNotBlank(number)) {
+                        chapterNos.add(number);
+                    }
+                    if (containChapterNos) {
+                        stringBuilder.append("章节号重复");
+                    }
+                    if (StringUtil.isNotBlank(stringBuilder)) {
+                        allStrBuilder.append("第").append(i + 1).append("行").append(stringBuilder).append("<br>");
+                    } else {
+                        // 10-> CX BASE长兴基地  20-> USER SITE码头现场
+                        if ("CX BASE长兴基地".equals(testAddress)) {
+                            testAddress = "10";
+                        } else {
+                            if ("USER SITE码头现场".equals(testAddress)) {
+                                testAddress = "20";
+                            }
+                        }
+                        if ("是".equals(isTitle)){
+                            importDetailVo.setChapterno(number);
+                            importDetailVo.setOnelevelclassification(oneLevelClass);
+                            importDetailVo.setSecondlevelclassification(twoLevelClass);
+                            importDetailVo.setThreelevelclassification(threeLevelClass);
+                            importDetailList.add(importDetailVo);
+                        }else {
+                            detailDo.setId(SecurityUtil.getUUID())
+                                    .setPid(mainId)
+                                    .setChapterno(number)
+                                    .setClassification(oneClassification)
+                                    .setClassificationtwo(twoClassification)
+                                    .setClassificationthree(threeClassification)
+                                    .setChtestcontent(zhContent)
+                                    .setEntestcontent(ehContent)
+                                    .setTestmethod(testMethod)
+                                    .setTesttime(new BigDecimal(testTime))
+                                    .setTestaddress(testAddress)
+                                    .setStatus(status)
+                                    .setDeleted("0");
+                            detailList.add(detailDo);
+                        }
+                    }
+                }
+                List<ImportCheckBaseInfoDetailVo> oneLevelTreeList = importDetailList.stream().filter(info->!info.getChapterno().contains(".")).sorted(Comparator.comparing(ImportCheckBaseInfoDetailVo::getChapterno)).collect(Collectors.toList());
+                List<String> oneLevelClassList = oneLevelTreeList.stream().map(ImportCheckBaseInfoDetailVo::getOnelevelclassification).distinct().collect(Collectors.toList());
+                int i = 0;
+                for (String one:oneLevelClassList){
+                    i++;
+                    ZhcxCommissionCheckBaseInfoTreeDo treeOneDo = new ZhcxCommissionCheckBaseInfoTreeDo();
+                    treeOneDo.setId(SecurityUtil.getUUID());
+                    treeOneDo.setBaseinfoid(mainId);
+                    treeOneDo.setName(one);
+                    treeOneDo.setLevel(1);
+                    treeOneDo.setPid("-1");
+                    treeOneDo.setTreecode("1."+i);
+                    treeList.add(treeOneDo);
+                    List<ImportCheckBaseInfoDetailVo> twoLevelTreeList = importDetailList.stream().filter(detail->detail.getOnelevelclassification().equals(one)&&detail.getChapterno().contains(".")).collect(Collectors.toList());
+                    int j = 0;
+                    for (ImportCheckBaseInfoDetailVo twoDetailVo:twoLevelTreeList){
+                        j++;
+                        ZhcxCommissionCheckBaseInfoTreeDo treeTwoDo = new ZhcxCommissionCheckBaseInfoTreeDo();
+                        treeTwoDo.setId(SecurityUtil.getUUID());
+                        treeTwoDo.setBaseinfoid(mainId);
+                        treeTwoDo.setName(twoDetailVo.getName());
+                        treeTwoDo.setLevel(2);
+                        treeTwoDo.setPid(treeOneDo.getId());
+                        treeTwoDo.setFullpid(","+treeOneDo.getId());
+                        treeTwoDo.setTreecode("2."+j);
+                        treeList.add(treeTwoDo);
+                        List<ImportCheckBaseInfoDetailVo> threeLevelTreeList = importDetailList.stream().filter(detail->detail.getSecondlevelclassification().equals(twoDetailVo.getName())&&detail.getChapterno().contains(".")).collect(Collectors.toList());
+                        int k=0;
+                        for (ImportCheckBaseInfoDetailVo threeDetailVo:threeLevelTreeList){
+                            k++;
+                            ZhcxCommissionCheckBaseInfoTreeDo treeThreeDo = new ZhcxCommissionCheckBaseInfoTreeDo();
+                            treeThreeDo.setId(SecurityUtil.getUUID());
+                            treeThreeDo.setBaseinfoid(mainId);
+                            treeThreeDo.setName(threeDetailVo.getName());
+                            treeThreeDo.setLevel(3);
+                            treeThreeDo.setPid(treeTwoDo.getId());
+                            treeThreeDo.setFullpid(","+treeOneDo.getId()+","+treeTwoDo.getId());
+                            treeThreeDo.setTreecode("3."+k);
+                            treeList.add(treeThreeDo);
+                        }
+                    }
+                }
+                String errMsg = allStrBuilder.toString();
+                if (StringUtils.isNotBlank(errMsg)) {
+                    return R.error(errMsg);
+                } else {
+                    if (!treeList.isEmpty()&&StringUtils.isNotBlank(mainId)) {
+                        final LambdaQueryWrapper<ZhcxCommissionCheckDetailTreeDo> removeTreeWrapper = Wrappers.lambdaQuery();
+                        removeTreeWrapper.eq(ZhcxCommissionCheckDetailTreeDo::getBaseinfoid, mainId);
+                        zhcxCommissionCheckDetailTreeService.remove(removeTreeWrapper);
+                        zhcxCommissionCheckBaseInfoTreeService.saveBatch(treeList);
+                        insertDetailData(treeList,detailList);
+                        if (!detailList.isEmpty()&&StringUtils.isNotBlank(mainId)){
+                            final LambdaQueryWrapper<ZhcxCommissionCheckBaseInfoDetailDo> removeDetailWrapper = Wrappers.lambdaQuery();
+                            removeDetailWrapper.eq(ZhcxCommissionCheckBaseInfoDetailDo::getPid, mainId);
+                            zhcxCommissionCheckBaseInfoDetailService.remove(removeDetailWrapper);
+                            zhcxCommissionCheckBaseInfoDetailService.saveBatch(detailList);
+                        }
+                    }
+                }
+            } catch (IOException e) {
+                return R.error("文件流读取失败");
+            }
+        } catch (Exception e) {
+            R.error("标准库导入异常");
+        }
+        return R.ok();
+    }
+
+    private void insertDetailData(List<ZhcxCommissionCheckBaseInfoTreeDo> treeList, List<ZhcxCommissionCheckBaseInfoDetailDo> detailList) {
+        if (!treeList.isEmpty()&&!detailList.isEmpty()){
+            for (ZhcxCommissionCheckBaseInfoDetailDo detailDo:detailList){
+                List<ZhcxCommissionCheckBaseInfoTreeDo> oneLevelTreeList = treeList.stream().filter(infoTreeDo->infoTreeDo.getLevel().equals(1)).collect(Collectors.toList());
+                List<ZhcxCommissionCheckBaseInfoTreeDo> twoLevelTreeList = treeList.stream().filter(infoTreeDo->infoTreeDo.getLevel().equals(2)).collect(Collectors.toList());
+                List<ZhcxCommissionCheckBaseInfoTreeDo> threeLevelTreeList = treeList.stream().filter(infoTreeDo->infoTreeDo.getLevel().equals(3)).collect(Collectors.toList());
+                List<ZhcxCommissionCheckBaseInfoTreeDo> queryOneLevel = oneLevelTreeList.stream().filter(treeDo->treeDo.getName().equals(detailDo.getOnelevelclassification())).collect(Collectors.toList());
+                if (!queryOneLevel.isEmpty()){
+                    detailDo.setOnelevelclassification(queryOneLevel.get(0).getId());
+                    detailDo.setTreefullid(","+queryOneLevel.get(0).getId());
+                    List<ZhcxCommissionCheckBaseInfoTreeDo> queryTwoLevel = twoLevelTreeList.stream().filter(twoTreeDo->twoTreeDo.getName().equals(detailDo.getSecondlevelclassification())).collect(Collectors.toList());
+                    if (!queryTwoLevel.isEmpty()){
+                        detailDo.setSecondlevelclassification(queryTwoLevel.get(0).getId());
+                        detailDo.setTreefullid(","+queryOneLevel.get(0).getId()+","+queryTwoLevel.get(0).getId());
+                        List<ZhcxCommissionCheckBaseInfoTreeDo> queryThreeLevel = threeLevelTreeList.stream().filter(threeTreeDo->threeTreeDo.getName().equals(detailDo.getThreelevelclassification())).collect(Collectors.toList());
+                        if (!queryThreeLevel.isEmpty()){
+                            detailDo.setThreelevelclassification(queryThreeLevel.get(0).getId());
+                            detailDo.setTreefullid(","+queryOneLevel.get(0).getId()+","+queryTwoLevel.get(0).getId()+","+queryThreeLevel.get(0).getId());
+                        }
+                    }
+                }
+            }
+        }
+    }
 }

+ 145 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/utils/BusinessExcelUtil.java

@@ -0,0 +1,145 @@
+package com.rongwei.bscommon.sys.utils;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.rongwei.bscommon.sys.dao.CommonDao;
+import com.rongwei.rwadmincommon.system.domain.PagePartDo;
+import com.rongwei.rwadmincommon.system.service.PagePartService;
+import lombok.SneakyThrows;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mock.web.MockMultipartFile;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.*;
+
+/**
+ * @author zhou
+ */
+@Component
+public class BusinessExcelUtil {
+
+    private static Logger logger = LoggerFactory.getLogger(BusinessExcelUtil.class);
+
+    @Autowired
+    private PagePartService pagePartService;
+    @Autowired
+    private CommonDao commonDao;
+
+    /**
+     * 获取文件表头名集合
+     * 用于校验上传文件与模板文件是否一致
+     * @author chenjiahao
+     * */
+    @SneakyThrows
+    public List<String> getColums(MultipartFile file) {
+        List<String> cs = new ArrayList<>();
+        XSSFWorkbook wb = new XSSFWorkbook(file.getInputStream());
+        int Sheets = wb.getNumberOfSheets();
+        for (int i = 0; i < Sheets; i++) {
+            XSSFSheet sheet = wb.getSheetAt(i);
+            //获取工作簿表头
+            XSSFRow head = sheet.getRow(0);
+            if (head != null) {
+                int o = 0;
+                Iterator<Cell> it = head.iterator();
+                while (it.hasNext()) {
+                    Cell cell = it.next();
+                    o++;
+                    if (cell == null) continue;
+                    String c = String.valueOf(cell);
+                    cs.add(c);
+                }
+            }
+        }
+        return cs;
+    }
+
+    /**
+     * 根据pageId获取模板文件
+     * 用于校验上传文件与模板文件是否一致
+     * @author chenjiahao
+     * */
+    @SneakyThrows
+    public XSSFWorkbook getTemplate(Map<String, Object> map) {
+        XSSFWorkbook wb = null;
+        String pageId = (String) map.get("pageid");
+        PagePartDo pagePart = pagePartService.getById(pageId);
+        String roption = pagePart.getRoption();
+        JSONObject jsonObject = JSONObject.parseObject(roption);
+        JSONObject globalJson = JSONObject.parseObject(jsonObject.get("global").toString());
+        JSONObject fileJson = JSONObject.parseObject(globalJson.get("base").toString());
+        logger.info("fileJson:{}",fileJson);
+        String fileId = JSONObject.parseObject(JSONObject.parseObject(fileJson.get("excelTemplate").toString()).get("data").toString()).get("id").toString();
+        Map<String, Object> fileInfo = commonDao.getFileUrlById(fileId);
+        if(ObjectUtil.isNotNull(fileInfo)){
+            File file = new File(fileInfo.get("FULLPATH").toString());
+            FileInputStream fileInputStream = new FileInputStream(file);
+            MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(),"application/sql", fileInputStream);
+            wb = new XSSFWorkbook(multipartFile.getInputStream());
+        }
+        return wb;
+    }
+
+    /**
+     * 校验上传文件与模板文件是否一致
+     * @author chenjiahao
+     * */
+    public String checkFile(List<String> colums, XSSFWorkbook wb) {
+        StringBuilder errMsg = new StringBuilder();
+        try {
+            Sheet sheet = wb.getSheetAt(0);
+            Row row = sheet.getRow(0);
+            if (row != null) {
+                int lastCellNum = row.getLastCellNum();//列数
+                for (int idx = 0; idx < lastCellNum; idx++) {
+                    String value = row.getCell(idx).getStringCellValue();//列名
+                    if (!colums.contains(value)) {
+                        errMsg.append("上传文件与模板不一致!");
+                    }
+                }
+            } else {
+                errMsg.append("上传的文件错误,请核对后再试");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return ObjectUtil.isNull(errMsg)?"":errMsg.toString();
+    }
+
+    /**
+     * 根据pageId获取当前列表的所有字段
+     * 用于映射实体
+     * @author chenjiahao
+     * */
+    public Map<String,Object> getKeyName(Map<String, Object> map){
+        Map<String,Object> keyMap = new HashMap<>();
+        String pageId = map.get("pageid").toString();
+        PagePartDo pagePart = pagePartService.getById(pageId);
+        String roption = pagePart.getRoption();
+        JSONObject jsonObject = JSONObject.parseObject(roption);
+        String columns1 = jsonObject.getString("columns");
+        JSONObject jsonObject2 = JSONObject.parseObject(columns1);
+        String base1 = jsonObject2.getString("base");
+        JSONArray columns2 = JSONArray.parseArray(base1);
+        for (int i = 0; i < columns2.size(); i++) {
+            JSONObject jsonObject1 = columns2.getJSONObject(i);
+            JSONObject base = jsonObject1.getJSONObject("base");
+            String field = base.getString("field");
+            String label = base.getString("label");
+            keyMap.put(label, field);
+        }
+        return keyMap;
+    }
+}

+ 45 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/utils/FileCheckUtil.java

@@ -0,0 +1,45 @@
+package com.rongwei.bscommon.sys.utils;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.rongwei.rwcommon.utils.StringUtils;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author admin
+ */
+@Component
+public class FileCheckUtil {
+
+    @Autowired
+    private BusinessExcelUtil excelUtil;
+
+    public String fileCheckDetail(MultipartFile file,String pageId) {
+        String errorMsg = "";
+        String fileName = file.getOriginalFilename();
+        if (!fileName.matches("^.+\\.(?i)(xlsx)$")) {
+            errorMsg = "当前只支持xlsx文件格式,请下载模板后重新上传!";
+        }
+        Map<String,Object> map = new HashMap<>(16);
+        map.put("pageid",pageId);
+        // 获取模板文件
+        XSSFWorkbook wb = excelUtil.getTemplate(map);
+        if(ObjectUtil.isNull(wb)){
+            errorMsg = "请先上传模板文件!";
+        }
+        // 解析上传的文件
+        List<String> colums = excelUtil.getColums(file);
+        String errMsg = excelUtil.checkFile(colums,wb);
+        if(StringUtils.isNotBlank(errMsg)){
+            errorMsg = errMsg;
+        }
+        return errorMsg;
+    }
+
+}

+ 30 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/utils/ImportExcelUtils.java

@@ -0,0 +1,30 @@
+package com.rongwei.bscommon.sys.utils;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.Row;
+
+/**
+ * @author zhou
+ */
+public class ImportExcelUtils {
+    /**
+     * 校验excel行是否为空
+     * @param row
+     * @return
+     */
+    public static boolean isRowEmpty(Row row) {
+        if (row == null){
+            return true;
+        }else {
+            for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) {
+                Cell cell = row.getCell(c);
+                if (cell != null && cell.getCellType() != CellType.BLANK){
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+}

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

@@ -0,0 +1,83 @@
+package com.rongwei.bsentity.vo;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.rongwei.rwcommon.base.BaseDo;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * <p>
+ * 试车检查标准库子表
+ * </p>
+ *
+ * @author wm
+ * @since 2024-10-11
+ */
+@Data
+public class ImportCheckBaseInfoDetailVo extends BaseDo implements Serializable {
+
+    private static final long serialVersionUID=1L;
+
+    /**
+     * 主键
+     */
+    private String id;
+    /**
+     * 父ID
+     */
+    private String pid;
+    /**
+     * 分类
+     */
+    private String name;
+    /**
+     * 排序
+     */
+    private Integer sort;
+    /**
+     * 标准主表id
+     */
+    private String baseinfoid;
+    /**
+     * 产品类型
+     */
+    private String producttype;
+    /**
+     * FULLPID
+     */
+    private String fullpid;
+    /**
+     * 层级
+     */
+    private Integer level;
+    /**
+     * 树编码
+     */
+    private String treecode;
+    /**
+     * 章节号
+     */
+    private String chapterno;
+    /**
+     * 一级分类
+     */
+    private String onelevelclassification;
+    /**
+     * 二级分类
+     */
+    private String secondlevelclassification;
+    /**
+     * 三级分类
+     */
+    private String threelevelclassification;
+    /**
+     * 四级分类
+     */
+    private String fouronelevelclassification;
+
+}

+ 18 - 0
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxCommissionCheckController.java

@@ -5,8 +5,10 @@ import com.rongwei.bscommon.sys.service.ZhcxCommissionCheckService;
 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;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +34,9 @@ public class ZhcxCommissionCheckController {
     @Autowired
     private ZhcxCommissionCheckService commissionCheckService;
 
+    @Autowired
+    private FileCheckUtil fileCheckDetail;
+
     /**
      * 试车报告新增
      * @param checkDTO 参数
@@ -95,5 +100,18 @@ public class ZhcxCommissionCheckController {
         commissionCheckService.saveImportCheckDetail(importDto, file);
         return R.ok();
     }
+
+    @RequestMapping("importStandard")
+    @ResponseBody
+    public R importStandard(@RequestParam MultipartFile file,String mainId) {
+        if (file == null){
+            return R.error("文件解析失败");
+        }
+        String errorMsg = fileCheckDetail.fileCheckDetail(file,"23621496edbd4c7faf69401ddee6156e");
+        if (StringUtils.isNotBlank(errorMsg)){
+            return R.error(errorMsg);
+        }
+        return commissionCheckService.importStandard(file,mainId);
+    }
 }