|
@@ -10,6 +10,7 @@ using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using SAGA.DotNetUtils;
|
|
|
+using SAGA.DotNetUtils.Extend;
|
|
|
using SAGA.DotNetUtils.Http;
|
|
|
using SAGA.DotNetUtils.Others;
|
|
|
using SAGA.MBI.Common;
|
|
@@ -288,5 +289,131 @@ namespace SAGA.MBI.RequestData
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///查询与指定Id的关系
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="itemId"></param>
|
|
|
+ /// <param name="graphId"></param>
|
|
|
+ /// <param name="relType"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static List<string> QueryRelations(string itemId, string graphId, string relType)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(itemId))
|
|
|
+ {
|
|
|
+ throw new ArgumentNullException(nameof(itemId));
|
|
|
+ }
|
|
|
+ List<string> items = new List<string>();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string url = MBIConst.DataPlatformLocalHost + $"data-platform-3/relation/query?secret={MBIControl.ProjectCur.Password}&projectId={MBIControl.ProjectCur.Id}";
|
|
|
+
|
|
|
+ JObject fromObject = new JObject();
|
|
|
+ fromObject.Add("from_id", itemId);
|
|
|
+ fromObject.Add("graph_id", graphId);
|
|
|
+
|
|
|
+ JObject toObject = new JObject();
|
|
|
+ toObject.Add("to_id", itemId);
|
|
|
+ toObject.Add("graph_id", graphId);
|
|
|
+
|
|
|
+ if (!string.IsNullOrWhiteSpace(relType))
|
|
|
+ {
|
|
|
+ fromObject.Add("rel_type", relType);
|
|
|
+ toObject.Add("rel_type", relType);
|
|
|
+ }
|
|
|
+
|
|
|
+ JArray array = new JArray();
|
|
|
+ array.Add(fromObject);
|
|
|
+ array.Add(toObject);
|
|
|
+ JObject queryObject = new JObject();
|
|
|
+ queryObject.Add("criterias", array);
|
|
|
+
|
|
|
+ string postData = queryObject.ToString();
|
|
|
+ RestClient client = new RestClient(url, HttpVerb.POST, postData);
|
|
|
+ string request = client.PostRequest();
|
|
|
+ if (request.IsRequestHasItem())
|
|
|
+ {
|
|
|
+ JObject jObject = JObject.Parse(request);
|
|
|
+ foreach (JObject jobj in jObject["Content"])
|
|
|
+ {
|
|
|
+ string toid = jobj.GetValueEx("to_id");
|
|
|
+ if (toid != itemId)
|
|
|
+ {
|
|
|
+ items.Add(toid);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ string fromid = jobj.GetValueEx("from_id");
|
|
|
+ if (fromid != itemId)
|
|
|
+ {
|
|
|
+ items.Add(fromid);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ MessageShowBase.Show(e);
|
|
|
+ }
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询实例的所有关系
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="graphId"></param>
|
|
|
+ /// <param name="relType"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static List<Tuple<string,string>> QueryRelations(string graphId, string relType)
|
|
|
+ {
|
|
|
+ List<Tuple<string, string>> items =new List<Tuple<string, string>>();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string url = MBIConst.DataPlatformLocalHost + $"data-platform-3/relation/query?secret={MBIControl.ProjectCur.Password}&projectId={MBIControl.ProjectCur.Id}";
|
|
|
+
|
|
|
+ JObject fromObject = new JObject();
|
|
|
+ fromObject.Add("graph_id", graphId);
|
|
|
+ if (!string.IsNullOrWhiteSpace(relType))
|
|
|
+ {
|
|
|
+ fromObject.Add("rel_type", relType);
|
|
|
+ }
|
|
|
+ JArray array = new JArray();
|
|
|
+ array.Add(fromObject);
|
|
|
+ JObject queryObject = new JObject();
|
|
|
+ queryObject.Add("criterias", array);
|
|
|
+
|
|
|
+ string postData = queryObject.ToString();
|
|
|
+ RestClient client = new RestClient(url, HttpVerb.POST, postData);
|
|
|
+ string request = client.PostRequest();
|
|
|
+ //if (request.IsRequestHasItem())
|
|
|
+ //{
|
|
|
+ JObject jObject = JObject.Parse(request);
|
|
|
+ if(jObject.IsContainKeyEx("Content"))
|
|
|
+ {
|
|
|
+ foreach (JObject item in jObject["Content"])
|
|
|
+ {
|
|
|
+ foreach (JObject jobj in item["Content"])
|
|
|
+ {
|
|
|
+ string toid = jobj.GetValueEx("to_id");
|
|
|
+ string fromid = jobj.GetValueEx("from_id");
|
|
|
+ if (!string.IsNullOrWhiteSpace(toid) && !string.IsNullOrWhiteSpace(fromid))
|
|
|
+ {
|
|
|
+ items.Add(new Tuple<string, string>(toid, fromid));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //}
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ MessageShowBase.Show(e);
|
|
|
+ }
|
|
|
+ return items;
|
|
|
+ }
|
|
|
}
|
|
|
}
|