From d0ae279ff3b83358d1c07f4481a041c4ad335026 Mon Sep 17 00:00:00 2001
From: dangsn <dangsn@chicecm.com>
Date: 星期二, 03 十二月 2024 11:57:38 +0800
Subject: [PATCH] 提取业务系统使用的功能,独立出一个单独的模块

---
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java |  271 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 239 insertions(+), 32 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 3af2c48..7045ac8 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
@@ -4,19 +4,17 @@
 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.common.utility.ObjectUtility;
 import com.vci.corba.common.PLException;
 import com.vci.corba.omd.atm.AttributeDef;
-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.enumpck.UI.ItemTypeEnum;
+import com.vci.model.OsAttributeDO;
 import com.vci.omd.dataType.VTDataType;
-import com.vci.pagemodel.OsEnumItemVO;
+import com.vci.omd.objects.OtherInfo;
+import com.vci.pagemodel.OsAttributeVO;
 import com.vci.pagemodel.OsEnumVO;
-import com.vci.pagemodel.OsUsedAttributeVO;
 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;
@@ -25,18 +23,14 @@
 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.BaseResult;
-import com.vci.starter.web.pagemodel.DataGrid;
+import com.vci.starter.web.pagemodel.*;
 import com.vci.starter.web.util.*;
-import com.vci.model.OsAttributeDO;
-import com.vci.pagemodel.OsAttributeVO;
+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.starter.web.util.Lcm.Func;
 import com.vci.web.util.PlatformClientUtil;
 import com.vci.web.util.WebUtil;
 import org.apache.commons.lang3.StringUtils;
@@ -47,16 +41,12 @@
 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 java.util.stream.Stream;
 
-//import static com.vci.client.omd.attribpool.ui.VTDataTypePanel.*;
 import static com.vci.omd.constants.AttributeConstants.*;
 
 /**
@@ -135,6 +125,100 @@
 	 * 榛樿灞炴�х殑鏄犲皠锛宬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);
+			}
+		}
+	}
 
 	/**
 	 * 鑾峰彇榛樿鐨勫睘鎬�
@@ -247,13 +331,20 @@
 				attributeVO.setLastModifyTime(new Date(attribItem.modifyTime));
 				attributeVO.setTs(VciDateUtil.str2Date(attribItem.ts,VciDateUtil.DateTimeMillFormat));
 			}catch (Throwable e){
-
+				e.printStackTrace();
+				String errorLog = "灞炴�O杞琕O鏃跺嚭閿欙紝鍘熷洜锛�"+VciBaseUtil.getExceptionMessage(e);
+				logger.error(errorLog);
+				throw new VciBaseException(errorLog);
 			}
 			attributeVO.setLastModifier(attribItem.modifier);
 			attributeVO.setName(attribItem.label);
 			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);
 			if(Func.isNotBlank(attribItem.rage)){
 				attributeVO.setRange(attribItem.rage.replace("&lt;","<"));
@@ -419,6 +510,32 @@
 	}
 
 	/**
+	 * 浣跨敤灞炴�х紪鍙疯幏鍙栧璞�--鎵归噺
+	 *
+	 * @param attrCodes 灞炴�х殑鑻辨枃鍚嶇О
+	 * @param attributeVOMap 灞炴�у璞�
+	 * @return 灞炴�х殑鏄剧ず瀵硅薄
+	 */
+	@Override
+	public List<OsAttributeVO> listAttrByIds(Collection<String> attrCodes,Map<String, OsAttributeVO> attributeVOMap) {
+		if(CollectionUtils.isEmpty(attrCodes)){
+			return null;
+		}
+		if(attributeVOMap == null){
+			attributeVOMap = self.selectAllAttributeMap();
+		}
+		List<OsAttributeVO> attributeVOS = new ArrayList<>();
+		Map<String, OsAttributeVO> finalAttributeVOMap = attributeVOMap;
+		attrCodes.stream().forEach(attrCode->{
+			OsAttributeVO attributeVO = finalAttributeVOMap.getOrDefault(attrCode.toLowerCase(),null);
+			if(attributeVO!=null){
+				attributeVOS.add(attributeVO);
+			}
+		});
+		return attributeVOS;
+	}
+
+	/**
 	 * 鎵归噺娣诲姞灞炴��
 	 *
 	 * @param attribItemList 灞炴�х殑鍒楄〃
@@ -479,6 +596,10 @@
 		);
 		//灞炴�ц嫳鏂囧悕绉版牎楠岋紙鍒ょ┖銆佺郴缁熶腑鍒ら噸銆佹槸鍚﹀叧閿瓧銆佹槸鍚﹀悎瑙勭瓑锛�
 		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));
@@ -510,9 +631,10 @@
 		//妫�鏌ラ粯璁ゅ�间笌灞炴�х被鍨嬫槸鍚﹀尮閰�
 		checkDefValue(osAttributeDTO);
 		boolean compatible = isCompatible(osAttributeVO,osAttributeDTO);
-		boolean hasInstance = hasInstance(osAttributeDTO.getName());
-		//浜х敓鏁版嵁, 骞朵笖涓嶅吋瀹�
-		if(hasInstance && !compatible){
+		//boolean hasInstance = hasInstance(osAttributeDTO.getId()); //涓嶅垽鏂槸鍚︿骇鐢熸暟鎹彧瑕佽寮曠敤灏遍渶瑕佽繘涓�姝ュ垽鏂被鍨嬫槸鍚﹀吋瀹�
+		boolean checkAttrIsUse = this.checkAttrIsUse(osAttributeDTO.getId());
+		//TODO锛氭寜鐓т互鍓嶆搷浣滈厤缃枃妗d腑鐨勯�昏緫搴旇鏄細涓嶈鏄惁浜х敓鏁版嵁鍙琚紩鐢ㄥ氨闇�瑕佽鍒ゆ柇绫诲瀷鏄惁鍏煎锛堝VTString涓嶈兘杞负VTIntger鎴朧TLong锛�
+		if(checkAttrIsUse/*hasInstance*/ && !compatible){
 			throw new PLException("500",new String[]{"鏃犳晥鍙樻洿, 涓嶅吋瀹瑰凡浜х敓鐨勬暟鎹紒"});
 		}
 		String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
