|
@@ -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;
|
|
|
+ }
|
|
|
}
|