Forráskód Böngészése

itp报验点导入导出

wangming 4 hónapja
szülő
commit
bb53739195
15 módosított fájl, 1073 hozzáadás és 0 törlés
  1. 4 0
      business-common/src/main/java/com/rongwei/bscommon/sys/dao/ZhcxItpTemplateNodesDao.java
  2. 21 0
      business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxItpTemplateNodesService.java
  3. 217 0
      business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxItpTemplateNodesServiceImpl.java
  4. 109 0
      business-common/src/main/java/com/rongwei/bscommon/sys/utils/ExcelService.java
  5. 120 0
      business-common/src/main/java/com/rongwei/bscommon/sys/utils/ImportExcelUtils.java
  6. 300 0
      business-common/src/main/java/com/rongwei/bscommon/sys/utils/ImportITPHelp.java
  7. 39 0
      business-entity/src/main/java/com/rongwei/bsentity/dto/node/ExportNodeExcelAssistantBO.java
  8. 16 0
      business-entity/src/main/java/com/rongwei/bsentity/dto/node/ExportNodeRequest.java
  9. 65 0
      business-entity/src/main/java/com/rongwei/bsentity/dto/node/ExportTemplateNodeBO.java
  10. 44 0
      business-entity/src/main/java/com/rongwei/bsentity/dto/node/ImportNodeExcelAssistantBO.java
  11. 38 0
      business-entity/src/main/java/com/rongwei/bsentity/dto/node/ImportNodeExcelBO.java
  12. 16 0
      business-entity/src/main/java/com/rongwei/bsentity/dto/node/ImportNodeRequest.java
  13. 49 0
      business-entity/src/main/java/com/rongwei/bsentity/dto/node/ImportTemplateNodeBO.java
  14. 18 0
      business-entity/src/main/java/com/rongwei/bsentity/dto/node/SaveITPNodeBO.java
  15. 17 0
      business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxItpTemplateNodesController.java

+ 4 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/dao/ZhcxItpTemplateNodesDao.java

@@ -3,6 +3,7 @@ package com.rongwei.bscommon.sys.dao;
 import com.rongwei.bsentity.domain.ZhcxItpTemplateNodesDo;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.rongwei.bsentity.vo.ZhcxItpTemplateNodesVo;
+import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
@@ -23,4 +24,7 @@ public interface ZhcxItpTemplateNodesDao extends BaseMapper<ZhcxItpTemplateNodes
     @Select("select a.*,b.NODENAME AS \"pname\" from ZHCX_ITP_TEMPLATE_NODES a left join ZHCX_ITP_TEMPLATE_NODES b on a.PID=b.ID " +
             " where a.ITPID in (${itpids}) and a.DELETED='0'")
     List<ZhcxItpTemplateNodesVo> selectPnameByTmpIds(@Param("itpids") String itpids);
+
+    @Delete("delete from ZHCX_ITP_TEMPLATE_NODES where ITPID = #{itpId}")
+    void delByItpId(@Param("itpId") String itpId);
 }

+ 21 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxItpTemplateNodesService.java

@@ -2,9 +2,14 @@ package com.rongwei.bscommon.sys.service;
 
 import com.rongwei.bsentity.domain.ZhcxItpTemplateNodesDo;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.rongwei.bsentity.dto.node.ExportNodeRequest;
+import com.rongwei.bsentity.dto.node.ImportNodeRequest;
 import com.rongwei.bsentity.vo.CopyNodeVo;
 import com.rongwei.bsentity.vo.ZhcxItpTemplateNodeSyncProjectVo;
 import com.rongwei.bsentity.vo.ZhcxItpTemplateNodesVo;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 import java.util.Map;
 
@@ -24,4 +29,20 @@ public interface ZhcxItpTemplateNodesService extends IService<ZhcxItpTemplateNod
 
     List<ZhcxItpTemplateNodesVo> selectPnameByTmpIds(List<String> itpidList);
 
+    /**
+     * 导入qcp
+     *
+     * @param req
+     * @param file
+     */
+    void importQcp(ImportNodeRequest req, MultipartFile file);
+
+    /**
+     * 导出qcp
+     *
+     * @param req
+     * @param res
+     */
+    void exportQcp(ExportNodeRequest req, HttpServletResponse res);
+
 }

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

@@ -1,26 +1,46 @@
 package com.rongwei.bscommon.sys.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.aspose.cells.SaveFormat;
+import com.aspose.cells.Workbook;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.rongwei.bscommon.sys.service.ZhcxItpProjectNodesService;
+import com.rongwei.bscommon.sys.service.ZhcxItpTemplateService;
 import com.rongwei.bscommon.sys.service.ZhcxProjectDeviceNumberService;
 import com.rongwei.bscommon.sys.utils.CxConstants;
+import com.rongwei.bscommon.sys.utils.ExcelService;
+import com.rongwei.bscommon.sys.utils.ImportITPHelp;
+import com.rongwei.bscommon.sys.utils.ZhcxCommon;
 import com.rongwei.bsentity.domain.ZhcxItpProjectNodesDo;
+import com.rongwei.bsentity.domain.ZhcxItpTemplateDo;
 import com.rongwei.bsentity.domain.ZhcxItpTemplateNodesDo;
 import com.rongwei.bscommon.sys.dao.ZhcxItpTemplateNodesDao;
 import com.rongwei.bscommon.sys.service.ZhcxItpTemplateNodesService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.rongwei.bsentity.domain.ZhcxProjectDeviceNumberDo;
