| | |
| | | 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.entity.DockingPreAttrMapping; |
| | | import com.vci.ubcs.code.applyjtcodeservice.feign.IMdmInterJtClient; |
| | | import com.vci.ubcs.code.applyjtcodeservice.vo.DockingPreAttrMappingVO; |
| | | import com.vci.ubcs.code.bo.AttributeValue; |
| | | import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO; |
| | | import com.vci.ubcs.code.bo.CodeTemplateAttrSqlBO; |
| | | import com.vci.ubcs.code.dto.CodeExportAttrDTO; |
| | | import com.vci.ubcs.code.dto.CodeOrderDTO; |
| | | import com.vci.ubcs.code.constant.MdmEngineConstant; |
| | | import com.vci.ubcs.code.dto.*; |
| | | import com.vci.ubcs.code.entity.CodeAllCode; |
| | | import com.vci.ubcs.code.enumpack.CodeDefaultLC; |
| | | import com.vci.ubcs.code.enumpack.CodeLevelTypeEnum; |
| | |
| | | } |
| | | } |
| | | |
| | | /*** |
| | | * @param codeClassifyOid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String exportGroupCodeExcel(String codeClassifyOid) throws ServiceException { |
| | | VciBaseUtil.alertNotNull(codeClassifyOid,"主题库分类的主键"); |
| | | CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyOid); |
| | | CodeClassifyVO codeClassifyVO= classifyFullInfo.getCurrentClassifyVO(); |
| | | //获取最新的模板 |
| | | CodeClassifyTemplateVO templateVO = engineService.getUsedTemplateByClassifyOid(codeClassifyOid); |
| | | LinkedList<String> colName=new LinkedList<>();//列头 |
| | | LinkedList<String> fieldList=new LinkedList<>();//列字段 |
| | | |
| | | ExecGroupCodePortDataDTO execGroupCodePortDataDTO=new ExecGroupCodePortDataDTO(); |
| | | createExportGroupCodeMapConfig(templateVO,execGroupCodePortDataDTO);//组织数据 |
| | | if(!CollectionUtils.isEmpty(execGroupCodePortDataDTO.getCodeAttrMapGroupAttrDTOS())){ |
| | | throw new ServiceException("集团属性映射未配置"); |
| | | } |
| | | fieldList=execGroupCodePortDataDTO.getFieldList(); |
| | | List<Map<String,String>>dataList=new ArrayList<>(); |
| | | getDatas(classifyFullInfo,templateVO,fieldList,dataList,null); |
| | | execGroupCodePortDataDTO.setDataList(dataList);//放数据 |
| | | execGroupCodePortDataDTO.setSheetName(codeClassifyVO.getName()+"集团码导入模板"); |
| | | String tempFolder = LocalFileUtil.getDefaultTempFolder(); |
| | | String excelName = tempFolder + File.separator + |
| | | classifyFullInfo.getCurrentClassifyVO().getId() + "_" + classifyFullInfo.getCurrentClassifyVO().getName() + "_集团码导出模板.xls"; |
| | | try { |
| | | new File(excelName).createNewFile(); |
| | | } catch (Throwable e) { |
| | | throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelName}, e); |
| | | } |
| | | LinkedList<String> finalFieldList = fieldList; |
| | | Map<String, CodeClassifyTemplateAttrVO> attrVOMap = templateVO.getAttributes().stream().filter(s-> finalFieldList.contains(s.getId().toLowerCase(Locale.ROOT))).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); |
| | | List<WriteExcelData> excelDataList = new ArrayList<>(); |
| | | Workbook workbook = new HSSFWorkbook(); |
| | | List<CodeAndGroupCodeAttrMappingDTO> codeAndGroupCodeAttrMappingDTOList= execGroupCodePortDataDTO.getCodeAttrMapGroupAttrDTOS(); |
| | | |
| | | Map<String, CodeAndGroupCodeAttrMappingDTO> jAttrVOMap = codeAndGroupCodeAttrMappingDTOList.stream().filter(s-> finalFieldList.contains(s.getTargetAttrKey().toLowerCase(Locale.ROOT))).collect(Collectors.toMap(s -> s.getTargetAttrKey().toLowerCase(Locale.ROOT), t -> t)); |
| | | |
| | | WriteExcelData codeExcelData = new WriteExcelData(0, 0, "企业编码"); |
| | | WriteExcelData groupExcelData = new WriteExcelData(0, 1, "集团码"); |
| | | excelDataList.add(codeExcelData); |
| | | excelDataList.add(groupExcelData); |
| | | for (int i = 0; i < fieldList.size(); i++) { |
| | | String attrId=fieldList.get(i); |
| | | if(attrId.equals(CODE_FIELD)||attrId.equals(CODE_GROUP_FIELD)){ |
| | | continue; |
| | | } |
| | | if (attrVOMap.containsKey(attrId)) { |
| | | CodeClassifyTemplateAttrVO attrVO = attrVOMap.get(attrId); |
| | | //Object text = attrVO.getName(); |
| | | CodeAndGroupCodeAttrMappingDTO codeAttrMappingDTO = jAttrVOMap.get(attrId); |
| | | Object text = codeAttrMappingDTO.getSourceAttrName(); |
| | | text = exportKeyAndRequired(workbook, attrVO, text); |
| | | WriteExcelData excelData = new WriteExcelData(0, i, text); |
| | | if (text instanceof RichTextString) { |
| | | excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex())); |
| | | } |
| | | excelDataList.add(excelData); |
| | | } |
| | | } |
| | | final Integer[] rowIndex = {0}; |
| | | dataList.stream().forEach(data -> { |
| | | rowIndex[0]++; |
| | | String id=data.getOrDefault("id", ""); |
| | | excelDataList.add(new WriteExcelData(rowIndex[0], 0, id)); |
| | | String groupCode=data.getOrDefault("groupcode", ""); |
| | | excelDataList.add(new WriteExcelData(rowIndex[0], 1, groupCode)); |
| | | List<String> newFieldList = finalFieldList.stream().filter(e -> !e.equals("id") &&!e.equals("groupcode")).collect(Collectors.toList()); |
| | | |
| | | for (int i = 0; i < newFieldList.size(); i++) { |
| | | String attrId = newFieldList.get(i).toLowerCase(Locale.ROOT); |
| | | if(attrId.equals("id")){ |
| | | |
| | | }else if(attrId.equals("groupcode")){ |
| | | |
| | | }else{ |
| | | if (attrVOMap.containsKey(attrId)) { |
| | | CodeClassifyTemplateAttrVO attrVO = attrVOMap.get(attrId); |
| | | if (StringUtils.isNotBlank(attrVO.getEnumId()) || StringUtils.isNotBlank(attrVO.getEnumString())) { |
| | | attrId = attrId + "Text"; |
| | | } |
| | | if (StringUtils.isNotBlank(attrVO.getReferBtmId()) || StringUtils.isNotBlank(attrVO.getReferConfig())) { |
| | | attrId = attrId + "name"; |
| | | } |
| | | if (VciQueryWrapperForDO.LC_STATUS_FIELD.equalsIgnoreCase(attrId)) { |
| | | attrId = VciQueryWrapperForDO.LC_STATUS_FIELD_TEXT.toLowerCase(Locale.ROOT); |
| | | } |
| | | excelDataList.add(new WriteExcelData(rowIndex[0], i+2, data.getOrDefault(attrId, ""))); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | WriteExcelOption excelOption = new WriteExcelOption(); |
| | | excelOption.addSheetDataList(execGroupCodePortDataDTO.getSheetName(),excelDataList); |
| | | |
| | | //增加模板的信息导入 |
| | | LinkedList<WriteExcelData> tempEDList = new LinkedList<>(); |
| | | tempEDList.add(new WriteExcelData(0,0,"模板主键")); |
| | | tempEDList.add(new WriteExcelData(0,1,"模板代号")); |
| | | tempEDList.add(new WriteExcelData(0,2,"模板名称")); |
| | | tempEDList.add(new WriteExcelData(1,0,templateVO.getOid())); |
| | | tempEDList.add(new WriteExcelData(1,1,templateVO.getId())); |
| | | tempEDList.add(new WriteExcelData(1,2,templateVO.getName())); |
| | | excelOption.addSheetDataList("模板信息【请勿删除或移动】",tempEDList); |
| | | ExcelUtil.writeDataToFile(excelName, excelOption); |
| | | log.info("文件路径"+excelName); |
| | | return excelName; |
| | | } |
| | | |
| | | /*** |
| | | * 导入集团码 |
| | | * @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 |
| | | */ |
| | | private void createExportGroupCodeMapConfig(CodeClassifyTemplateVO templateVO,ExecGroupCodePortDataDTO execGroupCodePortDataDTO){ |
| | | String classOid=templateVO.getCodeclassifyoid(); |
| | | String templateOid=templateVO.getOid(); |
| | | R r=mdmInterJtClient.list_mapping(classOid); |
| | | if(r.isSuccess()){ |
| | | List<DockingPreAttrMappingVO>dockingPreAttrMappingVOList= (List<DockingPreAttrMappingVO>) r.getData(); |
| | | List<CodeAndGroupCodeAttrMappingDTO> codeAttrMapGroupAttrDTOS=new ArrayList<>(); |
| | | LinkedList<String> fieldList=new LinkedList<>(); |
| | | LinkedList<String> colNameList=new LinkedList<>(); |
| | | dockingPreAttrMappingVOList.stream().forEach(dockingPreAttrMappingVO -> { |
| | | CodeAndGroupCodeAttrMappingDTO codeAndGroupCodeAttrMappingDTO=new CodeAndGroupCodeAttrMappingDTO(); |
| | | if(StringUtils.isNotBlank(dockingPreAttrMappingVO.getTargetAttrId())){ |
| | | codeAndGroupCodeAttrMappingDTO.setDefaultValue(dockingPreAttrMappingVO.getDefaultValue()); |
| | | codeAndGroupCodeAttrMappingDTO.setMetaListId(dockingPreAttrMappingVO.getMetaListId()); |
| | | codeAndGroupCodeAttrMappingDTO.setSourceAttrKey(dockingPreAttrMappingVO.getSourceAttrKey()); |
| | | codeAndGroupCodeAttrMappingDTO.setSourceAttrName(dockingPreAttrMappingVO.getSourceAttrName()); |
| | | codeAndGroupCodeAttrMappingDTO.setTargetAttrId(dockingPreAttrMappingVO.getTargetAttrId()); |
| | | codeAndGroupCodeAttrMappingDTO.setTargetAttrKey(dockingPreAttrMappingVO.getTargetAttrKey()); |
| | | codeAndGroupCodeAttrMappingDTO.setTargetAttrName(dockingPreAttrMappingVO.getTargetAttrName()); |
| | | fieldList.add(dockingPreAttrMappingVO.getTargetAttrKey()); |
| | | colNameList.add(dockingPreAttrMappingVO.getSourceAttrName()); |
| | | } |
| | | codeAttrMapGroupAttrDTOS.add(codeAndGroupCodeAttrMappingDTO); |
| | | }); |
| | | execGroupCodePortDataDTO.setCodeAttrMapGroupAttrDTOS(codeAttrMapGroupAttrDTOS); |
| | | execGroupCodePortDataDTO.setFieldList(fieldList); |
| | | execGroupCodePortDataDTO.setColName(colNameList); |
| | | } |
| | | } |
| | | |
| | | /*** |
| | | * 集团码属性转换 |
| | | * @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,List<String> codeList ){ |
| | | //先查询数据 |
| | | String btmTypeId = classifyFullInfo.getTopClassifyVO().getBtmTypeId(); |
| | | String codeClassifyOid=classifyFullInfo.getCurrentClassifyVO().getOid(); |
| | | 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"); |
| | | conditionMap.put("lastv", "1"); |
| | | |
| | | R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Arrays.asList(btmTypeId)); |
| | | String tableName = ""; |
| | | if(listR.isSuccess() && !listR.getData().isEmpty()){ |
| | | tableName = Func.isNotBlank(listR.getData().get(0).getTableName()) ? listR.getData().get(0).getTableName():VciBaseUtil.getTableName(btmTypeId); |
| | | }else{ |
| | | tableName = VciBaseUtil.getTableName(btmTypeId); |
| | | } |
| | | PageHelper pageHelper = new PageHelper(); |
| | | pageHelper.setLimit(1000000); |
| | | pageHelper.setPage(1); |
| | | pageHelper.addDefaultDesc("createTime"); |
| | | DataGrid<Map<String, String>> dataGrid = engineService.queryGrid(btmTypeId, templateVO, conditionMap, pageHelper); |
| | | //转换数据 |
| | | if(!CollectionUtils.isEmpty(dataGrid.getData())){ |
| | | dataList.addAll(dataGrid.getData()); |
| | | } |
| | | //封装查询出来的数据 |
| | | engineService.wrapperData(dataList, templateVO, selectFieldList,false); |
| | | //modify by weidy@2022-09-27 |
| | | //因为在列表和表单的显示的时候,我们的开关类型页面会处理,但是在导出的时候,我们需要将true和false都替换成中文 |
| | | engineService.wrapperBoolean(dataList,templateVO); |
| | | log.info("导出模板的数据条目数:"+dataList.size()); |
| | | } |
| | | } |