| | |
| | | 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; |
| | |
| | | */ |
| | | @Override |
| | | public String exportGroupCodeExcel(String codeClassifyOid) { |
| | | List<CodeClassifyTemplateVO> templateVOList=new ArrayList<>(); |
| | | VciBaseUtil.alertNotNull("å¯¼åºæ¨¡æ¿","导åºçé
ç½®",codeClassifyOid,"主é¢åºåç±»ç主é®"); |
| | | CodeClassifyVO codeClassifyVO = classifyService.getObjectByOid(codeClassifyOid); |
| | | //æ¾æ¨¡æ¿ |
| | | VciBaseUtil.alertNotNull(codeClassifyOid,"主é¢åºåç±»ç主é®"); |
| | | CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyOid); |
| | | CodeClassifyVO codeClassifyVO= classifyFullInfo.getCurrentClassifyVO(); |
| | | //è·åææ°çæ¨¡æ¿ |
| | | CodeClassifyTemplateVO templateVO = engineService.getUsedTemplateByClassifyOid(codeClassifyOid); |
| | | templateVOList.add(templateVO); |
| | | WriteExcelOption eo = new WriteExcelOption(); |
| | | eo.setAppend(true); |
| | | LinkedList<String> colName=new LinkedList<>();//å头 |
| | | LinkedList<String> fieldList=new LinkedList<>();//ååæ®µ |
| | | |
| | | ExecGroupCodePortDataDTO execGroupCodePortDataDTO=new ExecGroupCodePortDataDTO(); |
| | | createExportGroupCodeMapConfig(templateVO,execGroupCodePortDataDTO);//ç»ç»æ°æ® |
| | | 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,"模æ¿åç§°")); |
| | | CodeClassifyTemplateVO codeClassifyTemplateVO = new CodeClassifyTemplateVO(); |
| | | BeanUtils.copyProperties(templateVO,codeClassifyTemplateVO); |
| | | //ç»åæ ¼å¼çä¸å¯¼å
¥ï¼ |
| | | // æä¸¾çæä¾åºåçéæ© |
| | | //æ¶é´å
¨é¨ç»ä¸ä¸ºyyyy-MM-dd HH:mm:ss |
| | | //åç
§çèªè¡è¾å
¥åç§° |
| | | //å类注å
¥çä¸ç¨ï¼é½æ¯å¯¼å
¥åèªå¨å¤çç |
| | | //ç¼ç ï¼ç¶æçåæ®µä¸å¯¼å
¥ |
| | | List<CodeClassifyTemplateAttrVO> codeClassifyTemplateAttrVOList=codeClassifyTemplateVO.getAttributes(); |
| | | if(!CollectionUtils.isEmpty(codeClassifyTemplateAttrVOList)) { |
| | | if (CollectionUtils.isEmpty(codeClassifyTemplateAttrVOList)) { |
| | | throw new VciBaseException("æ¨¡æ¿æ²¡æé
ç½®å±æ§"); |
| | | } |
| | | } |
| | | List<CodeClassifyTemplateAttrVO> templateAttrVOS = codeClassifyTemplateAttrVOList.stream().filter(s -> |
| | | !DEFAULT_ATTR_LIST.contains(s.getId()) |
| | | && StringUtils.isBlank(s.getComponentRule()) |
| | | && StringUtils.isBlank(s.getClassifyInvokeAttr()) |
| | | && (VciBaseUtil.getBoolean(s.getFormDisplayFlag())) |
| | | ).collect(Collectors.toList()); |
| | | |
| | | if (CollectionUtils.isEmpty(templateAttrVOS)) { |
| | | throw new VciBaseException("æ¨¡æ¿æ²¡æé
置任ä½ãè¡¨åæ¾ç¤ºãä¸ºãæ¯ãç屿§"); |
| | | } |
| | | List<CodeClassifyTemplateAttrVO> idAttrVOList = codeClassifyTemplateVO.getAttributes().stream().filter(s -> s.getId().equalsIgnoreCase(CODE_FIELD)).collect(Collectors.toList()); |
| | | LinkedList<WriteExcelData> excelDataList = new LinkedList<>(); |
| | | Workbook workbook = new HSSFWorkbook(); |
| | | excelDataList.add(new WriteExcelData(0,0,!CollectionUtils.isEmpty(idAttrVOList)?idAttrVOList.get(0).getName():"ä¼ä¸ç¼ç ",idAttrVOList.get(0).getId())); |
| | | excelDataList.add(new WriteExcelData(0,1,"éå¢ç ","")); |
| | | for (int i = 0; i < templateAttrVOS.size(); i++) { |
| | | CodeClassifyTemplateAttrVO attrVO = templateAttrVOS.get(i); |
| | | |
| | | Object text = attrVO.getName(); |
| | | text = exportKeyAndRequired(workbook, attrVO, text); |
| | | int colIndex = 2 + i; |
| | | 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()) |
| | | || VciFieldTypeEnum.VTTime.name().equalsIgnoreCase(attrVO.getAttributeDataType())) { |
| | | excelData.setDateFormat(VciDateUtil.DateTimeFormat); |
| | | } |
| | | if (text instanceof RichTextString) { |
| | | excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex())); |
| | | } |
| | | excelDataList.add(excelData); |
| | | if (StringUtils.isNotBlank(attrVO.getEnumString()) || StringUtils.isNotBlank(attrVO.getEnumId())) { |
| | | //æ·»å æ°æ®æææ§ |
| | | List<String> enumValueList = new ArrayList<>(); |
| | | enumValueList.add(""); |
| | | List<KeyValue> valueList = engineService.listComboboxItems(attrVO); |
| | | if (!CollectionUtils.isEmpty(valueList)) { |
| | | valueList.stream().forEach(kv -> { |
| | | enumValueList.add(kv.getValue()); |
| | | }); |
| | | } |
| | | //é»è®¤å 1䏿¡ |
| | | WriteExcelData ed = new WriteExcelData(1, colIndex, ""); |
| | | ed.setRowTo(100); |
| | | ed.setColTo(colIndex); |
| | | ed.setValidation(true); |
| | | ed.setValidationDataList(enumValueList); |
| | | ed.setValidationErrorMsg("请å¨åºåä¸éæ©æ£ç¡®çå¼"); |
| | | excelDataList.add(ed); |
| | | } |
| | | if (VciFieldTypeEnum.VTBoolean.name().equalsIgnoreCase(attrVO.getAttributeDataType())) { |
| | | List<String> booleanList = new ArrayList<>(); |
| | | |
| | | booleanList.add("æ¯"); |
| | | booleanList.add("å¦"); |
| | | //é»è®¤å 1䏿¡ |
| | | WriteExcelData ed = new WriteExcelData(1, colIndex, ""); |
| | | ed.setRowTo(100); |
| | | ed.setColTo(colIndex); |
| | | ed.setValidation(true); |
| | | ed.setValidationDataList(booleanList); |
| | | ed.setValidationErrorMsg("请å¨åºåä¸éæ©æ£ç¡®çå¼"); |
| | | excelDataList.add(ed); |
| | | } |
| | | } |
| | | eo.addSheetDataList(templateVO.getName(),excelDataList); |
| | | tempEDList.add(new WriteExcelData(1,0,templateVO.getOid())); |
| | | tempEDList.add(new WriteExcelData(1,1,templateVO.getId())); |
| | | tempEDList.add(new WriteExcelData(1,2,templateVO.getName())); |
| | | String excelName = LocalFileUtil.getDefaultTempFolder() + File.separator + codeClassifyVO.getName() + "éå¢ç _导å
¥æ¨¡æ¿.xls"; |
| | | eo.addSheetDataList(templateVOList.size()+"模æ¿ä¿¡æ¯ã请å¿å é¤æç§»å¨ã",tempEDList); |
| | | ExcelUtil.writeDataToFile(excelName,eo); |
| | | excelOption.addSheetDataList("模æ¿ä¿¡æ¯ã请å¿å é¤æç§»å¨ã",tempEDList); |
| | | ExcelUtil.writeDataToFile(excelName, excelOption); |
| | | log.info("æä»¶è·¯å¾"+excelName); |
| | | return excelName; |
| | | } |
| | | /*** |
| | | * |
| | | */ |
| | | 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 |
| | | */ |
| | | 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()); |
| | | } |
| | | } |