From c826afb6dbc2c1d4433b3c127c5f30f9f72fb2dc Mon Sep 17 00:00:00 2001 From: xiejun <xiejun@vci-tech.com> Date: 星期一, 09 九月 2024 17:18:37 +0800 Subject: [PATCH] 属性加UI类型字段 --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java | 938 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 924 insertions(+), 14 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 45f22b4..038360c 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,30 +1,62 @@ 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.corba.omd.ltm.LinkType; +import com.vci.corba.omd.vrm.VersionRule; +import com.vci.dto.OsAttributeDTO; +import com.vci.dto.OsEnumDTO; +import com.vci.dto.OsEnumItemDTO; +import com.vci.omd.dataType.VTDataType; +import com.vci.omd.objects.OtherInfo; +import com.vci.pagemodel.*; +import com.vci.po.OsAttributePO; +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.VciFieldTypeEnum; -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.web.model.OsAttributeDO; -import com.vci.web.pageModel.OsAttributeVO; +import com.vci.starter.web.exception.VciBaseException; +import com.vci.starter.web.pagemodel.*; +import com.vci.starter.web.util.*; +import com.vci.model.OsAttributeDO; +import com.vci.web.enumpck.ItemTypeEnum; +import com.vci.web.enumpck.PortalVITypeFlag; +import com.vci.web.properties.UsedNames; import com.vci.web.service.OsAttributeServiceI; +import com.vci.web.service.OsBaseServiceI; +import com.vci.web.service.OsEnumServiceI; +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; +import org.apache.poi.hssf.util.HSSFColor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; +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.*; +//import static com.vci.client.omd.attribpool.ui.VTDataTypePanel.*; +import static com.vci.omd.constants.AttributeConstants.*; /** * 灞炴�ф睜鏈嶅姟 --宸茬粡璋冪敤浜嗗钩鍙扮殑鏈嶅姟锛屽洜姝や笉鍦ㄦ彁渚汥ao灞� @@ -53,6 +85,47 @@ 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; + + /** + * 鏋氫妇鐨勬湇鍔� + */ + @Autowired + @Lazy + private OsEnumServiceI enumService; + + /** + * 蹇呭~鍒� + */ + private List<Integer> ColumnNameisRed = new ArrayList<Integer>(); + + /** * 榛樿鐨勫睘鎬� */ private static List<OsAttributeVO> defaultAttributeVOs = new ArrayList<>(); @@ -61,6 +134,101 @@ * 榛樿灞炴�х殑鏄犲皠锛宬ey鏄皬鍐� */ private static Map<String,OsAttributeVO> defaultAttributeVOMap = new HashMap<>(); + + @Override + public List<Tree> getTreeAttributesByBtmName(TreeQueryObject treeQueryObject) { + List<Tree> rootTreeList=new ArrayList<>(); + + Map<String, String> conditionMap = treeQueryObject.getConditionMap(); + if (conditionMap == null) { + conditionMap = new HashMap<>(); + } + String typeName = StringUtils.isBlank(conditionMap.get("typeName")) ? "" : conditionMap.get("typeName"); + if (StringUtils.isBlank(typeName)) { + VciBaseUtil.alertNotNull(typeName,"涓氬姟绫诲瀷鍚嶇О"); + } + try { + String typeFlag=StringUtils.isBlank(conditionMap.get("typeFlag"))?"":conditionMap.get("typeFlag"); + PortalVITypeFlag portalVITypeFlag= PortalVITypeFlag.getByName(typeFlag); + Short viTypeFlag=-1; + if(portalVITypeFlag!=null){ + viTypeFlag=portalVITypeFlag.getIntVal(); + } + boolean isDefault =Boolean.parseBoolean(conditionMap.get("isDefault")); + Tree tree = new Tree("root", "銆�" + typeName + "銆戝睘鎬т俊鎭�", "root"); + tree.setLevel(0); + rootTreeList.add(tree); + getChildTree(rootTreeList,typeName, viTypeFlag,isDefault); + }catch (Throwable e){ + e.printStackTrace(); + } + return rootTreeList; + } + + /** + * 澶熺潃灞炴�ф爲鑺傜偣 + * @param parentTreeList + * @param refTypeName + * @param refFlag + * @param isDefault + * @throws Exception + */ + private void getChildTree(List<Tree> parentTreeList,String refTypeName,int refFlag,boolean isDefault) throws Exception { + for (Tree pTree : parentTreeList) { + if (pTree.getLevel()>= 3) { + continue; + } + Object o= pTree.getData(); + String pName=pTree.getText(); + boolean isOsAttributeVO=false; + if(o instanceof OsAttributeVO){ + isOsAttributeVO=true; + OsAttributeVO osAttributeVO=(OsAttributeVO)o; + String other = osAttributeVO.getOther(); + OtherInfo otherInfo = OtherInfo.getOtherInfoByText(other); + refFlag = otherInfo.getRefFlag(); + refTypeName = otherInfo.getRefTypeName(); + } + List<OsAttributeVO> childOsAttributeVOList=new ArrayList<>(); + if (refFlag != -1) { + // pName: 涓哄弬鐓у睘鎬у悕鍔犱笂璺緞 + childOsAttributeVOList=getOsAttributeVOSByBtName(refTypeName,refFlag,isDefault); + if(!CollectionUtils.isEmpty(childOsAttributeVOList)) { + List<Tree> childTreeList= new ArrayList<>(); + boolean finalIsOsAttributeVO = isOsAttributeVO; + childOsAttributeVOList.stream().forEach(childOsAttributeVO->{ + Tree childTree = new Tree(childOsAttributeVO.getOid(), childOsAttributeVO.getId(), childOsAttributeVO); + childTree.setOid(childOsAttributeVO.getOid()); + childTree.setParentName(pTree.getText()); + childTree.setParentId(pTree.getOid()); + childTree.setLevel(pTree.getLevel()+1); + childTree.setLeaf(true); + if(finalIsOsAttributeVO) { + childTree.setText(pName + "." + childOsAttributeVO.getId()); + }else{ + childTree.setText(childOsAttributeVO.getId()); + } + if (childTree.getLevel()>= 3) { + childTree.setLeaf(true); + } + childTreeList.add(childTree); + }); + if(childTreeList.size()>0){ + pTree.setChildren(childTreeList); + pTree.setExpanded(false); + getChildTree(childTreeList,refTypeName,refFlag,isDefault); + }else{ + pTree.setLeaf(true); + pTree.setExpanded(true); + } + + } + }else{ + pTree.setExpanded(true); + } + } + + } /** * 鑾峰彇榛樿鐨勫睘鎬� @@ -125,6 +293,22 @@ } /** + * 鏍规嵁澶氫釜灞炴�у悕绉版煡璇㈠睘鎬� + * @param attrNames + * @return + */ + @Override + public List<OsAttributeVO> getByAttributeNames(String[] attrNames) throws PLException { + VciBaseUtil.alertNotNull(attrNames,"灞炴�у悕"); + List<OsAttributeVO> osAttributeVOS = new ArrayList<>(); + AttributeDef[] attributeDefs = platformClientUtil.getAttributeService().getAttributeDefsByNames(attrNames); + Arrays.stream(attributeDefs).forEach(attr->{ + osAttributeVOS.add(attributeDO2VO(attr)); + }); + return osAttributeVOS; + } + + /** * 灞炴�х殑鏁版嵁瀵硅薄杞崲涓烘樉绀哄璞� * * @param attribItems 鏁版嵁瀵硅薄 @@ -153,8 +337,8 @@ attributeVO.setId(attribItem.name); attributeVO.setCreator(attribItem.creator); try { - attributeVO.setCreateTime(VciDateUtil.str2Date(String.valueOf(attribItem.createTime),VciDateUtil.DateTimeFormat)); - attributeVO.setLastModifyTime(VciDateUtil.str2Date(String.valueOf(attribItem.modifyTime),VciDateUtil.DateTimeFormat)); + attributeVO.setCreateTime(new Date(attribItem.createTime)); + attributeVO.setLastModifyTime(new Date(attribItem.modifyTime)); attributeVO.setTs(VciDateUtil.str2Date(attribItem.ts,VciDateUtil.DateTimeMillFormat)); }catch (Throwable e){ @@ -164,8 +348,18 @@ attributeVO.setDescription(attribItem.description); attributeVO.setAttributeDataType(attribItem.vtDataType); attributeVO.setAttributeDataTypeText(VciFieldTypeEnum.getTextByValue(attribItem.vtDataType)); + //鑾峰彇UI灞炴�х被鍨� + attributeVO.setAttributeUIType(ItemTypeEnum.convertAttributeTypeTOUITypeTextByValue(attribItem.vtDataType,false)); + //鑾峰彇UI灞炴�х被鍨嬫枃鏈� + attributeVO.setAttributeUITypeText(ItemTypeEnum.convertAttributeTypeTOUITypeTextByValue(attribItem.vtDataType,true)); attributeVO.setDefaultValue(attribItem.defValue); - attributeVO.setRange(attribItem.rage); + if(Func.isNotBlank(attribItem.rage)){ + attributeVO.setRange(attribItem.rage.replace("<","<")); + }else{ + attributeVO.setRange(attribItem.rage); + } + attributeVO.setOther(attribItem.other); + //澶勭悊鍙傜収鐩稿叧灞炴�� if(StringUtils.isNotBlank(attribItem.other)) { if (isReferAttr(attribItem.other)) { //璇存槑杩欎釜鐨勭‘鏄弬鐓у瓧娈� @@ -175,6 +369,12 @@ attributeVO.setBtmTypeId(s.split("=")[1].trim()); } //閾炬帴绫诲瀷涓嶆敮鎸� + if (s.toLowerCase().contains("link") && s.split("=").length > 1) {//蹇呴』瑕佸垽鏂暱搴︼紝鍥犱负鏋氫妇鐨勬椂鍊欎篃鏄寘鍚繖涓猙tm鐨� + attributeVO.setLinkTypeName(s.split("=")[1].trim()); + } + if (s.toLowerCase().contains("version") && s.split("=").length > 1) {//蹇呴』瑕佸垽鏂暱搴︼紝鍥犱负鏋氫妇鐨勬椂鍊欎篃鏄寘鍚繖涓猙tm鐨� + attributeVO.setVersion(WebUtil.getInt(s.split("=")[1].trim())); + } } } //蹇呰緭鍜岄暱搴� @@ -363,6 +563,663 @@ } /** + * 娣诲姞鍗曟潯灞炴�� + * @param osAttributeDTO + * @return true鎴愬姛锛宖alse澶辫触 + */ + @Override + public boolean addAttribute(OsAttributeDTO osAttributeDTO) throws PLException { + //鍒ょ┖ + VciBaseUtil.alertNotNull( + osAttributeDTO,"鍒涘缓鐨勫睘鎬у璞�", + osAttributeDTO.getId(),"灞炴�у悕绉�", + osAttributeDTO.getAttributeDataType(),"灞炴�х被鍨�" + ); + //灞炴�ц嫳鏂囧悕绉版牎楠岋紙鍒ょ┖銆佺郴缁熶腑鍒ら噸銆佹槸鍚﹀叧閿瓧銆佹槸鍚﹀悎瑙勭瓑锛� + checkName(osAttributeDTO.getId()); + //妫�鏌ュ睘鎬у悕鏄惁宸插瓨鍦ㄤ笌绯荤粺涓� + if(platformClientUtil.getAttributeService().checkRowIsExists(osAttributeDTO.getId())){ + throw new PLException("500",new String[]{"灞炴�у悕绉般��" + osAttributeDTO.getId() + "銆戝湪绯荤粺涓凡瀛樺湪!"}); + } + //妫�鏌ラ粯璁ゅ�间笌灞炴�х被鍨嬫槸鍚﹀尮閰� + checkDefValue(osAttributeDTO); + //osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); + 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.oid = osAttributeDTO.getOid(); + 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(); + if(Func.isBlank(osAttributeDTO.getRange())){ + attributeDef.rage = ""; + }else{ + //鐗规畩瀛楃澶勭悊锛岀洿鎺ュ瓨鍌�<浼氭姤閿� + attributeDef.rage = osAttributeDTO.getRange().replace("<","<"); + } + attributeDef.ts = Func.format((Func.isNotEmpty(osAttributeDTO.getTs()) ? osAttributeDTO.getTs():new Date()),VciDateUtil.DateTimeMillFormat); + attributeDef.creator = Func.isBlank(osAttributeDTO.getCreator()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getCreator(); + 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(";"); + } + if(StringUtils.isNotBlank(osAttributeDTO.getLinkTypeName())){ + //鍙傜収閾炬帴绫诲瀷 + sb.append(LINKTYPENAME).append(" = ").append(osAttributeDTO.getLinkTypeName()).append(";"); + sb.append(VERSION).append(" = ").append(osAttributeDTO.getVersion()).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[]{"娉ㄦ剰锛氬睘鎬у悕鍙兘涓鸿嫳鏂囧瓧姣�!"}); + } + + 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[]{"灞炴�у悕绉般��" + abName + "銆戝湪绯荤粺涓凡瀛樺湪!"}); + }*/ + } + + /** + * 妫�鏌ラ粯璁ゅ�间笌灞炴�х被鍨嬫槸鍚﹀尮閰� + * @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 闇�瑕佸鍑虹殑灞炴�у悕绉� + * @param flag 鎺у埗瀵煎嚭鐨勫垪鍚嶆槸鍚﹀拰瀵煎叆妯℃澘涓�鑷� + * @return + */ + @Override + public String exportAttributes(String exportFileName, String attrNames,boolean flag/*鎺у埗瀵煎嚭鐨勫垪鍚嶆槸鍚﹀拰瀵煎叆妯℃澘涓�鑷�*/) 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 = 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> attrameList = Func.toStrList(attrNames); + List<OsAttributeVO> osAttributeVOS = this.listAttrByIds(attrameList); + 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())); + if(flag){ + excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataType())); + }else{ + excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataType()+"("+osAttributeVO.getAttributeDataTypeText()+")")); + } + 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,7, osAttributeVO.getBtmTypeId())); + //excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getBtmTypeName())); + excelDataList.add(new WriteExcelData(i+1,8, osAttributeVO.getAttrLength())); + excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getLinkTypeName())); + excelDataList.add(new WriteExcelData(i+1,10, osAttributeVO.getVersion())); + 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())); + if(!flag){ + excelDataList.add(new WriteExcelData(i+1,14, Func.format(osAttributeVO.getCreateTime(),"yyyy骞碝M鏈坉d鏃� hh:mm:ss"))); + } + } + } + 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("灞炴�у悕", "鏍囩", "鎻忚堪", + "灞炴�х被鍨�(鍙傜収鏂板鐣岄潰鐨勫睘鎬х被鍨嬪VTString)", "鍏佽涓虹┖(鏄�/鍚�)", "榛樿鍊�", "浣跨敤鐨勬灇涓捐嫳鏂囧悕绉�" + , "鍙傜収鐨勪笟鍔$被鍨嬬紪鍙�","鍙傜収鐨勯摼鎺ョ被鍨嬬紪鍙�","鐗堟湰鐗堟","灞炴�ч暱搴�", "灏忔暟绮惧害浣嶆暟","灏忔暟鍒诲害浣嶆暟" + ,"鍙栧�艰寖鍥�" + ) + ); + } + return new ArrayList<>( + Arrays.asList("灞炴�у悕", "鏍囩", "鎻忚堪", + "灞炴�х被鍨�", "鍏佽涓虹┖", "榛樿鍊�", "浣跨敤鐨勬灇涓捐嫳鏂囧悕绉�(鏋氫妇鍚�)", + "鍙傜収鐨勪笟鍔$被鍨嬬紪鍙�", "鍙傜収鐨勯摼鎺ョ被鍨嬬紪鍙�","鐗堟湰鐗堟","灞炴�ч暱搴�", + "灏忔暟绮惧害浣嶆暟","灏忔暟鍒诲害浣嶆暟","鍙栧�艰寖鍥�","鍒涘缓鏃堕棿") + ); + } + + /** + * 涓嬭浇灞炴�у鍏ユā鏉� + * @param exportFileName + * @return + * @throws PLException + */ + @Override + public String downloadAttributeTemplate(String exportFileName) throws Exception { + //鐣岄潰娌′紶鍚嶇О锛屼娇鐢ㄩ粯璁ゅ鍑哄悕绉� + exportFileName = Func.isBlank(exportFileName) ? "灞炴�ф睜瀵煎叆妯℃澘_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName; + //璁剧疆鍒楀悕 + List<String> columns = this.getCloumns(true); + //璁剧疆蹇呭~鍒� + ColumnNameisRed.clear(); + ColumnNameisRed.add(0); + ColumnNameisRed.add(3); + ColumnNameisRed.add(10); + + //鍐檈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++) { + //鍒ゆ柇鏄惁涓哄繀濉垪锛岀粰蹇呭~鍒楄缃鑹� + 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))); + } + } + WriteExcelOption excelOption = new WriteExcelOption(excelDataList); + ExcelUtil.writeDataToFile(excelPath, excelOption); + return excelPath; + } + + /** + * 瀵煎叆灞炴�� + * @param file + * @param isContinue 绯荤粺涓嚭鐜伴噸澶嶆槸鍚﹁烦杩囨姤閿欑户缁墽琛� + * @return + * @throws Exception + */ + @Override + public BaseResult importAttributes(File file, boolean isContinue) 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<OsAttributePO> poList = ExcelUtil.readDataObjectFromExcel(file, OsAttributePO.class,excelOption,(value, po, fieldName)->{}); + //鍘婚櫎閮芥槸绌虹殑鎯呭喌 + if(CollectionUtils.isEmpty(poList)){ + return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{}); + } + //excel鍒ら噸锛屾暟鎹牎楠岋紝dto瀵硅薄杞崲锛屽瓨鍌ㄥ璞¤浆鎹紝鎵ц淇濆瓨 + List<OsAttributeDTO> dtoList = new ArrayList<>(); + //褰撳墠excel涓槸鍚﹂噸澶嶇敤鐨勫垽閲峂ap:锛坘ey锛氬垽閲嶅睘鎬э紝value锛氳鍙凤級 + Map<String, String> excelReapeat = new HashMap<>(); + for (int i = 0; i < poList.size(); i++) { + OsAttributePO osAttributePO = poList.get(i); + if(Func.isBlank(osAttributePO.getId())){//灞炴�у悕鍒ょ┖ + throw new VciBaseException("绗��"+osAttributePO.getRowIndex()+"銆戣锛宎ttrnameerror"); + }else if(Func.isBlank(osAttributePO.getAttributeDataType())){ + throw new VciBaseException("绗��"+osAttributePO.getRowIndex()+"銆戣锛宼ypeerror"); + }else if(excelReapeat.containsKey(osAttributePO.getId())){//灞炴�у悕琛ㄦ牸涓垽閲� + throw new VciBaseException("绗��"+excelReapeat.get(osAttributePO.getId())+"銆戣鍜岀銆�"+osAttributePO.getRowIndex()+"銆戣鏁版嵁锛屽睘鎬у悕閲嶅"); + }else { + try { + if(platformClientUtil.getAttributeService().checkRowIsExists(osAttributePO.getId())){ + throw new PLException("500",new String[]{"灞炴�у悕绉般��" + osAttributePO.getId() + "銆戝湪绯荤粺涓凡瀛樺湪!"}); + } + } catch (PLException e) { + e.printStackTrace(); + String errorMsg = "涓庣郴缁熶腑灞炴�у悕鏌ラ噸鏃跺嚭鐜伴敊璇�,鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e); + logger.error(errorMsg); + //鏄惁璺宠繃褰撴湡閲嶅鏁版嵁 + if(isContinue){ + continue; + } + throw new VciBaseException(errorMsg); + } + } + //灞炴�у悕鏍¢獙 + try { + checkName(osAttributePO.getId()); + } catch (PLException e) { + e.printStackTrace(); + throw new VciBaseException(VciBaseUtil.getExceptionMessage(e)); + } + //灞炴�у悕excel涓垽閲嶅鐞� + excelReapeat.put(osAttributePO.getId(),osAttributePO.getRowIndex()); + OsAttributeDTO osAttributeDTO = new OsAttributeDTO(); + //鏌ヨ灞炴�ф槸鍚﹀瓨鍦紝濉啓浜嗘灇涓句絾娌″~鍐欏彇鍊艰寖鍥达紝杩欐椂鍊欑洿鎺ヤ娇鐢ㄦ灇涓鹃」鍊间綔涓洪粯璁ょ殑range + if(Func.isNotBlank(osAttributePO.getEnumId()) && Func.isBlank(osAttributePO.getRange())){ + try { + OsEnumVO enumVO = enumService.getEnumTypeById(osAttributePO.getEnumId()); + if(Func.isEmpty(enumVO)){ + throw new VciBaseException("绗��" + osAttributePO.getRowIndex() + "銆戣鏁版嵁,閫氳繃鏋氫妇鍚嶇О銆�" + osAttributePO.getEnumId() + + "銆戞湭鑾峰彇鍒版灇涓句俊鎭�!"); + } + String itemValues = enumVO.getItemMaps().values().stream().collect(Collectors.joining(";")); + osAttributeDTO.setRange(itemValues); + } catch (PLException e) { + e.printStackTrace(); + throw new VciBaseException("鏋氫妇鏌ヨ澶辫触锛屽師鍥狅細"+e.getMessage()); + } + osAttributeDTO.setBtmTypeId(osAttributePO.getEnumId()); + } + osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); + osAttributeDTO.setId(osAttributePO.getId()); + osAttributeDTO.setName(osAttributePO.getName()); + osAttributeDTO.setDescription(osAttributePO.getDescription()); + osAttributeDTO.setDefaultValue(osAttributePO.getDefaultValue()); + osAttributeDTO.setAttrLength(osAttributePO.getAttrLength()); + osAttributeDTO.setAttributeDataType(osAttributePO.getAttributeDataType()); + osAttributeDTO.setBtmTypeId(osAttributePO.getBtmTypeId()); + //osAttributeDTO.setBtmTypeName(osAttributePO.getBtmname()); + osAttributeDTO.setLinkTypeName(osAttributePO.getLinkTypeName()); + osAttributeDTO.setVersion(osAttributePO.getVersion()); + osAttributeDTO.setEnumId(osAttributePO.getEnumId()); + //osAttributeDTO.setEnumName(osAttributePO.getEnumId()); + osAttributeDTO.setPrecisionLength(osAttributePO.getPrecisionLength()); + osAttributeDTO.setScaleLength(osAttributePO.getScaleLength()); + osAttributeDTO.setRange(osAttributePO.getRange()); + osAttributeDTO.setNullableFlag("鏄�".equals(osAttributePO.getNullableFlag()) ? true:false); + try { + //妫�鏌ラ粯璁ゅ�间笌灞炴�х被鍨嬫槸鍚﹀尮閰� + checkDefValue(osAttributeDTO); + } catch (PLException e) { + e.printStackTrace(); + throw new VciBaseException(VciBaseUtil.getExceptionMessage(e)); + } + dtoList.add(osAttributeDTO); + } + //鎵ц淇濆瓨鎿嶄綔 + dtoList.stream().forEach(dto->{ + try { + boolean b = platformClientUtil.getAttributeService().addAttributeDef(osAttributeDTO2AttributeDef(dto)); + if(!b){ + throw new VciBaseException("save and return false"); + } + } catch (PLException e) { + e.printStackTrace(); + throw new VciBaseException("鎵ц淇濆瓨鏃跺嚭鐜伴敊璇紝閿欒灞炴�у璞″悕涓猴細銆�" + dto.getId() + "銆戯紝鍘熷洜锛�"+VciBaseUtil.getExceptionMessage(e)); + } + }); + }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("灞炴�у鍏ユ垚鍔燂紒"); + } + + /** * 鏄惁榛樿鐨勫睘鎬� * * @param attr 灞炴�х紪鍙� @@ -377,24 +1234,67 @@ } /** + * 鏍规嵁涓氬姟绫诲瀷鑾峰彇灞炴�т俊鎭� + * @param btName 涓氬姟绫诲瀷/閾炬帴绫诲瀷 + * @param typeFlag 0:涓氬姟绫诲瀷,1:閾炬帴绫诲瀷 + * @return + */ + @Override + public List<OsAttributeVO> getOsAttributeVOSByBtName(String btName, int typeFlag,boolean isDefault) throws Exception{ + VciBaseUtil.alertNotNull(btName,"鍙傛暟涓嶅厑璁镐负绌�",typeFlag,"鍙傛暟涓嶅厑璁镐负绌�"); + List<OsAttributeVO> attributeVOS=new ArrayList<>(); + + try { + List<AttributeDef> attributeDefList=new ArrayList<>(); + if(typeFlag==0){ + AttributeDef [] attributeDefs= platformClientUtil.getBtmService().getAttributeDefs(btName); + if(attributeDefs!=null){ + attributeDefList.addAll(Arrays.stream(attributeDefs).collect(Collectors.toList())); + } + if(isDefault){ + AttributeDef [] sysAttributeDefs=platformClientUtil.getBtmService().getSysAttributeDefs(); + if(sysAttributeDefs!=null){ + attributeDefList.addAll(Arrays.stream(sysAttributeDefs).collect(Collectors.toList())); + } + } + }else{ + AttributeDef [] attributeDefs=platformClientUtil.getLinkTypeService().getAttributes(btName); + if(attributeDefs!=null){ + attributeDefList.addAll(Arrays.stream(attributeDefs).collect(Collectors.toList())); + } + if(isDefault){ + AttributeDef[] sysAbItems = platformClientUtil.getLinkTypeService().getSysAttributeDefs(); + if(sysAbItems!=null){ + attributeDefList.addAll(Arrays.stream(sysAbItems).collect(Collectors.toList())); + } + } + } + attributeVOS=attributeDO2VOs(attributeDefList); + }catch (PLException e){ + throw new Exception("鏍规嵁涓氬姟绫诲瀷鑾峰彇灞炴�у紓甯�"+e.getMessage()); + } + + return attributeVOS; + } + + /** * 鏄惁涓哄弬鐓у睘鎬� * @param other 閰嶇疆鐨勫叾浠� * @return true 鏄弬鐓� */ private boolean isReferAttr(String other){ if(StringUtils.isNotBlank(other) - && (other.toLowerCase().contains("btm") || other.toLowerCase().contains("ltm"))){ + && (other.toLowerCase().contains("btm") || other.toLowerCase().contains("link"))){ //杩樹笉鑳界‘瀹氾紝鍥犱负鏋氫妇鐨勬椂鍊欎篃浼氳缃産tm String[] temp = other.split(";"); for(String s : temp){ - if((s.contains("btm") || s.contains("ltm")) && s.split("=").length>1){ + if((s.contains("btm") || s.contains("link")) && s.split("=").length>1){ return true; } } } return false; } - /** * 鏄惁涓烘灇涓剧殑灞炴�� @@ -415,7 +1315,6 @@ return false; } - /** * 娓呴櫎缂撳瓨 */ @@ -423,4 +1322,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