| | |
| | | } |
| | | } |
| | | |
| | | /*** |
| | | * @param codeClassifyOid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String exportGroupCodeExcel(String codeClassifyOid) { |
| | | List<CodeClassifyTemplateVO> templateVOList=new ArrayList<>(); |
| | | VciBaseUtil.alertNotNull("导出模板","导出的配置",codeClassifyOid,"主题库分类的主键"); |
| | | CodeClassifyVO codeClassifyVO = classifyService.getObjectByOid(codeClassifyOid); |
| | | //找模板 |
| | | CodeClassifyTemplateVO templateVO = engineService.getUsedTemplateByClassifyOid(codeClassifyOid); |
| | | templateVOList.add(templateVO); |
| | | WriteExcelOption eo = new WriteExcelOption(); |
| | | eo.setAppend(true); |
| | | //增加模板的信息导入 |
| | | 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); |
| | | return excelName; |
| | | } |
| | | } |