| | |
| | | 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; |
| | |
| | | } |
| | | // 单次导入数量限制 |
| | | if(sheetDataSetList.get(i).getRowData().size() > IMPORT_DATA_LIMIT){ |
| | | throw new ServiceException("为了保证系统的稳定性,请一次不要导入超过"+IMPORT_DATA_LIMIT+"条的数据"); |
| | | throw new ServiceException(StringUtil.format("为了保证系统的稳定性,请一次不要导入超过{}条的数据",IMPORT_DATA_LIMIT)); |
| | | } |
| | | //历史导入的时候不处理编码 |
| | | //----逻辑内容---- |
| | |
| | | if(StringUtils.isNotBlank(excelFileName)) { |
| | | codeImProtRusultVO.setFilePath(excelFileName); |
| | | codeImProtRusultVO.setFileOid(""); |
| | | saveLogUtil.operateLog("历史数据导入",true, StringUtil.format("错误信息:{}",JSON.toJSONString(shetNameMap)) ); |
| | | saveLogUtil.operateLog("历史数据导入",true, StringUtil.format("错误信息:{}",JSON.toJSONString(shetNameMap))); |
| | | }else{ |
| | | saveLogUtil.operateLog("历史数据导入",false, StringUtil.format("导入到分类{}中,导入成功总数为:{}", JSON.toJSONString(classifyFullInfo),importCount.get(0))); |
| | | } |
| | |
| | | } |
| | | return codeImProtRusultVO; |
| | | }catch (Exception e){ |
| | | saveLogUtil.operateLog("历史数据导入",true,e.getMessage()); |
| | | saveLogUtil.operateLog("历史数据导入",true,e.toString()); |
| | | throw e; |
| | | } |
| | | } |
| | |
| | | } |
| | | saveLogUtil.operateLog("批量申请编码",false, StringUtil.format("批量导入申请成功共{}条数据,生成的码值如下【{}】",codeList.size(),codeList)); |
| | | }catch (Exception e){ |
| | | saveLogUtil.operateLog("批量申请编码",true,e.getMessage()); |
| | | saveLogUtil.operateLog("批量申请编码",true,e.toString()); |
| | | throw e; |
| | | } |
| | | return uuid; |
| | |
| | | private void batchSwitchClassifyAttrOnOrder(Collection<CodeClassifyTemplateAttrVO> attrVOS,List<ClientBusinessObject> dataList, |
| | | CodeClassifyFullInfoBO classifyFullInfo,boolean isImPort) { |
| | | Map<String, CodeClassifyTemplateAttrVO> dateAttrVOMap = attrVOS.stream().filter( |
| | | s -> StringUtils.isNotBlank(s.getClassifyInvokeAttr()) && StringUtils.isNotBlank(s.getClassifyInvokeAttr()) |
| | | s -> StringUtils.isNotBlank(s.getClassifyInvokeAttr()) |
| | | ).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); |
| | | Map<String,CodeClassifyFullInfoBO> classifyFullInfoMap=new HashMap<>(); |
| | | classifyFullInfoMap.put(classifyFullInfo.getCurrentClassifyVO().getOid(),classifyFullInfo); |
| | |
| | | } else { |
| | | Map<String, String> classifyDataMap = VciBaseUtil.objectToMapString(classifyVO); |
| | | String value = classifyDataMap.getOrDefault(attrVO.getClassifyInvokeAttr(), ""); |
| | | log.error("================================当前分类注入的value值为:==========================",value); |
| | | cbo.setAttributeValue(attrId, value); |
| | | } |
| | | } catch (Throwable e) { |
| | |
| | | } |
| | | } |
| | | |
| | | /*** |
| | | * @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); |
| | | 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 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 classifyFullInfo |
| | | * @param templateVO |
| | | * @param selectFieldList |
| | | * @param dataList |
| | | */ |
| | | private void getDatas(CodeClassifyFullInfoBO classifyFullInfo,CodeClassifyTemplateVO templateVO,LinkedList<String> selectFieldList,List<Map<String,String>>dataList){ |
| | | //先查询数据 |
| | | 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)) + ")"); |
| | | } |
| | | 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()); |
| | | } |
| | | } |