MGraphRelationBase.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* ==============================================================================
  2. * 功能描述:图类型基类
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/4/1 11:15:29
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Newtonsoft.Json.Linq;
  12. using SAGA.DotNetUtils;
  13. using SAGA.DotNetUtils.Logger;
  14. using SAGA.MBI.Common;
  15. using SAGA.MBI.JsonConvert;
  16. using SAGA.MBI.RequestData;
  17. namespace SAGA.MBI.Model
  18. {
  19. /// <summary>
  20. /// RltEquipInSpace
  21. /// </summary>
  22. public abstract class MGraphRelationBase : CloudDataBase
  23. {
  24. public string GraphId { get; set; }
  25. public string RelationType { get; set; }
  26. public MGraphRelationBase(string fromId, string toId)
  27. {
  28. FromId = fromId;
  29. ToId = toId;
  30. }
  31. public virtual string GetFromId()
  32. {
  33. return "";
  34. }
  35. public virtual string GetToId()
  36. {
  37. return "";
  38. }
  39. private string m_FromId;
  40. /// <summary>
  41. /// fromid
  42. /// </summary>
  43. public string FromId
  44. {
  45. get
  46. {
  47. if (m_FromId.IsNullOrEmpty() )
  48. {
  49. m_FromId = GetFromId();
  50. }
  51. return m_FromId;
  52. }
  53. set { m_FromId = value; }
  54. }
  55. private string m_ToId;
  56. /// <summary>
  57. /// toid
  58. /// </summary>
  59. public string ToId
  60. {
  61. get
  62. {
  63. if (m_ToId.IsNullOrEmpty())
  64. {
  65. m_ToId = GetToId();
  66. }
  67. return m_ToId;
  68. }
  69. set { m_ToId = value; }
  70. }
  71. public override bool AddObject()
  72. {
  73. if (GraphId.IsNullOrEmpty() || RelationType.IsNullOrEmpty())
  74. return false;
  75. string graphId = RelationRequest.GetCurrentGraphId(GraphId);
  76. if (graphId == null) return false;
  77. return RelationRequest.AddRelation(graphId, FromId, ToId, RelationType);
  78. }
  79. public override bool AddorUpdateObject()
  80. {
  81. switch (Operator)
  82. {
  83. case DocumentChangedOperator.Add:
  84. this.AddObject();
  85. break;
  86. case DocumentChangedOperator.Delete:
  87. this.DelObject();
  88. break;
  89. default:
  90. break;
  91. }
  92. return true;
  93. }
  94. public override bool DelObject()
  95. {
  96. if (GraphId.IsNullOrEmpty() || RelationType.IsNullOrEmpty())
  97. return false;
  98. string graphId = RelationRequest.GetCurrentGraphId(GraphId);
  99. if (graphId == null) return false;
  100. return RelationRequest.DeleteRelation(graphId, FromId, ToId, RelationType);
  101. }
  102. }
  103. }