FdcStation.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace WebAPIBase.NetCore.BusinessCore
  7. {
  8. public class FdcStation
  9. {
  10. private FdcUnitStructure fdcUnitStructure;
  11. private string stationCode;
  12. private string stationName;
  13. private string unitCode;
  14. internal List<FdcUnitRight> unitList = new List<FdcUnitRight>();
  15. internal Dictionary<string, innerFunction> functionList = new Dictionary<string, innerFunction>();
  16. public List<int> UserList = new List<int>();
  17. public string StationCode
  18. {
  19. get
  20. {
  21. return stationCode;
  22. }
  23. set
  24. {
  25. stationCode = value;
  26. }
  27. }
  28. public string StationName
  29. {
  30. get
  31. {
  32. return stationName;
  33. }
  34. set
  35. {
  36. stationName = value;
  37. }
  38. }
  39. public string UnitCode
  40. {
  41. get
  42. {
  43. return unitCode;
  44. }
  45. set
  46. {
  47. unitCode = value;
  48. }
  49. }
  50. internal FdcStation(FdcUnitStructure unitStructure, string code, string name)
  51. {
  52. fdcUnitStructure = unitStructure;
  53. StationCode = code;
  54. StationName = name;
  55. }
  56. public bool HasRight(string functionCode)
  57. {
  58. return functionList.ContainsKey(functionCode);
  59. }
  60. public bool HasUnitRight(string functionCode, string unitCode)
  61. {
  62. if (unitCode == null || unitCode == string.Empty)
  63. {
  64. throw new ArgumentException("unit code不能为空");
  65. }
  66. if (functionList.ContainsKey(functionCode))
  67. {
  68. innerFunction innerFunction = functionList[functionCode];
  69. foreach (FdcUnitRight unit in innerFunction.UnitList)
  70. {
  71. if (unit.unit.isMyChild(unitCode))
  72. {
  73. return true;
  74. }
  75. }
  76. }
  77. return false;
  78. }
  79. public bool HasSubUnitRight(string functionCode, string unitCode)
  80. {
  81. if (unitCode == null || unitCode == string.Empty)
  82. {
  83. throw new ArgumentException("unit code不能为空");
  84. }
  85. if (functionList.ContainsKey(functionCode))
  86. {
  87. innerFunction innerFunction = functionList[functionCode];
  88. foreach (FdcUnitRight unit in innerFunction.UnitList)
  89. {
  90. if (unit.unit.isMyChild(unitCode))
  91. {
  92. return true;
  93. }
  94. if (unit.unit.isMyParent(unitCode))
  95. {
  96. return true;
  97. }
  98. }
  99. }
  100. return false;
  101. }
  102. public bool HasGroupRight(string functionCode, string groupCode)
  103. {
  104. return HasRight(functionCode, "", groupCode);
  105. }
  106. public bool HasRight(string functionCode, string unitCode, string groupCode)
  107. {
  108. if ((unitCode == null || unitCode == string.Empty) && (groupCode == null || groupCode == string.Empty))
  109. {
  110. return HasRight(functionCode);
  111. }
  112. bool flag = true;
  113. if (unitCode == null || unitCode == string.Empty)
  114. {
  115. flag = false;
  116. }
  117. if (groupCode == null || groupCode == string.Empty)
  118. {
  119. return HasUnitRight(functionCode, unitCode);
  120. }
  121. if (functionList.ContainsKey(functionCode))
  122. {
  123. innerFunction innerFunction = functionList[functionCode];
  124. FdcFunction functionByCode = fdcUnitStructure.GetFunctionByCode(functionCode);
  125. if (!functionByCode.UnitRelated && !functionByCode.SystemGroupRelated)
  126. {
  127. return true;
  128. }
  129. if (functionByCode.UnitRelated && !functionByCode.SystemGroupRelated)
  130. {
  131. return HasUnitRight(functionCode, unitCode);
  132. }
  133. if (!functionByCode.UnitRelated && functionByCode.SystemGroupRelated)
  134. {
  135. flag = false;
  136. }
  137. foreach (FdcGroupUnitRight groupUnit in innerFunction.GroupUnitList)
  138. {
  139. if ((!flag || groupUnit.unit.isMyChild(unitCode)) && groupUnit.group.isMyChild(groupCode))
  140. {
  141. return true;
  142. }
  143. }
  144. }
  145. return false;
  146. }
  147. public RightScope GetUnitRightScope(string unitCode)
  148. {
  149. RightScope result = RightScope.无;
  150. foreach (FdcUnitRight unit in unitList)
  151. {
  152. if (unit.IsPerson == 0)
  153. {
  154. if (unit.unit.isMyChild(unitCode))
  155. {
  156. return RightScope.部门;
  157. }
  158. }
  159. else if (unit.unit.isMyParent(unitCode))
  160. {
  161. result = RightScope.个人;
  162. }
  163. }
  164. return result;
  165. }
  166. }
  167. public class FdcUnitRight
  168. {
  169. public FdcUnit unit;
  170. public int IsPerson;
  171. }
  172. }