+import com.rongwei.bsentity.dto.node.*;
 import com.rongwei.bsentity.vo.CopyNodeVo;
 import com.rongwei.bsentity.vo.ZhcxItpTemplateNodeSyncProjectVo;
 import com.rongwei.bsentity.vo.ZhcxItpTemplateNodesVo;
 import com.rongwei.commonservice.service.dao.CommonSqlDao;
+import com.rongwei.rwadmincommon.system.domain.SysDictDo;
+import com.rongwei.rwadmincommon.system.domain.SysOrganizationDo;
+import com.rongwei.rwadmincommon.system.service.SysDictService;
+import com.rongwei.rwadmincommon.system.service.SysOrganizationService;
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
+import com.rongwei.rwcommon.base.exception.CustomException;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommon.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -45,6 +65,21 @@ public class ZhcxItpTemplateNodesServiceImpl extends ServiceImpl<ZhcxItpTemplate
     @Autowired
     private ZhcxItpTemplateNodesDao zhcxItpTemplateNodesDao;
 
+    @Autowired
+    private ExcelService excelService;
+
+    @Autowired
+    private SysDictService sysDictService;
+
+    @Autowired
+    private ZhcxItpTemplateService zhcxItpTemplateService;
+
+    @Autowired
+    private ZhcxCommon zhcxCommon;
+
+    @Autowired
+    private SysOrganizationService sysOrganizationService;
+
     /**
      * 新增的ITP模板节点同步到指定项目
      * @param zhcxItpTemplateNodeSyncProjectVo
@@ -452,6 +487,132 @@ public class ZhcxItpTemplateNodesServiceImpl extends ServiceImpl<ZhcxItpTemplate
         return templateNodesVos;
     }
 
+    /**
+     * 导入qcp
+     *
+     * @param req
+     * @param file
+     */
+    @Override
+    public void importQcp(ImportNodeRequest req, MultipartFile file) {
+        //删除历史数据
+        zhcxItpTemplateNodesDao.delByItpId(req.getTmpId());
+
+        final List<JSONObject> rowList = excelService.parseMF(file); //excel数据
+
+        final ImportNodeExcelAssistantBO excelHelp = getNodeExcelHelp(); //辅助参数
+        final ZhcxItpTemplateDo templateDo = zhcxItpTemplateService.getById(req.getTmpId());
+        excelHelp.setFactoryId(templateDo.getTenantid());
+        excelHelp.setTmpId(req.getTmpId());
+
+        final SaveITPNodeBO itpNodeBO = ImportITPHelp.parseRow2Node(rowList, excelHelp); //解析每一行
+
+
+        if(ObjectUtil.isNotEmpty(itpNodeBO.getPhaseMap())) {//阶段
+            saveBatch(itpNodeBO.getPhaseMap().values());
+        }
+
+        if(ObjectUtil.isNotEmpty(itpNodeBO.getBigMap())) {//构件
+            saveBatch(itpNodeBO.getBigMap().values());
+        }
+        if(ObjectUtil.isNotEmpty(itpNodeBO.getSmallMap())) {//小构件
+            saveBatch(itpNodeBO.getSmallMap().values());
+        }
+        if(ObjectUtil.isNotEmpty(itpNodeBO.getCheckpointMap())) {//构件
+            saveBatch(itpNodeBO.getCheckpointMap().values());
+        }
+    }
+
+    /**
+     * 导出qcp
+     *
+     * @param req
+     * @param res
+     */
+    @Override
+    public void exportQcp(ExportNodeRequest req, HttpServletResponse res) {
+        //查询导出报验点
+        final LambdaQueryWrapper<ZhcxItpTemplateNodesDo> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(ZhcxItpTemplateNodesDo::getItpid, req.getTmpId())
+                .orderByAsc(ZhcxItpTemplateNodesDo::getSortindex);
+        final List<ZhcxItpTemplateNodesDo> nodesDos = list(queryWrapper);
+
+        final ExportNodeExcelAssistantBO excelExportHelp = getNodeExcelExportHelp(req); //辅助参数类
+
+        //加工导出数据
+        final List<ExportTemplateNodeBO> templateNodeList = assembleExportExcelData(nodesDos, excelExportHelp);
+
+        final JSONArray nodes = (JSONArray) JSONArray.toJSON(templateNodeList);
+        //生成excel
+        final Workbook wk = excelService.exportExcel(Arrays.asList(ExportTemplateNodeBO.EXPORT_COLS), nodes);
+
+        res.setContentType("application/octet-stream;charset=ISO8859-1");
+        res.setHeader("Content-Disposition", "attachment;filename="
+                .concat(excelExportHelp.getTemplate().getName())
+                .concat(".xlsx"));
+        try {
+            wk.save(res.getOutputStream(), SaveFormat.XLSX);
+        } catch (Exception e) {
+            log.error("导出失败", e);
+            throw new CustomException("导出失败");
+        }
+    }
+
+    /**
+     * 导入辅助
+     *
+     * @return
+     */
+    private ImportNodeExcelAssistantBO getNodeExcelHelp() {
+
+        //报验类型
+        List<SysDictDo> inspectionTypeList = sysDictService.getDictsByType("inside_inspection_type");
+        Map<String, String> inspectionTypeMap = new HashMap<>(inspectionTypeList.size());
+        inspectionTypeList.stream().filter(item -> !"-1".equals(item.getPid())).forEach(item -> inspectionTypeMap.put(item.getName(), item.getValue()));
+
+        List<SysDictDo> truefalseenumList = sysDictService.getDictsByType("truefalseenum");
+        Map<String, String> truefalseenumMap = new HashMap<>(truefalseenumList.size());
+        truefalseenumList.stream().filter(item -> !"-1".equals(item.getPid())).forEach(item -> truefalseenumMap.put(item.getName(), item.getValue()));
+
+        SysUserVo user = zhcxCommon.getCurrentUser();  //当前登录用户
+
+
+        return ImportNodeExcelAssistantBO.builder()
+                .inspectionTypeMap(inspectionTypeMap)
+                .whetherMap(truefalseenumMap)
+                .user(user)
+                .build();
+    }
+
+    /**
+     * 导入辅助
+     *
+     * @return
+     */
+    private ExportNodeExcelAssistantBO getNodeExcelExportHelp(ExportNodeRequest req) {
+
+        //报验类型
+        List<SysDictDo> inspectionTypeList = sysDictService.getDictsByType("inside_inspection_type");
+        Map<String, String> inspectionTypeMap = new HashMap<>(inspectionTypeList.size());
+        inspectionTypeList.stream().filter(item -> !"-1".equals(item.getPid())).forEach(item -> inspectionTypeMap.put(item.getValue(), item.getName()));
+
+        List<SysDictDo> truefalseenumList = sysDictService.getDictsByType("truefalseenum");
+        Map<String, String> truefalseenumMap = new HashMap<>(truefalseenumList.size());
+        truefalseenumList.stream().filter(item -> !"-1".equals(item.getPid())).forEach(item -> truefalseenumMap.put(item.getValue(), item.getName()));
+
+        final ZhcxItpTemplateDo templateDo = zhcxItpTemplateService.getById(req.getTmpId());
+
+        final SysOrganizationDo org = sysOrganizationService.getById(templateDo.getTenantid());//基地
+
+        return ExportNodeExcelAssistantBO.builder()
+                .inspectionTypeMap(inspectionTypeMap)
+                .whetherMap(truefalseenumMap)
+                .template(templateDo)
+                .factoryId(templateDo.getTenantid())
+                .factoryName(org.getShortname())
+                .build();
+    }
+
     /**
      * 返回最新数据
      * @param copyNodeVo
@@ -462,4 +623,60 @@ public class ZhcxItpTemplateNodesServiceImpl extends ServiceImpl<ZhcxItpTemplate
         List<Map<String, Object>> nodes = commonSqlDao.sqlExecutu(sql);
         return nodes;
     }
+
+    /**
+     * 加工导出
+     *
+     * @param nodesDos
+     * @param excelExportHelp
+     * @return
+     */
+    private List<ExportTemplateNodeBO> assembleExportExcelData(List<ZhcxItpTemplateNodesDo> nodesDos, ExportNodeExcelAssistantBO excelExportHelp) {
+
+        if(ObjectUtil.isEmpty(nodesDos)) {
+            return Collections.emptyList();
+        }
+
+        List<ZhcxItpTemplateNodesDo> l3NodeList = new ArrayList<>();  //报验点
+        Map<String, ZhcxItpTemplateNodesDo> nodeMap = new HashMap<>(nodesDos.size());
+
+        nodesDos.stream().forEach(item -> {
+            if("3".equals(item.getLevel())) { //报验点
+                l3NodeList.add(item);
+            }
+            nodeMap.put(item.getId(), item);
+        });
+
+        List<ExportTemplateNodeBO> exportNodeList = new ArrayList<>(l3NodeList.size());
+
+        for(ZhcxItpTemplateNodesDo node : l3NodeList) {
+
+            ExportTemplateNodeBO exportNode = ExportTemplateNodeBO.builder()
+                    .prdType(excelExportHelp.getTemplate().getType())
+                    .checkPoint(node.getNodename())
+                    .inspectionType(excelExportHelp.getInspectionTypeMap().get(node.getInspectiontype()))
+                    .issupp(excelExportHelp.getWhetherMap().get(node.getIssupp()))
+                    .factoryName(excelExportHelp.getFactoryName())
+                    .build();
+
+            //大小构件
+            final ZhcxItpTemplateNodesDo l2Node = nodeMap.get(node.getPid());
+            if("small".equals(l2Node.getNodetype())) {  //小构建
+                exportNode.setSmall(l2Node.getNodename());
+                final ZhcxItpTemplateNodesDo l2BigNode = nodeMap.get(l2Node.getPnodeid());
+                if(ObjectUtil.isNotNull(l2BigNode)) {
+                    exportNode.setBig(l2BigNode.getNodename());
+                }
+            } else { //大构建
+                exportNode.setBig(l2Node.getNodename());
+            }
+
+            //阶段
+            final ZhcxItpTemplateNodesDo l1Node = nodeMap.get(l2Node.getPid());
+            exportNode.setPhase(l1Node.getNodename());
+            exportNodeList.add(exportNode);
+        }
+
+        return exportNodeList;
+    }
 }

