From eee70eddb1464593aa08a0b108e4a1af01ce8a2f Mon Sep 17 00:00:00 2001
From: xiejun <xiejun@vci-tech.com>
Date: 星期一, 02 九月 2024 15:11:35 +0800
Subject: [PATCH] 属性树添加(包括参照)

---
 Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/pagemodel/Tree.java         |   41 ++++++++++
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java  |    4 
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsAttributeServiceI.java         |   13 ++-
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsAttributeController.java    |   24 ++++++
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java |  136 +++++++++++++++++++++++++++++++---
 5 files changed, 199 insertions(+), 19 deletions(-)

diff --git a/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/pagemodel/Tree.java b/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/pagemodel/Tree.java
index 53a3ae6..809dc3b 100644
--- a/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/pagemodel/Tree.java
+++ b/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/pagemodel/Tree.java
@@ -36,7 +36,19 @@
 		setOid(oid);
 		setText(text);
 	}
-	
+
+	/**
+	 * 鏋勯�犲嚱鏁�
+	 * @param oid 涓婚敭
+	 * @param text 鏍戣妭鐐规枃鏈�
+	 */
+	public Tree(String oid, String text,Object o){
+		setOid(oid);
+		setText(text);
+		setData(o);
+	}
+
+
 	/**
 	 * 涓婚敭
 	 */
@@ -63,6 +75,10 @@
 	 * 瀛愯妭鐐�
 	 */
 	private List<Tree> children = new ArrayList<Tree>();
+	/**
+	 * 灞傜骇
+	 */
+	private  int level;
 	/**
 	 * 鍥炬爣
 	 */
@@ -99,6 +115,10 @@
 	 * 鎺掑簭绱㈠紩
 	 */
 	private String index;//鎺掑簭绱㈠紩
+	/***
+	 * 褰撳墠鏁版嵁瀵硅薄
+	 */
+	private Object data;
 	
 	/**
 	 * 鍏朵粬鐨勫睘鎬�
@@ -383,6 +403,23 @@
 		}
 	}
 
+
+	public Object getData() {
+		return data;
+	}
+
+	public void setData(Object data) {
+		this.data = data;
+	}
+
+	public int getLevel() {
+		return level;
+	}
+
+	public void setLevel(int level) {
+		this.level = level;
+	}
+
 	@Override
 	public String toString() {
 		return "Tree{" +
@@ -392,6 +429,7 @@
 				", showCheckbox=" + showCheckbox +
 				", checked=" + checked +
 				", children=" + children +
+				", level=" + level +
 				", icon='" + icon + '\'' +
 				", iconCls='" + iconCls + '\'' +
 				", parentId='" + parentId + '\'' +
@@ -400,6 +438,7 @@
 				", expanded=" + expanded +
 				", href='" + href + '\'' +
 				", index='" + index + '\'' +
+				", data=" + data +
 				", attributes=" + attributes +
 				'}';
 	}
diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsAttributeController.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsAttributeController.java
index e4a6f13..8b982bd 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsAttributeController.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsAttributeController.java
@@ -8,6 +8,8 @@
 import com.vci.starter.web.pagemodel.BaseQueryObject;
 import com.vci.starter.web.pagemodel.BaseResult;
 import com.vci.pagemodel.OsAttributeVO;
+import com.vci.starter.web.pagemodel.Tree;
+import com.vci.starter.web.pagemodel.TreeQueryObject;
 import com.vci.starter.web.util.ControllerUtil;
 import com.vci.starter.web.util.LocalFileUtil;
 import com.vci.starter.web.util.VciBaseUtil;
@@ -46,6 +48,28 @@
      */
     private Logger logger = LoggerFactory.getLogger(getClass());
 
