Selaa lähdekoodia

xls:更新获取图实例方法

xulisong 6 vuotta sitten
vanhempi
commit
b6ff305eb0

+ 32 - 1
MBI/SAGA.MBI/RequestData/RelationRequest.cs

@@ -29,7 +29,8 @@ namespace SAGA.MBI.RequestData
         /// <returns></returns>
         public static string GetCurrentGraphId(string graphType)
         {
-            return GetExistGraphId(graphType) ?? CreateNewGraphId(graphType);
+            return GetCurrentId(graphType);
+            //return GetExistGraphId(graphType) ?? CreateNewGraphId(graphType);
         }
         /// <summary>
         /// 获取已经存在的GraphId
@@ -97,6 +98,36 @@ namespace SAGA.MBI.RequestData
             return graphid;
         }
 
+        /// <summary>
+        /// 从服务器获取相关图实例Id,不存在的话后台自动创建
+        /// </summary>
+        /// <param name="graphType"></param>
+        /// <returns></returns>
+        public static string GetCurrentId(string graphType)
+        {
+            string graphid = null;
+            try
+            {
+                string url = MBIConst.DataPlatformLocalHost + $"data-platform-3/relation/graph_instance/get?secret={MBIControl.ProjectCur.Password}&projectId={MBIControl.ProjectCur.Id}";
+
+                JObject jObject = new JObject();
+                jObject.Add("graph_type", graphType);
+             
+                string postData = jObject.ToString();
+                RestClient client = new RestClient(url, HttpVerb.POST, postData);
+                string request = client.PostRequest();
+                if (!request.IsSuccessRequest()) return graphid;
+                JObject result = JObject.Parse(request);
+                //获取生成的Id和Name
+                // result.TryGetValue<string>("graph_id", out graphid);
+                graphid = result["graph_id"].ToString();
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+            return graphid;
+        }
 
         /// <summary>
         /// 增加关系实例操作

+ 18 - 0
MBI/SAGA.MBI/ToolsData/UpdateRelationEquipinSpace.cs

@@ -82,6 +82,7 @@ namespace SAGA.MBI.ToolsData
             {
                 JObject jobject = new JObject();
                 JArray jcriterias = new JArray();
+                JArray deleteCriterias = new JArray();
                 string graphtype = RelationConst.EquipInSpaceGraphId;
                 string reltyp = RelationConst.EquipInSpaceGraphRelationType;
                 string graphid = RelationRequest.GetCurrentGraphId(graphtype);
@@ -101,6 +102,10 @@ namespace SAGA.MBI.ToolsData
                     jitem.Add("graph_id", graphid);
                     jitem.Add("rel_type", reltyp);
                     jcriterias.Add(jitem);
+                    JObject deleteItem = new JObject();
+                    deleteItem.Add("from_id", equipid);
+                    deleteItem.Add("graph_id", graphid);
+                    deleteCriterias.Add(deleteItem);
                 }
                 //检查部件 
                 foreach (var mode in baseContext.MEquipmentParts)
@@ -114,10 +119,23 @@ namespace SAGA.MBI.ToolsData
                     jitem.Add("graph_id", graphid);
                     jitem.Add("rel_type", reltyp);
                     jcriterias.Add(jitem);
+                    JObject deleteItem = new JObject();
+                    deleteItem.Add("from_id", equipid);
+                    deleteItem.Add("graph_id", graphid);
+                    deleteCriterias.Add(deleteItem);
                 }
                 //信标不用检查
+                //先删除旧的关系,再上传新的关系
+                #region 删除
+                JObject deleteJobject = new JObject();
+                deleteJobject.Add("criterias", deleteCriterias);
+                RelationRequest.DeleteRelation(deleteJobject); 
+                #endregion
+
+
                 jobject.Add("criterias", jcriterias);
                 RelationRequest.AddRelation(jobject);
+           
             }
             catch (Exception e)
             {