+ 109 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/utils/ExcelService.java

@@ -0,0 +1,109 @@
+package com.rongwei.bscommon.sys.utils;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.aspose.cells.*;
+import com.aspose.words.HorizontalAlignment;
+import com.aspose.words.VerticalAlignment;
+import com.rongwei.rwcommon.base.exception.CustomException;
+import com.rongwei.rwcommoncomponent.excel.aspose.ExcelUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+
+@Slf4j
+@Component
+public class ExcelService {
+
+    @Autowired
+    private ExcelUtils excelUtils;
+
+    /**
+     * 解析上传excel
+     *
+     * @param file
+     * @return
+     */
+    public List<JSONObject> parseMF(MultipartFile file) {
+        Workbook wkByMF = ImportExcelUtils.getWkByMF(file);
+        return ImportExcelUtils.parseExcel(wkByMF);
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param titleList
+     * @param dataList
+     * @return
+     */
+    public Workbook exportExcel(List<String> titleList, JSONArray dataList) {
+
+        final boolean licenseFlag = excelUtils.GetLicense();//验证license
+        if(!licenseFlag) {
+            throw new CustomException("验证失败");
+        }
+
+        // 创建工作簿
+        Workbook workbook = new Workbook();
+
+        // 获取第一个工作表
+        Worksheet worksheet = workbook.getWorksheets().get(0);
+        final Cells cells = worksheet.getCells();
+
+        //标题
+        for(int m = 0, n = titleList.size(); m < n; m++) {
+            worksheet.getCells().get(0, m).putValue(titleList.get(m));
+        }
+
+        //数据列
+        for(int m = 0, n = dataList.size(); m < n; m++) { //每行数据
+            for(int i = 0, j = titleList.size(); i < j; i++) { //每列
+                worksheet.getCells().get(m + 1, i).putValue(dataList.getJSONObject(m).getString(titleList.get(i)));
+            }
+        }
+
+        // 遍历所有单元格并添加网格线
+        int maxRow = cells.getMaxRow();
+        int maxColumn = cells.getMaxColumn();
+
+        Style commonStyle = workbook.createStyle();
+        commonStyle.setHorizontalAlignment(TextAlignmentType.CENTER);
+        commonStyle.setVerticalAlignment(TextAlignmentType.CENTER);
+        commonStyle.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
+        commonStyle.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
+        commonStyle.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
+        commonStyle.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());
+//        commonStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+//        commonStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        commonStyle.setPattern(BackgroundType.SOLID);
+
+        for (int i = 0; i <= maxRow; i++) {
+            for (int j = 0; j <= maxColumn; j++) {
+                Cell cell = cells.get(i, j);
+                // 设置顶部边框
+                cell.setStyle(commonStyle);
+
+                // 检查单元格是否为空
+                if (ObjectUtil.isNotEmpty(cell.getValue())) {
+                    // 设置单元格样式,使值居中
+                    Style style = cell.getStyle();
+                    style.setHorizontalAlignment(HorizontalAlignment.CENTER);
+                    style.setVerticalAlignment(VerticalAlignment.CENTER);
+                    cell.setStyle(style);
+                }
+            }
+        }
+
+        try {
+            worksheet.autoFitColumns();
+        } catch (Exception e) {
+            log.error("自适应异常", e);
+        }
+
+        return workbook;
+    }
+}

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

