| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.nacos.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.google.protobuf.ServiceException; |
| | | import com.vci.ubcs.code.applyjtcodeservice.feign.IMdmInterJtClient; |
| | | import com.vci.ubcs.code.bo.AttributeValue; |
| | | import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO; |
| | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.text.MessageFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | |
| | | |
| | | @Value("${batchadd.redis.time:6000000}") |
| | | public int BATCHADD_REDIS_TIME; |
| | | |
| | | @Value("${batchadd.import_data_limit:5001}") |
| | | private Integer IMPORT_DATA_LIMIT; |
| | | |
| | | /** |
| | | * 主题库分类的服务 |
| | | */ |
| | |
| | | LinkedList<WriteExcelData> excelDataList = new LinkedList<>(); |
| | | Workbook workbook = new HSSFWorkbook(); |
| | | if(isHistory){ |
| | | excelDataList.add(new WriteExcelData(0,0,"分类路径")); |
| | | excelDataList.add(new WriteExcelData(0,1,"码段宽度")); |
| | | excelDataList.add(new WriteExcelData(0,2,!CollectionUtils.isEmpty(idAttrVOList)?idAttrVOList.get(0).getName():"企业编码")); |
| | | excelDataList.add(new WriteExcelData(0,0,"分类路径","")); |
| | | excelDataList.add(new WriteExcelData(0,1,"码段宽度","")); |
| | | excelDataList.add(new WriteExcelData(0,2,!CollectionUtils.isEmpty(idAttrVOList)?idAttrVOList.get(0).getName():"企业编码",idAttrVOList.get(0).getId())); |
| | | } |
| | | for (int i = 0; i < templateAttrVOS.size(); i++) { |
| | | CodeClassifyTemplateAttrVO attrVO = templateAttrVOS.get(i); |
| | |
| | | Object text = attrVO.getName(); |
| | | text = exportKeyAndRequired(workbook,attrVO,text); |
| | | int colIndex = (isHistory?3:0) + i; |
| | | WriteExcelData excelData = new WriteExcelData(0, colIndex, text); |
| | | WriteExcelData excelData = new WriteExcelData(0, colIndex, text,attrVO.getId()); |
| | | if(StringUtils.isNotBlank(attrVO.getCodeDateFormat()) |
| | | || VciFieldTypeEnum.VTDateTime.name().equalsIgnoreCase(attrVO.getAttributeDataType()) |
| | | || VciFieldTypeEnum.VTDate.name().equalsIgnoreCase(attrVO.getAttributeDataType()) |
| | |
| | | String uuid=VciBaseUtil.getPk(); |
| | | boolean isCreateUUid=false; |
| | | boolean isExport=false; |
| | | long start = System.currentTimeMillis(); |
| | | //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; |
| | | } |
| | | // 单次导入数量限制 |
| | | if(sheetDataSetList.get(i).getRowData().size() > IMPORT_DATA_LIMIT){ |
| | | throw new ServiceException("为了保证系统的稳定性,请一次不要导入超过"+IMPORT_DATA_LIMIT+"条的数据"); |
| | | } |
| | | //历史导入的时候不处理编码 |
| | | //----逻辑内容---- |
| | |
| | | //找第一行,为了找标题 |
| | | CodeClassifyTemplateVO templateVO = new CodeClassifyTemplateVO(); |
| | | /** if (!templateService.checkChildHasSameTemplate(classifyFullInfo.getCurrentClassifyVO().getOid())) { |
| | | throw new VciBaseException("当前的分类以及下级分类的模板不相同"); |
| | | throw new VciBaseException("当前的分类以及下级分类的模板不相同"); |
| | | }***/ |
| | | //都转换完了。需要批量检查 |
| | | //找所有的分类路径,需要校验路径是否正确,是否都在当前的分类的下级 |
| | |
| | | if (CollectionUtils.isEmpty(ruleOidMap.values())) { |
| | | throw new VciBaseException("导入的数据所选择的分类都没有设置编码规则"); |
| | | } |
| | | Map<String, CodeRuleVO> ruleVOMap = ruleService.listCodeRuleByIds(ruleOidMap.values(), true).stream().collect(Collectors.toMap(s -> s.getOid(), t -> t)); |
| | | // 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); |
| | |
| | | //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 ArrayList<>(); |
| | | List<BaseModel> dataCBOList=new CopyOnWriteArrayList<>(); |
| | | thisCbos.stream().forEach(clientBusinessObject -> { |
| | | BaseModel baseModel=new BaseModel(); |
| | | BeanUtil.convert(clientBusinessObject,baseModel); |
| | |
| | | log.error("批量产生编码的时候出错了", e); |
| | | thisCbos.stream().forEach(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";系统错误,存储数据的时候出错了"); |
| | | errorMap.put(rowIndex, errorMap.getOrDefault(rowIndex, "") + ";系统错误,存储数据的时候出错了:"+e.getMessage()); |
| | | }); |
| | | |
| | | } |
| | |
| | | engineService.batchSaveSelectChar(templateVO, dataCBOIdList); |
| | | } |
| | | } |
| | | long end = System.currentTimeMillis(); |
| | | //long end = System.currentTimeMillis(); |
| | | //log.info("=============for执行时间================="+String.valueOf((end-start)/1000)); |
| | | String excelFileName=""; |
| | | if(isExport&&!CollectionUtils.isEmpty(shetNameMap)) { |
| | |
| | | * @param currentTemplateVO |
| | | * @param templateColumnVOMap |
| | | */ |
| | | |
| | | private void createTemplate(CodeClassifyTemplateVO currentTemplateVO,Map<String,List<ColumnVO>>templateColumnVOMap){ |
| | | |
| | | List<CodeClassifyTemplateAttrVO> templateAttrVOS = currentTemplateVO.getAttributes().stream().filter(s -> |
| | |
| | | Map<String/**分类主键**/, String/**规则主键**/> ruleOidMap = new ConcurrentHashMap<String, String>(); |
| | | List<String> unExistRuleClassifyOidList = new CopyOnWriteArrayList<>(); |
| | | checkRuleOidInHistory(classifyVOMap, ruleOidMap, unExistRuleClassifyOidList); |
| | | ruleVOMap = ruleService.listCodeRuleByIds(ruleOidMap.values(), true).stream().collect(Collectors.toMap(s -> s.getOid(), t -> t)); |
| | | // TODO 改用oid查询的,这儿不该用id |
| | | ruleVOMap = ruleService.listCodeRuleByOids(ruleOidMap.values()).stream().collect(Collectors.toMap(s -> s.getOid(), t -> t)); |
| | | |
| | | checkSecLengthInHistory(cboList, classifyVOMap, ruleVOMap, ruleOidMap, errorMap, ruleRowIndexMap); |
| | | } |
| | |
| | | String dataStatus=cbo.getLcStatus(); |
| | | RowDatas rowData=codeDataMap.get(code); |
| | | String status=rowData.getStatus(); |
| | | String lastModifier= rowData.getEditor(); |
| | | String operation=rowData.getOperation(); |
| | | if (cbo.getTs().compareTo(orderDTO.getTs())==0?false:true) { |
| | | // throw new VciBaseException("数据不是最新的,可能他人已经修改,请刷新后再试"); |
| | |
| | | cbo.setName(orderDTO.getName()); |
| | | try { |
| | | cbo.setAttributeValueWithNoCheck("description", orderDTO.getDescription()); |
| | | cbo.setAttributeValue("name", orderDTO.getName()); |
| | | // cbo.setAttributeValue("name", orderDTO.getName()); |
| | | // if(finalIsProcess){//在流程中不允许更改 |
| | | // errorMap.put(code,errorMap.getOrDefault(code, errorMap.getOrDefault(code,"")+";数据"+code+"在流程中,不允许更改!")); |
| | | // }else{ |
| | | Date date=new Date(); |
| | | cbo.setLcStatus(status); |
| | | cbo.setAttributeValue("lcstatus",status); |
| | | cbo.setLastModifyTime(date); |
| | | cbo.setLastModifier(lastModifier); |
| | | cbo.setLastModifyTime(date); |
| | | cbo.setAttributeValue("lastmodifier",lastModifier); |
| | | cbo.setAttributeValue("lastmodifytime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(date)); |
| | | cbo.setTs(date); |
| | | cbo.setAttributeValue("ts",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(date)); |
| | | // } |
| | | } catch (VciBaseException e) { |
| | | e.printStackTrace(); |
| | |
| | | // if (lifeCycleVO != null) { |
| | | // cbo.setLcStatus(lifeCycleVO.getStartStatus()); |
| | | // } else { |
| | | cbo.setLcStatus(CodeDefaultLC.EDITING.getValue()); |
| | | cbo.setLcStatus(CodeDefaultLC.RELEASED.getValue()); |
| | | // } |
| | | } else { |
| | | cbo.setLcStatus(CodeDefaultLC.EDITING.getValue()); |
| | | cbo.setLcStatus(CodeDefaultLC.RELEASED.getValue()); |
| | | } |
| | | |
| | | } |
| | |
| | | for (int j = 0; j < ruleVO.getSecVOList().size(); j++) { |
| | | CodeBasicSecVO secVO = ruleVO.getSecVOList().get(j); |
| | | String length= secValues[j]; |
| | | if(StringUtils.isNotBlank(secVO.getCodeSecLength())&&VciBaseUtil.getInt(length)>VciBaseUtil.getInt(secVO.getCodeSecLength())){ |
| | | if(StringUtils.isNotBlank(secVO.getCodeSecLength())&&VciBaseUtil.getInt(length)>(VciBaseUtil.getInt(secVO.getCodeSecLength())+((secVO.getPrefixCode()+secVO.getSuffixCode()).length()))){ |
| | | errorMap.put(rowIndex,errorMap.getOrDefault(rowIndex,"") + ";码段宽度与系统中的编码规则不同" ); |
| | | fined = true; |
| | | break; |
| | |
| | | Integer userSecret = VciBaseUtil.getCurrentUserSecret(); |
| | | cbo.setAttributeValue(SECRET_FIELD,String.valueOf((userSecret==null || userSecret ==0)? UserSecretEnum.NONE.getValue():userSecret)); |
| | | } |
| | | cbo.setLcStatus(CodeDefaultLC.EDITING.getValue()); |
| | | cbo.setLcStatus(CodeDefaultLC.RELEASED.getValue()); |
| | | }else{ |
| | | //此时还没有转换路径 |
| | | //cbo.setAttributeValue(CODE_FULL_PATH_FILED, childOidPathMap.getOrDefault(rowData.getData().getOrDefault(CODE_CLASSIFY_OID_FIELD,""),fullPath)); |
| | |
| | | Integer userSecret = VciBaseUtil.getCurrentUserSecret(); |
| | | cbo.setAttributeValue(SECRET_FIELD,String.valueOf((userSecret==null || userSecret ==0)? UserSecretEnum.NONE.getValue():userSecret)); |
| | | } |
| | | cbo.setLcStatus(CodeDefaultLC.EDITING.getValue()); |
| | | cbo.setLcStatus(CodeDefaultLC.RELEASED.getValue()); |
| | | }else{ |
| | | //此时还没有转换路径 |
| | | //cbo.setAttributeValue(CODE_FULL_PATH_FILED, childOidPathMap.getOrDefault(rowData.getData().getOrDefault(CODE_CLASSIFY_OID_FIELD,""),fullPath)); |
| | |
| | | } |
| | | } |
| | | CodeClassifyFullInfoBO newClassifyFullInfo= classifyFullInfoMap.get(cbo.getAttributeValue(CODE_CLASSIFY_OID_FIELD)); |
| | | List<CodeClassifyVO> classifyVOS = newClassifyFullInfo.getParentClassifyVOs().stream().sorted(((o1, o2) -> o2.getDataLevel().compareTo(o1.getDataLevel()))).collect(Collectors.toList()); |
| | | List<CodeClassifyVO> classifyVOS = newClassifyFullInfo.getParentClassifyVOs().stream().sorted(((o1, o2) -> -o2.getDataLevel().compareTo(o1.getDataLevel()))).collect(Collectors.toList()); |
| | | |
| | | int level = VciBaseUtil.getInt(attrVO.getClassifyInvokeLevel()); |
| | | if (classifyVOS.size()>=level && level > 0 ) { |
| | | classifyVO = classifyVOS.get(level-1); |
| | |
| | | //2.判断关键属性在系统里是否重复 |
| | | //因为数据量很大,所以得想办法并行 |
| | | //SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo(); |
| | | Map<String,List<BaseModel>> indexTODataMap=new HashMap<>(); |
| | | Map<String,List<BaseModel>> indexTODataMap=new ConcurrentHashMap<>(); |
| | | List<ClientBusinessObject> repeatDataMap = cboList.parallelStream().filter(cbo -> { |
| | | //每行都得查询.如果其中出现了错误,我们就直接抛出异常,其余的显示 |
| | | //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo); |