FdcUnit.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using SqlSugar;
  8. using Sugar.Enties;
  9. namespace WebAPIBase.NetCore.BusinessCore
  10. {
  11. public class FdcUnit : DbContext<SystemUser>
  12. {
  13. public string UnitCode;
  14. public string FullCode;
  15. private string[] fullCodeList;
  16. public string UnitType;
  17. public string ParentCode;
  18. public string UnitName;
  19. public string RelaCode;
  20. public int RelSystem;
  21. private string fullName;
  22. public string SortId;
  23. private string fullSortId;
  24. internal List<FdcUnit> Children = new List<FdcUnit>();
  25. private FdcUnitStructure fus;
  26. public List<FdcStation> StationList = new List<FdcStation>();
  27. protected List<int> allUser = null;
  28. public string FullName
  29. {
  30. get
  31. {
  32. if (string.IsNullOrEmpty(fullName))
  33. {
  34. for (int i = 0; i < fullCodeList.Length - 1; i++)
  35. {
  36. fullName = fullName + fus.GetUnitByCode(fullCodeList[i]).UnitName + "-";
  37. }
  38. fullName += UnitName;
  39. }
  40. return fullName;
  41. }
  42. }
  43. public string FullSortId
  44. {
  45. get
  46. {
  47. if (string.IsNullOrEmpty(fullSortId))
  48. {
  49. for (int i = 0; i < fullCodeList.Length - 1; i++)
  50. {
  51. fullSortId = fullSortId + GetFillSortId(fus.GetUnitByCode(fullCodeList[i]).SortId) + ".";
  52. }
  53. fullSortId += GetFillSortId(SortId);
  54. }
  55. return fullSortId;
  56. }
  57. }
  58. private string GetFillSortId(string sortId)
  59. {
  60. string text = sortId;
  61. if (string.IsNullOrEmpty(text))
  62. {
  63. return text.PadLeft(25, 'ÿ');
  64. }
  65. return text.PadLeft(25, ' ');
  66. }
  67. internal FdcUnit(FdcUnitStructure _fus, string unitcode, string fullcode, string unittype, string parentcode, string unitname, string relacode, int systemcode)
  68. {
  69. fus = _fus;
  70. UnitCode = unitcode;
  71. FullCode = fullcode;
  72. UnitType = unittype;
  73. fullCodeList = fullcode.Split('-');
  74. ParentCode = parentcode;
  75. UnitName = unitname;
  76. RelaCode = relacode;
  77. RelSystem = systemcode;
  78. Children = new List<FdcUnit>();
  79. }
  80. public bool isMyParent(FdcUnit parentUnit)
  81. {
  82. if (FullCode.IndexOf(parentUnit.UnitCode) >= 0)
  83. {
  84. return true;
  85. }
  86. return false;
  87. }
  88. public bool isMyParent(string parentUnitCode)
  89. {
  90. if (FullCode.IndexOf(parentUnitCode) >= 0)
  91. {
  92. return true;
  93. }
  94. return false;
  95. }
  96. public bool isMyChild(FdcUnit unit)
  97. {
  98. if (unit.isMyParent(this))
  99. {
  100. return true;
  101. }
  102. return false;
  103. }
  104. public bool isMyChild(string unitCode)
  105. {
  106. FdcUnit unitByCode = fus.GetUnitByCode(unitCode);
  107. if (unitByCode != null)
  108. {
  109. return isMyChild(unitByCode);
  110. }
  111. return false;
  112. }
  113. internal void GetParent2List(List<FdcUnit> parent, string unittype)
  114. {
  115. for (int i = 0; i < fullCodeList.Length - 1; i++)
  116. {
  117. FdcUnit unitByCode = fus.GetUnitByCode(fullCodeList[i]);
  118. if (unitByCode != null && unitByCode.UnitType == unittype && !parent.Contains(unitByCode))
  119. {
  120. parent.Add(unitByCode);
  121. }
  122. }
  123. }
  124. internal void GetChild2List(List<FdcUnit> children, string unittype)
  125. {
  126. bool flag = true;
  127. if (unittype == null || unittype.Length == 0)
  128. {
  129. throw new ApplicationException("参数错误 type不能为空");
  130. }
  131. if (children.Contains(this))
  132. {
  133. flag = false;
  134. }
  135. if (UnitType == unittype && flag)
  136. {
  137. children.Add(this);
  138. }
  139. foreach (FdcUnit child in Children)
  140. {
  141. child.GetChild2List(children, unittype);
  142. }
  143. }
  144. internal void GetChild2List(List<FdcUnit> children)
  145. {
  146. if (children.Contains(this))
  147. {
  148. return;
  149. }
  150. children.Add(this);
  151. foreach (FdcUnit child in Children)
  152. {
  153. child.GetChild2List(children);
  154. }
  155. }
  156. public void GetProject2List(List<FdcUnit> projectList)
  157. {
  158. GetChild2List(projectList, "项目");
  159. GetParent2List(projectList, "项目");
  160. GetChild2List(projectList, "物管处");
  161. GetParent2List(projectList, "物管处");
  162. }
  163. public void GetCompany2List(List<FdcUnit> companyList)
  164. {
  165. GetChild2List(companyList, "公司");
  166. GetParent2List(companyList, "公司");
  167. GetChild2List(companyList, "集团");
  168. GetParent2List(companyList, "集团");
  169. }
  170. public List<int> GetUnitAllUserList()
  171. {
  172. if (allUser == null)
  173. {
  174. allUser = new List<int>();
  175. string commandText = "select distinct su.usercode from unit u join station s on u.unitcode=s.unitcode join stationuser su on s.stationcode=su.stationcode where u.fullcode like '%' + @FullCode + '%'";
  176. var parameters = new List<SugarParameter>()
  177. {
  178. new SugarParameter("@FullCode", FullCode)
  179. };
  180. var dataTable = Db.Ado.GetDataTable(commandText, parameters);
  181. foreach (DataRow row in dataTable.Rows)
  182. {
  183. allUser.Add(int.Parse(row["usercode"].ToString()));
  184. }
  185. }
  186. return allUser;
  187. }
  188. public List<int> GetUnitUserList()
  189. {
  190. List<int> list = new List<int>();
  191. foreach (FdcStation station in StationList)
  192. {
  193. foreach (int user in station.UserList)
  194. {
  195. if (!list.Contains(user))
  196. {
  197. list.Add(user);
  198. }
  199. }
  200. }
  201. return list;
  202. }
  203. }
  204. }