| | |
| | | package com.vci.web.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.vci.client.common.providers.ClientServiceProvider; |
| | | import com.vci.corba.common.PLException; |
| | | import com.vci.corba.omd.atm.AttributeDef; |
| | | import com.vci.corba.omd.data.BusinessObject; |
| | | import com.vci.corba.omd.etm.EnumItem; |
| | | import com.vci.corba.omd.etm.EnumType; |
| | | import com.vci.dto.OsEnumDTO; |
| | | import com.vci.dto.OsEnumItemDTO; |
| | | import com.vci.omd.objects.OtherInfo; |
| | | import com.vci.omd.utils.ObjectTool; |
| | | import com.vci.pagemodel.*; |
| | | import com.vci.po.OsEnumPO; |
| | |
| | | /** |
| | | * 必填列 |
| | | */ |
| | | private ArrayList<Integer> ColumnNameisRed = new ArrayList<Integer>(); |
| | | private List<Integer> ColumnNameisRed = new ArrayList<Integer>(); |
| | | |
| | | /** |
| | | * 日志 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String exportEnumTypes(String exportFileName,String enumNames) throws PLException { |
| | | public String exportEnumTypes(String exportFileName,String enumNames,boolean flag/*控制导出的列名是否和导入模板一致*/) throws PLException { |
| | | if(Func.isBlank(enumNames)){ |
| | | throw new PLException("500",new String[]{"请勾选要导出的枚举!"}); |
| | | } |
| | | //界面没传名称,使用默认导出名称 |
| | | exportFileName = Func.isBlank(exportFileName) ? "枚举类型导出_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName; |
| | | //设置列名 |
| | | List<String> columns = new ArrayList<>(Arrays.asList("枚举名称", "标签", "返回类型", "长度", "枚举项名称", "枚举值", "描述")); |
| | | List<String> columns = this.getCloumns(flag); |
| | | |
| | | //写excel |
| | | String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls"; |
| | |
| | | if(Func.isEmpty(osEnumVO) && Func.isBlank(osEnumVO.getOid())){ |
| | | throw new PLException("500",new String[]{"未查询到枚举名为【" + enumNameList.get(i) + "】的枚举,请刷新后重新导出!"}); |
| | | } |
| | | //枚举项不为空时需要考虑合并行问题 |
| | | //按照导出列名控制变量和枚举项不为空时决定是否需要考虑合并行问题 |
| | | List<OsEnumItemVO> enumVOItems = osEnumVO.getItems(); |
| | | //枚举项不为空时需要进行合并行处理 |
| | | if(Func.isNotEmpty(enumVOItems) || enumVOItems.size() > 1){ |
| | | //excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,0, osEnumVO.getOid())); |
| | | excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,0, osEnumVO.getId())); |
| | | excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,1, osEnumVO.getName())); |
| | | excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,2, osEnumVO.getEnumValueDataType()+"("+osEnumVO.getEnumValueDataTypeText()+")")); |
| | | excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,3, osEnumVO.getLength())); |
| | | //excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,5, osEnumVO.getCreator())); |
| | | excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,4, Func.format(osEnumVO.getCreateTime(),"yyyy年MM月dd日 hh:mm:ss"))); |
| | | |
| | | //处理枚举项写入 |
| | | //判断是按照什么列名导出 |
| | | if(flag){ |
| | | for (int j = 0; j < enumVOItems.size(); j++) { |
| | | OsEnumItemVO osEnumItemVO = enumVOItems.get(j); |
| | | excelDataList.add(new WriteExcelData(startRow+j,7, true,osEnumItemVO.getName())); |
| | | excelDataList.add(new WriteExcelData(startRow+j,8, true, osEnumItemVO.getValue())); |
| | | excelDataList.add(new WriteExcelData(startRow+j,9, true, osEnumItemVO.getDescription())); |
| | | } |
| | | excelDataList.add(new WriteExcelData(i+j+1,0, osEnumVO.getId())); |
| | | excelDataList.add(new WriteExcelData(i+j+1,1, osEnumVO.getName())); |
| | | excelDataList.add(new WriteExcelData(i+j+1,2, osEnumVO.getEnumValueDataType())); |
| | | excelDataList.add(new WriteExcelData(i+j+1,3, osEnumVO.getLength())); |
| | | |
| | | startRow += enumVOItems.size(); |
| | | excelDataList.add(new WriteExcelData(i+j+1,4,osEnumItemVO.getName())); |
| | | excelDataList.add(new WriteExcelData(i+j+1,5, osEnumItemVO.getValue())); |
| | | excelDataList.add(new WriteExcelData(i+j+1,6, osEnumItemVO.getDescription())); |
| | | } |
| | | }else{ |
| | | //枚举项为空时就不需要合并行 |
| | | //excelDataList.add(new WriteExcelData(startRow,0, true,osEnumVO.getOid())); |
| | | excelDataList.add(new WriteExcelData(startRow,0, true, osEnumVO.getId())); |
| | | excelDataList.add(new WriteExcelData(startRow,1, true, osEnumVO.getName())); |
| | | excelDataList.add(new WriteExcelData(startRow,1, true, osEnumVO.getEnumValueDataType()+"("+osEnumVO.getEnumValueDataTypeText()+")")); |
| | | excelDataList.add(new WriteExcelData(startRow,3, true, osEnumVO.getLength())); |
| | | //excelDataList.add(new WriteExcelData(startRow,5, true, osEnumVO.getCreator())); |
| | | excelDataList.add(new WriteExcelData(startRow,4, true, Func.format(osEnumVO.getCreateTime(),"yyyy年MM月dd日 hh:mm:ss"))); |
| | | //枚举项不为空时需要进行合并行处理 |
| | | if(Func.isNotEmpty(enumVOItems) || enumVOItems.size() > 1){ |
| | | //excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,0, osEnumVO.getOid())); |
| | | excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,0, osEnumVO.getId())); |
| | | excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,1, osEnumVO.getName())); |
| | | excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,2, osEnumVO.getEnumValueDataType()+"("+osEnumVO.getEnumValueDataTypeText()+")")); |
| | | excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,3, osEnumVO.getLength())); |
| | | //excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,5, osEnumVO.getCreator())); |
| | | excelDataList.add(new WriteExcelData(startRow,(enumVOItems.size()+startRow)-1,true,true,4, Func.format(osEnumVO.getCreateTime(),"yyyy年MM月dd日 hh:mm:ss"))); |
| | | |
| | | //处理枚举项写入 |
| | | for (int j = 0; j < enumVOItems.size(); j++) { |
| | | OsEnumItemVO osEnumItemVO = enumVOItems.get(j); |
| | | excelDataList.add(new WriteExcelData(startRow+j,5, true,osEnumItemVO.getName())); |
| | | excelDataList.add(new WriteExcelData(startRow+j,6, true, osEnumItemVO.getValue())); |
| | | excelDataList.add(new WriteExcelData(startRow+j,7, true, osEnumItemVO.getDescription())); |
| | | } |
| | | |
| | | startRow += enumVOItems.size(); |
| | | }else{ |
| | | //枚举项为空时就不需要合并行 |
| | | //excelDataList.add(new WriteExcelData(startRow,0, true,osEnumVO.getOid())); |
| | | excelDataList.add(new WriteExcelData(startRow,0, true, osEnumVO.getId())); |
| | | excelDataList.add(new WriteExcelData(startRow,1, true, osEnumVO.getName())); |
| | | excelDataList.add(new WriteExcelData(startRow,1, true, osEnumVO.getEnumValueDataType()+"("+osEnumVO.getEnumValueDataTypeText()+")")); |
| | | excelDataList.add(new WriteExcelData(startRow,3, true, osEnumVO.getLength())); |
| | | //excelDataList.add(new WriteExcelData(startRow,5, true, osEnumVO.getCreator())); |
| | | excelDataList.add(new WriteExcelData(startRow,4, true, Func.format(osEnumVO.getCreateTime(),"yyyy年MM月dd日 hh:mm:ss"))); |
| | | } |
| | | //记录下上一组数据结束时的行号,方便用做合并行的起始行 |
| | | startRow += 1; |
| | | } |
| | | //记录下上一组数据结束时的行号,方便用做合并行的起始行 |
| | | startRow += 1; |
| | | } |
| | | WriteExcelOption excelOption = new WriteExcelOption(excelDataList); |
| | | ExcelUtil.writeDataToFile(excelPath, excelOption); |
| | |
| | | //界面没传名称,使用默认导出名称 |
| | | exportFileName = Func.isBlank(exportFileName) ? "枚举导入模板_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName; |
| | | //设置列名 |
| | | List<String> columns = new ArrayList<>(Arrays.asList("枚举名称", "标签", "返回类型", "长度", "枚举项名称(当前枚举下有枚举项时必填)", "枚举值(当前枚举下有枚举项时必填)", "描述","*注意*:第二行开始的数据为示例数据,导入前请将其删除,当导入的枚举下具备多个枚举项时,应按照示例enum2的写法")); |
| | | List<String> columns = this.getCloumns(true); |
| | | //写excel |
| | | String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls"; |
| | | //设置必填列 |
| | |
| | | WriteExcelOption excelOption = new WriteExcelOption(excelDataList); |
| | | ExcelUtil.writeDataToFile(excelPath, excelOption); |
| | | return excelPath; |
| | | } |
| | | |
| | | /** |
| | | * 获取导出或导入模板的列名 |
| | | * @param flag 是否获取导入模板列名 |
| | | * @return |
| | | */ |
| | | private List<String> getCloumns(boolean flag){ |
| | | if(flag){ |
| | | return new ArrayList<>( |
| | | Arrays.asList("枚举名称", "标签", "返回类型", "长度", "枚举项名称(当前枚举下有枚举项时必填)", |
| | | "枚举值(当前枚举下有枚举项时必填)", "描述","*注意*:第二行开始的数据为示例数据,导入前请将其删除," + |
| | | "当导入的枚举下具备多个枚举项时,应按照示例enumb的写法" |
| | | ) |
| | | ); |
| | | } |
| | | return new ArrayList<>( |
| | | Arrays.asList("枚举名称", "标签", "返回类型", "长度", |
| | | "创建时间", "枚举项名称", "枚举值", "描述" |
| | | ) |
| | | ); |
| | | } |
| | | |
| | | /** |
| | |
| | | if(Func.isNotEmpty(osEnumVOList)){ |
| | | repeatEnumId = osEnumVOList.stream().map(OsEnumVO::getId).collect(Collectors.toList()); |
| | | } |
| | | //当前excel中是否重复用的判重Map:(key:账号,value:行号) |
| | | //当前excel中是否重复用的判重Map:(key:判重属性,value:行号) |
| | | Map<String, String> excelReapeat = new HashMap<>(); |
| | | //判断必填属性是否为空,用户是否已存在,以及部门是否填错等校验逻辑 |
| | | //判断必填属性是否为空等等 |
| | | List<String> finalRepeatEnumId = repeatEnumId; |
| | | newPOList.stream().forEach(osEnumPO -> { |
| | | if(Func.isBlank(osEnumPO.getId())){//枚举名 |
| | |
| | | throw new VciBaseException("第【"+osEnumPO.getRowIndex()+"】行数据,枚举名称只能为英文字母"); |
| | | }else if(excelReapeat.containsKey(osEnumPO.getId())){//枚举名表格中判重 |
| | | throw new VciBaseException("第【"+excelReapeat.get(osEnumPO.getId())+"】行和第【"+osEnumPO.getRowIndex()+"】行数据,枚举名重复"); |
| | | }else if (Func.isNotEmpty(osEnumVOList) && finalRepeatEnumId.contains(osEnumPO.getId())){//2、判断枚举名是否与系统中重复 |
| | | }else if (Func.isNotEmpty(finalRepeatEnumId) && finalRepeatEnumId.contains(osEnumPO.getId())){//2、判断枚举名是否与系统中重复 |
| | | throw new VciBaseException("第【"+osEnumPO.getRowIndex()+"】行,枚举名在系统中已经存在,请修改!"); |
| | | } |
| | | //先对必填属性判空处理 |
| | | //先对枚举名excel中需要判重处理 |
| | | excelReapeat.put(osEnumPO.getId(),osEnumPO.getRowIndex()); |
| | | }); |
| | | //保存逻辑 |
| | |
| | | } |
| | | }catch (Exception e){ |
| | | if(logger.isErrorEnabled()){ |
| | | logger.error("读取excel内容时或保存用户信息时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e)); |
| | | logger.error("读取excel内容时或保存枚举时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e)); |
| | | } |
| | | e.printStackTrace(); |
| | | return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e); |
| | |
| | | * @return |
| | | */ |
| | | private List<OsEnumVO> getExportEnumTempExample(){ |
| | | String testJosn = "[{\"enumValueDataType\":\"String\",\"id\":\"enum1\",\"items\":[{\"description\":\"enumitem1.1\",\"name\":\"enumitem1.1\",\"value\":\"1\"},{\"description\":\"enumitem1.2\",\"name\":\"enumitem1.2\",\"value\":\"2\"}],\"length\":2,\"name\":\"enum1\"},{\"enumValueDataType\":\"String\",\"id\":\"enum2\",\"items\":[{\"description\":\"enumitem2.1\",\"name\":\"enumitem2.1\",\"value\":\"1\"},{\"description\":\"enumitem2.2\",\"name\":\"enumitem2.2\",\"value\":\"2\"},{\"description\":\"enumitem2.3\",\"name\":\"enumitem2.3\",\"value\":\"3\"}],\"length\":6,\"name\":\"enum2\"}]"; |
| | | String testJosn = "[{\"enumValueDataType\":\"String\",\"id\":\"enuma\",\"items\":[{\"description\":\"enumitem1.1\",\"name\":\"enumitem1.1\",\"value\":\"1\"},{\"description\":\"enumitem1.2\",\"name\":\"enumitem1.2\",\"value\":\"2\"}],\"length\":2,\"name\":\"enuma\"},{\"enumValueDataType\":\"String\",\"id\":\"enumb\",\"items\":[{\"description\":\"enumitem2.1\",\"name\":\"enumitem2.1\",\"value\":\"1\"},{\"description\":\"enumitem2.2\",\"name\":\"enumitem2.2\",\"value\":\"2\"},{\"description\":\"enumitem2.3\",\"name\":\"enumitem2.3\",\"value\":\"3\"}],\"length\":6,\"name\":\"enumb\"}]"; |
| | | List<OsEnumVO> OsEnumVOs = JSON.parseArray(testJosn,OsEnumVO.class); |
| | | return OsEnumVOs; |
| | | } |
| | |
| | | private EnumType osEnumDTO2EnumType(OsEnumDTO osEnumDTO){ |
| | | EnumType enumType = new EnumType(); |
| | | enumType.oid = osEnumDTO.getOid(); |
| | | //枚举名统一转成小写,避免后期出现其他问题 |
| | | enumType.name = osEnumDTO.getId().toLowerCase(Locale.ROOT); |
| | | enumType.name = osEnumDTO.getId();//osEnumDTO.getId().toLowerCase(Locale.ROOT); |
| | | enumType.label = osEnumDTO.getName(); |
| | | enumType.length = osEnumDTO.getLength(); |
| | | enumType.creator = osEnumDTO.getCreator(); |
| | |
| | | for(int k = 0; k < emChildren.length; k++){ |
| | | EnumItem emChild = emChildren[k]; |
| | | String value = emChild.value; |
| | | valueList.add(value); |
| | | String symbol = ""; |
| | | //当为Integer时需要将枚举项值拼接上= |
| | | if("Integer".equals(enumType)){ |
| | | symbol = "="; |
| | | } |
| | | valueList.add(symbol + value); |
| | | } |
| | | Map<String, List<String>> enumMap = new HashMap<>(); |
| | | enumMap.put(emItem.name, valueList); |