123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- /* ==============================================================================
- * 功能描述:关系实例请求接口
- * 创 建 者:Garrett
- * 创建日期:2018/7/31 16:55:30
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Newtonsoft.Json.Linq;
- using SAGA.DotNetUtils.Extend;
- using SAGA.DotNetUtils.Others;
- using SAGA.MBI.Common;
- using SAGA.MBI.Model;
- using SAGA.MBI.RequestData;
- using SAGA.MBI.Tools;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Logger;
- namespace SAGA.MBI.JsonConvert
- {
- /// <summary>
- /// RelationConvert
- /// </summary>
- public class RelationConvert
- {
- /// <summary>
- /// 设备所在空间关系更新 用新的岗位替换旧的岗位
- /// </summary>
- /// <param name="oldequipid"></param>
- /// <param name="newequipid"></param>
- public static void UpdateEquipInSpaceRelation(string oldequipid,string newequipid)
- {
- string graphtype = RelationConst.EquipInSpaceGraphId;
- string reltype = RelationConst.EquipInSpaceGraphRelationType;
- UpdateFromIdRelation(graphtype, reltype, oldequipid, newequipid);
- }
- /// <summary>
- /// 更新关系实例
- /// </summary>
- /// <param name="graphType"></param>
- /// <param name="relType"></param>
- /// <param name="oldfromId"></param>
- /// <param name="newfromId"></param>
- private static void UpdateFromIdRelation(string graphType, string relType, string oldfromId,string newfromId)
- {
- try
- {
- var graphid = RelationRequest.GetCurrentGraphId(graphType);
- if (graphid == null) return;
- string json = RelationRequest.QueryRelation(graphid, oldfromId, null, relType);
- if (json.IsRequestHasItem())
- {
- JObject jObject = JObject.Parse(json);
- foreach (JObject jobj in jObject["Content"])
- {
- string toid = jobj.GetValueEx("to_id");
- UpdateFromIdRelation(graphid,relType,toid, oldfromId, newfromId);
- }
- }
- }
- catch (Exception e)
- {
- MessageShowBase.Show(e);
- }
- }
- /// <summary>
- /// 更新关系实例
- /// </summary>
- /// <param name="graphId"></param>
- /// <param name="relType"></param>
- /// <param name="toid"></param>
- /// <param name="oldfromId"></param>
- /// <param name="newfromId"></param>
- private static void UpdateFromIdRelation(string graphId, string relType, string toid, string oldfromId, string newfromId)
- {
- try
- {
- if (RelationRequest.DeleteRelation(graphId, oldfromId, toid, relType))
- RelationRequest.AddRelation(graphId, newfromId, toid, relType);
- }
- catch (Exception e)
- {
- MessageShowBase.Show(e);
- }
- }
- /// <summary>
- /// 跟据设备所在空间关系,取出空间
- /// </summary>
- /// <param name="fromid"></param>
- /// <returns></returns>
- public static string GetSpaceByRelationElementInSpace(string fromid)
- {
- string toid = null;
- string graphType = RelationConst.EquipInSpaceGraphId;
- string relType = RelationConst.EquipInSpaceGraphRelationType;
- var graphid = RelationRequest.GetCurrentGraphId(graphType);
- if (graphid == null) return null;
- string json = RelationRequest.QueryRelation(graphid, fromid, null, relType);
- if (json.IsRequestHasItem())
- {
- JObject jObject = JObject.Parse(json);
- foreach (JObject jobj in jObject["Content"])
- {
- toid = jobj.GetValueEx("to_id");
- //取第一个即可
- break;
- }
- }
- return toid;
- }
- }
- }
|