From 34c25ddf37a3eb8da9efb04efedad089f13efe83 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期三, 24 七月 2024 18:20:27 +0800 Subject: [PATCH] 部门导入调整,按照部门名称/实现层级关系。枚举导入功能接口上传,属性池添加新增、查询、修改、导出、查看应用范围等接口。业务类型、链接类型、枚举类型增加等接口属性是否产生数据检查、根据属性名修改业务类型和连接类型中对应属性方法,以及属性池中需要的一些下拉查询接口。 --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java | 542 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 538 insertions(+), 4 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java index 6f33a37..b2d484d 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java @@ -1,16 +1,33 @@ package com.vci.web.service.impl; +import com.vci.client.common.datatype.VTDouble; +import com.vci.client.common.datatype.VTInteger; +import com.vci.client.common.datatype.VTLong; +import com.vci.client.common.datatype.VTString; +import com.vci.client.mw.ClientSessionUtility; import com.vci.corba.common.PLException; import com.vci.corba.omd.atm.AttributeDef; +import com.vci.dto.OsAttributeDTO; +import com.vci.omd.dataType.VTDataType; +import com.vci.pagemodel.OsEnumItemVO; +import com.vci.pagemodel.OsEnumVO; +import com.vci.pagemodel.OsUsedAttributeVO; +import com.vci.starter.poi.bo.WriteExcelData; +import com.vci.starter.poi.bo.WriteExcelOption; +import com.vci.starter.poi.util.ExcelUtil; import com.vci.starter.web.annotation.log.VciUnLog; import com.vci.starter.web.enumpck.VciFieldTypeEnum; +import com.vci.starter.web.exception.VciBaseException; import com.vci.starter.web.pagemodel.BaseQueryObject; import com.vci.starter.web.pagemodel.DataGrid; -import com.vci.starter.web.util.VciBaseUtil; -import com.vci.starter.web.util.VciDateUtil; +import com.vci.starter.web.util.*; import com.vci.model.OsAttributeDO; import com.vci.pagemodel.OsAttributeVO; +import com.vci.web.properties.UsedNames; import com.vci.web.service.OsAttributeServiceI; +import com.vci.web.service.OsBaseServiceI; +import com.vci.web.service.OsLinkTypeServiceI; +import com.vci.web.util.Func; import com.vci.web.util.PlatformClientUtil; import com.vci.web.util.WebUtil; import org.apache.commons.lang3.StringUtils; @@ -21,7 +38,11 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import javax.swing.*; +import java.awt.*; +import java.io.File; import java.util.*; +import java.util.List; import java.util.stream.Collectors; //import static com.vci.client.omd.attribpool.ui.VTDataTypePanel.*; @@ -52,6 +73,35 @@ @Autowired(required = false) @Lazy private OsAttributeServiceI self; + + /** + * 灞炴�у悕绉版渶澶ч暱搴� + */ + private Integer NAME_MAX_LENGTH = 28; + + /** + * 绯荤粺涓彉閲忛厤缃枃浠朵腑閰嶇疆鐨刱ey + */ + private final String SYSUSEDNAMES = "sysUsedNames"; + + /** + * 鏁版嵁搴撲腑鍏抽敭瀛楅厤缃枃浠朵腑閰嶇疆鐨刱ey + */ + private final String DATABASEUSEDNAMES = "dataBaseUsedNames"; + + /** + * 閾炬帴绫诲瀷鏈嶅姟 + */ + @Autowired(required = false) + @Lazy + private OsLinkTypeServiceI osLinkTypeServiceI; + + /** + * 涓氬姟绫诲瀷鏈嶅姟 + */ + @Autowired(required = false) + @Lazy + private OsBtmServiceImpl osBtmService; /** * 榛樿鐨勫睘鎬� @@ -126,6 +176,26 @@ } /** + * 鏍规嵁澶氫釜灞炴�у悕绉版煡璇㈠睘鎬� + * @param attrNames + * @return + */ + @Override + public List<OsAttributeVO> getByAttributeNames(String[] attrNames) throws PLException { + VciBaseUtil.alertNotNull(attrNames,"灞炴�у悕"); + List<OsAttributeVO> osAttributeVOS = new ArrayList<>(); + for (int i = 0; i < attrNames.length; i++) { + AttributeDef[] attributeDefs = platformClientUtil.getAttributeService().getAttributeDefs(attrNames[i],1,1); + if(Func.isNotEmpty(attributeDefs)){ + Arrays.stream(attributeDefs).forEach(attributeDef -> { + osAttributeVOS.add(attributeDO2VO(attributeDef)); + }); + } + } + return osAttributeVOS; + } + + /** * 灞炴�х殑鏁版嵁瀵硅薄杞崲涓烘樉绀哄璞� * * @param attribItems 鏁版嵁瀵硅薄 @@ -167,6 +237,8 @@ attributeVO.setAttributeDataTypeText(VciFieldTypeEnum.getTextByValue(attribItem.vtDataType)); attributeVO.setDefaultValue(attribItem.defValue); attributeVO.setRange(attribItem.rage); + attributeVO.setOther(attribItem.other); + //澶勭悊鍙傜収鐩稿叧灞炴�� if(StringUtils.isNotBlank(attribItem.other)) { if (isReferAttr(attribItem.other)) { //璇存槑杩欎釜鐨勭‘鏄弬鐓у瓧娈� @@ -364,6 +436,459 @@ } /** + * 娣诲姞鍗曟潯灞炴�� + * @param osAttributeDTO + * @return true鎴愬姛锛宖alse澶辫触 + */ + @Override + public boolean addAttribute(OsAttributeDTO osAttributeDTO) throws PLException { + //鍒ょ┖ + VciBaseUtil.alertNotNull( + osAttributeDTO,"鍒涘缓鐨勫睘鎬у璞�", + osAttributeDTO.getId(),"灞炴�у悕绉�", + osAttributeDTO.getAttributeDataType(),"灞炴�х被鍨�" + ); + //灞炴�ц嫳鏂囧悕绉版牎楠岋紙鍒ょ┖銆佺郴缁熶腑鍒ら噸銆佹槸鍚﹀叧閿瓧銆佹槸鍚﹀悎瑙勭瓑锛� + checkName(osAttributeDTO.getId()); + //妫�鏌ラ粯璁ゅ�间笌灞炴�х被鍨嬫槸鍚﹀尮閰� + checkDefValue(osAttributeDTO); + //dto瀵硅薄杞崲涓哄瓨鍌ㄦ墍闇�瀵硅薄 + AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO); + return platformClientUtil.getAttributeService().addAttributeDef(attributeDef); + } + + /** + * 淇敼鍗曟潯灞炴�� + * @param osAttributeDTO + * @return true鎴愬姛锛宖alse澶辫触 + */ + @Override + public boolean updateAttribute(OsAttributeDTO osAttributeDTO) throws PLException { + //鍒ょ┖ + VciBaseUtil.alertNotNull( + osAttributeDTO,"淇敼鐨勫睘鎬у璞�", + osAttributeDTO.getId(),"灞炴�у悕绉�", + osAttributeDTO.getTs(),"浜嬪姟TS", + osAttributeDTO.getAttributeDataType(),"灞炴�х被鍨�" + ); + + //鍚嶇О涓嶅厑璁镐慨鏀规墍浠ヤ笉鐢ㄦ煡閲� + //浣嗘槸闇�瑕佹鏌ュ睘鎬ф槸鍚﹀瓨鍦� + OsAttributeVO osAttributeVO = getByAttributeNames(new String[]{osAttributeDTO.getId()}).get(0); + if(Func.isEmpty(osAttributeVO) || Func.isBlank(osAttributeVO.getOid())){ + throw new PLException("500",new String[]{"灞炴�у湪绯荤粺涓笉瀛樺湪锛岃鍒锋柊鍚庨噸璇曪紒"}); + } + //妫�鏌ラ粯璁ゅ�间笌灞炴�х被鍨嬫槸鍚﹀尮閰� + checkDefValue(osAttributeDTO); + boolean compatible = isCompatible(osAttributeVO,osAttributeDTO); + boolean hasInstance = hasInstance(osAttributeDTO.getName()); + //浜х敓鏁版嵁, 骞朵笖涓嶅吋瀹� + if(hasInstance && !compatible){ + throw new PLException("500",new String[]{"鏃犳晥鍙樻洿, 涓嶅吋瀹瑰凡浜х敓鐨勬暟鎹紒"}); + } + String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); + osAttributeDTO.setLastModifier(userId); + osAttributeDTO.setCreator(osAttributeVO.getCreator()); + osAttributeDTO.setCreateTime(osAttributeVO.getCreateTime()); + osAttributeDTO.setLastModifyTime(new Date()); + + try { + AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO); + boolean mdSuccess = platformClientUtil.getAttributeService().modifyAttributeDef(attributeDef); + if(!mdSuccess){ + return false; + } + + //灞炴�т慨鏀规垚鍔�,淇敼涓氬姟绫诲瀷, 閾炬帴绫诲瀷涓灞炴�у瓧娈� + boolean alterApBoolean = this.alterAp(attributeDef.name); + if(!alterApBoolean){ + logger.error("灞炴�т慨鏀瑰畬鎴愶紝浣嗗湪璋冩暣涓氬姟绫诲瀷鎴栭摼鎺ョ被鍨嬩腑瀵瑰簲灞炴�у悕鐨勫睘鎬ф椂鍑虹幇閿欒锛�"); + throw new PLException("500",new String[]{"灞炴�т慨鏀瑰畬鎴愶紝浣嗗湪璋冩暣涓氬姟绫诲瀷鎴栭摼鎺ョ被鍨嬩腑瀵瑰簲灞炴�у悕鐨勫睘鎬ф椂鍑虹幇閿欒锛�"}); + } + return true; + } catch (PLException e1) { + e1.printStackTrace(); + } + return false; + } + + /** + * DTO瀵硅薄杞疄闄呭瓨鍌ㄦ墍闇�鐨凙ttributeDef瀵硅薄 + * @param osAttributeDTO + * @return + */ + private AttributeDef osAttributeDTO2AttributeDef(OsAttributeDTO osAttributeDTO) { + AttributeDef attributeDef = new AttributeDef(); + attributeDef.name = osAttributeDTO.getId().toLowerCase().replaceAll(" ", ""); + attributeDef.label = osAttributeDTO.getName(); + attributeDef.description = osAttributeDTO.getDescription(); + attributeDef.vtDataType = (String)osAttributeDTO.getAttributeDataType(); + attributeDef.defValue = Func.isBlank(osAttributeDTO.getDefaultValue()) ? "" : osAttributeDTO.getDefaultValue(); + attributeDef.rage = Func.isBlank(osAttributeDTO.getRange()) ? "" : osAttributeDTO.getRange(); + attributeDef.creator = Func.isBlank(osAttributeDTO.getCreator()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getCreator(); + attributeDef.ts = Func.format((Func.isNotEmpty(osAttributeDTO.getTs()) ? osAttributeDTO.getTs():new Date()),VciDateUtil.DateTimeMillFormat); + attributeDef.createTime = Func.isEmpty(osAttributeDTO.getCreateTime()) ? System.currentTimeMillis():osAttributeDTO.getCreateTime().getTime(); + attributeDef.modifier = Func.isBlank(osAttributeDTO.getLastModifier()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getLastModifier(); + attributeDef.modifyTime = System.currentTimeMillis(); + //other闇�瑕佽嚜琛屽鐞� + StringBuffer sb = new StringBuffer(); + sb.append(ALLOWNULL).append(" = ").append(osAttributeDTO.isNullableFlag() ? "yes" : "no").append(";"); + VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.valueOf(osAttributeDTO.getAttributeDataType()); + String[] otherInfos = attributeDef.other.split(";"); + int length = 0; + if(otherInfos!=null&& otherInfos.length > 0){ + for(String s : otherInfos){ + if(s.contains(LENGTH+" =") || s.contains(LENGTH+"=")){ + length = VciBaseUtil.getInt(s.split("=")[1]); + break; + } + } + } + switch (fieldTypeEnum) { + case VTDouble: + if(osAttributeDTO.getAttrLength() == null){ + osAttributeDTO.setAttrLength(20); + } + if(osAttributeDTO.getPrecisionLength() == null){ + osAttributeDTO.setPrecisionLength(2); + } + sb.append(ACCURACY).append(" = ").append(osAttributeDTO.getPrecisionLength()).append(";"); + sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";"); + + break; + case VTInteger: + if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) { + sb.append(ENUMNAME).append(" = ").append(osAttributeDTO.getEnumId()).append(";"); + } + break; + case VTString: + if (StringUtils.isNotBlank(osAttributeDTO.getBtmTypeId())) { + //鍙傜収 + sb.append(BTM).append(" = ").append(osAttributeDTO.getBtmTypeId()).append(";"); + //閾炬帴绫诲瀷鏆傛椂涓嶆敮鎸� + } + sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";"); + if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) { + sb.append(ENUMNAME).append(" = ").append(osAttributeDTO.getEnumId()).append(";"); + } + break; + default: + //涓嶉渶瑕佸鐞� + break; + } + attributeDef.other = sb.toString(); + if (attributeDef.other.endsWith(";")) { + attributeDef.other = attributeDef.other.substring(0, attributeDef.other.length() - 1); + } + return attributeDef; + } + + /** + * 淇敼灞炴�ф椂, 鍒ゆ柇褰撳墠杈撳叆鐨勫睘鎬ф槸鍚﹁兘鍏煎涔嬪墠鐨勫睘鎬� + * @param osAttributeVO 鏁版嵁搴撲腑瀛樺偍鐨� + * @param osAttributeDTO 淇敼鍚庣殑鍐呭 + * @return + */ + private boolean isCompatible(OsAttributeVO osAttributeVO/*鏁版嵁搴撲腑瀛樺偍鐨�*/,OsAttributeDTO osAttributeDTO/*淇敼鍚庣殑鍐呭*/){ + String dataType = osAttributeVO.getAttributeDataType(); + //String other = osAttributeVO.getOther(); + //String newOther = abItem.other == null ? "" : abItem.other; + String newType = osAttributeDTO.getAttributeDataType(); + if(newType.equals(VTDataType.VTSTRING)){ + if(dataType.equals(VTDataType.VTINTEGER) || dataType.equals(VTDataType.VTLONG)){ + return true; + } + if(dataType.equals(VTDataType.VTSTRING)){ + int length = osAttributeVO.getAttrLength();//Integer.valueOf(getOtherValueByType(other, "length")); + int newLen = osAttributeDTO.getAttrLength();//Integer.valueOf(getOtherValueByType(newOther, "length")); + if(length <= newLen){ + return true; + }else{ + return false; + } + } + } + + if(newType.equals(dataType)){ + return true; + } + + return false; + } + + /** + * 鍒ゆ柇璇ュ睘鎬ф槸鍚﹀凡缁忓湪涓氬姟绫诲瀷涓�, 鎴栬�呴摼鎺ョ被鍨嬩腑浜х敓浜嗘暟鎹� + * @param abName + * @return + */ + private boolean hasInstance(String abName) throws PLException { + return osBtmService.hasInstance(abName) && osLinkTypeServiceI.hasInstance(abName); + } + + /** + * 妫�鏌ュ睘鎬у悕绉版槸鍚︾鍚堣鑼� + * @param attributeName + * @return 娌℃湁杩斿洖鍊硷紝瀛樺湪闂鐩存帴鎶涘嚭閿欒 + */ + private void checkName(String attributeName) throws PLException { + if(attributeName.equals("")){ + throw new PLException("500",new String[]{"娉ㄦ剰,灞炴�у悕涓嶈兘涓虹┖!"}); + } + + if(!attributeName.matches("[a-z A-Z]*")){ + throw new PLException("500",new String[]{"娉ㄦ剰锛氬睘鎬у悕鍙兘涓鸿嫳鏂囧瓧姣�!"+ NAME_MAX_LENGTH}); + } + + int length = attributeName.length(); + if(length > NAME_MAX_LENGTH){ + throw new PLException("500",new String[]{"灞炴�у悕杩囬暱,灞炴�у悕闀垮害涓嶈兘瓒呰繃!"+ NAME_MAX_LENGTH}); + } + + String abName = attributeName.toLowerCase(); + //妫�鏌ュ睘鎬у悕鏄惁鏄负绯荤粺鍩虹灞炴�э紝濡俢reateTime,ts,oid绛� + if(usedBySystem(abName)){ + throw new PLException("500",new String[]{"灞炴�у悕鏃犳晥,鍘熷洜锛氬睘鎬у悕宸茶绯荤粺灞炴�т娇鐢�!"}); + } + //妫�鏌ュ睘鎬у悕鏄惁鏄叧閿瓧 + if(usedByDataBase(abName)){ + throw new PLException("500",new String[]{"灞炴�у悕鏃犳晥,鍘熷洜锛氬睘鎬у悕鏄暟鎹簱鍏抽敭瀛�!"}); + } + //妫�鏌ュ睘鎬у悕鏄惁宸插瓨鍦ㄤ笌绯荤粺涓� + if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){ + throw new PLException("500",new String[]{"灞炴�у悕绉板湪绯荤粺涓凡瀛樺湪!"}); + } + } + + /** + * 妫�鏌ラ粯璁ゅ�间笌灞炴�х被鍨嬫槸鍚﹀尮閰� + * @param osAttributeDTO + * @return + */ + private void checkDefValue(OsAttributeDTO osAttributeDTO) throws PLException { + String defValue = osAttributeDTO.getDefaultValue(); + String vtType = osAttributeDTO.getAttributeDataType(); + String rages = osAttributeDTO.getRange(); + if(defValue != null && !defValue.equals("")){ + if(vtType.equals(VTDataType.VTSTRING)){ + try{ + String.valueOf(defValue); + }catch(Exception e){ + throw new PLException("500",new String[]{"璇疯緭鍏tring绫诲瀷鐨勯粯璁ゅ�硷紒"}); + } + if(rages == null || rages.equals("")){ + return; + } + VTString obj = new VTString(String.valueOf(defValue)); + boolean flag = obj.checkRageValueByRage(rages); + if(!flag){ + throw new PLException("500",new String[]{"榛樿鍊间笌鍊煎煙鍐茬獊锛�"}); + } + }else if(vtType.equals(VTDataType.VTINTEGER)){ + try{ + Integer.valueOf(defValue); + }catch(Exception e){ + throw new PLException("500",new String[]{"璇疯緭鍏nteger绫诲瀷鐨勯粯璁ゅ�硷紒"}); + } + if(rages == null || rages.equals("")){ + return; + } + + VTInteger obj = new VTInteger(Integer.valueOf(defValue)); + boolean flag = obj.checkRageValueByRage(rages); + if(!flag){ + throw new PLException("500",new String[]{"榛樿鍊间笌鍊煎煙鍐茬獊锛�"}); + } + }else if(vtType.equals(VTDataType.VTLONG)){ + try{ + Long.valueOf(defValue); + }catch(Exception e){ + throw new PLException("500",new String[]{"璇疯緭鍏ong绫诲瀷鐨勯粯璁ゅ�硷紒"}); + } + if(rages == null || rages.equals("")){ + return; + } + + VTLong obj = new VTLong(Long.valueOf(defValue)); + boolean flag = obj.checkRageValueByRage(rages); + if(!flag){ + throw new PLException("500",new String[]{"榛樿鍊间笌鍊煎煙鍐茬獊锛�"}); + } + }else if(vtType.equals(VTDataType.VTDOUBLE)){ + try{ + Double.valueOf(defValue); + }catch(Exception e){ + throw new PLException("500",new String[]{"璇疯緭鍏ouble绫诲瀷鐨勯粯璁ゅ�硷紒"}); + } + if(rages == null || rages.equals("")){ + return; + } + VTDouble obj = new VTDouble(Double.valueOf(defValue)); + boolean flag = obj.checkRageValueByRage(rages); + if(!flag){ + throw new PLException("500",new String[]{"榛樿鍊间笌鍊煎煙鍐茬獊锛�"}); + } + + } + } + } + + /** + * 妫�鏌ヨ灞炴�у悕鏄惁琚郴缁熷睘鎬т娇鐢� + * @param abName + * @return + */ + private boolean usedBySystem(String abName) { + boolean flag = false; + String[] names = UsedNames.getProperty(SYSUSEDNAMES).toUpperCase().split(","); + List<String> nameList = Arrays.asList(names); + if(nameList.contains(abName.toUpperCase())){ + flag = true; + } + return flag; + } + + /** + * 妫�鏌ヨ灞炴�у悕鏄惁灞炰簬鏁版嵁搴撳叧閿瓧 + * @param abName + * @return + */ + private boolean usedByDataBase(String abName){ + boolean flag = false; + String[] names = UsedNames.getProperty(DATABASEUSEDNAMES).toUpperCase().split(","); + List<String> nameList = Arrays.asList(names); + if(nameList.contains(abName.toUpperCase())){ + flag = true; + } + return flag; + } + + /** + * 鍒犻櫎灞炴�� + * @param osAttributeDTOS + * @return true鎴愬姛锛宖alse澶辫触 + */ + @Override + public boolean deleteAttributes(List<OsAttributeDTO> osAttributeDTOS) throws PLException { + VciBaseUtil.alertNotNull(osAttributeDTOS,"寰呭垹闄ょ殑灞炴�у垪琛�"); + //骞冲彴鐨刣eleteEnumTypes鏂规硶蹇呬紶涓変釜鍙傛暟锛宱id銆乶ame鍜宼s + List<AttributeDef> attributeDefs = new ArrayList<>(); + for(OsAttributeDTO osAttributeDTO : osAttributeDTOS){ + //oid鍜宼s鍒ょ┖ + String oid = osAttributeDTO.getOid(); + //name涓昏鐢ㄦ潵瀵圭紦瀛樻暟鎹垹闄� + String name = osAttributeDTO.getName(); + Date ts = osAttributeDTO.getTs(); + if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){ + throw new PLException("500",new String[]{"寰呭垹闄ょ殑灞炴�у垪琛ㄤ腑涓婚敭銆恛id銆戙�佽皟鏁存椂闂淬�恡s銆戙�佸睘鎬у悕銆恘ame銆戜笉鑳戒负绌猴紒"}); + } + //鍒ゆ柇鏋氫妇鏄惁鏈夎寮曠敤 + List<Map<String, String>> usedAttrList = this.getUsedAttributeList(name); + if(Func.isNotEmpty(usedAttrList)){ + throw new PLException("500",new String[]{"鍒犻櫎鐨勫睘鎬т腑锛屽睘鎬у悕绉颁负锛氥��" + name + "銆�,宸茶寮曠敤锛�"}); + } + AttributeDef attributeDef = new AttributeDef(); + attributeDef.oid = oid; + attributeDef.name = name; + attributeDef.ts = Func.format(ts,VciDateUtil.DateTimeMillFormat); + attributeDefs.add(attributeDef); + } + if(Func.isEmpty(attributeDefs)){ + return false; + } + return platformClientUtil.getAttributeService().deleteAttributeDefs(attributeDefs.toArray(new AttributeDef[attributeDefs.size()])); + } + + /** + * 鏌ョ湅灞炴�х殑浣跨敤鑼冨洿 + * @param attributeName + * @return key:灞炴�� 锛寁alue浣跨敤璇ュ睘鎬х殑涓氬姟绫诲瀷 + */ + @Override + public List<Map<String, String>> getUsedAttributeList(String attributeName) throws PLException { + if(Func.isBlank(attributeName)){ + throw new PLException("500",new String[]{"璇烽�夋嫨瑕佹煡璇㈠簲鐢ㄨ寖鍥寸殑灞炴��!"}); + } + String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(attributeName); + if(Func.isEmpty(btNames)){ + return new ArrayList<>(); + } + List<Map<String,String>> btmNameMapList = new ArrayList<>(); + Arrays.stream(btNames).forEach(btName->{ + Map<String, String> itemMap = new HashMap<>(); + itemMap.put("attributeName",attributeName); + itemMap.put("source",btName); + btmNameMapList.add(itemMap); + }); + return btmNameMapList; + } + + /** + * 瀵煎嚭閫変腑鐨勫睘鎬� + * @param exportFileName 瀵煎嚭鐨勬枃浠跺悕 + * @param attrNames 闇�瑕佸鍑虹殑灞炴�у悕绉� + * @return + */ + @Override + public String exportAttributes(String exportFileName, String attrNames) throws PLException { + if(Func.isBlank(attrNames)){ + 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("灞炴�у悕", "鏍囩", "鎻忚堪", + "灞炴�х被鍨�", "鍏佽涓虹┖", "榛樿鍊�", "浣跨敤鐨勬灇涓捐嫳鏂囧悕绉�(鏋氫妇鍚�)", + "浣跨敤鐨勬灇涓句腑鏂囧悕绉�(鏍囩)", "鍙傜収鐨勪笟鍔$被鍨嬬紪鍙�", "鍙傜収鐨勪笟鍔$被鍨嬪悕绉�", + "灞炴�ч暱搴�", "灏忔暟绮惧害浣嶆暟","灏忔暟鍒诲害浣嶆暟","鍙栧�艰寖鍥�","鍒涘缓鏃堕棿") + ); + + //鍐檈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(attrNames); + List<OsAttributeVO> osAttributeVOS = this.listAttrByIds(enumNameList); + if(Func.isEmpty(osAttributeVOS)){ + excelDataList.add(new WriteExcelData(1,1, "鏍规嵁灞炴�у悕绉版湭鏌ヨ鍒板睘鎬т俊鎭紝璇峰埛鏂板悗灏濊瘯閲嶆柊瀵煎嚭锛�")); + }else{ + //鍏堟寜鐓у睘鎬х被鍨嬫帓搴忥紝涓嶅悓灞炴�х被鍨嬪鍑虹殑鏁版嵁涔辩殑鏁堟灉 + osAttributeVOS.sort(Comparator.comparing(OsAttributeVO::getAttributeDataType)); + for (int i = 0; i < osAttributeVOS.size(); i++) { + OsAttributeVO osAttributeVO = osAttributeVOS.get(i); + excelDataList.add(new WriteExcelData(i+1,0, osAttributeVO.getId())); + excelDataList.add(new WriteExcelData(i+1,1, osAttributeVO.getName())); + excelDataList.add(new WriteExcelData(i+1,2, osAttributeVO.getDescription())); + excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataTypeText()+(osAttributeVO.getAttributeDataType()))); + excelDataList.add(new WriteExcelData(i+1,4, osAttributeVO.isNullableFlag())); + excelDataList.add(new WriteExcelData(i+1,5, osAttributeVO.getDefaultValue())); + excelDataList.add(new WriteExcelData(i+1,6, osAttributeVO.getEnumId())); + excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getEnumName())); + excelDataList.add(new WriteExcelData(i+1,8, osAttributeVO.getBtmTypeId())); + excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getBtmTypeName())); + excelDataList.add(new WriteExcelData(i+1,10, osAttributeVO.getAttrLength())); + excelDataList.add(new WriteExcelData(i+1,11, osAttributeVO.getPrecisionLength())); + excelDataList.add(new WriteExcelData(i+1,12, osAttributeVO.getScaleLength())); + excelDataList.add(new WriteExcelData(i+1,13, osAttributeVO.getRange())); + excelDataList.add(new WriteExcelData(i+1,14, osAttributeVO.getCreateTime())); + } + } + WriteExcelOption excelOption = new WriteExcelOption(excelDataList); + ExcelUtil.writeDataToFile(excelPath, excelOption); + return excelPath; + } + + /** * 鏄惁榛樿鐨勫睘鎬� * * @param attr 灞炴�х紪鍙� @@ -396,7 +921,6 @@ return false; } - /** * 鏄惁涓烘灇涓剧殑灞炴�� * @param other 閰嶇疆鐨勫唴瀹� @@ -416,7 +940,6 @@ return false; } - /** * 娓呴櫎缂撳瓨 */ @@ -424,4 +947,15 @@ public void clearCache() { } + + /** + * 璋冪敤淇敼涓氬姟绫诲瀷鍜岃繛鎺ョ被鍨嬩腑瀵瑰簲灞炴�у悕鐨勫睘鎬� + * @param apName + * @return + * @throws PLException + */ + private boolean alterAp(String apName) throws PLException { + return osBtmService.alterAp(apName) && osLinkTypeServiceI.alterAp(apName); + } + } -- Gitblit v1.9.3