@@ -1,12 +1,25 @@
 package com.rongwei.bscommon.sys.utils;
 
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.aspose.cells.Cells;
+import com.aspose.cells.Workbook;
+import com.aspose.cells.Worksheet;
+import com.rongwei.rwcommon.base.exception.CustomException;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.Row;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author zhou
  */
+@Slf4j
 public class ImportExcelUtils {
     /**
      * 校验excel行是否为空
@@ -27,4 +40,111 @@ public class ImportExcelUtils {
         return true;
     }
 
+    /**
+     * 通过MultipartFile获取excel工作簿
+     *
+     * @param file
+     * @return
+     */
+    public static Workbook getWkByMF(MultipartFile file) {
+        try {
+            return new Workbook(file.getInputStream());
+        } catch (Exception e) {
+            log.error("获取工作簿失败", e);
+            throw new CustomException("获取工作簿失败");
+        }
+    }
+
+    /**
+     * 解析word
+     *
+     * @param wk
+     * @return
+     */
+    public static List<JSONObject> parseExcel(Workbook wk) {
+        return parseSheet(wk.getWorksheets().get(0));
+    }
+
+    /**
+     * 解析word
+     *
+     * @param wk
+     * @param sheetIdx
+     * @return
+     */
+    public static List<JSONObject> parseExcel(Workbook wk, int sheetIdx) {
+        return parseSheet(wk.getWorksheets().get(sheetIdx));
+    }
+
+    /**
+     * 解析sheet页
+     *
+     * @param worksheet
+     * @return
+     */
+    public static List<JSONObject> parseSheet(Worksheet worksheet) {
+        return parseSheet(worksheet, 0);
+    }
+
+    /**
+     * 解析sheet页
+     *
+     * @param worksheet
+     * @return
+     */
+    public static List<JSONObject> parseSheet(Worksheet worksheet, int titleRowIdx) {
+
+        final Cells cells = worksheet.getCells();
+        List<JSONObject> rowList = new ArrayList<>(cells.getMaxDataRow()); //存放解析的数据
+
+        final List<String> titleList = parseTitle(cells, titleRowIdx); //标题
+
+        for(int rowIdx = titleRowIdx + 1, n = cells.getMaxDataRow(); rowIdx <= n; rowIdx++) { //遍历每行
+            JSONObject row = new JSONObject();
+            for(int colIdx = 0, h = titleList.size(); colIdx < h; colIdx++) { //遍历每列
+                String value = cells.get(rowIdx, colIdx).getStringValue();
+                if("".equals(StrUtil.trim(value))) { //空字符串时,值当null处理
+                    value = null;
+                }
+                row.put(titleList.get(colIdx), value);
+            }
+
+            rowList.add(row);
+        }
+
+        return rowList;
+    }
+
+    /**
+     * 解析标题
+     *
+     * @param worksheet
+     * @param titleRowIdx
+     * @return
+     */
+    private static List<String> parseTitle(Worksheet worksheet, int titleRowIdx) {
+        final Cells cells = worksheet.getCells();
+        return parseTitle(cells, titleRowIdx);
+    }
+
+    /**
+     * 解析标题
+     *
+     * @param cells
+     * @param titleRowIdx
+     * @return
+     */
+    private static List<String> parseTitle(Cells cells, int titleRowIdx) {
+        List<String> titleList = new ArrayList<>(cells.getMaxColumn());
+        for(int m = 0, n = cells.getMaxColumn(); m <= n; m++) {
+            String title = cells.get(titleRowIdx, m).getStringValue();
+            if(ObjectUtil.isNotEmpty(title)) {
+                title = title.replace("*", "");
+            }
+            titleList.add(title);
+        }
+
+        return titleList;
+    }
+
 }

