| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.nacos.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | 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.CodeTemplateAttrSqlBO; |
| | | import com.vci.ubcs.code.dto.*; |
| | | import com.vci.ubcs.code.entity.CodeAllCode; |
| | | import com.vci.ubcs.code.entity.CodeSynonym; |
| | | import com.vci.ubcs.code.enumpack.*; |
| | | import com.vci.ubcs.code.lifecycle.CodeAllCodeLC; |
| | | import com.vci.ubcs.code.mapper.CommonsMapper; |
| | |
| | | import com.vci.ubcs.omd.feign.IBtmTypeClient; |
| | | import com.vci.ubcs.omd.feign.IWebSecretClient; |
| | | import com.vci.ubcs.omd.vo.BtmTypeVO; |
| | | import com.vci.ubcs.omd.vo.RevisionRuleVO; |
| | | import com.vci.ubcs.starter.bo.WriteExcelData; |
| | | import com.vci.ubcs.starter.exception.VciBaseException; |
| | | import com.vci.ubcs.starter.poi.bo.ReadExcelOption; |
| | |
| | | import org.apache.poi.ss.usermodel.Font; |
| | | import org.apache.poi.ss.usermodel.RichTextString; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.aspectj.apache.bcel.classfile.Code; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.xml.bind.ValidationEvent; |
| | | import java.beans.BeanInfo; |
| | | import java.beans.Introspector; |
| | | import java.beans.PropertyDescriptor; |
| | |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | import java.util.concurrent.CopyOnWriteArraySet; |
| | | import java.util.concurrent.ForkJoinPool; |
| | | 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; |
| | |
| | | @Service |
| | | @Slf4j |
| | | public class MdmIOServiceImpl implements MdmIOService { |
| | | |
| | | |
| | | /** |
| | | * 字段 |
| | |
| | | * 模板的服务 |
| | | */ |
| | | @Resource |
| | | private CodeClstemplateServiceImpl templateService; |
| | | private ICodeClstemplateService templateService; |
| | | |
| | | /** |
| | | * 主数据引擎的服务 |
| | |
| | | private ICodeKeyAttrRepeatService keyRuleService; |
| | | |
| | | /** |
| | | * 近义词规则查询服务 |
| | | */ |
| | | @Autowired ICodeSynonymService codeSynonymService; |
| | | |
| | | /** |
| | | * 公式的服务 |
| | | */ |
| | | @Autowired |
| | | private FormulaServiceImpl formulaService; |
| | | |
| | | /** |
| | | * 规则的服务 |
| | | */ |
| | | @Autowired |
| | | private ICodeRuleService ruleService; |
| | | |
| | | /** |
| | | * 业务类型的服务 |
| | | */ |
| | | @Autowired |
| | | private IBtmTypeClient btmTypeClient; |
| | | |
| | | /*** |
| | | * 申请集团编码服务 |
| | | */ |
| | | @Resource |
| | | private IMdmInterJtClient mdmInterJtClient; |
| | | |
| | | /*** |
| | | * 密级服务 |
| | | */ |
| | | @Resource |
| | | private IWebSecretClient secretService; |
| | | |
| | | /** |
| | | * 日志保存工具类 |
| | | */ |
| | | @Autowired |
| | | private SaveLogUtil saveLogUtil; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 客户现场excel为老版本,导出的总数限制为65535 |
| | | */ |
| | | public static final int EXPORT_LIMIT = 65535; |
| | | |
| | | /** |
| | | * 自定义并发ForkJoinPool |
| | | */ |
| | | private static final ForkJoinPool customForkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors()-1); |
| | | |
| | | /** |
| | | * 批量申请:选取选中分类下的所有模板关键属性,相似属性,必填属性,写入execl中 |
| | |
| | | //最后弄组合规则 |
| | | batchSwitchComponentAttrOnOrder(attrVOS,allCboList); |
| | | |
| | | |
| | | Map<String, ClientBusinessObject> rowIndexCboMap = allCboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t)); |
| | | |
| | | |
| | | List<ClientBusinessObject> needSaveCboList = allCboList.stream().filter(cbo -> { |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | |
| | | Map<String,String>resembleMap=new HashMap<>(); |
| | | List<DataResembleVO> dataResembleVOS=new ArrayList<>(); |
| | | String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmTypeId(); |
| | | //相似项查询规则 |
| | | bathcResembleQuery(codeClassifyOid,templateVO,needSaveCboList,resembleMap,btmtypeid,dataResembleVOS); |
| | | if(resembleMap.size()>0) { |
| | | if(!CollectionUtils.isEmpty(dataResembleVOS)) { |
| | |
| | | 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)) { |
| | |
| | | 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); |
| | |
| | | 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"; |
| | |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e)); |
| | | } |
| | | ExcelUtil.writeDataToFile(excelFileName, eo); |
| | | saveLogUtil.operateLog("历史数据导入",true, StringUtil.format("错误信息:{}",JSON.toJSONString(shetNameMap))); |
| | | }else{ |
| | | // 历史数据导入时出现了相似项返回结果时不算导入成功 |
| | | if(shetNameMap.isEmpty() || !isCreateUUid){ |
| | | saveLogUtil.operateLog("历史数据导入",false, StringUtil.format("导入到分类{}中,导入成功总数为:{}", JSON.toJSONString(classifyFullInfo), Func.isEmpty(importCount) ? 0:importCount.get(0))); |
| | | } |
| | | } |
| | | 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); |
| | |
| | | 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; |
| | |
| | | ExcelUtil.writeDataToFile(excelName, excelOption); |
| | | } |
| | | |
| | | /** |
| | | * 相似项查询出来之后再点击确认时调用的 |
| | | * @param codeImprotSaveDatVOList |
| | | * @param classifyAttr |
| | | * @param isImprot |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R batchImportData(List<CodeImprotSaveDatVO> codeImprotSaveDatVOList, String classifyAttr, boolean isImprot) { |
| | | WriteExcelOption eo = new WriteExcelOption(); |
| | | AtomicBoolean success= new AtomicBoolean(true); |
| | | AtomicReference<CodeClassifyTemplateVO> codeClassifyTemplateVO = new AtomicReference<>(); |
| | | codeImprotSaveDatVOList.stream().forEach(codeImprotSaveDatVO -> { |
| | | List<SheetRowData> rowDataList = new ArrayList<>(); |
| | | List<ClientBusinessObject>cboList=new ArrayList<>(); |
| | |
| | | log.info("分类:"+classifyFullInfo.getCurrentClassifyVO().getName()+"数据:"+codeImprotSaveDatVO.getDataList().size()); |
| | | |
| | | // CodeClassifyTemplateVO codeClassifyTemplateVO= engineService.getUsedTemplateByClassifyOid(orderDTO.getCodeClassifyOid()); |
| | | CodeClassifyTemplateVO codeClassifyTemplateVO= templateService.getObjectHasAttrByOid(orderDTO.getTemplateOid()); |
| | | codeClassifyTemplateVO.set(templateService.getObjectHasAttrByOid(orderDTO.getTemplateOid())); |
| | | //规则的主键需要去获取 |
| | | CodeRuleVO ruleVO = engineService.getCodeRuleByClassifyFullInfo(classifyFullInfo); |
| | | //除去默认的属性.还有只有表单显示的字段才导入 |
| | | List<CodeClassifyTemplateAttrVO> attrVOS = codeClassifyTemplateVO.getAttributes().stream().filter(s -> |
| | | List<CodeClassifyTemplateAttrVO> attrVOS = codeClassifyTemplateVO.get().getAttributes().stream().filter(s -> |
| | | !DEFAULT_ATTR_LIST.contains(s.getId()) && |
| | | ((Func.isNotEmpty(s.getClassifyInvokeAttr()) || Func.isNotEmpty(s.getClassifyInvokeAttrName())) || VciBaseUtil.getBoolean(s.getFormDisplayFlag())) |
| | | ).collect(Collectors.toList()); |
| | | String fullPath = getFullPath(classifyFullInfo); |
| | | excelToCbo(classifyFullInfo,fieldIndexMap,rowDataList, codeClassifyTemplateVO,cboList,fullPath,!isImprot); |
| | | excelToCbo(classifyFullInfo,fieldIndexMap,rowDataList, codeClassifyTemplateVO.get(),cboList,fullPath,!isImprot); |
| | | Map<String,String> errorMap=new ConcurrentHashMap<>(); |
| | | Map<String/**路径**/, CodeClassifyVO> pathMap=new HashMap<>() ; |
| | | //校验编码规则和码段是否正确 |
| | |
| | | //最后弄组合规则 |
| | | batchSwitchComponentAttrOnOrder(attrVOS,cboList); |
| | | //3.判断关键属性 |
| | | CodeImportResultVO keyResultVO = batchCheckKeyAttrOnOrder(classifyFullInfo, codeClassifyTemplateVO, cboList,false,errorMap); |
| | | CodeImportResultVO keyResultVO = batchCheckKeyAttrOnOrder(classifyFullInfo, codeClassifyTemplateVO.get(), cboList,false,errorMap); |
| | | Set<String> selfRepeatRowIndexList = keyResultVO.getSelfRepeatRowIndexList(); |
| | | Set<String> keyAttrRepeatRowIndexList = keyResultVO.getKeyAttrRepeatRowIndexList(); |
| | | if(!CollectionUtils.isEmpty(keyAttrRepeatRowIndexList)){ |
| | |
| | | dataCBOList.add(baseModel); |
| | | }); |
| | | try { |
| | | productCodeService.productCodeAndSaveData(classifyFullInfo, codeClassifyTemplateVO, finalRuleVOMap.get(ruleOid), null, dataCBOList, user); |
| | | productCodeService.productCodeAndSaveData(classifyFullInfo, codeClassifyTemplateVO.get(), finalRuleVOMap.get(ruleOid), null, dataCBOList, user); |
| | | } catch (Throwable e) { |
| | | //success=false; |
| | | log.error("批量产生编码的时候出错了", e); |
| | |
| | | }); |
| | | } |
| | | } |
| | | engineService.batchSaveSelectChar(codeClassifyTemplateVO, dataCBOList); |
| | | engineService.batchSaveSelectChar(codeClassifyTemplateVO.get(), dataCBOList); |
| | | }); |
| | | }else { |
| | | final BladeUser user = AuthUtil.getUser(); |
| | |
| | | dataCBOList.add(baseModel); |
| | | }); |
| | | try { |
| | | productCodeService.productCodeAndSaveData(classifyFullInfo, codeClassifyTemplateVO, ruleVO, orderDTO.getSecDTOList(), dataCBOList,user); |
| | | productCodeService.productCodeAndSaveData(classifyFullInfo, codeClassifyTemplateVO.get(), ruleVO, orderDTO.getSecDTOList(), dataCBOList,user); |
| | | } catch (Exception e) { |
| | | log.error("批量产生编码的时候出错了", e); |
| | | needSaveCboList.stream().forEach(cbo -> { |
| | |
| | | }); |
| | | } |
| | | //如果是编码生成失败,则直接就失败了,其他的判断出来有错误的我们都统一返回到excel里面 |
| | | engineService.batchSaveSelectChar(codeClassifyTemplateVO, dataCBOList); |
| | | engineService.batchSaveSelectChar(codeClassifyTemplateVO.get(), dataCBOList); |
| | | } |
| | | } |
| | | if(errorMap.size()>0) { |
| | |
| | | errorMap.forEach((key,v)->{ |
| | | excelDataList.add(new WriteExcelData(index[0]++, 0, "第"+(Integer.parseInt(key)+1)+"行数据:"+v)); |
| | | }); |
| | | eo.addSheetDataList(codeClassifyTemplateVO.getName() + "导入模板", excelDataList); |
| | | eo.addSheetDataList(codeClassifyTemplateVO.get().getName() + "导入模板", excelDataList); |
| | | } |
| | | }); |
| | | if(!success.get()){ |
| | | String excelName = LocalFileUtil.getDefaultTempFolder() + File.separator + (isImprot?"批量历史错误信息.xls":"批量申请错误信息.xls"); |
| | | ExcelUtil.writeDataToFile(excelName,eo); |
| | | return R.fail(excelName); |
| | | saveLogUtil.operateLog("历史数据导入",true, StringUtil.format("错误信息:{}",JSON.toJSONString(eo.getWriteDataMap()))); |
| | | return R.fail(excelName); |
| | | }else { |
| | | saveLogUtil.operateLog("历史数据导入",false, StringUtil.format("导入到分类{}中,导入成功总数为:{}", JSON.toJSONString(codeClassifyTemplateVO), Func.isEmpty(codeImprotSaveDatVOList.get(0).getDataList().size()))); |
| | | return R.success(isImprot ? "批量历史导入成功" : "批量申请成功"); |
| | | } |
| | | } |
| | |
| | | if (!CollectionUtils.isEmpty(newCboList)) { |
| | | //处理关键属性查出多条的话,根据集成调用的当前分类代号取当前分类的码值。 |
| | | Map<String/**编码**/, BaseModel/**重复编码数据**/> classOidTOBaseModelMap = new HashMap<>(); |
| | | newCboList.stream().forEach(baseModel->{ |
| | | String codeclsfid=baseModel.getData().get(CODE_CLASSIFY_OID_FIELD.toUpperCase(Locale.ROOT)); |
| | | classOidTOBaseModelMap.put(codeclsfid,baseModel); |
| | | }); |
| | | newCboList.stream().forEach(baseModel->{ |
| | | String codeclsfid=baseModel.getData().get(CODE_CLASSIFY_OID_FIELD.toLowerCase(Locale.ROOT)); |
| | | classOidTOBaseModelMap.put(codeclsfid,baseModel); |
| | | }); |
| | | String codeclsfid= classifyFullInfo.getCurrentClassifyVO().getOid(); |
| | | if(classOidTOBaseModelMap.containsKey(codeclsfid)){ |
| | | BaseModel newCbo= classOidTOBaseModelMap.get(codeclsfid); |
| | |
| | | } |
| | | } |
| | | }); |
| | | //关键熟悉更改 |
| | | //关键属性更改 |
| | | if (!CollectionUtils.isEmpty(editBoList)) { |
| | | engineService.updateBatchByBaseModel(classifyFullInfo.getTopClassifyVO().getBtmTypeId(),editBoList);//保存数据 |
| | | } |
| | |
| | | //cboOidMap.put("id", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(codeDataMap.keySet().toArray(new String[0])) + ")"); |
| | | String tableName =""; |
| | | try { |
| | | R<BtmTypeVO> r = btmTypeClient.getAllAttributeByBtmId(templateVO.getBtmTypeId()); |
| | | R<BtmTypeVO> r = btmTypeClient.getAllAttributeByBtmId(classifyFullInfo.getTopClassifyVO().getBtmTypeId()); |
| | | if(!r.isSuccess()) { |
| | | throw new Throwable(r.getMsg()); |
| | | } |
| | |
| | | } |
| | | |
| | | List<Map<String,String>> dataMapList=commonsMapper.queryByOnlySqlForMap(sb.toString()); |
| | | DefaultAttrAssimtUtil.mapToLowerCase(dataMapList,true); |
| | | List<ClientBusinessObject> cboList= ChangeMapTOClientBusinessObjects(dataMapList); |
| | | Map<String, ClientBusinessObject> codeSystemObjectMap = cboList.stream().filter(systeDataObject -> systeDataObject != null && StringUtils.isNotBlank(systeDataObject.getId())).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getId(), t -> t)); |
| | | Map<String, String> errorMap = new HashMap<>(); |
| | |
| | | cbo.setDescription(StringUtils.isBlank(orderDTO.getDescription())?"":orderDTO.getDescription()); |
| | | cbo.setName(orderDTO.getName()); |
| | | try { |
| | | cbo.setAttributeValueWithNoCheck("description", orderDTO.getDescription()); |
| | | //主要处理大小写问题,将data里面的数据的key都转为小写 |
| | | HashMap<String,String> lowerData = new HashMap<>(); |
| | | Iterator<Map.Entry<String, String>> iterator = cbo.getData().entrySet().iterator(); |
| | | while (iterator.hasNext()){ |
| | | Map.Entry<String, String> next = iterator.next(); |
| | | lowerData.put(next.getKey().toLowerCase(Locale.ROOT),next.getValue()); |
| | | } |
| | | cbo.getData().clear(); |
| | | cbo.getData().putAll(lowerData); |
| | | cbo.setAttributeValueWithNoCheck("description", (StringUtil.isNotBlank(orderDTO.getData() |
| | | .get("description")) ? orderDTO.getData().get("description") : orderDTO.getDescription() )); |
| | | // cbo.setAttributeValue("name", orderDTO.getName()); |
| | | // if(finalIsProcess){//在流程中不允许更改 |
| | | // errorMap.put(code,errorMap.getOrDefault(code, errorMap.getOrDefault(code,"")+";数据"+code+"在流程中,不允许更改!")); |
| | |
| | | |
| | | List<CodeAllCode>newCodeAllCodeList= codeAllCodeService.selectByWrapper(Wrappers.<CodeAllCode>query().lambda().eq(CodeAllCode::getCreateCodeOid, cbo.getOid())); |
| | | if (!CollectionUtils.isEmpty(newCodeAllCodeList)) { |
| | | CodeAllCode codeCbo = codeAllCodeList.get(0); |
| | | CodeAllCode codeCbo = newCodeAllCodeList.get(0); |
| | | log.info("codeCbos code:" + codeCbo.getId()); |
| | | codeCbo.setLcStatus(status); |
| | | codeAllCodeList.add(codeCbo); |
| | |
| | | engineService.updateBatchByBaseModel(classifyFullInfo.getTopClassifyVO().getBtmTypeId(),updateList); |
| | | codeAllCodeService.saveOrUpdateBatch(codeAllCodeList); |
| | | if(deleteList.size()>0) { |
| | | commonsMapper.deleteByTaleAndOid(tableName, VciBaseUtil.array2String(deleteList.toArray(new String[]{}))); |
| | | commonsMapper.deleteByTaleAndOid(tableName, VciBaseUtil.toInSql(deleteList.toArray(new String[]{}))); |
| | | } |
| | | //是否调用集团接口申请接口 |
| | | if(isCodeOrGroupCode){ |
| | |
| | | //注意的是keyRuleVO可能为空,表示不使用规则控制 |
| | | //获取所有的关键属性 |
| | | Map<String, CodeClassifyTemplateAttrVO> ketAttrMap = templateVO.getAttributes().stream().filter(s -> VciBaseUtil.getBoolean(s.getKeyAttrFlag())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); |
| | | // TODO:2024-02-01 先获取配置了近义词查询规则的属性,不同于关键属性,设置了近义词查询规则的属性可能是多条不同的近义词查询规则 |
| | | Map<String, CodeClassifyTemplateAttrVO> sysonymAttrMaps = templateVO.getAttributes().stream().filter(item -> Func.isNotBlank(item.getSysonymRuleOids())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); |
| | | // 获取是否有配置近义词查询规则属性 |
| | | Map<String, List<CodeSynonym>> codeSynonymMaps = new HashMap<>(); |
| | | if(!sysonymAttrMaps.isEmpty()){ |
| | | // 查询近义词规则,存储方式key:属性id,value近义词查询规则列表 |
| | | codeSynonymMaps = codeSynonymService.getCodeSynonymByOids(sysonymAttrMaps); |
| | | } |
| | | Map<String, String> conditionMap = new HashMap<>(); |
| | | boolean trimAll = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnoreallspaceflag()); |
| | | //全部去空的优先级大于去空 |
| | | boolean trim = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnorespaceflag()); |
| | | boolean ignoreCase = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnorecaseflag()); |
| | | boolean ignoreWidth = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnorewidthflag()); |
| | | Map<String, List<CodeSynonym>> finalCodeSynonymMaps = codeSynonymMaps; |
| | | ketAttrMap.forEach((attrId, attrVO) -> { |
| | | String value = getValueFromOrderDTO(orderDTO, attrId); |
| | | if (value == null) { |
| | | value = ""; |
| | | } |
| | | engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap); |
| | | engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, finalCodeSynonymMaps.get(attrId), attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap); |
| | | }); |
| | | |
| | | //没有限制分类,但是一个模板只可能在一个业务类型里面,所以直接查询这个业务类型即可 |
| | |
| | | rowDataList.stream().forEach(rowData -> { |
| | | ClientBusinessObject cbo=new ClientBusinessObject(); |
| | | DefaultAttrAssimtUtil.addDefaultAttrAssimt(cbo, classifyFullInfo.getTopClassifyVO().getBtmTypeId()); |
| | | R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(classifyFullInfo.getTopClassifyVO().getBtmTypeId())); |
| | | if(!listR.isSuccess() || listR.getData().size() == 0){ |
| | | throw new VciBaseException("传入业务类型未查询到相应表单,请检查!"); |
| | | } |
| | | cbo.setRevisionRule("".equals(listR.getData().get(0).getVersionRule())?"1":listR.getData().get(0).getVersionRule()); |
| | | rowData.getData().forEach((index,value)->{ |
| | | String field = fieldIndexMap.get(index); |
| | | if (StringUtils.isBlank(field)) { |
| | |
| | | String sql = "select " + valueField + "," + showText.toLowerCase(Locale.ROOT) +" from " + table + " where " + showText + " in (%s)"; |
| | | valueCollections.stream().forEach(values->{ |
| | | List<Map<String,String>> dataMapList = commonsMapper.queryByOnlySqlForMap(String.format(sql, VciBaseUtil.toInSql(values.toArray(new String[0])))); |
| | | List<ClientBusinessObject> cbos= ChangeMapTOClientBusinessObjects(dataMapList); |
| | | DefaultAttrAssimtUtil.mapToLowerCase(dataMapList,true); |
| | | List<ClientBusinessObject> cbos=ChangeMapTOClientBusinessObjects(dataMapList); |
| | | if(!CollectionUtils.isEmpty(cbos)){ |
| | | valueOidTextMap.putAll(cbos.stream().collect(Collectors.toMap(s->s.getAttributeValue(valueField),t->t.getAttributeValue(showText)))); |
| | | } |
| | |
| | | } else { |
| | | Map<String, String> classifyDataMap = VciBaseUtil.objectToMapString(classifyVO); |
| | | String value = classifyDataMap.getOrDefault(attrVO.getClassifyInvokeAttr(), ""); |
| | | log.error("================================当前分类注入的value值为:==========================",value); |
| | | // log.error("================================当前分类注入的value值为:==========================",value); |
| | | cbo.setAttributeValue(attrId, value); |
| | | } |
| | | } catch (Throwable e) { |
| | |
| | | } |
| | | } |
| | | /** |
| | | * 校验关键属性 |
| | | * 校验关键属性,和近义词查询规则 |
| | | * @param classifyFullInfo 分类的全部信息 |
| | | * @param templateVO 模板的内容,必须包含模板属性 |
| | | * @param cboList 批量的数据 |
| | |
| | | CodeKeyAttrRepeatVO keyRuleVO = keyRuleService.getRuleByClassifyFullInfo(classifyFullInfo); |
| | | //注意的是keyRuleVO可能为空,表示不使用规则控制 |
| | | //获取所有的关键属性 |
| | | Map<String/**属性的编号**/, CodeClassifyTemplateAttrVO> ketAttrMap = templateVO.getAttributes().stream().filter(s -> VciBaseUtil.getBoolean(s.getKeyAttrFlag())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); |
| | | Map<String/**属性的编号**/, CodeClassifyTemplateAttrVO> keyAttrMap = templateVO.getAttributes().stream().filter(s -> VciBaseUtil.getBoolean(s.getKeyAttrFlag())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); |
| | | |
| | | // TODO:2024-02-01 先获取配置了近义词查询规则的属性,不同于关键属性,设置了近义词查询规则的属性可能是多条不同的近义词查询规则 |
| | | Map<String, CodeClassifyTemplateAttrVO> sysonymAttrMaps = templateVO.getAttributes().stream().filter(item -> Func.isNotBlank(item.getSysonymRuleOids())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); |
| | | // 获取是否有配置近义词查询规则属性 |
| | | Map<String, List<CodeSynonym>> codeSynonymMaps = new HashMap<>(); |
| | | if(!sysonymAttrMaps.isEmpty()){ |
| | | // 查询近义词规则,存储方式key:属性id,value近义词查询规则列表 |
| | | codeSynonymMaps = codeSynonymService.getCodeSynonymByOids(sysonymAttrMaps); |
| | | } |
| | | |
| | | boolean trimAll =keyRuleVO ==null?false: VciBaseUtil.getBoolean(keyRuleVO.getIgnoreallspaceflag()); |
| | | //全部去空的优先级大于去空 |
| | |
| | | CodeImportResultVO resultVO = new CodeImportResultVO(); |
| | | resultVO.setKeyAttrRuleInfo(String.format(keyRuleVO ==null?"":"查询规则:去除空格--{0},忽略大小写--{1},忽略全半角--{2},忽略全部空格--{3}", |
| | | new String[]{trim?"是":"否",ignoreCase?"是":"否",ignoreWidth?"是":"否",trimAll?"是":"否"})); |
| | | //resultVO.setSelfRepeatRowIndexList(getSelfRepeatRowIndex(ketAttrMap,cboList,keyRuleVO)); |
| | | getSelfRepeatRowIndex(ketAttrMap,cboList,keyRuleVO,resultVO); |
| | | //resultVO.setSelfRepeatRowIndexList(getSelfRepeatRowIndex(keyAttrMap,cboList,keyRuleVO)); |
| | | |
| | | // 先在表格中查询关键属性和近义词转换后重复的列 |
| | | getSelfRepeatRowIndex(keyAttrMap,cboList,keyRuleVO,codeSynonymMaps,resultVO); |
| | | // 再在表格中查询近义词查询规则的列 |
| | | //getSelfRepeatSysnomRowIndex(sysonymAttrMaps,cboList,codeSynonymMaps,resultVO); |
| | | |
| | | if(!CollectionUtils.isEmpty(resultVO.getSelfRepeatRowIndexList())){ |
| | | //我们移除本身重复的数据 |
| | | cboList = cboList.stream().filter(s->!resultVO.getSelfRepeatRowIndexList().contains(s.getAttributeValue(IMPORT_ROW_INDEX))).collect(Collectors.toList()); |
| | | } |
| | | //2.判断关键属性在系统里是否重复 |
| | | //因为数据量很大,所以得想办法并行 |
| | | //SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo(); |
| | | Map<String,List<BaseModel>> indexTODataMap=new ConcurrentHashMap<>(); |
| | | // 查询不需要参与关键属性校验的除自己以外的所有分类oid |
| | | final String isParticipateCheckOids = classifyService.selectLeafByParentClassifyOid(classifyFullInfo.getTopClassifyVO().getOid(), classifyFullInfo.getCurrentClassifyVO().getOid()); |
| | | final BladeUser user = AuthUtil.getUser(); |
| | | List<ClientBusinessObject> repeatDataMap = cboList.parallelStream().filter(cbo -> { |
| | | //每行都得查询.如果其中出现了错误,我们就直接抛出异常,其余的显示 |
| | | //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo); |
| | | Map<String, String> conditionMap = new HashMap<>(); |
| | | ketAttrMap.forEach((attrId, attrVO) -> { |
| | | String value =cbo.getAttributeValue(attrId.toLowerCase(Locale.ROOT)); |
| | | if (value == null) { |
| | | value = ""; |
| | | } |
| | | value= value.replace(REQUIRED_CHAR,SPECIAL_CHAR); |
| | | engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap); |
| | | }); |
| | | if (!CollectionUtils.isEmpty(ketAttrMap)) { |
| | | // 添加不参与关键属性校验的分类oid判断 |
| | | if(Func.isNotBlank(isParticipateCheckOids)){ |
| | | conditionMap.put("t.codeclsfid",QueryOptionConstant.NOTIN+isParticipateCheckOids); |
| | | } |
| | | if(isEdit){//如果是更改则需排除系统本身 |
| | | conditionMap.put("t.id",QueryOptionConstant.NOTEQUAL+cbo.getId()); |
| | | } |
| | | conditionMap.put("t.lastr", "1"); |
| | | conditionMap.put("t.lastv", "1"); |
| | | |
| | | CodeTemplateAttrSqlBO sqlBO = engineService.getSqlByTemplateVO(classifyFullInfo.getTopClassifyVO().getBtmTypeId(), templateVO, conditionMap, null); |
| | | List<String> repeatData = commonsMapper.selectList(sqlBO.getSqlId()); |
| | | if(!repeatData.isEmpty()){ |
| | | final List<Map<String,String>> newDataList = commonsMapper.queryByOnlySqlForMap(sqlBO.getSqlUnPage()); |
| | | //List<ClientBusinessObject> newCboList=ChangeMapTOClientBusinessObjects(newDataList); |
| | | List<BaseModel> newCboList = new ArrayList<>(); |
| | | newDataList.stream().forEach(stringStringMap -> { |
| | | BaseModel baseModel=new BaseModel(); |
| | | DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(stringStringMap,baseModel,false,user); |
| | | baseModel.setData(stringStringMap); |
| | | newCboList.add(baseModel); |
| | | }); |
| | | // 添加错误值 |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | errorMap.put(rowIndex, "重复的记录编号为:"+repeatData.stream().collect(Collectors.joining(","))); |
| | | if(!CollectionUtils.isEmpty(newCboList)) { |
| | | indexTODataMap.put(cbo.getAttributeValue(IMPORT_ROW_INDEX), newCboList); |
| | | // TODO:Thread limit exceeded replacing blocked 异常是这部分代码抛出的 |
| | | // ,所以暂时将parallelStream改成了stream,改成了stream之后发现巨慢 |
| | | // customForkJoinPool控制并发度 |
| | | List<ClientBusinessObject> finalCboList = cboList; |
| | | Map<String, List<CodeSynonym>> finalCodeSynonymMaps = codeSynonymMaps; |
| | | List<ClientBusinessObject> repeatDataMap = (List<ClientBusinessObject>) customForkJoinPool.submit(()->{ |
| | | finalCboList.parallelStream().filter(cbo -> { |
| | | //每行都得查询.如果其中出现了错误,我们就直接抛出异常,其余的显示 |
| | | //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo); |
| | | Map<String, String> conditionMap = new HashMap<>(); |
| | | keyAttrMap.forEach((attrId, attrVO) -> { |
| | | String value =cbo.getAttributeValue(attrId.toLowerCase(Locale.ROOT)); |
| | | if (value == null) { |
| | | value = ""; |
| | | } |
| | | value= value.replace(REQUIRED_CHAR,SPECIAL_CHAR); |
| | | // 关键属性查询条件map获取 |
| | | engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, finalCodeSynonymMaps.get(attrId), attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap); |
| | | }); |
| | | |
| | | if (!CollectionUtils.isEmpty(keyAttrMap)) { |
| | | // 添加不参与关键属性校验的分类oid判断 |
| | | if(Func.isNotBlank(isParticipateCheckOids)){ |
| | | conditionMap.put("t.codeclsfid",QueryOptionConstant.NOTIN+isParticipateCheckOids); |
| | | } |
| | | //如果是更改则需排除系统本身 |
| | | if(isEdit){ |
| | | conditionMap.put("t.id",QueryOptionConstant.NOTEQUAL+cbo.getId()); |
| | | } |
| | | conditionMap.put("t.lastr", "1"); |
| | | conditionMap.put("t.lastv", "1"); |
| | | |
| | | CodeTemplateAttrSqlBO sqlBO = engineService.getSqlByTemplateVO(classifyFullInfo.getTopClassifyVO().getBtmTypeId(), templateVO, conditionMap, null); |
| | | List<String> repeatData = commonsMapper.selectList(sqlBO.getSqlId()); |
| | | if(!repeatData.isEmpty()){ |
| | | final List<Map<String,String>> newDataList = commonsMapper.queryByOnlySqlForMap(sqlBO.getSqlUnPage()); |
| | | DefaultAttrAssimtUtil.mapToLowerCase(newDataList,true); |
| | | //List<ClientBusinessObject> newCboList=ChangeMapTOClientBusinessObjects(newDataList); |
| | | List<BaseModel> newCboList = new ArrayList<>(); |
| | | newDataList.stream().forEach(stringStringMap -> { |
| | | BaseModel baseModel=new BaseModel(); |
| | | DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(stringStringMap,baseModel,false,user); |
| | | baseModel.setData(stringStringMap); |
| | | newCboList.add(baseModel); |
| | | }); |
| | | // 添加错误值 |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | errorMap.put(rowIndex, "重复的记录编号为:"+repeatData.stream().collect(Collectors.joining(","))); |
| | | if(!CollectionUtils.isEmpty(newCboList)) { |
| | | indexTODataMap.put(cbo.getAttributeValue(IMPORT_ROW_INDEX), newCboList); |
| | | } |
| | | } |
| | | return !repeatData.isEmpty(); |
| | | }else{ |
| | | return false; |
| | | } |
| | | return !repeatData.isEmpty(); |
| | | }else{ |
| | | return false; |
| | | } |
| | | }).collect(Collectors.toList()); |
| | | }).collect(Collectors.toList()); |
| | | }).join(); |
| | | if(!CollectionUtils.isEmpty(repeatDataMap)){ |
| | | resultVO.setKeyAttrRepeatRowIndexList(repeatDataMap.stream().map(s->s.getAttributeValue(IMPORT_ROW_INDEX)).collect(Collectors.toSet())); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取导入的内容中关键属性重复的行号 |
| | | * 获取导入的内容中关键属性近义词转换后重复的行号 |
| | | * @param ketAttrMap 关键属性的映射 |
| | | * @param dataList 导入的数据 |
| | | * @param keyRuleVO 关键属性控制规则 |
| | | * @return 重复的行号 |
| | | */ |
| | | private void getSelfRepeatRowIndex(Map<String/**属性的编号**/, CodeClassifyTemplateAttrVO> ketAttrMap, |
| | | List<ClientBusinessObject> dataList,CodeKeyAttrRepeatVO keyRuleVO,CodeImportResultVO resultVO){ |
| | | List<ClientBusinessObject> dataList,CodeKeyAttrRepeatVO keyRuleVO,/*近义词查询规则*/Map<String,List<CodeSynonym>> codeSynonymMaps, CodeImportResultVO resultVO){ |
| | | Set<String> selfRepeatRowIndexList = new CopyOnWriteArraySet<>(); |
| | | Map<String,List<String>> keyAttrOkOidTORepeatOidMap=new HashMap<>(); |
| | | boolean trimAll =keyRuleVO ==null?false: VciBaseUtil.getBoolean(keyRuleVO.getIgnoreallspaceflag()); |
| | |
| | | String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX); |
| | | String oid=cbo.getOid(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (int i = 0; i < attrVOList.size(); i++) { |
| | | CodeClassifyTemplateAttrVO attrVO = attrVOList.get(i); |
| | | String attrId = attrVO.getId().toLowerCase(Locale.ROOT); |
| | | |
| | | // TODO: 2024-02-25改造实现近义词查询规则功能;关键属性重复校验值处理 |
| | | attrVOList.stream().forEach(item->{ |
| | | String attrId = item.getId().toLowerCase(Locale.ROOT); |
| | | String value = cbo.getAttributeValue( attrId); |
| | | if (value == null) { |
| | | value = ""; |
| | |
| | | if(ignoreWidth){ |
| | | value = VciBaseUtil.toDBC(value); |
| | | } |
| | | value = mdmEngineService.getValueToSynony(codeSynonymMaps.get(attrId),value); |
| | | sb.append(value).append("${ks}"); |
| | | } |
| | | }); |
| | | String keyString = sb.toString(); |
| | | if(rowIndexKeyStringMap.containsValue(keyString) && StringUtils.isNotBlank(keyString)){ |
| | | selfRepeatRowIndexList.add(rowIndex); |
| | |
| | | if(keyAttrOkOidTORepeatOidMap.containsKey(okOid)){ |
| | | List<String> oldOidList = keyAttrOkOidTORepeatOidMap.get(okOid); |
| | | newOidList.addAll(oldOidList); |
| | | |
| | | } |
| | | keyAttrOkOidTORepeatOidMap.put(okOid,newOidList); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private List<ClientBusinessObject> ChangeMapTOClientBusinessObjects(List<Map<String,String>> oldDataMap){ |
| | | List<ClientBusinessObject> clientBusinessObjectList=new ArrayList<>(); |
| | | DefaultAttrAssimtUtil.mapToLowerCase(oldDataMap,true); |
| | | final BladeUser user = AuthUtil.getUser(); |
| | | oldDataMap.stream().forEach(dataMap->{ |
| | | ClientBusinessObject clientBusinessObject=new ClientBusinessObject(); |
| | | DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(dataMap,clientBusinessObject,true,user); |
| | | DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(dataMap,clientBusinessObject,false,user); |
| | | for (String key:dataMap.keySet()){ |
| | | Object value= dataMap.getOrDefault(key,""); |
| | | clientBusinessObject.setAttributeValue(key.toLowerCase(Locale.ROOT),value==null?"":value.toString()); |
| | |
| | | pageHelper.addDefaultDesc("id"); |
| | | CodeTemplateAttrSqlBO sqlBO = engineService.getSqlByTemplateVO(btmtypeid, templateVO, conditionMap, pageHelper); |
| | | List<Map<String,String>> dataMapList=commonsMapper.queryByOnlySqlForMap(sqlBO.getSqlUnPage()); |
| | | DefaultAttrAssimtUtil.mapToLowerCase(dataMapList,true); |
| | | List<ClientBusinessObject> resembleCboList= ChangeMapTOClientBusinessObjects(dataMapList); |
| | | if(!CollectionUtils.isEmpty(resembleCboList)) { |
| | | List<Map<String, String>> finalDataMap = dataMap; |
| | |
| | | final BladeUser user = AuthUtil.getUser(); |
| | | cboList.stream().forEach(clientBusinessObject -> { |
| | | BaseModel newBaseModel=new BaseModel(); |
| | | DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(clientBusinessObject.getData(),newBaseModel,true,user); |
| | | DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(clientBusinessObject.getData(),newBaseModel,false,user); |
| | | newCbos.add(newBaseModel); |
| | | }); |
| | | // 插入新的数据 |
| | |
| | | List<Map<String,String>>dataList=new ArrayList<>(); |
| | | List<String> fieldList= execGroupCodePortDataDTO.getFieldList(); |
| | | getDatas(classifyFullInfo,templateVO,execGroupCodePortDataDTO.getFieldList(),dataList,Arrays.asList(code)); |
| | | DefaultAttrAssimtUtil.mapToLowerCase(dataList,true); |
| | | if(!CollectionUtils.isEmpty(dataList)){ |
| | | Map<String,String> newDataMap=new HashMap<>();//将新对象属性暂时存储在Map<> |
| | | newDataMap.putAll(clientBusinessObject.getData()); |
| | | Map<String,String> dataMap=dataList.get(0); |
| | | BaseModel oldBaseModel=new BaseModel(); |
| | | |
| | | DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(dataMap,oldBaseModel,false,user); |
| | | String oldOid=oldBaseModel.getOid(); |
| | | |