From ac3f3629a261770f573f27e5e23f7ec19d096c2a Mon Sep 17 00:00:00 2001 From: xiejun <xiejun@vci-tech.com> Date: 星期三, 04 九月 2024 18:29:05 +0800 Subject: [PATCH] UI授权功能查询 --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsEnumServiceImpl.java | 617 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 584 insertions(+), 33 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsEnumServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsEnumServiceImpl.java index c9cb8d8..00c2d6b 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsEnumServiceImpl.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsEnumServiceImpl.java @@ -1,28 +1,39 @@ 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; +import com.vci.starter.poi.bo.ReadExcelOption; +import com.vci.starter.poi.bo.WriteExcelData; +import com.vci.starter.poi.bo.WriteExcelOption; +import com.vci.starter.poi.constant.ExcelLangCodeConstant; +import com.vci.starter.poi.util.ExcelUtil; import com.vci.starter.web.annotation.log.VciUnLog; import com.vci.starter.web.enumpck.UserSecretEnum; import com.vci.starter.web.exception.VciBaseException; +import com.vci.starter.web.pagemodel.BaseResult; import com.vci.starter.web.pagemodel.DataGrid; import com.vci.starter.web.pagemodel.PageHelper; -import com.vci.starter.web.util.VciBaseUtil; -import com.vci.starter.web.util.VciDateUtil; +import com.vci.starter.web.util.*; import com.vci.constant.EnumIdConstant; -import com.vci.pagemodel.KeyValue; -import com.vci.pagemodel.OsEnumItemVO; -import com.vci.pagemodel.OsEnumVO; -import com.vci.pagemodel.OsStatusVO; import com.vci.web.service.OsEnumServiceI; import com.vci.web.service.OsLifeCycleServiceI; import com.vci.web.service.WebBoServiceI; +import com.vci.web.util.Func; import com.vci.web.util.PlatformClientUtil; import com.vci.web.util.WebUtil; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.util.HSSFColor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -31,6 +42,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.util.HtmlUtils; +import java.io.File; import java.util.*; import java.util.stream.Collectors; @@ -68,18 +80,21 @@ private WebBoServiceI boService; /** - * 鏃ュ織 - */ - private Logger logger = LoggerFactory.getLogger(getClass()); - - - /** * 鍔犺浇鑷韩 */ @Autowired(required = false) @Lazy private OsEnumServiceI self; + /** + * 蹇呭~鍒� + */ + private List<Integer> ColumnNameisRed = new ArrayList<Integer>(); + + /** + * 鏃ュ織 + */ + private Logger logger = LoggerFactory.getLogger(getClass()); /** * 浣跨敤缂栧彿鑾峰彇鏋氫妇鏄庣粏 @@ -98,13 +113,14 @@ int userSecret = WebUtil.getInt(WebUtil.getCurrentUserSessionInfoNotException().getUserSecret()); List<OsEnumItemVO> itemVOS = new ArrayList<>(); if(enumVO!=null && !CollectionUtils.isEmpty(enumVO.getItems())){ - itemVOS = enumVO.getItems().stream().filter(item->WebUtil.getInt(item.getId()) <= userSecret).collect(Collectors.toList()); + itemVOS = enumVO.getItems().stream().filter(item->WebUtil.getInt(item.getValue()) <= userSecret).collect(Collectors.toList()); } return itemVOS; }else{ return enumVOMap.getOrDefault(enumCode.toLowerCase(),new OsEnumVO()).getItems(); } } + /** * 鑾峰彇鏋氫妇鐨勫唴瀹� * @param enumCode 鏋氫妇鐨勭紪鍙凤紙鑻辨枃鍚嶇О锛� @@ -217,6 +233,501 @@ } /** + * 鏋氫妇瀹氫箟鍒楄〃鏌ヨ锛堢紦瀛橀噷闈㈡壘涓斿甫name鏌ヨ鏉′欢锛� + * @param enumName + * @return 鏋氫妇鐨勬樉绀哄璞� + */ + @Override + public List<OsEnumVO> getEnumTypeList(String enumName) throws PLException { + return enumDO2VOs(Arrays.stream(platformClientUtil.getEnumService().getEnumTypes(enumName,1,1)).collect(Collectors.toList())); + } + + /** + * 鏌ョ湅鏋氫妇鐨勪娇鐢ㄨ寖鍥� + * @param enumName 鏋氫妇鍚嶇О + * @return + * @throws PLException + */ + @Override + public List<Map<String,String>> getUsedEnumList(String enumName) throws PLException { + if(Func.isBlank(enumName)){ + throw new PLException("500",new String[]{"璇烽�夋嫨瑕佹煡璇㈠簲鐢ㄨ寖鍥寸殑鏋氫妇!"}); + } + String[] attrubuteNames = platformClientUtil.getAttributeService().getAttrubyteNamesByEMName(enumName); + if(Func.isEmpty(attrubuteNames)){ + return new ArrayList<>(); + } + 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); + attrubuteMapList.add(itemMap); + }); + return attrubuteMapList; + } + + /** + * 鏍规嵁鏋氫妇鑻辨枃鍚嶇О鑾峰彇鏋氫妇绫诲瀷 + * @param id + * @return + */ + @Override + public OsEnumVO getEnumTypeById(String id) throws PLException { + if (Func.isBlank(id)) { + return null; + } + EnumType enumType = platformClientUtil.getEnumService().getEnumTypeByName(id); + return enumDO2VO(enumType); + } + + /** + * 鏂板鏋氫妇绫诲瀷 + * @param osEnumDTO + * @return + */ + @Override + public boolean addEnumType(OsEnumDTO osEnumDTO) throws PLException { + //1銆佹灇涓惧�煎垽绌� + VciBaseUtil.alertNotNull( + osEnumDTO,"鏋氫妇绫诲瀷瀵硅薄", + osEnumDTO.getId(),"鏋氫妇鍚嶇О", + osEnumDTO.getEnumValueDataType(),"鏋氫妇鐨勭被鍨�", + osEnumDTO.getLength(),"鏋氫妇闀垮害" + ); + //2銆佹灇涓剧被鍨嬪悕绉版鍒欐牎楠屽拰鏌ラ噸 + if(!osEnumDTO.getId().matches("^[A-Za-z]+$")){ + throw new PLException("500", new String[] { "鏋氫妇鍚嶇О鍙兘涓鸿嫳鏂囧瓧姣�!"}); + } + OsEnumVO osEnumVO = this.getEnumTypeById(osEnumDTO.getId()); + if(Func.isNotEmpty(osEnumVO) && Func.isNotBlank(osEnumVO.getOid())){ + throw new PLException("500", new String[] { "鏋氫妇鍚嶇О宸插瓨鍦紝璇蜂慨鏀规灇涓惧悕绉�!"}); + } + //鏋氫妇椤瑰悕绉板垽閲嶇瓑鎿嶄綔 + checkOsEnumItem(osEnumDTO); + //榛樿鍊煎鐞� + String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); + osEnumDTO.setCreator(userId); + //鎵嬪姩璁剧疆涓婚敭锛屽惁鍒欏钩鍙扮洿鎺ョ敤娌℃湁涓婚敭鐨勬灇涓炬斁杩涗簡缂撳瓨涓紝瀵艰嚧鍚庣画鏌ヨ鐨勬暟鎹病鏈塷id + osEnumDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); + osEnumDTO.setLastModifier(userId); + return platformClientUtil.getEnumService().addEnumType(this.osEnumDTO2EnumType(osEnumDTO)); + } + + /** + * 淇敼鏋氫妇绫诲瀷 + * @param osEnumDTO + * @return + */ + @Override + public boolean updateEnumType(OsEnumDTO osEnumDTO) throws PLException { + //1銆佹灇涓惧�煎垽绌� + VciBaseUtil.alertNotNull( + osEnumDTO,"鏋氫妇绫诲瀷瀵硅薄", + osEnumDTO.getOid(),"鏋氫妇鐨勪富閿�", + osEnumDTO.getId(),"鏋氫妇鍚嶇О", + osEnumDTO.getEnumValueDataType(),"鏋氫妇鐨勭被鍨�", + osEnumDTO.getLength(),"鏋氫妇闀垮害" + ); + //2銆佹灇涓剧被鍨嬪悕绉�(鍚嶇О涓嶅厑璁镐慨鏀�)鎵�浠ュ彲浠ョ敤鍚嶇О鏌ヨ鏄惁瀛樺湪 + OsEnumVO osEnumVO = this.getEnumTypeById(osEnumDTO.getId()); + if(Func.isEmpty(osEnumVO) || Func.isBlank(osEnumVO.getOid())){ + throw new PLException("500", new String[] { "褰撳墠淇敼鏋氫妇瀵硅薄涓嶅瓨鍦紝璇峰埛鏂板悗閲嶈瘯!"}); + } + //3銆佹灇涓鹃」鍒ら噸锛屽拰闀垮害绛夋牎楠� + checkOsEnumItem(osEnumDTO); + //灏唎sEnumVO涓殑榛樿鍊艰祴鍊肩粰osEnumDTO瀵硅薄 + String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); + osEnumDTO.setLastModifier(userId); + osEnumDTO.setCreator(osEnumVO.getCreator()); + osEnumDTO.setCreateTime(osEnumVO.getCreateTime()); + //淇敼鍜屽垹闄ゆ椂ts鍙傛暟涓哄墠绔繀浼犲弬鏁� + return platformClientUtil.getEnumService().modifyEnumType(osEnumDTO2EnumType(osEnumDTO)); + } + + /** + * 鍒犻櫎鏋氫妇绫诲瀷(鍖呭惈鍒犻櫎鏋氫妇椤瑰姛鑳�) + * @param osEnumDTOS + * @return + */ + @Override + public boolean deleteEnumTypes(List<OsEnumDTO> osEnumDTOS) throws PLException { + VciBaseUtil.alertNotNull(osEnumDTOS,"寰呭垹闄ょ殑鏋氫妇鍒楄〃"); + //骞冲彴鐨刣eleteEnumTypes鏂规硶蹇呬紶涓変釜鍙傛暟锛宱id銆乶ame鍜宼s + List<EnumType> enumTypes = new ArrayList<>(); + for(OsEnumDTO osEnumDTO : osEnumDTOS){ + //oid鍜宼s鍒ょ┖ + String oid = osEnumDTO.getOid(); + //name涓昏鐢ㄦ潵瀵圭紦瀛樻暟鎹垹闄� + String name = osEnumDTO.getName(); + Date ts = osEnumDTO.getTs(); + if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){ + throw new PLException("500",new String[]{"寰呭垹闄ょ殑鏋氫妇鍒楄〃涓富閿�恛id銆戙�佽皟鏁存椂闂淬�恡s銆戙�佸睘鎬у悕銆恘ame銆戜笉鑳戒负绌猴紒"}); + } + //鍒ゆ柇鏋氫妇鏄惁鏈夎寮曠敤 + List<Map<String, String>> usedEnumList = this.getUsedEnumList(name); + if(Func.isNotEmpty(usedEnumList)){ + throw new PLException("500",new String[]{"鍒犻櫎鐨勬灇涓句腑锛屾灇涓惧悕绉颁负锛氥��" + name + "銆�,宸茶寮曠敤锛�"}); + } + EnumType enumType = new EnumType(); + enumType.oid = oid; + enumType.name = name; + enumType.ts = Func.format(ts,VciDateUtil.DateTimeMillFormat); + enumTypes.add(enumType); + } + if(Func.isEmpty(enumTypes)){ + return false; + } + return platformClientUtil.getEnumService().deleteEnumTypes(enumTypes.toArray(new EnumType[enumTypes.size()])); + } + + /** + * 瀵煎嚭鏋氫妇绫诲瀷 + * @param exportFileName 瀵煎嚭鐨勬枃浠跺悕 + * @param enumNames 闇�瑕佸鍑虹殑鏋氫妇鍚嶇О + * @return + */ + @Override + 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 = this.getCloumns(flag); + + //鍐檈xcel + String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls"; + try { + new File(excelPath).createNewFile(); + } catch (Throwable e) { + throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e); + } + //璁剧疆鍒� + List<WriteExcelData> excelDataList = new ArrayList<>(); + //璁剧疆鍒楀ご + for (int index = 0; index < columns.size(); index++) { + excelDataList.add(new WriteExcelData(0,index, columns.get(index))); + } + //鎸夌収鏋氫妇鍚嶆煡璇㈡灇涓撅紝鐒跺悗澶勭悊鏋氫妇瀵煎嚭 + List<String> enumNameList = Func.toStrList(enumNames); + int startRow = 1; + for (int i = 0; i < enumNameList.size(); i++) { + //鏍规嵁鏋氫妇鍚嶇О鏌ヨ鏋氫妇鍜屾灇涓鹃」 + OsEnumVO osEnumVO = this.getEnumTypeById(enumNameList.get(i)); + //OsEnumVO osEnumVO = getTestJson(i); + //鏌ヨ缁撴灉涓嶅簲璇ヤ负绌� + if(Func.isEmpty(osEnumVO) && Func.isBlank(osEnumVO.getOid())){ + throw new PLException("500",new String[]{"鏈煡璇㈠埌鏋氫妇鍚嶄负銆�" + enumNameList.get(i) + "銆戠殑鏋氫妇锛岃鍒锋柊鍚庨噸鏂板鍑�!"}); + } + //鎸夌収瀵煎嚭鍒楀悕鎺у埗鍙橀噺鍜屾灇涓鹃」涓嶄负绌烘椂鍐冲畾鏄惁闇�瑕佽�冭檻鍚堝苟琛岄棶棰� + List<OsEnumItemVO> enumVOItems = osEnumVO.getItems(); + //鍒ゆ柇鏄寜鐓т粈涔堝垪鍚嶅鍑� + if(flag){ + for (int j = 0; j < enumVOItems.size(); j++) { + OsEnumItemVO osEnumItemVO = enumVOItems.get(j); + 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())); + + 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{ + //鏋氫妇椤逛笉涓虹┖鏃堕渶瑕佽繘琛屽悎骞惰澶勭悊 + 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骞碝M鏈坉d鏃� 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骞碝M鏈坉d鏃� hh:mm:ss"))); + } + //璁板綍涓嬩笂涓�缁勬暟鎹粨鏉熸椂鐨勮鍙凤紝鏂逛究鐢ㄥ仛鍚堝苟琛岀殑璧峰琛� + startRow += 1; + } + } + WriteExcelOption excelOption = new WriteExcelOption(excelDataList); + ExcelUtil.writeDataToFile(excelPath, excelOption); + return excelPath; + } + + /** + * 涓嬭浇瀵煎叆妯℃澘 + * @param exportFileName + * @return + */ + @Override + public String downloadEnumTemplate(String exportFileName) { + //鐣岄潰娌′紶鍚嶇О锛屼娇鐢ㄩ粯璁ゅ鍑哄悕绉� + exportFileName = Func.isBlank(exportFileName) ? "鏋氫妇瀵煎叆妯℃澘_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName; + //璁剧疆鍒楀悕 + List<String> columns = this.getCloumns(true); + //鍐檈xcel + String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName + ".xls"; + //璁剧疆蹇呭~鍒� + ColumnNameisRed.clear(); + ColumnNameisRed.add(0); + ColumnNameisRed.add(2); + ColumnNameisRed.add(3); + ColumnNameisRed.add(4); + ColumnNameisRed.add(5); + try { + new File(excelPath).createNewFile(); + } catch (Throwable e) { + throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e); + } + //璁剧疆鍒� + List<WriteExcelData> excelDataList = new ArrayList<>(); + //璁剧疆鍒楀ご + for (int index = 0; index < columns.size(); index++) { + //鍒ゆ柇鏄惁涓哄繀濉垪锛岀粰蹇呭~鍒楄缃鑹� + if(ColumnNameisRed.contains(index)){ + WriteExcelData excelData = new WriteExcelData(0, index, columns.get(index)); + excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex())); + excelDataList.add(excelData); + }else{ + excelDataList.add(new WriteExcelData(0,index, columns.get(index))); + } + } + List<OsEnumVO> exportEnumTempExample = this.getExportEnumTempExample(); + for (int i = 0; i < exportEnumTempExample.size(); i++) { + OsEnumVO osEnumVO = exportEnumTempExample.get(i); + List<OsEnumItemVO> enumVOItems = osEnumVO.getItems(); + for (int j = 0; j < enumVOItems.size(); j++) { + OsEnumItemVO osEnumItemVO = enumVOItems.get(j); + 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())); + + 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())); + } + } + 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("鏋氫妇鍚嶇О", "鏍囩", "杩斿洖绫诲瀷", "闀垮害", "鏋氫妇椤瑰悕绉�(褰撳墠鏋氫妇涓嬫湁鏋氫妇椤规椂蹇呭~)", + "鏋氫妇鍊�(褰撳墠鏋氫妇涓嬫湁鏋氫妇椤规椂蹇呭~)", "鎻忚堪","*娉ㄦ剰*:绗簩琛屽紑濮嬬殑鏁版嵁涓虹ず渚嬫暟鎹紝瀵煎叆鍓嶈灏嗗叾鍒犻櫎锛�" + + "褰撳鍏ョ殑鏋氫妇涓嬪叿澶囧涓灇涓鹃」鏃讹紝搴旀寜鐓хず渚媏numb鐨勫啓娉�" + ) + ); + } + return new ArrayList<>( + Arrays.asList("鏋氫妇鍚嶇О", "鏍囩", "杩斿洖绫诲瀷", "闀垮害", + "鍒涘缓鏃堕棿", "鏋氫妇椤瑰悕绉�", "鏋氫妇鍊�", "鎻忚堪" + ) + ); + } + + /** + * 瀵煎叆鏋氫妇 + * @param file + * @return + * @throws Exception + */ + @Override + public BaseResult importEnumTypes(File file) throws Exception { + VciBaseUtil.alertNotNull(file,"excel鏂囦欢"); + if(!file.exists()){ + throw new VciBaseException("瀵煎叆鐨別xcel鏂囦欢涓嶅瓨鍦�,{0}",new String[]{file.getPath()}); + } + try{ + //1銆佽鍙杄xcel涓殑鏁版嵁锛岀粍鎴愬璞� + ReadExcelOption excelOption = new ReadExcelOption(); + List<OsEnumPO> poList = ExcelUtil.readDataObjectFromExcel(file, OsEnumPO.class,excelOption,(value, po, fieldName)->{}); + //鍘婚櫎閮芥槸绌虹殑鎯呭喌 + if(CollectionUtils.isEmpty(poList)){ + return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{}); + } + //灏嗘灇涓惧拰鏋氫妇椤瑰鐞嗘垚涓�瀵瑰鍏崇郴鐨勫璞� + Map<String, OsEnumPO> groupPOMap = new HashMap<>(); + for (OsEnumPO po : poList) { + //鎷兼帴鐢ㄦ潵浣滀负鍒嗙粍鐨刱ey + String key = po.getId() + "_" + po.getName() + "_" + po.getEnumValueDataType() + "_" + po.getLength(); + OsEnumPO group = groupPOMap.get(key); + if (group == null) { + group = new OsEnumPO(); + //鎷垮嚭鐜扮殑棣栬鍋氬悗缁殑鎻愮ず琛� + group.setRowIndex(po.getRowIndex()); + group.setId(po.getId()); + group.setName(po.getName()); + group.setEnumValueDataType(po.getEnumValueDataType()); + group.setLength(po.getLength()); + groupPOMap.put(key, group); + } + + OsEnumItemDTO itemDTO = new OsEnumItemDTO(); + itemDTO.setName(po.getEnumItemName()); + itemDTO.setValue(po.getValue()); + itemDTO.setDescription(po.getDescription()); + + group.getItems().add(itemDTO); + } + Collection<OsEnumPO> newPOList = groupPOMap.values(); + //鏁版嵁搴撴煡璇㈡槸鍚︽湁宸插瓨鍦ㄧ殑鏋氫妇鍚嶏紝鏂逛究鍚庣画鍋氬垽閲嶅鐞� + List<OsEnumVO> osEnumVOList = this.listEnumByIdCollection(poList.stream().map(OsEnumPO::getId).collect(Collectors.toSet())); + List<String> repeatEnumId = new ArrayList<>(); + if(Func.isNotEmpty(osEnumVOList)){ + repeatEnumId = osEnumVOList.stream().map(OsEnumVO::getId).collect(Collectors.toList()); + } + //褰撳墠excel涓槸鍚﹂噸澶嶇敤鐨勫垽閲峂ap:锛坘ey锛氬垽閲嶅睘鎬э紝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()+"銆戣锛宔numnameerror"); + }else if(Func.isBlank(osEnumPO.getEnumValueDataType())){ + throw new VciBaseException("绗��"+osEnumPO.getRowIndex()+"銆戣锛宼ypeerror"); + }else if(Func.isEmpty(osEnumPO.getLength())){ + throw new VciBaseException("绗��"+osEnumPO.getRowIndex()+"銆戣锛宭engtherror"); + }else if(!osEnumPO.getId().matches("^[A-Za-z]+$")){ + throw new VciBaseException("绗��"+osEnumPO.getRowIndex()+"銆戣鏁版嵁锛屾灇涓惧悕绉板彧鑳戒负鑻辨枃瀛楁瘝"); + }else if(excelReapeat.containsKey(osEnumPO.getId())){//鏋氫妇鍚嶈〃鏍间腑鍒ら噸 + throw new VciBaseException("绗��"+excelReapeat.get(osEnumPO.getId())+"銆戣鍜岀銆�"+osEnumPO.getRowIndex()+"銆戣鏁版嵁锛屾灇涓惧悕閲嶅"); + }else if (Func.isNotEmpty(finalRepeatEnumId) && finalRepeatEnumId.contains(osEnumPO.getId())){//2銆佸垽鏂灇涓惧悕鏄惁涓庣郴缁熶腑閲嶅 + throw new VciBaseException("绗��"+osEnumPO.getRowIndex()+"銆戣锛屾灇涓惧悕鍦ㄧ郴缁熶腑宸茬粡瀛樺湪,璇蜂慨鏀�!"); + } + //鍏堝鏋氫妇鍚峞xcel涓渶瑕佸垽閲嶅鐞� + excelReapeat.put(osEnumPO.getId(),osEnumPO.getRowIndex()); + }); + //淇濆瓨閫昏緫 + for (OsEnumPO osEnumPO : newPOList) { + OsEnumDTO osEnumDTO = new OsEnumDTO(); + //鐢熸垚瀛樺偍鐨凞TO瀵硅薄 + osEnumDTO.setId(osEnumPO.getId()); + osEnumDTO.setName(osEnumPO.getName()); + osEnumDTO.setEnumValueDataType(osEnumPO.getEnumValueDataType()); + osEnumDTO.setLength(osEnumPO.getLength()); + osEnumDTO.setItems(osEnumPO.getItems()); + + //璋冪敤鏂板鏋氫妇鏂规硶 + boolean addBoolean = this.addEnumType(osEnumDTO); + if(!addBoolean){ + throw new PLException("500",new String[]{"淇濆瓨鏋氫妇鍚嶄负銆�" + osEnumDTO.getId() + "銆戠殑鏁版嵁鏃跺嚭鐜伴敊璇�!"}); + } + } + }catch (Exception e){ + if(logger.isErrorEnabled()){ + logger.error("璇诲彇excel鍐呭鏃舵垨淇濆瓨鏋氫妇鏃跺嚭鐜颁簡閿欒锛屽叿浣撳師鍥狅細",VciBaseUtil.getExceptionMessage(e)); + } + e.printStackTrace(); + return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e); + } + return BaseResult.success("鏋氫妇瀵煎叆鎴愬姛锛�"); + } + + /** + * 鑾峰彇瀵煎叆妯℃澘鐨勭ず渚嬫暟鎹� + * @return + */ + private List<OsEnumVO> getExportEnumTempExample(){ + 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; + } + + /** + * 鏋氫妇椤规牎楠� + * @param osEnumDTO + * @return 鏍¢獙澶辫触鐩存帴鎶涘嚭寮傚父锛屽惁鍒欎笉浼氬仛浠讳綍杩斿洖 + */ + private void checkOsEnumItem(OsEnumDTO osEnumDTO) throws PLException { + List<OsEnumItemDTO> items = osEnumDTO.getItems(); + if (Func.isNotEmpty(items)) { + //鑾峰彇姝e垯锛屼富瑕佹槸閽堝Integer绫诲瀷鐨勬椂鍊� + String regular = "Integer".equals(osEnumDTO.getEnumValueDataType()) ? "^-?\\d+$" : ""; + //鍒╃敤set鐨刟dd杩斿洖鍊艰繘琛宯ame鍒ら噸 + Set<String> uniqueNames = new HashSet<>(); + for (OsEnumItemDTO item : items) { + // 鍒ゆ柇name灞炴�ф槸鍚︽湁閲嶅鐨勫�� + if (!uniqueNames.add(item.getName())) { + throw new PLException("500", new String[] {"浠ヤ笅鏋氫妇椤瑰悕绉�: 銆�" + item.getName()+ "銆戦噸澶嶏紝璇蜂慨鏀规灇涓鹃」鍚嶅悗閲嶈瘯!"}); + } + //鍒ゆ柇鏋氫妇鍊兼槸鍚﹁秴杩囪瀹氶暱搴� + if (item.getValue().length() > osEnumDTO.getLength()) { + throw new PLException("500", new String[] {"鏋氫妇椤瑰悕绉颁负锛氥��" + item.getName() + "銆戠殑鏋氫妇鍊奸暱搴︼紝瓒呰繃闄愬畾闀垮害銆�" + osEnumDTO.getLength() + "銆�"}); + } + //鏋氫妇绫诲瀷姝e垯鏍¢獙 + if(Func.isNotBlank(regular) && !item.getValue().matches(regular)){ + throw new PLException("500", new String[] { "鏋氫妇鍊煎彧鑳戒负銆�" + + ("String".equals(osEnumDTO.getEnumValueDataType()) ? "瀛楃涓�":"鏁村瀷") + "銆戠被鍨�!"}); + } + } + } + } + + /** + * 鏂板钩鍙版灇涓綝TO瀵硅薄杞钩鍙癊numType瀵硅薄 + * @param osEnumDTO + * @return + */ + private EnumType osEnumDTO2EnumType(OsEnumDTO osEnumDTO){ + EnumType enumType = new EnumType(); + //enumType.oid = osEnumDTO.getOid(); + //鏋氫妇鍚嶇粺涓�杞垚灏忓啓锛岄伩鍏嶅悗鏈熷嚭鐜板叾浠栭棶棰� + enumType.name = osEnumDTO.getId().toLowerCase(Locale.ROOT); + enumType.label = osEnumDTO.getName(); + enumType.length = osEnumDTO.getLength(); + enumType.creator = osEnumDTO.getCreator(); + enumType.ts = Func.format((Func.isNotEmpty(osEnumDTO.getTs()) ? osEnumDTO.getTs():new Date()),VciDateUtil.DateTimeMillFormat); + enumType.createTime = Func.isNotEmpty(osEnumDTO.getCreateTime()) ? osEnumDTO.getCreateTime().getTime():System.currentTimeMillis(); + enumType.modifier = osEnumDTO.getLastModifier(); + enumType.modifyTime = System.currentTimeMillis(); + enumType.type = osEnumDTO.getEnumValueDataType(); + //澶勭悊鏋氫妇椤� + List<EnumItem> enumItems = new ArrayList<>(); + List<OsEnumItemDTO> items = osEnumDTO.getItems(); + if(Func.isNotEmpty(items)){ + items.stream().forEach(item->{ + EnumItem enumItem = new EnumItem(); + enumItem.name = item.getName(); + enumItem.value = item.getValue(); + enumItem.description = item.getDescription(); + enumItems.add(enumItem); + }); + } + enumType.items = enumItems.toArray(new EnumItem[enumItems.size()]); + return enumType; + } + + /** * 鏌ヨ鎵�鏈夌殑鏋氫妇鏄犲皠 * * @return key鏄灇涓剧殑鑻辨枃鍚嶇О @@ -246,43 +757,45 @@ /** * 鏋氫妇鐨勬暟鎹璞¤浆鎹负鏄剧ず瀵硅薄 * - * @param enumItem 鏁版嵁瀵硅薄 + * @param enumType 鏁版嵁瀵硅薄 * @return 鏄剧ず瀵硅薄 */ @Override - public OsEnumVO enumDO2VO(EnumType enumItem) { + public OsEnumVO enumDO2VO(EnumType enumType) { OsEnumVO enumVO = new OsEnumVO(); - if(enumItem!=null){ - enumVO.setOid(enumItem.oid); - enumVO.setCreator(enumItem.creator); - enumVO.setLastModifier(enumItem.modifier); - enumVO.setId(enumItem.name); - enumVO.setName(enumItem.label); - enumVO.setEnumValueDataType(enumItem.type); - enumVO.setLength((int) enumItem.length); + if(enumType!=null){ + enumVO.setOid(enumType.oid); + enumVO.setCreator(enumType.creator); + enumVO.setLastModifier(enumType.modifier); + enumVO.setId(enumType.name); + enumVO.setName(enumType.label); + enumVO.setEnumValueDataType(enumType.type); + enumVO.setEnumValueDataTypeText("String".equalsIgnoreCase(enumType.type) ? "瀛楃涓�":"鏁村瀷"); + enumVO.setLength((int) enumType.length); try { - enumVO.setLastModifyTime(new Date(enumItem.createTime)); + enumVO.setLastModifyTime(new Date(enumType.createTime)); } catch (Exception e) { e.printStackTrace(); } try { - enumVO.setCreateTime(new Date(enumItem.createTime)); + enumVO.setCreateTime(new Date(enumType.createTime)); } catch (Exception e) { e.printStackTrace(); } try { - enumVO.setTs(VciDateUtil.str2Date(enumItem.ts,VciDateUtil.DateTimeMillFormat)); + enumVO.setTs(VciDateUtil.str2Date(enumType.ts,VciDateUtil.DateTimeMillFormat)); } catch (Exception e) { e.printStackTrace(); } + //鏋氫妇椤瑰鐞� List<OsEnumItemVO> itemVOS = new ArrayList<>(); Map<String,String> itemVOMap = new HashMap<>(); - if(enumItem.items!=null && enumItem.items.length > 0){ - for(int i = 0 ; i < enumItem.items.length ; i ++){ + if(enumType.items!=null && enumType.items.length > 0){ + for(int i = 0 ; i < enumType.items.length ; i ++){ OsEnumItemVO enumItemVO = new OsEnumItemVO(); - EnumItem enumChild = enumItem.items[i]; - enumItemVO.setId(enumChild.value); + EnumItem enumChild = enumType.items[i]; + enumItemVO.setValue(enumChild.value); enumItemVO.setName(enumChild.name); enumItemVO.setDescription(enumChild.description); itemVOS.add(enumItemVO); @@ -307,7 +820,7 @@ if(!CollectionUtils.isEmpty(enumItemVO)){ enumItemVO.forEach(itemVO->{ KeyValue keyValue = new KeyValue(); - keyValue.setKey(itemVO.getId()); + keyValue.setKey(itemVO.getValue()); keyValue.setValue(itemVO.getName()); keyValueList.add(keyValue); }); @@ -421,7 +934,7 @@ } /** - * 鍙傜収鏋氫妇鐨勪俊鎭� + * 鍙傜収鏋氫妇鐨勪俊鎭� 涓嶅缓璁娇鐢ㄨ繖涓柟娉曪紝鍥犱负鏄痵ql鎷兼帴鍋氱殑鏌ヨ * * @param conditionMap 鏌ヨ鏉′欢 * @param pageHelper 鍒嗛〉 @@ -429,7 +942,7 @@ */ @Override public DataGrid<OsEnumVO> referDataGrid(Map<String, String> conditionMap, PageHelper pageHelper) { - DataGrid<OsEnumVO> dataGrid = queryObjectServiceInfoBySql(conditionMap, pageHelper, "plenum",OsEnumVO.class,null); + DataGrid<OsEnumVO> dataGrid = queryObjectServiceInfoBySql(conditionMap, pageHelper, "plenumtype",OsEnumVO.class,null); return dataGrid; } @@ -454,6 +967,43 @@ return dataGrid; } + /** + * 鏍规嵁鏋氫妇绫诲瀷鏌ヨ鏋氫妇锛氭灇涓惧悕 , 鏋氫妇 + * @param enumType锛歋tring, 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; + } /** * 娓呴櫎缂撳瓨 @@ -462,4 +1012,5 @@ public void clearCache() { } + } -- Gitblit v1.9.3