+ 300 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/utils/ImportITPHelp.java

@@ -0,0 +1,300 @@
+package com.rongwei.bscommon.sys.utils;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.rongwei.bsentity.domain.ZhcxItpTemplateNodesDo;
+import com.rongwei.bsentity.dto.node.ImportNodeExcelAssistantBO;
+import com.rongwei.bsentity.dto.node.ImportNodeExcelBO;
+import com.rongwei.bsentity.dto.node.ImportTemplateNodeBO;
+import com.rongwei.bsentity.dto.node.SaveITPNodeBO;
+import com.rongwei.rwcommon.base.exception.CustomException;
+import com.rongwei.rwcommon.utils.SecurityUtil;
+import com.rongwei.rwcommon.utils.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+/**
+ * itp导入
+ *
+ */
+@Slf4j
+public class ImportITPHelp {
+
+    /**
+     * 解析行数据
+     *
+     * @param rowList
+     * @param excelHelp
+     * @return
+     */
+    public static SaveITPNodeBO parseRow2Node(List<JSONObject> rowList, ImportNodeExcelAssistantBO excelHelp) {
+        if(ObjectUtil.isEmpty(rowList)) {
+            return SaveITPNodeBO.builder()
+                    .phaseMap(Collections.emptyMap())
+                    .bigMap(Collections.emptyMap())
+                    .smallMap(Collections.emptyMap())
+                    .checkpointMap(Collections.emptyMap())
+                    .build();
+        }
+
+        Map<String, ZhcxItpTemplateNodesDo> phaseMap = new HashMap<>();  //阶段
+        Map<String, ZhcxItpTemplateNodesDo>  bigMap = new HashMap<>(); //大构件
+        Map<String, ZhcxItpTemplateNodesDo>  smallMap = new HashMap<>(); //构件
+        Map<String, ZhcxItpTemplateNodesDo>  checkpointMap = new HashMap<>(); //报验点
+
+        List<String> msgList = new ArrayList<>();
+        for(int m = 0, n = rowList.size(); m < n; m++) { //遍历每行数据
+            JSONObject row = rowList.get(m);
+            final ImportTemplateNodeBO nodeBO = row.toJavaObject(ImportTemplateNodeBO.class);
+            //参数校验
+            List<String> requiredList = checkExcelRequired(nodeBO);
+            if(ObjectUtil.isNotEmpty(requiredList)) {
+                StringBuilder sb = new StringBuilder();
+                sb.append("第");
+                sb.append(m + 2);
+                sb.append("行: ");
+                sb.append(StringUtils.join(requiredList, ","));
+                msgList.add(sb.toString());
+                continue;
+            }
+
+            //阶段
+            ImportNodeExcelBO excelBO = ImportNodeExcelBO.builder()
+                    .nodeBO(nodeBO)
+                    .nodeMap(phaseMap)
+                    .build();
+            ZhcxItpTemplateNodesDo phaseNode = doPhase(excelBO, excelHelp);
+            excelBO.setPhase(phaseNode);
+
+            //大构建
+            if(ObjectUtil.isNotEmpty(nodeBO.getBig())) {
+                excelBO.setNodeMap(bigMap);
+                ZhcxItpTemplateNodesDo bigNode = doBig(excelBO, excelHelp);//大构建
+                if(ObjectUtil.isNull(bigNode.getSortindex())) {
+                    bigNode.setSortindex(new BigDecimal(String.valueOf(bigMap.size() + smallMap.size())));
+                }
+                //小构建
+                excelBO.setBig(bigNode);
+            }
+
+            excelBO.setNodeMap(smallMap);
+            ZhcxItpTemplateNodesDo smallNode = doSmall(excelBO, excelHelp);//小构建
+            if(ObjectUtil.isNotNull(smallNode) && ObjectUtil.isNull(smallNode.getSortindex())) {
+                smallNode.setSortindex(new BigDecimal(String.valueOf(bigMap.size() + smallMap.size())));
+            }
+
+            //报验点
+            excelBO.setSmall(smallNode);
+            excelBO.setNodeMap(checkpointMap);
+            doCheckpoint(excelBO, excelHelp);
+        }
+
+        if(ObjectUtil.isNotEmpty(msgList)) {
+            throw new CustomException(StringUtils.join(msgList, ";"));
+        }
+
+        return SaveITPNodeBO.builder()
+                .phaseMap(phaseMap)
+                .bigMap(bigMap)
+                .smallMap(smallMap)
+                .checkpointMap(checkpointMap)
+                .build();
+    }
+
+
+    /**
+     * 报验点
+     *
+     * @param excelBO
+     * @return
+     */
+    private static ZhcxItpTemplateNodesDo doCheckpoint(ImportNodeExcelBO excelBO, ImportNodeExcelAssistantBO excelHelp) {
+        final String checkpoint = excelBO.getNodeBO().getCheckPoint();
+
+        if(ObjectUtil.isEmpty(checkpoint)) {
+            return null;
+        }
+
+        StringBuilder sb  = new StringBuilder();
+        sb.append(excelBO.getPhase().getNodename());
+        sb.append("_");
+        sb.append(excelBO.getBig().getNodename());
+        if(ObjectUtil.isNotNull(excelBO.getSmall())) {
+            sb.append("_");
+            sb.append(excelBO.getSmall().getNodename());
+        }
+        sb.append("_");
+        sb.append(checkpoint);
+
+        ZhcxItpTemplateNodesDo node = excelBO.getNodeMap().get(sb.toString());
+        if(ObjectUtil.isNotNull(node)) {
+            return node;
+        }
+
+        node = getNewNode("checkpoint", checkpoint, excelHelp);
+        node.setLevel("3");
+
+        if(ObjectUtil.isNull(excelBO.getBig())) { //大构建不存在
+            node.setPid(excelBO.getSmall().getId());
+            node.setPath(excelBO.getSmall().getPath().concat(",").concat(excelBO.getSmall().getId()));
+        } else {
+            node.setPid(excelBO.getBig().getId());
+            node.setPath(excelBO.getBig().getPath().concat(",").concat(excelBO.getBig().getId()));
+        }
+
+        final String inspectionType = excelBO.getNodeBO().getInspectionType();
+        node.setInspectiontype(excelHelp.getInspectionTypeMap().get(inspectionType));
+
+        final String issupp = excelBO.getNodeBO().getIssupp();
+        node.setIssupp(excelHelp.getWhetherMap().get(issupp));
+
+        node.setSortindex(new BigDecimal(String.valueOf(excelBO.getNodeMap().size() + 1)));
+
+        excelBO.getNodeMap().put(sb.toString(), node);
+        return node;
+    }
+
+    /**
+     * 小构建
+     *
+     * @param excelBO
+     * @return
+     */
+    private static ZhcxItpTemplateNodesDo doSmall(ImportNodeExcelBO excelBO, ImportNodeExcelAssistantBO excelHelp) {
+        final String small = excelBO.getNodeBO().getSmall();
+
+        if(ObjectUtil.isEmpty(small)) {
+            return null;
+        }
+
+        StringBuilder sb  = new StringBuilder();
+        sb.append(excelBO.getPhase().getNodename());
+
+        if(ObjectUtil.isNotNull(excelBO.getBig())) {
+            sb.append("_");
+            sb.append(excelBO.getBig().getNodename());
+        }
+
+        sb.append("_");
+        sb.append(small);
+
+        ZhcxItpTemplateNodesDo node = excelBO.getNodeMap().get(sb.toString());
+        if(ObjectUtil.isNotNull(node)) {
+            return node;
+        }
+
+        node = getNewNode("small", small, excelHelp);
+        node.setLevel("2");
+        node.setPid(excelBO.getPhase().getId());
+        node.setPath(excelBO.getPhase().getId());
+
+        if(ObjectUtil.isNotNull(excelBO.getBig())) {
+            node.setPnodeid(excelBO.getBig().getId());
+            node.setPnodename(excelBO.getBig().getNodename());
+        }
+
+        excelBO.getNodeMap().put(sb.toString(), node);
+        return node;
+    }
+
+    /**
+     * 大构建
+     *
+     * @param excelBO
+     * @return
+     */
+    private static ZhcxItpTemplateNodesDo doBig(ImportNodeExcelBO excelBO, ImportNodeExcelAssistantBO excelHelp) {
+        final String big = excelBO.getNodeBO().getBig();
+        if(ObjectUtil.isEmpty(big)) {
+            return null;
+        }
+
+        String key = excelBO.getPhase().getNodename().concat("_").concat(big);
+        ZhcxItpTemplateNodesDo node = excelBO.getNodeMap().get(key);
+        if(ObjectUtil.isNotNull(node)) { //大构建
+            return node;
+        }
+        node = getNewNode("big", big, excelHelp);
+        node.setLevel("2");
+        node.setPid(excelBO.getPhase().getId());
+        node.setPath(excelBO.getPhase().getId());
+        excelBO.getNodeMap().put(key, node);
+        return node;
+    }
+
+    /**
+     * 阶段
+     *
+     * @param excelBO
+     * @return
+     */
+    private static ZhcxItpTemplateNodesDo doPhase(ImportNodeExcelBO excelBO, ImportNodeExcelAssistantBO excelHelp) {
+        final String phase = excelBO.getNodeBO().getPhase();
+
+        ZhcxItpTemplateNodesDo phaseNode = excelBO.getNodeMap().get(phase); //阶段
+        if(ObjectUtil.isNotNull(phaseNode)) {  //阶段
+            return phaseNode;
+        }
+
+        phaseNode = getNewNode("phase", phase, excelHelp);
+        phaseNode.setLevel("1");
+        phaseNode.setPid("-1");
+        phaseNode.setSortindex(new BigDecimal(String.valueOf(excelBO.getNodeMap().size() + 1)));
+        excelBO.getNodeMap().put(phase, phaseNode);
+        return phaseNode;
+    }
+
+    /**
+     * 返回一空节点
+     *
+     * @param nodeType
+     * @param nodeName
+     * @return
+     */
+    private static ZhcxItpTemplateNodesDo getNewNode(String nodeType, String nodeName, ImportNodeExcelAssistantBO excelHelp) {
+        ZhcxItpTemplateNodesDo node = new ZhcxItpTemplateNodesDo();
+        node.setId(SecurityUtil.getUUID());
+        node.setItpid(excelHelp.getTmpId());
+        node.setNodename(nodeName);
+        node.setNodetype(nodeType);
+        node.setDeleted("0");
+        node.setTenantid(excelHelp.getUser().getTenantid());
+        node.setOrgid(excelHelp.getFactoryId());
+        node.setOrgname(excelHelp.getFactoryName());
+
+        return node;
+    }
+
+    /**
+     * 必填项校验
+     *
+     * @param row
+     * @return
+     */
+    private static List<String> checkExcelRequired(ImportTemplateNodeBO row) {
+        List<String> requiredList = new ArrayList<>();
+        if(ObjectUtil.isEmpty(row.getPhase())) {
+            requiredList.add("阶段必填");
+        }
+
+        if(ObjectUtil.isEmpty(row.getSmall())) {
+            requiredList.add("小构件名称必填");
+        }
+
+        if(ObjectUtil.isEmpty(row.getCheckPoint())) {
+            requiredList.add("检验点必填");
+        }
+
+        if(ObjectUtil.isEmpty(row.getInspectionType())) {
+            requiredList.add("报检类型必填");
+        }
+
+        if(ObjectUtil.isEmpty(row.getIssupp())) {
+            requiredList.add("是否外协");
+        }
+
+        return requiredList;
+    }
+}