+
+
+    /**
+     * 鑾峰彇鎵�鏈変笟鍔$被鍨嬶紙鏍戝舰缁撴瀯锛�
+     * @return 鏌ヨ缁撴灉
+     */
+    @GetMapping( "/getTreeAttributes")
+    @VciBusinessLog(operateName = "鑾峰彇灞炴�э紙鏍戝舰缁撴瀯锛�")
+    public BaseResult<List<Tree>> getTreeAttributesByBtmName(TreeQueryObject treeQueryObject){
+        try {
+            List<Tree>  trees=   attributeService.getTreeAttributesByBtmName(treeQueryObject);
+            return BaseResult.dataList(trees);
+          //  return BaseResult.tree(trees);
+        }catch (Throwable e) {
+            e.printStackTrace();
+            String exceptionMessage = "鏌ヨ涓氬姟绫诲瀷鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e);
+            logger.error(exceptionMessage);
+            return BaseResult.fail(exceptionMessage);
+        }
+    }
+
+
     /**
      * 灞炴�у垪琛�
      * @param baseQueryObject 鏌ヨ瀵硅薄
diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsAttributeServiceI.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsAttributeServiceI.java
index 96ffd58..91400a3 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsAttributeServiceI.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsAttributeServiceI.java
@@ -3,9 +3,7 @@
 import com.vci.corba.common.PLException;
 import com.vci.corba.omd.atm.AttributeDef;
 import com.vci.dto.OsAttributeDTO;
-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.pagemodel.OsAttributeVO;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -21,6 +19,12 @@
  */
 public interface OsAttributeServiceI extends OsBaseServiceI{
 
+	/**
+	 * 鑾峰彇鏍戠姸
+	 * @param treeQueryObject
+	 * @return
+	 */
+	List<Tree> getTreeAttributesByBtmName(TreeQueryObject treeQueryObject);
 	/**
 	 * 鑾峰彇榛樿鐨勫睘鎬�
 	 * @return 榛樿鐨勫睘鎬у垪琛�
@@ -182,8 +186,9 @@
 	 * 鏍规嵁涓氬姟绫诲瀷/閾炬帴绫诲瀷鑾峰彇灞炴�т俊鎭�
 	 * @param btName 涓氬姟绫诲瀷/閾炬帴绫诲瀷
 	 * @param typeFlag 0:涓氬姟绫诲瀷,1:閾炬帴绫诲瀷
+	 * @param isDefault 鏄惁鍖呭惈榛樿灞炴�� true锛氬寘鍚紝false 涓嶅寘鍚�
 	 * @return
 	 */
-	List<OsAttributeVO> getOsAttributeVOSByBtName(String btName,int typeFlag)throws Exception;
+	List<OsAttributeVO> getOsAttributeVOSByBtName(String btName,int typeFlag,boolean isDefault)throws Exception;
 
 }
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 c8facba..ec96cc5 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
@@ -7,14 +7,14 @@
 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.pagemodel.OsEnumItemVO;
-import com.vci.pagemodel.OsEnumVO;
-import com.vci.pagemodel.OsUsedAttributeVO;
+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;
@@ -25,12 +25,10 @@
 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;
@@ -135,6 +133,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);
+			}
+		}
+
+	}
 
 	/**
 	 * 鑾峰彇榛樿鐨勫睘鎬�
@@ -1142,17 +1235,36 @@
 	 * @return
 	 */
 	@Override
-	public List<OsAttributeVO> getOsAttributeVOSByBtName(String btName, int typeFlag) throws Exception{
+	public List<OsAttributeVO> getOsAttributeVOSByBtName(String btName, int typeFlag,boolean isDefault) throws Exception{
 		VciBaseUtil.alertNotNull(btName,"鍙傛暟涓嶅厑璁镐负绌�",typeFlag,"鍙傛暟涓嶅厑璁镐负绌�");
 		List<OsAttributeVO> attributeVOS=new ArrayList<>();
+
 		try {
-			AttributeDef[] attributeDefs=new AttributeDef[]{};
+			List<AttributeDef> attributeDefList=new ArrayList<>();
 			if(typeFlag==0){
-				attributeDefs=	platformClientUtil.getBtmService().getAttributeDefs(btName);
+				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{
-				attributeDefs=platformClientUtil.getLinkTypeService().getAttributes(btName);
+				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(Arrays.asList(attributeDefs));
+			attributeVOS=attributeDO2VOs(attributeDefList);
 		}catch (PLException e){
 			throw new Exception("鏍规嵁涓氬姟绫诲瀷鑾峰彇灞炴�у紓甯�"+e.getMessage());
 		}
diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java
index 45abd95..f6ed246 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsPortalVIServiceImpl.java
@@ -381,7 +381,7 @@
                 }
                 String attributeStr="";
                 try {
-                    List<OsAttributeVO> osAttributeVOList=osAttributeService.getOsAttributeVOSByBtName(portalVIDTO.getTypeName(),portalVIDTO.getTypeFlag());
+                    List<OsAttributeVO> osAttributeVOList=osAttributeService.getOsAttributeVOSByBtName(portalVIDTO.getTypeName(),portalVIDTO.getTypeFlag(),false);
                     if(!CollectionUtils.isEmpty(osAttributeVOList)){
                       List<String> filedList= osAttributeVOList.stream().map(OsAttributeVO::getId).collect(Collectors.toList());
                         attributeStr=VciBaseUtil.array2String(filedList.toArray(new String[]{}));
@@ -521,7 +521,7 @@
                             });
                         }
                         //鏍¢獙灞炴�ф槸鍚︽纭�
-                        List<OsAttributeVO> osAttributeVOList = osAttributeService.getOsAttributeVOSByBtName(portalVI.typeName, portalVI.typeFlag);
+                        List<OsAttributeVO> osAttributeVOList = osAttributeService.getOsAttributeVOSByBtName(portalVI.typeName, portalVI.typeFlag,false);
                         if (!CollectionUtils.isEmpty(osAttributeVOList)) {
                             List<String> filedList = osAttributeVOList.stream().map(OsAttributeVO::getId).collect(Collectors.toList());
                             List<String> attributeList = VciBaseUtil.str2List(portalVIPO.getAttributeKey());

--
Gitblit v1.9.3