| | |
| | | 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.common.data.UserEntityInfo; |
| | | 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.dto.SmUserDTO; |
| | | import com.vci.omd.objects.OtherInfo; |
| | | import com.vci.omd.utils.ObjectTool; |
| | | import com.vci.pagemodel.*; |
| | | import com.vci.po.OsEnumPO; |
| | | import com.vci.po.SmUserPO; |
| | | import com.vci.starter.poi.bo.ReadExcelOption; |
| | | import com.vci.starter.poi.bo.WriteExcelData; |
| | | import com.vci.starter.poi.bo.WriteExcelOption; |
| | |
| | | /** |
| | | * 必填列 |
| | | */ |
| | | private ArrayList<Integer> ColumnNameisRed = new ArrayList<Integer>(); |
| | | private List<Integer> ColumnNameisRed = new ArrayList<Integer>(); |
| | | |
| | | /** |
| | | * 日志 |
| | |
| | | if(Func.isBlank(enumName)){ |
| | | throw new PLException("500",new String[]{"请选择要查询应用范围的枚举!"}); |
| | | } |
| | | String[] attrubyteNames = platformClientUtil.getAttributeService().getAttrubyteNamesByEMName(enumName); |
| | | if(Func.isEmpty(attrubyteNames)){ |
| | | String[] attrubuteNames = platformClientUtil.getAttributeService().getAttrubyteNamesByEMName(enumName); |
| | | if(Func.isEmpty(attrubuteNames)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | List<Map<String,String>> attrubyteMapList = new ArrayList<>(); |
| | | Arrays.stream(attrubyteNames).forEach(attrName->{ |
| | | List<Map<String,String>> attrubuteMapList = new ArrayList<>(); |
| | | Arrays.stream(attrubuteNames).forEach(attrName->{ |
| | | Map<String, String> itemMap = new HashMap<>(); |
| | | itemMap.put("enumName",enumName); |
| | | itemMap.put("source",attrName); |
| | | attrubyteMapList.add(itemMap); |
| | | attrubuteMapList.add(itemMap); |
| | | }); |
| | | return attrubyteMapList; |
| | | return attrubuteMapList; |
| | | } |
| | | |
| | | /** |
| | |
| | | String name = osEnumDTO.getName(); |
| | | Date ts = osEnumDTO.getTs(); |
| | | if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){ |
| | | throw new PLException("500",new String[]{"待删除的枚举列表中主键【oid】和调整时间【ts】不能为空!"}); |
| | | throw new PLException("500",new String[]{"待删除的枚举列表中主键【oid】、调整时间【ts】、属性名【name】不能为空!"}); |
| | | } |
| | | //判断枚举是否有被引用 |
| | | List<Map<String, String>> usedEnumList = this.getUsedEnumList(name); |
| | | if(Func.isNotEmpty(usedEnumList)){ |
| | | throw new PLException("500",new String[]{"删除的枚举中【" + name + "】,已被引用!"}); |
| | | throw new PLException("500",new String[]{"删除的枚举中,枚举名称为:【" + name + "】,已被引用!"}); |
| | | } |
| | | EnumType enumType = new EnumType(); |
| | | enumType.oid = oid; |
| | |
| | | * @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 BaseResult.success("枚举导入成功!"); |
| | | } |
| | | |
| | | /* private OsEnumVO getTestJson(int i){ |
| | | String testJosn = "[{\"createTime\":\"2024-07-17 17:06:30.170\",\"creator\":\"developer\",\"enumValueDataType\":\"String\",\"enumValueDataTypeText\":\"字符串\",\"id\":\"test\",\"items\":[{\"description\":\"\",\"name\":\"1\",\"value\":\"11\"},{\"description\":\"\",\"name\":\"1\",\"value\":\"11\"}],\"lastModifier\":\"developer\",\"lastModifyTime\":\"2024-07-17 17:06:30.170\",\"length\":2,\"name\":\"test1\",\"oid\":\"4F9B4094-A4F5-E3CD-AC7C-1F33AA65F1E7\",\"ts\":\"2024-07-18 09:40:52.512\"},{\"createTime\":\"2024-07-17 09:49:31.592\",\"creator\":\"developer\",\"description\":null,\"enumValueDataType\":\"String\",\"enumValueDataTypeText\":\"字符串\",\"id\":\"testString\",\"items\":[{\"description\":\"11\",\"name\":\"11\",\"value\":\"11\"},{\"description\":\"\",\"name\":\"test1\",\"value\":\"1\"},,{\"description\":\"\",\"name\":\"test1\",\"value\":\"1\"}],\"lastModifier\":\"developer\",\"lastModifyTime\":\"2024-07-17 09:49:31.592\",\"length\":6,\"name\":\"testString\",\"oid\":\"AB3A7718-55C6-555E-A1FD-934763ACA3F2\",\"ts\":\"2024-07-17 16:47:33.038\"}]"; |
| | | List<OsEnumVO> OsEnumVOs = JSON.parseArray(testJosn,OsEnumVO.class); |
| | | return OsEnumVOs.get(i); |
| | | }*/ |
| | | |
| | | /** |
| | | * 获取导入模板的示例数据 |
| | | * @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(); |
| | | enumType.name = osEnumDTO.getId();//osEnumDTO.getId().toLowerCase(Locale.ROOT); |
| | | enumType.label = osEnumDTO.getName(); |
| | | enumType.length = osEnumDTO.getLength(); |
| | | enumType.creator = osEnumDTO.getCreator(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据枚举类型查询枚举:枚举名 , 枚举 |
| | | * @param enumType:String, Integer |
| | | * @return |
| | | */ |
| | | public List<Map<String,List<String>>> getEnumMapByType(String enumType){ |
| | | List<Map<String,List<String>>> enumMapList = new ArrayList<>(); |
| | | EnumType[] emArray = null; |
| | | try { |
| | | emArray = platformClientUtil.getEnumService().getEnumTypesByType(enumType); |
| | | } catch (PLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if(emArray == null || emArray.length == 0){ |
| | | return null; |
| | | } |
| | | EnumType emItem; |
| | | for(int i = 0; i < emArray.length; i++){ |
| | | emItem = emArray[i]; |
| | | EnumItem[] emChildren = emItem.items; |
| | | ArrayList<String> valueList = new ArrayList<String>(); |
| | | for(int k = 0; k < emChildren.length; k++){ |
| | | EnumItem emChild = emChildren[k]; |
| | | String value = emChild.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); |
| | | enumMapList.add(enumMap); |
| | | } |
| | | return enumMapList; |
| | | } |
| | | |
| | | /** |
| | | * 清除缓存 |
| | | */ |
| | | @Override |