+ 39 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/node/ExportNodeExcelAssistantBO.java

@@ -0,0 +1,39 @@
+package com.rongwei.bsentity.dto.node;
+
+import com.rongwei.bsentity.domain.ZhcxItpTemplateDo;
+import lombok.*;
+
+import java.util.Map;
+
+@Setter
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class ExportNodeExcelAssistantBO {
+
+    /**
+     * 报验类型,key;值,value;名称
+     */
+    private Map<String, String> inspectionTypeMap;
+
+    /**
+     * 是否标识
+     */
+    private Map<String, String> whetherMap;
+
+    /**
+     * 模板
+     */
+    private ZhcxItpTemplateDo template;
+
+    /**
+     * 工厂id
+     */
+    private String factoryId;
+
+    /**
+     * 工厂名称
+     */
+    private String factoryName;
+}

+ 16 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/node/ExportNodeRequest.java

@@ -0,0 +1,16 @@
+package com.rongwei.bsentity.dto.node;
+
+import lombok.*;
+
+@Setter
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class ExportNodeRequest {
+
+    /**
+     * 标准库id
+     */
+    private String tmpId;
+}

+ 65 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/node/ExportTemplateNodeBO.java

@@ -0,0 +1,65 @@
+package com.rongwei.bsentity.dto.node;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.*;
+
+@Setter
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class ExportTemplateNodeBO {
+
+    /**
+     * 导出字段
+     */
+    public static String [] EXPORT_COLS = {"基地", "产品类型", "阶段", "大构件名称", "小构件名称", "检验点", "报检类型", "是否外协"};
+
+    /**
+     * 工厂名称
+     */
+    @JSONField(name = "基地")
+    private String factoryName;
+
+    /**
+     * 产品类型
+     */
+    @JSONField(name = "产品类型")
+    private String prdType;
+
+    /**
+     * 阶段
+     */
+    @JSONField(name = "阶段")
+    private String phase;
+
+    /**
+     * 大构建
+     */
+    @JSONField(name = "大构件名称")
+    private String big;
+
+    /**
+     * 小构建
+     */
+    @JSONField(name = "小构件名称")
+    private String small;
+
+    /**
+     * 报验点
+     */
+    @JSONField(name = "检验点")
+    private String checkPoint;
+
+    /**
+     * 报验类型
+     */
+    @JSONField(name = "报检类型")
+    private String inspectionType;
+
+    /**
+     * 是否外部报检点
+     */
+    @JSONField(name = "是否外协")
+    private String issupp;
+}

