فهرست منبع

mxg:添加读取 图关系的定义 的方法;添加JObject转化为Instance的方法

mengxiangge 6 سال پیش
والد
کامیت
905dfca47c

+ 74 - 0
MBI/SAGA.DotNetUtils/Extend/JObjectExt.cs

@@ -5,7 +5,9 @@
  * ==============================================================================*/
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
 using Newtonsoft.Json.Linq;
@@ -45,6 +47,78 @@ namespace SAGA.DotNetUtils.Extend
             }
             return value;
         }
+        /// <summary>
+        /// JObject 转化为实体类
+        /// 通过Description标记
+        /// </summary>
+        /// <param name="jObject"></param>
+        /// <param name="type"></param>
+        /// <returns></returns>
+        public static Object ConvertToInstance(this JObject jObject, Type type)
+        {
+            var obj = type.Assembly.CreateInstance(type.FullName);
+            try
+            {
+                var properties = obj.GetType().GetProperties();
+
+                foreach (var propertyInfo in properties)
+                {
+                    var descriptionAttribute = propertyInfo.GetCustomAttribute<DescriptionAttribute>();
+                    if (descriptionAttribute == null) continue;
+                    var description = descriptionAttribute.Description;
+                    var jToken = jObject[description];
+                    if (jToken == null) continue;
+                    var ptype = propertyInfo.PropertyType;
+                    
+                    if (propertyInfo.PropertyType == typeof(string))
+                    {//String类型
+                        var str = jToken.Value<string>();
+                        propertyInfo.SetValue(obj, str);
+                    }
+                    else if (propertyInfo.PropertyType.IsGenericType)
+                    {//集合Content
+                        Type genericType = ptype.GetGenericArguments().First();
+                        //创建集合
+                        object genericList = CreateGeneric(typeof(List<>), genericType);
+                        if (genericList != null)
+                        {
+                            var addMethods = genericList.GetType().GetMethods().FirstOrDefault(t => t.Name == "Add");
+                            if (addMethods != null)
+                            {
+                                foreach (JObject jItem in (JArray)jToken)
+                                {//集合赋值
+                                    var subObj = ConvertToInstance(jItem, genericType);
+                                    addMethods.Invoke(genericList, new object[] { subObj });
+                                }
+                            }
+
+                            propertyInfo.SetValue(obj, genericList);
+                        }
+
+
+                    }
+
+                }
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e);
+            }
+
+            return obj;
+        }
+        /// <summary>
+        /// 初始化集合
+        /// </summary>
+        /// <param name="generic"></param>
+        /// <param name="innerType"></param>
+        /// <param name="args"></param>
+        /// <returns></returns>
+        public static object CreateGeneric(Type generic, Type innerType, params object[] args)
+        {
+            Type specificType = generic.MakeGenericType(new System.Type[] { innerType });
+            return Activator.CreateInstance(specificType, args);
+        }
         public static JObject Merge(this JObject jObject, JObject jObject2)
         {
             JObject result = new JObject();

+ 2 - 0
MBI/SAGA.MBI/App.xaml.cs

@@ -13,6 +13,7 @@ using CEFSharpWpf;
 using SAGA.DotNetUtils;
 using SAGA.DotNetUtils.Others;
 using SAGA.MBI.DataArrange;
+using SAGA.MBI.Model;
 using SAGA.MBI.WinView.Login;
 
 namespace SAGA.MBI
@@ -25,6 +26,7 @@ namespace SAGA.MBI
         [STAThread]
         static void Main()
         {
+
             WinLogin win = new WinLogin();
             Application myAp = new Application();
             myAp.ShutdownMode = ShutdownMode.OnExplicitShutdown;

+ 101 - 0
MBI/SAGA.MBI/Model/Global_Relation_Defination.cs

@@ -0,0 +1,101 @@
+/* ==============================================================================
+ * 功能描述:Global_Relation_Defination  
+ * 创 建 者:Garrett
+ * 创建日期:2019/1/21 10:04:23
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json.Linq;
+using SAGA.DotNetUtils.Extend;
+using SAGA.MBI.RequestData;
+
+namespace SAGA.MBI.Model
+{
+    /// <summary>
+    /// Global_Relation_Defination
+    /// </summary>
+    public class Global_Relation_Defination
+    {
+        private static Global_Relation_Defination m_Instance;
+        public static Global_Relation_Defination Instance
+        {
+            get
+            {
+                if (m_Instance == null)
+                {
+                    string json = RelationRequest.GetGlobalRelationDefination();
+                    JObject jObject = JObject.Parse(json);
+                    m_Instance =
+                        jObject.ConvertToInstance(typeof(Global_Relation_Defination)) as Global_Relation_Defination;
+                }
+
+                return m_Instance;
+            }
+        }
+
+        [Description("Content")]
+        public List<Relation_Graph_Defination> Content { get; set; }
+        /// <summary>
+        /// 查找图类型的定义
+        /// </summary>
+        /// <param name="graph_Type"></param>
+        /// <returns></returns>
+        public Relation_Graph_Defination FindGraphDefination(string graph_Type)
+        {
+            return Content?.FirstOrDefault(t => t.Graph_Type == graph_Type);
+        }
+        /// <summary>
+        /// 查找关系类型的定义
+        /// </summary>
+        /// <param name="graph_Type"></param>
+        /// <param name="descrption"></param>
+        /// <returns></returns>
+        public Relation_Type_Defination FindTypeDefination(string graph_Type, string descrption)
+        {
+            var graphModel = FindGraphDefination(graph_Type);
+
+            return graphModel?.Content?.FirstOrDefault(t=>t.Description== descrption);
+        }
+
+        
+    }
+    
+    /// <summary>
+    /// 图类型的定义
+    /// </summary>
+    public class Relation_Graph_Defination
+    {
+        public Relation_Graph_Defination()
+        {
+            Content=new List<Relation_Type_Defination>();
+        }
+        [Description("graph_type")]
+        public string Graph_Type { get; set; }
+        [Description("graph_name")]
+        public string Graph_Name { get; set; }
+        [Description("Content")]
+        public List<Relation_Type_Defination> Content { get; set; }
+    }
+    /// <summary>
+    /// 关系类型的定义
+    /// </summary>
+    public class Relation_Type_Defination
+    {
+        [Description("rel_name")]
+        public string Rel_Name { get; set; }
+        [Description("directional")]
+        public string Directional { get; set; }
+        [Description("target_objs")]
+        public string Target_Objs { get; set; }
+        [Description("rel_type")]
+        public string Rel_Type { get; set; }
+        [Description("description")]
+        public string Description { get; set; }
+
+    }
+}

+ 21 - 0
MBI/SAGA.MBI/RequestData/RelationRequest.cs

@@ -236,5 +236,26 @@ namespace SAGA.MBI.RequestData
             }
             return null;
         }
+
+        /// <summary>
+        /// 全局图类型关系类型定义
+        /// </summary>
+        /// <returns></returns>
+        public static string GetGlobalRelationDefination()
+        {
+            try
+            {
+                string url = MBIConst.DataPlatformLocalHost + $"data-platform-3/dict/query/global_relation_defination";
+                
+                RestClient client = new RestClient(url, HttpVerb.GET);
+                string request = client.PostRequest();
+                return request;
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+            return null;
+        }
     }
 }

+ 1 - 0
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -274,6 +274,7 @@
     <Compile Include="ModeInfoEdit\WinPointInfoMerge.xaml.cs">
       <DependentUpon>WinPointInfoMerge.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Model\Global_Relation_Defination.cs" />
     <Compile Include="Model\GraphRelationType.cs" />
     <Compile Include="Model\MBSpace.cs" />
     <Compile Include="Model\MQRCode.cs" />

+ 10 - 3
MBI/SAGA.MBI/ToolsData/DataCheck/SpaceEquipFloorCheck.cs

@@ -90,11 +90,14 @@ namespace SAGA.MBI.ToolsData.DataCheck
 
                 JObject jObject = new JObject();
                 JArray jArray = new JArray();
+                string graph = "EquipinSpace";
+                string graphType = GetEquipInSpaceGraphType(graph, businessSpaceType.Code);
                 foreach (MRevitEquipBase space in spacesB)
                 {
                     JObject graphJObject = new JObject();
-                    graphJObject.Add("graphType", "EquipinSpace");
-                    graphJObject.Add("relType", "1");
+                    
+                    graphJObject.Add("graphType", graph);
+                    graphJObject.Add("relType", graphType);
                     graphJObject.Add("side", "fromId");
                     graphJObject.Add("toId", space.Id);
                     jArray.Add(graphJObject);
@@ -149,7 +152,11 @@ namespace SAGA.MBI.ToolsData.DataCheck
             var items = CommonConvert.FloorQuery_SubSet(floorId, jObject, new[] { businessSpaceType.Code });
             return items.FirstOrDefault();
         }
-        
+
+        private string GetEquipInSpaceGraphType(string graph, string description)
+        {
+            return Global_Relation_Defination.Instance.FindTypeDefination(graph, description)?.Rel_Type;
+        }
 
         #endregion