| | |
| | | package com.vci.ubcs.code.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.nacos.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import com.vci.ubcs.starter.revision.model.BaseModel; |
| | | import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil; |
| | | import com.vci.ubcs.starter.util.LocalFileUtil; |
| | | import com.vci.ubcs.starter.util.SaveLogUtil; |
| | | import com.vci.ubcs.starter.web.constant.QueryOptionConstant; |
| | | import com.vci.ubcs.starter.web.enumpck.BooleanEnum; |
| | | import com.vci.ubcs.starter.web.enumpck.UserSecretEnum; |
| | |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | import java.util.concurrent.CopyOnWriteArraySet; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.alibaba.druid.util.FnvHash.Constants.LIMIT; |
| | |
| | | */ |
| | | @Resource |
| | | private IWebSecretClient secretService; |
| | | /** |
| | | * 日志保存工具类 |
| | | */ |
| | | @Autowired |
| | | private SaveLogUtil saveLogUtil; |
| | | |
| | | /** |
| | | * 导出的十万条 |
| | |
| | | * @return 有错误信息的excel的文件 |
| | | */ |
| | | @Override |
| | | public CodeImProtRusultVO batchImportCode(CodeOrderDTO orderDTO, File file) { |
| | | public CodeImProtRusultVO batchImportCode(CodeOrderDTO orderDTO, File file) throws Exception { |
| | | VciBaseUtil.alertNotNull(orderDTO,"编码申请相关的数据",orderDTO.getCodeClassifyOid(),"主题库分类主键"); |
| | | ReadExcelOption reo = new ReadExcelOption(); |
| | | reo.setReadAllSheet(true); |
| | |
| | | */ |
| | | @Override |
| | | public CodeImProtRusultVO batchImportHistoryData(String codeClassifyOid, String classifyAttr,File file) throws Throwable{ |
| | | VciBaseUtil.alertNotNull(codeClassifyOid,"分类的主键"); |
| | | ReadExcelOption reo = new ReadExcelOption(); |
| | | reo.setReadAllSheet(true); |
| | | List<SheetDataSet> sheetDataSetList = ExcelUtil.readDataObjectFromExcel(file,null,reo); |
| | | if (sheetDataSetList.size() > LIMIT + 1) { |
| | | throw new VciBaseException("为了保证系统的稳定性,请一次不要导入超过1万条的数据"); |
| | | } |
| | | Map<String,List<WriteExcelData>> shetNameMap=new HashMap<>(); |
| | | //相似项目查重 |
| | | String uuid=VciBaseUtil.getPk(); |
| | | boolean isCreateUUid=false; |
| | | boolean isExport=false; |
| | | //long start = System.currentTimeMillis(); |
| | | for(int i=0;i<sheetDataSetList.size()-1;i++) { |
| | | if (CollectionUtils.isEmpty(sheetDataSetList) || CollectionUtils.isEmpty(sheetDataSetList.get(i).getRowData()) |
| | | || sheetDataSetList.get(i).getRowData().size() < 1) { |
| | | continue; |
| | | try { |
| | | VciBaseUtil.alertNotNull(codeClassifyOid,"分类的主键"); |
| | | ReadExcelOption reo = new ReadExcelOption(); |
| | | reo.setReadAllSheet(true); |
| | | List<SheetDataSet> sheetDataSetList = ExcelUtil.readDataObjectFromExcel(file,null,reo); |
| | | if (sheetDataSetList.size() > LIMIT + 1) { |
| | | throw new VciBaseException("为了保证系统的稳定性,请一次不要导入超过1万条的数据"); |
| | | } |
| | | // 单次导入数量限制 |
| | | if(sheetDataSetList.get(i).getRowData().size() > IMPORT_DATA_LIMIT){ |
| | | throw new ServiceException("为了保证系统的稳定性,请一次不要导入超过"+IMPORT_DATA_LIMIT+"条的数据"); |
| | | } |
| | | //历史导入的时候不处理编码 |
| | | //----逻辑内容---- |
| | | //1. 分类的路径可以在页面上选择是分类编号还是分类的名称 |
| | | //2. 分类的路径,必须是当前导入选择的分类的节点,以及其下级节点 |
| | | //3. 通过数据要导入的分类去查找对应的编码规则 |
| | | //4. 数据存储和批量申请一样, |
| | | //5. 需要单独处理企业编码的内容, |
| | | // 5.1 企业编码在当前excel里不能重复 |
| | | // 5.2 企业编码在系统中不能重复(可以是已经回收的) |
| | | // 5.3 企业编码的长度,和编码规则的长度要对应上 |
| | | // 5.4 获取流水码段的值,去除填充的字符,看流水号是多少,然后将流水号和现在的最大流水号判断,小于就直接录入,大于则修改最大流水号 |
| | | // 5.5 存储企业编码到allcode中 |
| | | //查询分类和模板 |
| | | Map<String,List<WriteExcelData>> shetNameMap=new HashMap<>(); |
| | | //相似项目查重 |
| | | String uuid=VciBaseUtil.getPk(); |
| | | boolean isCreateUUid=false; |
| | | boolean isExport=false; |
| | | //long start = System.currentTimeMillis(); |
| | | // 记录导入成功的总数 |
| | | List<Integer> importCount = new ArrayList<>(); |
| | | CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyOid); |
| | | |
| | | //先找到每一行的标题,然后根据标题来获取对应的属性 |
| | | SheetDataSet dataSet = sheetDataSetList.get(i); |
| | | List<SheetRowData> rowDataList = dataSet.getRowData(); |
| | | |
| | | //找第一行,为了找标题 |
| | | CodeClassifyTemplateVO templateVO = new CodeClassifyTemplateVO(); |
| | | /** if (!templateService.checkChildHasSameTemplate(classifyFullInfo.getCurrentClassifyVO().getOid())) { |
| | | throw new VciBaseException("当前的分类以及下级分类的模板不相同"); |
| | | }***/ |
| | | //都转换完了。需要批量检查 |
| | | //找所有的分类路径,需要校验路径是否正确,是否都在当前的分类的下级 |
| | | List<CodeClassifyVO> childClassifyVOs = classifyService.listChildrenClassify(codeClassifyOid, true, classifyAttr, true); |
| | | Map<String/**路径**/, CodeClassifyVO> pathMap = Optional.ofNullable(childClassifyVOs).orElseGet(() -> new ArrayList<>()).stream().collect(Collectors.toMap(s -> s.getPath().startsWith("#") ? s.getPath().substring(1) : s.getPath(), t -> t)); |
| | | List<String> titleRowData = dataSet.getColName(); |
| | | Map<String, String> errorMap = new ConcurrentHashMap<>(); |
| | | pathMap.put("#current#",classifyFullInfo.getCurrentClassifyVO()); |
| | | |
| | | try { |
| | | List<CodeClassifyTemplateVO> templateVOList= checkSamesTemplate(titleRowData,sheetDataSetList,i,pathMap,errorMap); |
| | | templateVO= templateVOList.get(0); |
| | | }catch (Throwable e){ |
| | | throw new VciBaseException(e.getMessage()); |
| | | } |
| | | |
| | | List<SheetRowData> needowDataList = rowDataList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getRowIndex(); |
| | | return !errorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | |
| | | //checkTemplateSync(sheetDataSetList, templateVO,i); |
| | | //这里不除去默认的属性 |
| | | List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes(); |
| | | Map<Integer/**列号**/, String/**字段的名称**/> fieldIndexMap = new HashMap<>(); |
| | | |
| | | Map<String/**中文名称**/, String/**英文名称**/> attrNameIdMap = attrVOS.stream().collect(Collectors.toMap(s -> s.getName(), t -> t.getId())); |
| | | String idFieldName = attrVOS.stream().filter(s -> VciQueryWrapperForDO.ID_FIELD.equalsIgnoreCase(s.getId())).findFirst().orElseGet(() -> new CodeClassifyTemplateAttrVO()).getName(); |
| | | getFieldIndexMap(titleRowData, attrNameIdMap, fieldIndexMap); |
| | | //先不用管属性是否都存在,先转换一下数据 |
| | | List<ClientBusinessObject> cboList = new ArrayList<>(); |
| | | String fullPath = getFullPath(classifyFullInfo); |
| | | //我们需要获取到所有的下级分类的oid的路径,因为后面需要 |
| | | Map<String/**主键**/, String/**路径**/> childOidPathMap = getChildClassifyPathMap(classifyFullInfo, fullPath); |
| | | excelToCbo(classifyFullInfo, fieldIndexMap, needowDataList, templateVO, cboList, fullPath, false); |
| | | |
| | | |
| | | Map<String/**主键**/, CodeClassifyVO> classifyVOMap = Optional.ofNullable(childClassifyVOs).orElseGet(() -> new ArrayList<>()).stream().collect(Collectors.toMap(s -> s.getOid(), t -> t)); |
| | | classifyVOMap.put(classifyFullInfo.getCurrentClassifyVO().getOid(), classifyFullInfo.getCurrentClassifyVO()); |
| | | pathMap.put("#current#", classifyFullInfo.getCurrentClassifyVO()); |
| | | |
| | | //判断编号在excel里本身就重复的 |
| | | Map<String, Long> idCountMap = cboList.stream().collect(Collectors.groupingBy(ClientBusinessObject::getId, Collectors.counting())); |
| | | List<String> repeatIdList = new ArrayList<>(); |
| | | idCountMap.forEach((id, count) -> { |
| | | if (count > 1) { |
| | | repeatIdList.add(id); |
| | | for(int i=0;i<sheetDataSetList.size()-1;i++) { |
| | | if (CollectionUtils.isEmpty(sheetDataSetList) || CollectionUtils.isEmpty(sheetDataSetList.get(i).getRowData()) |
| | | || sheetDataSetList.get(i).getRowData().size() < 1) { |
| | | continue; |
| | | } |
| | | }); |
| | | if (!CollectionUtils.isEmpty(repeatIdList)) { |
| | | cboList.stream().filter(s -> repeatIdList.contains(s.getId())).map(s -> s.getAttributeValue(IMPORT_ROW_INDEX)).forEach(rowIndex -> { |
| | | errorMap.put(rowIndex, "编号在当前excel中重复;"); |
| | | }); |
| | | } |
| | | //我们需要判断这些分类的模板是不是一样的,只需要校验,不用获取 |
| | | //检查分类的路径 |
| | | checkClassifyPathInHistory(cboList, errorMap, pathMap, childOidPathMap); |
| | | // 单次导入数量限制 |
| | | if(sheetDataSetList.get(i).getRowData().size() > IMPORT_DATA_LIMIT){ |
| | | throw new ServiceException("为了保证系统的稳定性,请一次不要导入超过"+IMPORT_DATA_LIMIT+"条的数据"); |
| | | } |
| | | //历史导入的时候不处理编码 |
| | | //----逻辑内容---- |
| | | //1. 分类的路径可以在页面上选择是分类编号还是分类的名称 |
| | | //2. 分类的路径,必须是当前导入选择的分类的节点,以及其下级节点 |
| | | //3. 通过数据要导入的分类去查找对应的编码规则 |
| | | //4. 数据存储和批量申请一样, |
| | | //5. 需要单独处理企业编码的内容, |
| | | // 5.1 企业编码在当前excel里不能重复 |
| | | // 5.2 企业编码在系统中不能重复(可以是已经回收的) |
| | | // 5.3 企业编码的长度,和编码规则的长度要对应上 |
| | | // 5.4 获取流水码段的值,去除填充的字符,看流水号是多少,然后将流水号和现在的最大流水号判断,小于就直接录入,大于则修改最大流水号 |
| | | // 5.5 存储企业编码到allcode中 |
| | | //查询分类和模板 |
| | | |
| | | //检查规则 |
| | | Map<String/**分类主键**/, String/**规则主键**/> ruleOidMap = new ConcurrentHashMap<String, String>(); |
| | | List<String> unExistRuleClassifyOidList = new CopyOnWriteArrayList<>(); |
| | | checkRuleOidInHistory(classifyVOMap, ruleOidMap, unExistRuleClassifyOidList); |
| | | //如果出错了,我们依然执行有效的数据,无效的数据写回到excel中 |
| | | //先找到每一行的标题,然后根据标题来获取对应的属性 |
| | | SheetDataSet dataSet = sheetDataSetList.get(i); |
| | | List<SheetRowData> rowDataList = dataSet.getRowData(); |
| | | |
| | | //我们根据出错的分类的主键,去找行号 |
| | | if (!CollectionUtils.isEmpty(unExistRuleClassifyOidList)) { |
| | | cboList.stream().forEach(cbo -> { |
| | | if (unExistRuleClassifyOidList.contains(cbo.getAttributeValue(CODE_CLASSIFY_OID_FIELD))) { |
| | | String row_index = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | errorMap.put(row_index, errorMap.getOrDefault(row_index, "") + ";根据分类路径对应的分类,没有设置编码规则"); |
| | | //找第一行,为了找标题 |
| | | CodeClassifyTemplateVO templateVO = new CodeClassifyTemplateVO(); |
| | | /** if (!templateService.checkChildHasSameTemplate(classifyFullInfo.getCurrentClassifyVO().getOid())) { |
| | | throw new VciBaseException("当前的分类以及下级分类的模板不相同"); |
| | | }***/ |
| | | //都转换完了。需要批量检查 |
| | | //找所有的分类路径,需要校验路径是否正确,是否都在当前的分类的下级 |
| | | List<CodeClassifyVO> childClassifyVOs = classifyService.listChildrenClassify(codeClassifyOid, true, classifyAttr, true); |
| | | Map<String/**路径**/, CodeClassifyVO> pathMap = Optional.ofNullable(childClassifyVOs).orElseGet(() -> new ArrayList<>()).stream().collect(Collectors.toMap(s -> s.getPath().startsWith("#") ? s.getPath().substring(1) : s.getPath(), t -> t)); |
| | | List<String> titleRowData = dataSet.getColName(); |
| | | Map<String, String> errorMap = new ConcurrentHashMap<>(); |
| | | pathMap.put("#current#",classifyFullInfo.getCurrentClassifyVO()); |
| | | |
| | | try { |
| | | List<CodeClassifyTemplateVO> templateVOList= checkSamesTemplate(titleRowData,sheetDataSetList,i,pathMap,errorMap); |
| | | templateVO= templateVOList.get(0); |
| | | }catch (Throwable e){ |
| | | throw new VciBaseException(e.getMessage()); |
| | | } |
| | | |
| | | List<SheetRowData> needowDataList = rowDataList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getRowIndex(); |
| | | return !errorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | |
| | | //checkTemplateSync(sheetDataSetList, templateVO,i); |
| | | //这里不除去默认的属性 |
| | | List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes(); |
| | | Map<Integer/**列号**/, String/**字段的名称**/> fieldIndexMap = new HashMap<>(); |
| | | |
| | | Map<String/**中文名称**/, String/**英文名称**/> attrNameIdMap = attrVOS.stream().collect(Collectors.toMap(s -> s.getName(), t -> t.getId())); |
| | | String idFieldName = attrVOS.stream().filter(s -> VciQueryWrapperForDO.ID_FIELD.equalsIgnoreCase(s.getId())).findFirst().orElseGet(() -> new CodeClassifyTemplateAttrVO()).getName(); |
| | | getFieldIndexMap(titleRowData, attrNameIdMap, fieldIndexMap); |
| | | //先不用管属性是否都存在,先转换一下数据 |
| | | List<ClientBusinessObject> cboList = new ArrayList<>(); |
| | | String fullPath = getFullPath(classifyFullInfo); |
| | | //我们需要获取到所有的下级分类的oid的路径,因为后面需要 |
| | | Map<String/**主键**/, String/**路径**/> childOidPathMap = getChildClassifyPathMap(classifyFullInfo, fullPath); |
| | | excelToCbo(classifyFullInfo, fieldIndexMap, needowDataList, templateVO, cboList, fullPath, false); |
| | | |
| | | |
| | | Map<String/**主键**/, CodeClassifyVO> classifyVOMap = Optional.ofNullable(childClassifyVOs).orElseGet(() -> new ArrayList<>()).stream().collect(Collectors.toMap(s -> s.getOid(), t -> t)); |
| | | classifyVOMap.put(classifyFullInfo.getCurrentClassifyVO().getOid(), classifyFullInfo.getCurrentClassifyVO()); |
| | | pathMap.put("#current#", classifyFullInfo.getCurrentClassifyVO()); |
| | | |
| | | //判断编号在excel里本身就重复的 |
| | | Map<String, Long> idCountMap = cboList.stream().collect(Collectors.groupingBy(ClientBusinessObject::getId, Collectors.counting())); |
| | | List<String> repeatIdList = new ArrayList<>(); |
| | | idCountMap.forEach((id, count) -> { |
| | | if (count > 1) { |
| | | repeatIdList.add(id); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | //判断必输项 |
| | | batchCheckRequiredAttrOnOrder(templateVO, cboList, errorMap); |
| | | |
| | | //优先校验编码是否存在 |
| | | batchCheckIdExistOnOrder(templateVO, cboList, errorMap); |
| | | |
| | | //boolean |
| | | reSwitchBooleanAttrOnOrder(attrVOS, cboList); |
| | | |
| | | // 枚举的内容需要根据名称转换为枚举的值 |
| | | batchSwitchEnumAttrOnOrder(attrVOS, cboList, errorMap); |
| | | |
| | | batchSwitchReferAttrOnOrder(attrVOS, cboList, errorMap); |
| | | |
| | | //6.处理分类注入 |
| | | batchSwitchClassifyAttrOnOrder(attrVOS, cboList, classifyFullInfo,true); |
| | | |
| | | //设置默认值 |
| | | batchSwitchAttrDefault(attrVOS, cboList); |
| | | |
| | | //7.处理组合规则 |
| | | batchSwitchComponentAttrOnOrder(attrVOS, cboList); |
| | | |
| | | //3.判断关键属性 |
| | | CodeImportResultVO keyResultVO = batchCheckKeyAttrOnOrder(classifyFullInfo, templateVO, cboList,errorMap); |
| | | Set<String> selfRepeatRowIndexList = keyResultVO.getSelfRepeatRowIndexList(); |
| | | Set<String> keyAttrRepeatRowIndexList = keyResultVO.getKeyAttrRepeatRowIndexList(); |
| | | if (!CollectionUtils.isEmpty(selfRepeatRowIndexList)) { |
| | | selfRepeatRowIndexList.stream().forEach(rowIndex -> { |
| | | errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";在当前excel文件中关键属性重复"); |
| | | }); |
| | | } |
| | | if (!CollectionUtils.isEmpty(keyAttrRepeatRowIndexList)) { |
| | | keyAttrRepeatRowIndexList.stream().forEach(rowIndex -> { |
| | | errorMap.put(rowIndex, "关键属性与系统中的重复;" + errorMap.getOrDefault(rowIndex, "")); |
| | | }); |
| | | } |
| | | //4.校验规则 |
| | | batchCheckVerifyOnOrder(attrVOS, cboList, errorMap); |
| | | |
| | | //6.时间的,必须统一为yyyy-MM-dd HH:mm:ss |
| | | batchSwitchDateAttrOnOrder(attrVOS, cboList, errorMap); |
| | | if (CollectionUtils.isEmpty(ruleOidMap.values())) { |
| | | throw new VciBaseException("导入的数据所选择的分类都没有设置编码规则"); |
| | | } |
| | | // TODO: 该用oid查询规则的,别用id |
| | | Map<String, CodeRuleVO> ruleVOMap = ruleService.listCodeRuleByOids(ruleOidMap.values()).stream().collect(Collectors.toMap(s -> s.getOid(), t -> t)); |
| | | //校验编码规则和码段是否正确 |
| | | Map<String, List<String>> ruleRowIndexMap = new ConcurrentHashMap<>(); |
| | | checkSecLengthInHistory(cboList, classifyVOMap, ruleVOMap, ruleOidMap, errorMap, ruleRowIndexMap); |
| | | ruleRowIndexMap.keySet().parallelStream().forEach(ruleOid -> { |
| | | List<String> rowIndexList = ruleRowIndexMap.get(ruleOid); |
| | | List<ClientBusinessObject> thisCbos = cboList.stream().filter(cbo -> rowIndexList.contains(cbo.getAttributeValue(IMPORT_ROW_INDEX)) && !errorMap.containsKey(cbo.getAttributeValue(IMPORT_ROW_INDEX))).collect(Collectors.toList()); |
| | | //我们需要先查询一下,内容是否已经存在 |
| | | if(!CollectionUtils.isEmpty(thisCbos)){ |
| | | List<String> existIds = new ArrayList<>(); |
| | | VciBaseUtil.switchCollectionForOracleIn(thisCbos).stream().forEach(cbos -> { |
| | | List<CodeAllCode> codeAllCodeList= codeAllCodeService.selectByWrapper(Wrappers.<CodeAllCode>query().lambda().eq(CodeAllCode::getCodeRuleOid, ruleOid) |
| | | .notIn(CodeAllCode::getId,cbos.stream().map(s -> s.getId()).collect(Collectors.toSet()).toArray(new String[0])) |
| | | .notIn(CodeAllCode::getLcStatus,CodeAllCodeLC.TASK_BACK.getValue() + "','" + CodeAllCodeLC.OBSOLETED.getValue()) |
| | | ); |
| | | existIds.addAll(Optional.ofNullable(codeAllCodeList).orElseGet(() -> new ArrayList<>()).stream().map(s -> { |
| | | String id = s.getId(); |
| | | if (StringUtils.isBlank(id)) { |
| | | id = s.getId(); |
| | | } |
| | | return id; |
| | | }).collect(Collectors.toList())); |
| | | if (!CollectionUtils.isEmpty(repeatIdList)) { |
| | | cboList.stream().filter(s -> repeatIdList.contains(s.getId())).map(s -> s.getAttributeValue(IMPORT_ROW_INDEX)).forEach(rowIndex -> { |
| | | errorMap.put(rowIndex, "编号在当前excel中重复;"); |
| | | }); |
| | | List<String> existIdCbos = thisCbos.stream().filter(s -> { |
| | | String id = s.getId(); |
| | | if (StringUtils.isBlank(id)) { |
| | | id = s.getAttributeValue("id"); |
| | | } |
| | | //我们需要判断这些分类的模板是不是一样的,只需要校验,不用获取 |
| | | //检查分类的路径 |
| | | checkClassifyPathInHistory(cboList, errorMap, pathMap, childOidPathMap); |
| | | |
| | | //检查规则 |
| | | Map<String/**分类主键**/, String/**规则主键**/> ruleOidMap = new ConcurrentHashMap<String, String>(); |
| | | List<String> unExistRuleClassifyOidList = new CopyOnWriteArrayList<>(); |
| | | checkRuleOidInHistory(classifyVOMap, ruleOidMap, unExistRuleClassifyOidList); |
| | | //如果出错了,我们依然执行有效的数据,无效的数据写回到excel中 |
| | | |
| | | //我们根据出错的分类的主键,去找行号 |
| | | if (!CollectionUtils.isEmpty(unExistRuleClassifyOidList)) { |
| | | cboList.stream().forEach(cbo -> { |
| | | if (unExistRuleClassifyOidList.contains(cbo.getAttributeValue(CODE_CLASSIFY_OID_FIELD))) { |
| | | String row_index = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | errorMap.put(row_index, errorMap.getOrDefault(row_index, "") + ";根据分类路径对应的分类,没有设置编码规则"); |
| | | } |
| | | return existIds.contains(id); |
| | | }).map(s -> s.getAttributeValue(IMPORT_ROW_INDEX)).collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(existIdCbos)) { |
| | | thisCbos = thisCbos.stream().filter(s -> { |
| | | }); |
| | | } |
| | | |
| | | //判断必输项 |
| | | batchCheckRequiredAttrOnOrder(templateVO, cboList, errorMap); |
| | | |
| | | //优先校验编码是否存在 |
| | | batchCheckIdExistOnOrder(templateVO, cboList, errorMap); |
| | | |
| | | //boolean |
| | | reSwitchBooleanAttrOnOrder(attrVOS, cboList); |
| | | |
| | | // 枚举的内容需要根据名称转换为枚举的值 |
| | | batchSwitchEnumAttrOnOrder(attrVOS, cboList, errorMap); |
| | | |
| | | batchSwitchReferAttrOnOrder(attrVOS, cboList, errorMap); |
| | | |
| | | //6.处理分类注入 |
| | | batchSwitchClassifyAttrOnOrder(attrVOS, cboList, classifyFullInfo,true); |
| | | |
| | | //设置默认值 |
| | | batchSwitchAttrDefault(attrVOS, cboList); |
| | | |
| | | //7.处理组合规则 |
| | | batchSwitchComponentAttrOnOrder(attrVOS, cboList); |
| | | |
| | | //3.判断关键属性 |
| | | CodeImportResultVO keyResultVO = batchCheckKeyAttrOnOrder(classifyFullInfo, templateVO, cboList,errorMap); |
| | | Set<String> selfRepeatRowIndexList = keyResultVO.getSelfRepeatRowIndexList(); |
| | | Set<String> keyAttrRepeatRowIndexList = keyResultVO.getKeyAttrRepeatRowIndexList(); |
| | | if (!CollectionUtils.isEmpty(selfRepeatRowIndexList)) { |
| | | selfRepeatRowIndexList.stream().forEach(rowIndex -> { |
| | | errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";在当前excel文件中关键属性重复"); |
| | | }); |
| | | } |
| | | if (!CollectionUtils.isEmpty(keyAttrRepeatRowIndexList)) { |
| | | keyAttrRepeatRowIndexList.stream().forEach(rowIndex -> { |
| | | errorMap.put(rowIndex, "关键属性与系统中的重复;" + errorMap.getOrDefault(rowIndex, "")); |
| | | }); |
| | | } |
| | | //4.校验规则 |
| | | batchCheckVerifyOnOrder(attrVOS, cboList, errorMap); |
| | | |
| | | //6.时间的,必须统一为yyyy-MM-dd HH:mm:ss |
| | | batchSwitchDateAttrOnOrder(attrVOS, cboList, errorMap); |
| | | if (CollectionUtils.isEmpty(ruleOidMap.values())) { |
| | | throw new VciBaseException("导入的数据所选择的分类都没有设置编码规则"); |
| | | } |
| | | // TODO: 该用oid查询规则的,别用id |
| | | Map<String, CodeRuleVO> ruleVOMap = ruleService.listCodeRuleByOids(ruleOidMap.values()).stream().collect(Collectors.toMap(s -> s.getOid(), t -> t)); |
| | | //校验编码规则和码段是否正确 |
| | | Map<String, List<String>> ruleRowIndexMap = new ConcurrentHashMap<>(); |
| | | checkSecLengthInHistory(cboList, classifyVOMap, ruleVOMap, ruleOidMap, errorMap, ruleRowIndexMap); |
| | | ruleRowIndexMap.keySet().parallelStream().forEach(ruleOid -> { |
| | | List<String> rowIndexList = ruleRowIndexMap.get(ruleOid); |
| | | List<ClientBusinessObject> thisCbos = cboList.stream().filter(cbo -> rowIndexList.contains(cbo.getAttributeValue(IMPORT_ROW_INDEX)) && !errorMap.containsKey(cbo.getAttributeValue(IMPORT_ROW_INDEX))).collect(Collectors.toList()); |
| | | //我们需要先查询一下,内容是否已经存在 |
| | | if(!CollectionUtils.isEmpty(thisCbos)){ |
| | | List<String> existIds = new ArrayList<>(); |
| | | VciBaseUtil.switchCollectionForOracleIn(thisCbos).stream().forEach(cbos -> { |
| | | List<CodeAllCode> codeAllCodeList= codeAllCodeService.selectByWrapper(Wrappers.<CodeAllCode>query().lambda().eq(CodeAllCode::getCodeRuleOid, ruleOid) |
| | | .notIn(CodeAllCode::getId,cbos.stream().map(s -> s.getId()).collect(Collectors.toSet()).toArray(new String[0])) |
| | | .notIn(CodeAllCode::getLcStatus,CodeAllCodeLC.TASK_BACK.getValue() + "','" + CodeAllCodeLC.OBSOLETED.getValue()) |
| | | ); |
| | | existIds.addAll(Optional.ofNullable(codeAllCodeList).orElseGet(() -> new ArrayList<>()).stream().map(s -> { |
| | | String id = s.getId(); |
| | | if (StringUtils.isBlank(id)) { |
| | | id = s.getId(); |
| | | } |
| | | return id; |
| | | }).collect(Collectors.toList())); |
| | | }); |
| | | List<String> existIdCbos = thisCbos.stream().filter(s -> { |
| | | String id = s.getId(); |
| | | if (StringUtils.isBlank(id)) { |
| | | id = s.getAttributeValue("id"); |
| | | } |
| | | return !existIdCbos.contains(id); |
| | | }).collect(Collectors.toList()); |
| | | existIdCbos.stream().forEach(rowIndex -> { |
| | | errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";【" + idFieldName + "】在系统中已经被占用"); |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | Map<String, ClientBusinessObject> rowIndexCboMap = cboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t)); |
| | | if (errorMap.size() > 0) { |
| | | isExport=true; |
| | | createRedisDatas(uuid + "-error", templateVO, rowIndexCboMap, dataSet, fieldIndexMap, errorMap, false); |
| | | } |
| | | createWriteExcelData(rowDataList, errorMap, new ArrayList<>(), titleRowData, shetNameMap, templateVO); |
| | | List<ClientBusinessObject> needSaveCboList = cboList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | return !errorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | //相似校验 |
| | | Map<String, String> resembleMap = new HashMap<>(); |
| | | List<DataResembleVO> dataResembleVOS = new ArrayList<>(); |
| | | String btmtypeid = classifyFullInfo.getTopClassifyVO().getBtmTypeId(); |
| | | bathcResembleQuery(templateVO.getCodeclassifyoid(), templateVO, needSaveCboList, resembleMap, btmtypeid, dataResembleVOS); |
| | | if (resembleMap.size() > 0) { |
| | | if (!CollectionUtils.isEmpty(dataResembleVOS)) { |
| | | bladeRedis.set(uuid + "-resemble-data", dataResembleVOS); |
| | | createRedisDatas(uuid + "-resemble", templateVO, rowIndexCboMap, dataSet, fieldIndexMap, resembleMap, false); |
| | | } |
| | | } |
| | | //生成class缓存 |
| | | Map<String, String> rowIndexClsOidMap = cboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t.getAttributeValue(CODE_CLASSIFY_OID_FIELD))); |
| | | createRedisByCodeClassify(uuid + "-class",templateVO,dataSet,fieldIndexMap,true); |
| | | //获取编码,查询在系统中是否被其他的引用了 |
| | | //排除错误的,剩下正确的 |
| | | Map<String, String> newErrorMap = new HashMap<>(); |
| | | newErrorMap.putAll(resembleMap); |
| | | newErrorMap.putAll(errorMap); |
| | | //要把以上的错误的都抛出后,再继续处理时间和组合规则 |
| | | needSaveCboList = cboList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | return !newErrorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | if((errorMap.size()>0&&needSaveCboList.size()>0)||resembleMap.size()>0){ |
| | | isCreateUUid=true; |
| | | } |
| | | |
| | | List<String> needRowIndexList = needSaveCboList.stream().filter(s -> errorMap.containsKey(s.getAttributeValue(IMPORT_ROW_INDEX))).map(s -> s.getAttributeValue(IMPORT_ROW_INDEX)).collect(Collectors.toList()); |
| | | if (isExport||newErrorMap.size() > 0) { |
| | | createRedisDatas(uuid + "-ok", templateVO, rowIndexCboMap, dataSet, fieldIndexMap, newErrorMap, true); |
| | | } else { |
| | | List<BaseModel> dataCBOIdList=new ArrayList<>(); |
| | | //SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo(); |
| | | List<ClientBusinessObject> finalNeedSaveCboList = needSaveCboList; |
| | | CodeClassifyTemplateVO finalTemplateVO = templateVO; |
| | | ruleRowIndexMap.keySet().parallelStream().forEach(ruleOid -> { |
| | | //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo); |
| | | List<String> rowIndexList = ruleRowIndexMap.get(ruleOid); |
| | | List<ClientBusinessObject> thisCbos = finalNeedSaveCboList.stream().filter(cbo -> rowIndexList.contains(cbo.getAttributeValue(IMPORT_ROW_INDEX)) && !errorMap.containsKey(cbo.getAttributeValue(IMPORT_ROW_INDEX))).collect(Collectors.toList()); |
| | | List<BaseModel> dataCBOList=new CopyOnWriteArrayList<>(); |
| | | thisCbos.stream().forEach(clientBusinessObject -> { |
| | | BaseModel baseModel=new BaseModel(); |
| | | BeanUtil.convert(clientBusinessObject,baseModel); |
| | | //baseModel.setData(VciBaseUtil.objectToMapString(clientBusinessObject)); |
| | | dataCBOList.add(baseModel); |
| | | dataCBOIdList.add(baseModel); |
| | | }); |
| | | |
| | | if (!CollectionUtils.isEmpty(thisCbos)) { |
| | | try { |
| | | // TODO 多线程流问题 |
| | | productCodeService.productCodeAndSaveData(classifyFullInfo, finalTemplateVO, ruleVOMap.get(ruleOid), null, dataCBOList); |
| | | } catch (Throwable e) { |
| | | log.error("批量产生编码的时候出错了", e); |
| | | thisCbos.stream().forEach(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";系统错误,存储数据的时候出错了:"+e.getMessage()); |
| | | return existIds.contains(id); |
| | | }).map(s -> s.getAttributeValue(IMPORT_ROW_INDEX)).collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(existIdCbos)) { |
| | | thisCbos = thisCbos.stream().filter(s -> { |
| | | String id = s.getId(); |
| | | if (StringUtils.isBlank(id)) { |
| | | id = s.getAttributeValue("id"); |
| | | } |
| | | return !existIdCbos.contains(id); |
| | | }).collect(Collectors.toList()); |
| | | existIdCbos.stream().forEach(rowIndex -> { |
| | | errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";【" + idFieldName + "】在系统中已经被占用"); |
| | | }); |
| | | |
| | | } |
| | | } |
| | | }); |
| | | if (errorMap.size() > 0) { |
| | | isExport = true; |
| | | } |
| | | createWriteExcelData(rowDataList, errorMap, new ArrayList<>(), titleRowData, shetNameMap, finalTemplateVO); |
| | | engineService.batchSaveSelectChar(templateVO, dataCBOIdList); |
| | | } |
| | | } |
| | | //long end = System.currentTimeMillis(); |
| | | //log.info("=============for执行时间================="+String.valueOf((end-start)/1000)); |
| | | String excelFileName=""; |
| | | if(isExport&&!CollectionUtils.isEmpty(shetNameMap)) { |
| | | excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + "错误信息.xls"; |
| | | WriteExcelOption eo = new WriteExcelOption(); |
| | | shetNameMap.forEach((shetName, errorDataList) -> { |
| | | eo.addSheetDataList(shetName, errorDataList); |
| | | }); |
| | | try { |
| | | new File(excelFileName).createNewFile(); |
| | | } catch (IOException e) { |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e)); |
| | | } |
| | | ExcelUtil.writeDataToFile(excelFileName, eo); |
| | | } |
| | | CodeImProtRusultVO codeImProtRusultVO=new CodeImProtRusultVO(); |
| | | if(StringUtils.isNotBlank(excelFileName)) { |
| | | codeImProtRusultVO.setFilePath(excelFileName); |
| | | codeImProtRusultVO.setFileOid(""); |
| | | } |
| | | if(isCreateUUid){ |
| | | codeImProtRusultVO.setRedisUuid(uuid); |
| | | } |
| | | |
| | | return codeImProtRusultVO; |
| | | Map<String, ClientBusinessObject> rowIndexCboMap = cboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t)); |
| | | if (errorMap.size() > 0) { |
| | | isExport=true; |
| | | createRedisDatas(uuid + "-error", templateVO, rowIndexCboMap, dataSet, fieldIndexMap, errorMap, false); |
| | | } |
| | | createWriteExcelData(rowDataList, errorMap, new ArrayList<>(), titleRowData, shetNameMap, templateVO); |
| | | List<ClientBusinessObject> needSaveCboList = cboList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | return !errorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | //相似校验 |
| | | Map<String, String> resembleMap = new HashMap<>(); |
| | | List<DataResembleVO> dataResembleVOS = new ArrayList<>(); |
| | | String btmtypeid = classifyFullInfo.getTopClassifyVO().getBtmTypeId(); |
| | | bathcResembleQuery(templateVO.getCodeclassifyoid(), templateVO, needSaveCboList, resembleMap, btmtypeid, dataResembleVOS); |
| | | if (resembleMap.size() > 0) { |
| | | if (!CollectionUtils.isEmpty(dataResembleVOS)) { |
| | | bladeRedis.set(uuid + "-resemble-data", dataResembleVOS); |
| | | createRedisDatas(uuid + "-resemble", templateVO, rowIndexCboMap, dataSet, fieldIndexMap, resembleMap, false); |
| | | } |
| | | } |
| | | //生成class缓存 |
| | | Map<String, String> rowIndexClsOidMap = cboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t.getAttributeValue(CODE_CLASSIFY_OID_FIELD))); |
| | | createRedisByCodeClassify(uuid + "-class",templateVO,dataSet,fieldIndexMap,true); |
| | | //获取编码,查询在系统中是否被其他的引用了 |
| | | //排除错误的,剩下正确的 |
| | | Map<String, String> newErrorMap = new HashMap<>(); |
| | | newErrorMap.putAll(resembleMap); |
| | | newErrorMap.putAll(errorMap); |
| | | //要把以上的错误的都抛出后,再继续处理时间和组合规则 |
| | | needSaveCboList = cboList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | return !newErrorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | if((errorMap.size()>0&&needSaveCboList.size()>0)||resembleMap.size()>0){ |
| | | isCreateUUid=true; |
| | | } |
| | | |
| | | List<String> needRowIndexList = needSaveCboList.stream().filter(s -> errorMap.containsKey(s.getAttributeValue(IMPORT_ROW_INDEX))).map(s -> s.getAttributeValue(IMPORT_ROW_INDEX)).collect(Collectors.toList()); |
| | | if (isExport||newErrorMap.size() > 0) { |
| | | createRedisDatas(uuid + "-ok", templateVO, rowIndexCboMap, dataSet, fieldIndexMap, newErrorMap, true); |
| | | } else { |
| | | List<BaseModel> dataCBOIdList=new ArrayList<>(); |
| | | //SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo(); |
| | | List<ClientBusinessObject> finalNeedSaveCboList = needSaveCboList; |
| | | CodeClassifyTemplateVO finalTemplateVO = templateVO; |
| | | ruleRowIndexMap.keySet().parallelStream().forEach(ruleOid -> { |
| | | //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo); |
| | | List<String> rowIndexList = ruleRowIndexMap.get(ruleOid); |
| | | List<ClientBusinessObject> thisCbos = finalNeedSaveCboList.stream().filter(cbo -> rowIndexList.contains(cbo.getAttributeValue(IMPORT_ROW_INDEX)) && !errorMap.containsKey(cbo.getAttributeValue(IMPORT_ROW_INDEX))).collect(Collectors.toList()); |
| | | List<BaseModel> dataCBOList=new CopyOnWriteArrayList<>(); |
| | | thisCbos.stream().forEach(clientBusinessObject -> { |
| | | BaseModel baseModel=new BaseModel(); |
| | | BeanUtil.convert(clientBusinessObject,baseModel); |
| | | //baseModel.setData(VciBaseUtil.objectToMapString(clientBusinessObject)); |
| | | dataCBOList.add(baseModel); |
| | | dataCBOIdList.add(baseModel); |
| | | }); |
| | | |
| | | if (!CollectionUtils.isEmpty(thisCbos)) { |
| | | try { |
| | | // TODO 多线程流问题 |
| | | productCodeService.productCodeAndSaveData(classifyFullInfo, finalTemplateVO, ruleVOMap.get(ruleOid), null, dataCBOList); |
| | | importCount.add(dataCBOList.size()); |
| | | } catch (Throwable e) { |
| | | log.error("批量产生编码的时候出错了", e); |
| | | thisCbos.stream().forEach(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";系统错误,存储数据的时候出错了:"+e.getMessage()); |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | if (errorMap.size() > 0) { |
| | | isExport = true; |
| | | } |
| | | createWriteExcelData(rowDataList, errorMap, new ArrayList<>(), titleRowData, shetNameMap, finalTemplateVO); |
| | | engineService.batchSaveSelectChar(templateVO, dataCBOIdList); |
| | | } |
| | | } |
| | | //long end = System.currentTimeMillis(); |
| | | //log.info("=============for执行时间================="+String.valueOf((end-start)/1000)); |
| | | String excelFileName=""; |
| | | if(isExport&&!CollectionUtils.isEmpty(shetNameMap)) { |
| | | excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + "错误信息.xls"; |
| | | WriteExcelOption eo = new WriteExcelOption(); |
| | | shetNameMap.forEach((shetName, errorDataList) -> { |
| | | eo.addSheetDataList(shetName, errorDataList); |
| | | }); |
| | | try { |
| | | new File(excelFileName).createNewFile(); |
| | | } catch (IOException e) { |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e)); |
| | | } |
| | | ExcelUtil.writeDataToFile(excelFileName, eo); |
| | | } |
| | | CodeImProtRusultVO codeImProtRusultVO=new CodeImProtRusultVO(); |
| | | if(StringUtils.isNotBlank(excelFileName)) { |
| | | codeImProtRusultVO.setFilePath(excelFileName); |
| | | codeImProtRusultVO.setFileOid(""); |
| | | saveLogUtil.operateLog("历史数据导入",true, StringUtil.format("错误信息:{}",JSON.toJSONString(shetNameMap)) ); |
| | | }else{ |
| | | saveLogUtil.operateLog("历史数据导入",false, StringUtil.format("导入到分类{}中,导入成功总数为:{}", JSON.toJSONString(classifyFullInfo),importCount.get(0))); |
| | | } |
| | | if(isCreateUUid){ |
| | | codeImProtRusultVO.setRedisUuid(uuid); |
| | | } |
| | | return codeImProtRusultVO; |
| | | }catch (Exception e){ |
| | | saveLogUtil.operateLog("历史数据导入",true,e.getMessage()); |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | /*private void converBaseModels(List<ClientBusinessObject> clientBusinessObjects,List<BaseModel>dataCBOList){ |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | /*** |
| | | * 批量处理申请数据 |
| | | * @param orderDTO |
| | |
| | | * @param dataSet |
| | | * @return |
| | | */ |
| | | private String batchImportCodes(CodeOrderDTO orderDTO,CodeClassifyTemplateVO templateVO,SheetDataSet dataSet,Map<String,String> errorMap,boolean isEnumType){ |
| | | private String batchImportCodes(CodeOrderDTO orderDTO,CodeClassifyTemplateVO templateVO,SheetDataSet dataSet,Map<String,String> errorMap,boolean isEnumType) throws Exception { |
| | | List<String> codeList=new ArrayList<>(); |
| | | CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid()); |
| | | //规则的主键需要去获取 |
| | | CodeRuleVO ruleVO = engineService.getCodeRuleByClassifyFullInfo(classifyFullInfo); |
| | | //1.判断规则中除了流水码段,是否有其他码段 |
| | | engineService.checkSecValueOnOrder(ruleVO,orderDTO); |
| | | List<SheetRowData> rowDataList = dataSet.getRowData(); |
| | | String uuid = ""; |
| | | try { |
| | | CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid()); |
| | | //规则的主键需要去获取 |
| | | CodeRuleVO ruleVO = engineService.getCodeRuleByClassifyFullInfo(classifyFullInfo); |
| | | //1.判断规则中除了流水码段,是否有其他码段 |
| | | engineService.checkSecValueOnOrder(ruleVO,orderDTO); |
| | | List<SheetRowData> rowDataList = dataSet.getRowData(); |
| | | |
| | | //除去默认的属性.还有只有表单显示的字段才导入 |
| | | List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes().stream().filter(s -> |
| | | !DEFAULT_ATTR_LIST.contains(s.getId()) && VciBaseUtil.getBoolean(s.getFormDisplayFlag()) |
| | | ).collect(Collectors.toList()); |
| | | Map<Integer/**列号**/,String/**字段的名称**/> fieldIndexMap = new HashMap<>(); |
| | | List<String> titleRowData = dataSet.getColName(); |
| | | Map<String/**中文名称**/, String/**英文名称**/> attrNameIdMap = attrVOS.stream().collect(Collectors.toMap(s -> s.getName(), t -> t.getId().toLowerCase(Locale.ROOT),(o1, o2)->o2)); |
| | | getFieldIndexMap(titleRowData,attrNameIdMap,fieldIndexMap); |
| | | //除去默认的属性.还有只有表单显示的字段才导入 |
| | | List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes().stream().filter(s -> |
| | | !DEFAULT_ATTR_LIST.contains(s.getId()) && VciBaseUtil.getBoolean(s.getFormDisplayFlag()) |
| | | ).collect(Collectors.toList()); |
| | | Map<Integer/**列号**/,String/**字段的名称**/> fieldIndexMap = new HashMap<>(); |
| | | List<String> titleRowData = dataSet.getColName(); |
| | | Map<String/**中文名称**/, String/**英文名称**/> attrNameIdMap = attrVOS.stream().collect(Collectors.toMap(s -> s.getName(), t -> t.getId().toLowerCase(Locale.ROOT),(o1, o2)->o2)); |
| | | getFieldIndexMap(titleRowData,attrNameIdMap,fieldIndexMap); |
| | | |
| | | //需要判断是否所有的属性都在模板上了 |
| | | List<CodeClassifyTemplateAttrVO> unExistAttrVOs = attrVOS.stream().filter(s -> !fieldIndexMap.containsValue(s.getId().toLowerCase(Locale.ROOT)) |
| | | && StringUtils.isBlank(s.getComponentRule()) && StringUtils.isBlank(s.getClassifyInvokeAttr())//组合规则和分类注入确实没给用户导出去 |
| | | ).collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(unExistAttrVOs)){ |
| | | throw new VciBaseException("【" + unExistAttrVOs.stream().map(CodeClassifyTemplateAttrVO::getName) + "】这些属性在列表中没有找到"); |
| | | } |
| | | List<ClientBusinessObject> cboList = new ArrayList<>(); |
| | | String fullPath = getFullPath(classifyFullInfo); |
| | | excelToCbo(classifyFullInfo,fieldIndexMap,rowDataList,templateVO,cboList,fullPath,true); |
| | | |
| | | //都转换完了。需要批量检查 |
| | | //如果出错了,我们依然执行有效的数据,无效的数据写回到excel中 |
| | | //2.判断必输项。。需要全部的属性,如果是必输,但是表单里面不显示的,只能是分类注入或者组合规则 |
| | | batchCheckRequiredAttrOnOrder(templateVO,cboList,errorMap); |
| | | //3.判断关键属性 |
| | | CodeImportResultVO keyResultVO = batchCheckKeyAttrOnOrder(classifyFullInfo, templateVO, cboList,errorMap); |
| | | Set<String> selfRepeatRowIndexList = keyResultVO.getSelfRepeatRowIndexList(); |
| | | Set<String> keyAttrRepeatRowIndexList = keyResultVO.getKeyAttrRepeatRowIndexList(); |
| | | if(!CollectionUtils.isEmpty(selfRepeatRowIndexList)){ |
| | | selfRepeatRowIndexList.stream().forEach(rowIndex->{ |
| | | errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";在当前处理的数据文件中关键属性重复" ); |
| | | }); |
| | | } |
| | | if(!CollectionUtils.isEmpty(keyAttrRepeatRowIndexList)){ |
| | | keyAttrRepeatRowIndexList.stream().forEach(rowIndex->{ |
| | | errorMap.put(rowIndex,"关键属性与系统中的重复;" + errorMap.getOrDefault(rowIndex,"")); |
| | | }); |
| | | } |
| | | //分类注入 |
| | | batchSwitchClassifyAttrOnOrder(attrVOS,cboList,classifyFullInfo,false); |
| | | //boolean |
| | | reSwitchBooleanAttrOnOrder(attrVOS,cboList); |
| | | //4.校验规则 |
| | | batchCheckVerifyOnOrder(attrVOS, cboList,errorMap); |
| | | if(isEnumType) {//是否需要校验枚举/参照 |
| | | //5.校验枚举是否正确 |
| | | batchSwitchEnumAttrOnOrder(attrVOS, cboList, errorMap); |
| | | //7.处理参照的情况 |
| | | batchSwitchReferAttrOnOrder(attrVOS,cboList,errorMap); |
| | | } |
| | | //6.时间格式的验证 |
| | | //6.时间的,必须统一为yyyy-MM-dd HH:mm:ss |
| | | batchSwitchDateAttrOnOrder(attrVOS,cboList,errorMap); |
| | | //最后弄组合规则 |
| | | batchSwitchComponentAttrOnOrder(attrVOS,cboList); |
| | | String uuid=VciBaseUtil.getPk(); |
| | | Map<String, ClientBusinessObject> rowIndexCboMap = cboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t)); |
| | | |
| | | if(errorMap.size()>0) { |
| | | createRedisDatas(uuid + "-error",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, errorMap,false); |
| | | } |
| | | boolean isCreateUUid=false; |
| | | List<ClientBusinessObject> needSaveCboList = cboList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | return !errorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | //相似校验 |
| | | Map<String,String>resembleMap=new HashMap<>(); |
| | | List<DataResembleVO> dataResembleVOS=new ArrayList<>(); |
| | | String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmTypeId(); |
| | | bathcResembleQuery(orderDTO.getCodeClassifyOid(),templateVO,needSaveCboList,resembleMap,btmtypeid,dataResembleVOS); |
| | | if(resembleMap.size()>0) { |
| | | isCreateUUid=true; |
| | | if(!CollectionUtils.isEmpty(dataResembleVOS)) { |
| | | bladeRedis.set(uuid + "-resemble-data", dataResembleVOS); |
| | | createRedisDatas(uuid + "-resemble",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, resembleMap, false); |
| | | //需要判断是否所有的属性都在模板上了 |
| | | List<CodeClassifyTemplateAttrVO> unExistAttrVOs = attrVOS.stream().filter(s -> !fieldIndexMap.containsValue(s.getId().toLowerCase(Locale.ROOT)) |
| | | && StringUtils.isBlank(s.getComponentRule()) && StringUtils.isBlank(s.getClassifyInvokeAttr())//组合规则和分类注入确实没给用户导出去 |
| | | ).collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(unExistAttrVOs)){ |
| | | throw new VciBaseException("【" + unExistAttrVOs.stream().map(CodeClassifyTemplateAttrVO::getName) + "】这些属性在列表中没有找到"); |
| | | } |
| | | } |
| | | //排除错误的,剩下正确的 |
| | | Map<String,String> newErrorMap=new HashMap<>(); |
| | | newErrorMap.putAll(resembleMap); |
| | | newErrorMap.putAll(errorMap); |
| | | needSaveCboList = cboList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | return !newErrorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | if((errorMap.size()>0&&needSaveCboList.size()>0)||resembleMap.size()>0){ |
| | | isCreateUUid=true; |
| | | } |
| | | createRedisByCodeClassify(uuid + "-class",templateVO,dataSet,fieldIndexMap,false); |
| | | if(newErrorMap.size()>0) { |
| | | createRedisDatas(uuid + "-ok",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, newErrorMap,true); |
| | | }else { |
| | | uuid=""; |
| | | List<ClientBusinessObject> cboList = new ArrayList<>(); |
| | | String fullPath = getFullPath(classifyFullInfo); |
| | | excelToCbo(classifyFullInfo,fieldIndexMap,rowDataList,templateVO,cboList,fullPath,true); |
| | | |
| | | //要把以上的错误的都抛出后,再继续处理时间和组合规则 |
| | | //都转换完了。需要批量检查 |
| | | //如果出错了,我们依然执行有效的数据,无效的数据写回到excel中 |
| | | //2.判断必输项。。需要全部的属性,如果是必输,但是表单里面不显示的,只能是分类注入或者组合规则 |
| | | batchCheckRequiredAttrOnOrder(templateVO,cboList,errorMap); |
| | | //3.判断关键属性 |
| | | CodeImportResultVO keyResultVO = batchCheckKeyAttrOnOrder(classifyFullInfo, templateVO, cboList,errorMap); |
| | | Set<String> selfRepeatRowIndexList = keyResultVO.getSelfRepeatRowIndexList(); |
| | | Set<String> keyAttrRepeatRowIndexList = keyResultVO.getKeyAttrRepeatRowIndexList(); |
| | | if(!CollectionUtils.isEmpty(selfRepeatRowIndexList)){ |
| | | selfRepeatRowIndexList.stream().forEach(rowIndex->{ |
| | | errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";在当前处理的数据文件中关键属性重复" ); |
| | | }); |
| | | } |
| | | if(!CollectionUtils.isEmpty(keyAttrRepeatRowIndexList)){ |
| | | keyAttrRepeatRowIndexList.stream().forEach(rowIndex->{ |
| | | errorMap.put(rowIndex,"关键属性与系统中的重复;" + errorMap.getOrDefault(rowIndex,"")); |
| | | }); |
| | | } |
| | | //分类注入 |
| | | batchSwitchClassifyAttrOnOrder(attrVOS,cboList,classifyFullInfo,false); |
| | | //boolean |
| | | reSwitchBooleanAttrOnOrder(attrVOS,cboList); |
| | | //4.校验规则 |
| | | batchCheckVerifyOnOrder(attrVOS, cboList,errorMap); |
| | | if(isEnumType) {//是否需要校验枚举/参照 |
| | | //5.校验枚举是否正确 |
| | | batchSwitchEnumAttrOnOrder(attrVOS, cboList, errorMap); |
| | | //7.处理参照的情况 |
| | | batchSwitchReferAttrOnOrder(attrVOS,cboList,errorMap); |
| | | } |
| | | //6.时间格式的验证 |
| | | //6.时间的,必须统一为yyyy-MM-dd HH:mm:ss |
| | | batchSwitchDateAttrOnOrder(attrVOS,cboList,errorMap); |
| | | //最后弄组合规则 |
| | | batchSwitchComponentAttrOnOrder(attrVOS,cboList); |
| | | uuid=VciBaseUtil.getPk(); |
| | | Map<String, ClientBusinessObject> rowIndexCboMap = cboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t)); |
| | | |
| | | if(errorMap.size()>0) { |
| | | createRedisDatas(uuid + "-error",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, errorMap,false); |
| | | } |
| | | boolean isCreateUUid=false; |
| | | List<ClientBusinessObject> needSaveCboList = cboList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | return !errorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | //相似校验 |
| | | Map<String,String>resembleMap=new HashMap<>(); |
| | | List<DataResembleVO> dataResembleVOS=new ArrayList<>(); |
| | | String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmTypeId(); |
| | | bathcResembleQuery(orderDTO.getCodeClassifyOid(),templateVO,needSaveCboList,resembleMap,btmtypeid,dataResembleVOS); |
| | | if(resembleMap.size()>0) { |
| | | isCreateUUid=true; |
| | | if(!CollectionUtils.isEmpty(dataResembleVOS)) { |
| | | bladeRedis.set(uuid + "-resemble-data", dataResembleVOS); |
| | | createRedisDatas(uuid + "-resemble",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, resembleMap, false); |
| | | } |
| | | } |
| | | //排除错误的,剩下正确的 |
| | | Map<String,String> newErrorMap=new HashMap<>(); |
| | | newErrorMap.putAll(resembleMap); |
| | | newErrorMap.putAll(errorMap); |
| | | needSaveCboList = cboList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | return !newErrorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | if((errorMap.size()>0&&needSaveCboList.size()>0)||resembleMap.size()>0){ |
| | | isCreateUUid=true; |
| | | } |
| | | createRedisByCodeClassify(uuid + "-class",templateVO,dataSet,fieldIndexMap,false); |
| | | if(newErrorMap.size()>0) { |
| | | createRedisDatas(uuid + "-ok",templateVO, rowIndexCboMap, dataSet, fieldIndexMap, newErrorMap,true); |
| | | }else { |
| | | uuid=""; |
| | | |
| | | if (!CollectionUtils.isEmpty(needSaveCboList)) { |
| | | //9.我们处理业务数据 |
| | | //生成编码的内容 |
| | | List<String> dataCBOIdList=new ArrayList<>(); |
| | | List<BaseModel> dataCBOList=new ArrayList<>(); |
| | | cboList.stream().forEach(clientBusinessObject -> { |
| | | BaseModel baseModel=new BaseModel(); |
| | | BeanUtil.convert(clientBusinessObject,baseModel); |
| | | //baseModel.setData(VciBaseUtil.objectToMapString(clientBusinessObject)); |
| | | dataCBOList.add(baseModel); |
| | | dataCBOIdList.add(baseModel.getOid()); |
| | | }); |
| | | try { |
| | | codeList = productCodeService.productCodeAndSaveData(classifyFullInfo,templateVO,ruleVO, orderDTO.getSecDTOList(),dataCBOList); |
| | | //如果是编码生成失败,则直接就失败了,其他的判断出来有错误的我们都统一返回到excel里面 |
| | | engineService.batchSaveSelectChar(templateVO, dataCBOList); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("批了申请时失败"); |
| | | //要把以上的错误的都抛出后,再继续处理时间和组合规则 |
| | | needSaveCboList = cboList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | return !newErrorMap.containsKey(rowIndex); |
| | | }).collect(Collectors.toList()); |
| | | |
| | | if (!CollectionUtils.isEmpty(needSaveCboList)) { |
| | | //9.我们处理业务数据 |
| | | //生成编码的内容 |
| | | List<String> dataCBOIdList=new ArrayList<>(); |
| | | List<BaseModel> dataCBOList=new ArrayList<>(); |
| | | cboList.stream().forEach(clientBusinessObject -> { |
| | | BaseModel baseModel=new BaseModel(); |
| | | BeanUtil.convert(clientBusinessObject,baseModel); |
| | | //baseModel.setData(VciBaseUtil.objectToMapString(clientBusinessObject)); |
| | | dataCBOList.add(baseModel); |
| | | dataCBOIdList.add(baseModel.getOid()); |
| | | }); |
| | | try { |
| | | codeList = productCodeService.productCodeAndSaveData(classifyFullInfo,templateVO,ruleVO, orderDTO.getSecDTOList(),dataCBOList); |
| | | //如果是编码生成失败,则直接就失败了,其他的判断出来有错误的我们都统一返回到excel里面 |
| | | engineService.batchSaveSelectChar(templateVO, dataCBOList); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("批量申请时失败"); |
| | | throw e; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(!isCreateUUid){ |
| | | return uuid=""; |
| | | if(!isCreateUUid){ |
| | | return uuid=""; |
| | | } |
| | | saveLogUtil.operateLog("批量申请编码",false, StringUtil.format("批量导入申请成功共{}条数据,生成的码值如下【{}】",codeList.size(),codeList)); |
| | | }catch (Exception e){ |
| | | saveLogUtil.operateLog("批量申请编码",true,e.getMessage()); |
| | | throw e; |
| | | } |
| | | return uuid; |
| | | } |