+ 44 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/node/ImportNodeExcelAssistantBO.java

@@ -0,0 +1,44 @@
+package com.rongwei.bsentity.dto.node;
+
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
+import lombok.*;
+
+import java.util.Map;
+
+@Setter
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class ImportNodeExcelAssistantBO {
+
+    /**
+     * 报验类型,key;名称,value;值
+     */
+    private Map<String, String> inspectionTypeMap;
+
+    /**
+     * 是否标识
+     */
+    private Map<String, String> whetherMap;
+
+    /**
+     * 登录用户
+     */
+    private SysUserVo user;
+
+    /**
+     * 工厂id
+     */
+    private String factoryId;
+
+    /**
+     * 工厂名称
+     */
+    private String factoryName;
+
+    /**
+     * 模板id
+     */
+    private String tmpId;
+}

+ 38 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/node/ImportNodeExcelBO.java

@@ -0,0 +1,38 @@
+package com.rongwei.bsentity.dto.node;
+
+import com.alibaba.fastjson.JSONObject;
+import com.rongwei.bsentity.domain.ZhcxItpTemplateNodesDo;
+import lombok.*;
+
+import java.util.Map;
+
+@Setter
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class ImportNodeExcelBO {
+
+    /**
+     * 行数据
+     */
+    private ImportTemplateNodeBO nodeBO;
+
+    private Map<String, ZhcxItpTemplateNodesDo> nodeMap;
+    private ImportNodeRequest req;
+
+    /**
+     * 阶段
+     */
+    private ZhcxItpTemplateNodesDo phase;
+
+    /**
+     * 大构建
+     */
+    private ZhcxItpTemplateNodesDo big;
+
+    /**
+     * 小构建
+     */
+    private ZhcxItpTemplateNodesDo small;
+}

