| | |
| | | } |
| | | fieldList=execGroupCodePortDataDTO.getFieldList(); |
| | | List<Map<String,String>>dataList=new ArrayList<>(); |
| | | getDatas(classifyFullInfo,templateVO,fieldList,dataList); |
| | | getDatas(classifyFullInfo,templateVO,fieldList,dataList,null); |
| | | execGroupCodePortDataDTO.setDataList(dataList);//放数据 |
| | | execGroupCodePortDataDTO.setSheetName(codeClassifyVO.getName()+"集团码导入模板"); |
| | | String tempFolder = LocalFileUtil.getDefaultTempFolder(); |
| | |
| | | } |
| | | |
| | | /*** |
| | | * 导入集团码 |
| | | * @param codeClassifyOid |
| | | * @param file |
| | | * @return |
| | | */ |
| | | public String improtGroupCode(String codeClassifyOid, File file) throws ServiceException { |
| | | 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 ServiceException("为了保证系统的稳定性,请一次不要导入超过1万条的数据"); |
| | | } |
| | | CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyOid); |
| | | CodeClassifyTemplateVO templateVO = new CodeClassifyTemplateVO(); |
| | | //除去默认的属性.还有只有表单显示的字段才导入 |
| | | List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes().stream().filter(s ->!DEFAULT_SYNC_ATTR_LIST.contains(s.getId()) && VciBaseUtil.getBoolean(s.getFormDisplayFlag()) |
| | | ).collect(Collectors.toList()); |
| | | ExecGroupCodePortDataDTO execGroupCodePortDataDTO=new ExecGroupCodePortDataDTO(); |
| | | createExportGroupCodeMapConfig(templateVO,execGroupCodePortDataDTO);//组织数据 |
| | | List<CodeAndGroupCodeAttrMappingDTO> codeAttrMapGroupAttrDTOS=execGroupCodePortDataDTO.getCodeAttrMapGroupAttrDTOS(); |
| | | if(!CollectionUtils.isEmpty(codeAttrMapGroupAttrDTOS)){ |
| | | throw new ServiceException("集团属性映射未配置"); |
| | | } |
| | | Map<String, CodeAndGroupCodeAttrMappingDTO> codeSystemObjectMap = codeAttrMapGroupAttrDTOS.stream().filter(codeAttrMappingDTO -> codeAttrMappingDTO != null && StringUtils.isNotBlank(codeAttrMappingDTO.getSourceAttrName())).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getSourceAttrName(), t -> t)); |
| | | SheetDataSet dataSet= sheetDataSetList.get(0); |
| | | List<String> titleRowData = dataSet.getColName(); |
| | | Map<Integer/**列号**/,String/**字段的名称**/> fieldIndexMap = new HashMap<>(); |
| | | getGroupCodeFieldIndexMap(titleRowData,codeAttrMapGroupAttrDTOS,fieldIndexMap); |
| | | //需要判断是否所有的属性都在模板上了 |
| | | List<CodeClassifyTemplateAttrVO> unExistAttrVOs = attrVOS.stream().filter(s -> !fieldIndexMap.containsValue(s.getId().toLowerCase(Locale.ROOT)) |
| | | && com.alibaba.cloud.commons.lang.StringUtils.isBlank(s.getComponentRule()) && com.alibaba.cloud.commons.lang.StringUtils.isBlank(s.getClassifyInvokeAttr())//组合规则和分类注入确实没给用户导出去 |
| | | ).collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(unExistAttrVOs)){ |
| | | String message=unExistAttrVOs.stream().map(CodeClassifyTemplateAttrVO::getName).collect(Collectors.joining(SERIAL_UNIT_SPACE)); |
| | | throw new VciBaseException("【" + message + "】这些属性在excel中没有找到"); |
| | | } |
| | | List<ClientBusinessObject> cboList = new ArrayList<>(); |
| | | List<SheetRowData> rowDataList = dataSet.getRowData(); |
| | | |
| | | getExportGroupCodeDatas(fieldIndexMap,rowDataList,cboList);//构建数据对象 |
| | | List<String> codeList= cboList.stream().map(ClientBusinessObject::getId).collect(Collectors.toList()); |
| | | List<Map<String,String>>dataList=new ArrayList<>(); |
| | | getDatas(classifyFullInfo,templateVO,execGroupCodePortDataDTO.getFieldList(),dataList,codeList); |
| | | //查询系统中存在 |
| | | if(!CollectionUtils.isEmpty(dataList)){ |
| | | |
| | | |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param fieldIndexMap |
| | | * @param rowDataList |
| | | * @param cboList |
| | | */ |
| | | private void getExportGroupCodeDatas(Map<Integer,String> fieldIndexMap,List<SheetRowData> rowDataList,List<ClientBusinessObject>cboList){ |
| | | rowDataList.stream().forEach(sheetRowData -> { |
| | | sheetRowData.getData().forEach((index,value)->{ |
| | | ClientBusinessObject cbo=new ClientBusinessObject(); |
| | | String field = fieldIndexMap.get(index); |
| | | if (StringUtils.isBlank(field)) { |
| | | throw new VciBaseException("第" + (index + 1) + "列的标题在系统中不存在"); |
| | | } |
| | | try { |
| | | cbo.setAttributeValueWithNoCheck(field, value); |
| | | if (WebUtil.isDefaultField(field)) { |
| | | WebUtil.setValueToField(field, cbo, value); |
| | | } |
| | | } catch (VciBaseException e) { |
| | | log.error("设置属性的值错误", e); |
| | | } |
| | | cboList.add(cbo); |
| | | }); |
| | | }); |
| | | } |
| | | /*** |
| | | * 集团导出模板属性映射信息获取 |
| | | * @param templateVO |
| | | * @param execGroupCodePortDataDTO |
| | |
| | | } |
| | | |
| | | /*** |
| | | * 集团码属性转换 |
| | | * @param titleRowData |
| | | * @param codeAttrMapGroupAttrDTOS |
| | | * @param fieldIndexMap |
| | | */ |
| | | private void getGroupCodeFieldIndexMap(List<String> titleRowData,List<CodeAndGroupCodeAttrMappingDTO> codeAttrMapGroupAttrDTOS,Map<Integer/**列号**/,String/**字段的名称**/> fieldIndexMap){ |
| | | Map<String, CodeAndGroupCodeAttrMappingDTO> codeSystemObjectMap = codeAttrMapGroupAttrDTOS.stream().filter(codeAttrMappingDTO -> codeAttrMappingDTO != null && StringUtils.isNotBlank(codeAttrMappingDTO.getSourceAttrName())).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getSourceAttrName(), t -> t)); |
| | | for (int i = 0; i < titleRowData.size(); i++) { |
| | | String title = titleRowData.get(i); |
| | | CodeAndGroupCodeAttrMappingDTO codeAndGroupCodeAttrMappingDTO =codeSystemObjectMap.get(title.replace(KEY_ATTR_CHAR,"").replace(REQUIRED_CHAR,"")); |
| | | String id=codeAndGroupCodeAttrMappingDTO.getTargetAttrKey(); |
| | | if(com.alibaba.cloud.commons.lang.StringUtils.isBlank(id) && "集团码".equalsIgnoreCase(title)){ |
| | | id = CODE_GROUP_FIELD; |
| | | } |
| | | if(com.alibaba.cloud.commons.lang.StringUtils.isBlank(id) && "企业编码".equalsIgnoreCase(title)){ |
| | | id = CODE_FIELD; |
| | | } |
| | | if(com.alibaba.cloud.commons.lang.StringUtils.isNotBlank(id)){ |
| | | fieldIndexMap.put(i,id); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | /*** |
| | | * 查询未有集团码的数据 |
| | | * @param classifyFullInfo |
| | | * @param templateVO |
| | | * @param selectFieldList |
| | | * @param dataList |
| | | */ |
| | | private void getDatas(CodeClassifyFullInfoBO classifyFullInfo,CodeClassifyTemplateVO templateVO,LinkedList<String> selectFieldList,List<Map<String,String>>dataList){ |
| | | private void getDatas(CodeClassifyFullInfoBO classifyFullInfo,CodeClassifyTemplateVO templateVO,LinkedList<String> selectFieldList,List<Map<String,String>>dataList,List<String> codeList ){ |
| | | //先查询数据 |
| | | String btmTypeId = classifyFullInfo.getTopClassifyVO().getBtmTypeId(); |
| | | String codeClassifyOid=classifyFullInfo.getCurrentClassifyVO().getOid(); |
| | | Map<String, String> conditionMap = new HashMap<>(); |
| | | Map<String, String> conditionMap=new HashMap<>(); |
| | | if(conditionMap == null){ |
| | | conditionMap = new HashMap<>(); |
| | | } |
| | | if(conditionMap.containsKey(VciQueryWrapperForDO.OID_FIELD)){ |
| | | conditionMap.put(VciQueryWrapperForDO.OID_FIELD,QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(conditionMap.get(VciQueryWrapperForDO.OID_FIELD)) + ")"); |
| | | } |
| | | if(!CollectionUtils.isEmpty(codeList)){ |
| | | conditionMap.put("id_in",VciBaseUtil.array2String(codeList.toArray(new String[]{}))); |
| | | } |
| | | conditionMap.put("codeclsfpath","*" + codeClassifyOid + "*"); |
| | | conditionMap.put("groupcode_null", "null"); |
| | | conditionMap.put("lastr", "1"); |