@@ -665,6 +787,26 @@
 	}
 
 	/**
+	 * 鏌ョ湅灞炴�ф槸鍚﹁寮曠敤
+	 * @param abName
+	 * @return false鏈寮曠敤 true琚紩鐢�
+	 */
+	private boolean checkAttrIsUse(String abName) throws PLException {
+		if(Func.isBlank(abName)){
+			return false;
+		}
+		String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(abName);
+		if(Func.isNotEmpty(btNames)){
+			return true;
+		}
+		String[] ltNames = platformClientUtil.getLinkTypeService().getLTNamesByAPName(abName);
+		if(Func.isNotEmpty(ltNames)){
+			return true;
+		}
+		return false;
+	}
+
+	/**
 	 * 妫�鏌ュ睘鎬у悕绉版槸鍚︾鍚堣鑼�
 	 * @param attributeName
 	 * @return 娌℃湁杩斿洖鍊硷紝瀛樺湪闂鐩存帴鎶涘嚭閿欒
@@ -693,9 +835,9 @@
 			throw new PLException("500",new String[]{"灞炴�у悕鏃犳晥,鍘熷洜锛氬睘鎬у悕鏄暟鎹簱鍏抽敭瀛�!"});
 		}
 		//妫�鏌ュ睘鎬у悕鏄惁宸插瓨鍦ㄤ笌绯荤粺涓�
-		if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){
+		/*if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){
 			throw new PLException("500",new String[]{"灞炴�у悕绉般��" + abName + "銆戝湪绯荤粺涓凡瀛樺湪!"});
-		}
+		}*/
 	}
 
 	/**
@@ -845,11 +987,14 @@
 			throw new PLException("500",new String[]{"璇烽�夋嫨瑕佹煡璇㈠簲鐢ㄨ寖鍥寸殑灞炴��!"});
 		}
 		String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(attributeName);
-		if(Func.isEmpty(btNames)){
+		String[] ltNames = platformClientUtil.getLinkTypeService().getLTNamesByAPName(attributeName);
+		String[] mergedArray = Stream.concat(Stream.of(btNames), Stream.of(ltNames)).toArray(String[]::new);
+
+		if(Func.isEmpty(mergedArray)){
 			return new ArrayList<>();
 		}
 		List<Map<String,String>> btmNameMapList = new ArrayList<>();
-		Arrays.stream(btNames).forEach(btName->{
+		Arrays.stream(mergedArray).forEach(btName->{
 			Map<String, String> itemMap = new HashMap<>();
 			itemMap.put("attributeName",attributeName);
 			itemMap.put("source",btName);
@@ -997,10 +1142,12 @@
 	/**
 	 * 瀵煎叆灞炴��
 	 * @param file
+	 * @param isContinue 绯荤粺涓嚭鐜伴噸澶嶆槸鍚﹁烦杩囨姤閿欑户缁墽琛�
 	 * @return
+	 * @throws Exception
 	 */
 	@Override
-	public BaseResult importAttributes(File file) throws Exception{
+	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()});
@@ -1017,13 +1164,29 @@
 			List<OsAttributeDTO> dtoList = new ArrayList<>();
 			//褰撳墠excel涓槸鍚﹂噸澶嶇敤鐨勫垽閲峂ap:锛坘ey锛氬垽閲嶅睘鎬э紝value锛氳鍙凤級
 			Map<String, String> excelReapeat = new HashMap<>();
-			poList.stream().forEach(osAttributePO -> {
+			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 {
@@ -1051,7 +1214,7 @@
 					}
 					osAttributeDTO.setBtmTypeId(osAttributePO.getEnumId());
 				}
-				osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT));
+				osAttributeDTO.setOid(ObjectUtility.getNewObjectID36());
 				osAttributeDTO.setId(osAttributePO.getId());
 				osAttributeDTO.setName(osAttributePO.getName());
 				osAttributeDTO.setDescription(osAttributePO.getDescription());
@@ -1076,7 +1239,7 @@
 					throw new VciBaseException(VciBaseUtil.getExceptionMessage(e));
 				}
 				dtoList.add(osAttributeDTO);
-			});
+			}
 			//鎵ц淇濆瓨鎿嶄綔
 			dtoList.stream().forEach(dto->{
 				try {
@@ -1091,7 +1254,7 @@
 			});
 		}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);
@@ -1114,6 +1277,50 @@
 	}
 
 	/**
+	 * 鏍规嵁涓氬姟绫诲瀷鑾峰彇灞炴�т俊鎭�
+	 * @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 鏄弬鐓�

--
Gitblit v1.9.3