+ 16 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/node/ImportNodeRequest.java

@@ -0,0 +1,16 @@
+package com.rongwei.bsentity.dto.node;
+
+import lombok.*;
+
+@Setter
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class ImportNodeRequest {
+
+    /**
+     * 标准库id
+     */
+    private String tmpId;
+}

+ 49 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/node/ImportTemplateNodeBO.java

@@ -0,0 +1,49 @@
+package com.rongwei.bsentity.dto.node;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.*;
+
+@Setter
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class ImportTemplateNodeBO {
+
+    /**
+     * 阶段
+     */
+    @JSONField(name = "阶段")
+    private String phase;
+
+    /**
+     * 大构建
+     */
+    @JSONField(name = "大构件名称")
+    private String big;
+
+    /**
+     * 小构建
+     */
+    @JSONField(name = "小构件名称")
+    private String small;
+
+    /**
+     * 报验点
+     */
+    @JSONField(name = "报验点")
+    private String checkPoint;
+
+    /**
+     * 报验类型
+     */
+    @JSONField(name = "报检类型")
+    private String inspectionType;
+
+    /**
+     * 是否外部报检点
+     */
+    @JSONField(name = "是否外协")
+    private String issupp;
+
+}

+ 18 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/node/SaveITPNodeBO.java

@@ -0,0 +1,18 @@
+package com.rongwei.bsentity.dto.node;
+
+import com.rongwei.bsentity.domain.ZhcxItpTemplateNodesDo;
+import lombok.*;
+
+import java.util.Map;
+
+@Setter
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class SaveITPNodeBO {
+    private Map<String, ZhcxItpTemplateNodesDo> phaseMap;  //阶段
+    private Map<String, ZhcxItpTemplateNodesDo>  bigMap; //大构件
+    private Map<String, ZhcxItpTemplateNodesDo>  smallMap; //构件
+    private Map<String, ZhcxItpTemplateNodesDo>  checkpointMap; //报验点
+}

+ 17 - 0
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxItpTemplateNodesController.java

@@ -2,6 +2,8 @@ package com.rongwei.bsserver.controller;
 
 
 import com.rongwei.bscommon.sys.service.ZhcxItpTemplateNodesService;
+import com.rongwei.bsentity.dto.node.ExportNodeRequest;
+import com.rongwei.bsentity.dto.node.ImportNodeRequest;
 import com.rongwei.bsentity.vo.CopyNodeVo;
 import com.rongwei.rwcommon.base.R;
 import io.swagger.annotations.Api;
@@ -11,7 +13,9 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 import java.util.Map;
 
@@ -38,5 +42,18 @@ public class ZhcxItpTemplateNodesController {
         return R.ok(maps);
     }
 
+    @PostMapping("excelImport")
+    @ApiOperation("excel导入")
+    public R excelImport(ImportNodeRequest req, MultipartFile file) {
+        zhcxItpTemplateNodesService.importQcp(req, file);
+        return R.ok("导入成功");
+    }
+
+    @PostMapping("excelExport")
+    @ApiOperation("excel导出")
+    public void excelExport(@RequestBody ExportNodeRequest req, HttpServletResponse res) {
+        zhcxItpTemplateNodesService.exportQcp(req, res);
+    }
+
 }