TsysLicenseRepository.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. using Ropin.Inspection.Model;
  2. using Ropin.Inspection.Model.Entities;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Ropin.Inspection.Repository
  9. {
  10. public class TsysLicenseRepository : RepositoryBase<TSYS_License, Guid>, ITsysLicenseRepository
  11. {
  12. public TsysLicenseRepository(InspectionDbContext dbContext) : base(dbContext)
  13. {
  14. }
  15. public IList<TSYS_LicenseType> GetALLLicenseType()
  16. {
  17. return DbContext.Set<TSYS_LicenseType>().Where(i => i.C_Status == "1").OrderByDescending(t=>t.I_Sort).ToList();
  18. }
  19. public TSYS_LicenseType GetLicenseTypeByCode(string code)
  20. {
  21. return DbContext.Set<TSYS_LicenseType>().Where(i => i.C_Code == code).FirstOrDefault();
  22. }
  23. public async Task CreateLicenseTypeAsync(TSYS_LicenseType entity)
  24. {
  25. await DbContext.Set<TSYS_LicenseType>().AddAsync(entity);
  26. }
  27. public void UpdateLicenseType(TSYS_LicenseType entity)
  28. {
  29. DbContext.Set<TSYS_LicenseType>().Update(entity);
  30. }
  31. public Task<IEnumerable<LicenseTypePrivViewModel>> GetLicensePrivsByTypeIdAsync(string typeId)
  32. {
  33. MySqlConnector.MySqlParameter[] parameters = new[] { new MySqlConnector.MySqlParameter("typeId", typeId) };
  34. string sql = "SELECT * FROM TSYS_LicenseTypePriv where C_LicenseTypeCode = @typeId";
  35. IEnumerable<LicenseTypePrivViewModel> result = EntityFrameworkCoreExtensions.GetList<LicenseTypePrivViewModel>(DbContext.Database, sql, parameters);
  36. return Task.FromResult(result);
  37. }
  38. public Task<TsysLicenseTypePrivViewModel> GetLicensePrivByType(string typeCode)
  39. {
  40. var query = from a in DbContext.TSYS_LicenseTypePriv
  41. join b in DbContext.TSYS_Priv
  42. on a.C_PrivilegeCode equals b.C_Code
  43. where a.C_LicenseTypeCode == typeCode && b.C_Status == "1"
  44. select new TSYS_Priv
  45. {
  46. C_Code = b.C_Code,
  47. C_ParentCode = b.C_ParentCode,
  48. C_Module = b.C_Module,
  49. C_Type = b.C_Type,
  50. C_Name = b.C_Name,
  51. I_Sort = b.I_Sort,
  52. C_ImageUrl = b.C_ImageUrl,
  53. C_PageUrl = b.C_PageUrl,
  54. C_Remark = b.C_Remark,
  55. C_Status = b.C_Status,
  56. };
  57. var licenseTypePrivList = query.ToList();
  58. var treeList = new List<LicenseTypePrivTree>();
  59. //foreach (var item in licenseTypePrivList.Where(m => m.C_ParentCode == null).OrderBy(m => m.I_Sort))
  60. //{
  61. // //获得子级
  62. // var children = RecursionRoleTypePriv(licenseTypePrivList.Where(m => m.C_ParentCode != null).ToList(), new List<LicenseTypePrivTree>(), item.C_Code);
  63. // treeList.Add(new LicenseTypePrivTree()
  64. // {
  65. // C_Code = item.C_Code,
  66. // C_Name = item.C_Name,
  67. // C_ParentCode = item.C_ParentCode,
  68. // C_Type = item.C_Type,
  69. // I_Sort = item.I_Sort,
  70. // C_Remark = item.C_Remark,
  71. // C_ImageUrl = item.C_ImageUrl,
  72. // C_PageUrl = item.C_PageUrl,
  73. // C_Module = item.C_Module,
  74. // Open = children.Count > 0,
  75. // Children = children.Count == 0 ? null : children
  76. // });
  77. //}
  78. //var model = new TsysLicenseTypePrivViewModel {LicenseTypeCode = typeCode,LicenseTypePrivS = treeList };
  79. //return Task.FromResult(model);
  80. //var treeList = new List<LicenseTypePrivTree>();
  81. var SysPriv = DbContext.TSYS_Priv.ToList();
  82. foreach (var item in SysPriv.Where(m => m.C_ParentCode == null))
  83. {
  84. List<LicenseTypePrivTree> Part2Children = new List<LicenseTypePrivTree>();
  85. foreach (var item2 in SysPriv.Where(m => m.C_ParentCode == item.C_Code))
  86. {
  87. List<LicenseTypePrivTree> Part3Children = new List<LicenseTypePrivTree>();
  88. foreach (var item3 in SysPriv.Where(m => m.C_ParentCode == item2.C_Code))
  89. {
  90. List<LicenseTypePrivTree> Part4Children = new List<LicenseTypePrivTree>();
  91. foreach (var item4 in SysPriv.Where(m => m.C_ParentCode == item3.C_Code))
  92. {
  93. var treeList4 = new List<LicenseTypePrivTree>();
  94. List<LicenseTypePrivTree> v3 = LicenseRoleTypePriv(licenseTypePrivList.Where(m => m.C_ParentCode != null).ToList(), new List<LicenseTypePrivTree>(), item4.C_Code);
  95. var query4 = from p in SysPriv
  96. join pp in licenseTypePrivList
  97. on p.C_Code equals pp.C_Code
  98. where p.C_Code == item4.C_Code
  99. select new
  100. {
  101. pp.C_Code
  102. };
  103. if (v3.Count > 0 || query4.Any())
  104. treeList4.Add(new LicenseTypePrivTree()
  105. {
  106. C_Code = item4.C_Code,
  107. C_Name = item4.C_Name,
  108. C_ParentCode = item4.C_ParentCode,
  109. C_Type = item4.C_Type,
  110. I_Sort = item4.I_Sort,
  111. C_Remark = item4.C_Remark,
  112. C_ImageUrl = item4.C_ImageUrl,
  113. C_PageUrl = item4.C_PageUrl,
  114. C_Module = item4.C_Module,
  115. Open = v3.Count > 0,
  116. Children = v3.Count == 0 ? null : v3
  117. });
  118. Part4Children.AddRange(treeList4);
  119. }
  120. var treeList3 = new List<LicenseTypePrivTree>();
  121. var query3 = from p in SysPriv
  122. join pp in licenseTypePrivList
  123. on p.C_Code equals pp.C_Code
  124. where p.C_Code == item3.C_Code
  125. select new
  126. {
  127. pp.C_Code
  128. };
  129. if (Part4Children.Count > 0 || query3.Any())
  130. treeList3.Add(new LicenseTypePrivTree()
  131. {
  132. C_Code = item3.C_Code,
  133. C_Name = item3.C_Name,
  134. C_ParentCode = item3.C_ParentCode,
  135. C_Type = item3.C_Type,
  136. I_Sort = item3.I_Sort,
  137. C_Remark = item3.C_Remark,
  138. C_ImageUrl = item3.C_ImageUrl,
  139. C_PageUrl = item3.C_PageUrl,
  140. C_Module = item3.C_Module,
  141. Open = Part4Children.Count > 0,
  142. Children = Part4Children.Count == 0 ? null : Part4Children
  143. });
  144. Part3Children.AddRange(treeList3);
  145. }
  146. var treeList2 = new List<LicenseTypePrivTree>();
  147. var query2 = from p in SysPriv
  148. join pp in licenseTypePrivList
  149. on p.C_Code equals pp.C_Code
  150. where p.C_Code == item2.C_Code
  151. select new
  152. {
  153. pp.C_Code
  154. };
  155. if (Part3Children.Count > 0 || query2.Any())
  156. treeList2.Add(new LicenseTypePrivTree()
  157. {
  158. C_Code = item2.C_Code,
  159. C_Name = item2.C_Name,
  160. C_ParentCode = item2.C_ParentCode,
  161. C_Type = item2.C_Type,
  162. I_Sort = item2.I_Sort,
  163. C_Remark = item2.C_Remark,
  164. C_ImageUrl = item2.C_ImageUrl,
  165. C_PageUrl = item2.C_PageUrl,
  166. C_Module = item2.C_Module,
  167. Open = Part3Children.Count > 0,
  168. Children = Part3Children.Count == 0 ? null : Part3Children
  169. });
  170. Part2Children.AddRange(treeList2);
  171. }
  172. var query1 = from p in SysPriv
  173. join pp in licenseTypePrivList
  174. on p.C_Code equals pp.C_Code
  175. where p.C_Code == item.C_Code
  176. select new
  177. {
  178. pp.C_Code
  179. };
  180. if (Part2Children.Count > 0 || query1.Any())
  181. treeList.Add(new LicenseTypePrivTree()
  182. {
  183. C_Code = item.C_Code,
  184. C_Name = item.C_Name,
  185. C_ParentCode = item.C_ParentCode,
  186. C_Type = item.C_Type,
  187. I_Sort = item.I_Sort,
  188. C_Remark = item.C_Remark,
  189. C_ImageUrl = item.C_ImageUrl,
  190. C_PageUrl = item.C_PageUrl,
  191. C_Module = item.C_Module,
  192. Open = Part2Children.Count > 0,
  193. Children = Part2Children.Count == 0 ? null : Part2Children
  194. });
  195. }
  196. var model = new TsysLicenseTypePrivViewModel { LicenseTypeCode = typeCode, LicenseTypePrivS = treeList };
  197. return Task.FromResult(model);
  198. }
  199. List<LicenseTypePrivTree> LicenseRoleTypePriv(List<TSYS_Priv> sourceList, List<LicenseTypePrivTree> list, string guid)
  200. {
  201. foreach (var item in sourceList.Where(m => m.C_ParentCode.Equals(guid)))
  202. {
  203. var res = LicenseRoleTypePriv(sourceList, new List<LicenseTypePrivTree>(), item.C_Code);
  204. list.Add(new LicenseTypePrivTree()
  205. {
  206. C_Code = item.C_Code,
  207. C_Name = item.C_Name,
  208. C_ParentCode = item.C_ParentCode,
  209. C_Type = item.C_Type,
  210. I_Sort = item.I_Sort,
  211. C_Remark = item.C_Remark,
  212. //LicenseTypeCode = item.LicenseTypeCode,
  213. //LicenseTypeName = item.LicenseTypeName,
  214. C_ImageUrl = item.C_ImageUrl,
  215. C_PageUrl = item.C_PageUrl,
  216. C_Module = item.C_Module,
  217. Open = res.Count > 0,
  218. Children = res.Count > 0 ? res : null
  219. });
  220. }
  221. return list;
  222. }
  223. List<LicenseTypePrivTree> RecursionRoleTypePriv(List<TSYS_Priv> sourceList, List<LicenseTypePrivTree> list, string guid)
  224. {
  225. foreach (var item in sourceList.Where(m => m.C_ParentCode.Equals(guid)))
  226. {
  227. var res = RecursionRoleTypePriv(sourceList, new List<LicenseTypePrivTree>(), item.C_Code);
  228. list.Add(new LicenseTypePrivTree()
  229. {
  230. C_Code = item.C_Code,
  231. C_Name = item.C_Name,
  232. C_ParentCode = item.C_ParentCode,
  233. C_Type = item.C_Type,
  234. I_Sort = item.I_Sort,
  235. C_Remark = item.C_Remark,
  236. C_ImageUrl = item.C_ImageUrl,
  237. C_PageUrl = item.C_PageUrl,
  238. C_Module = item.C_Module,
  239. Open = res.Count > 0,
  240. Children = res.Count > 0 ? res : null
  241. });
  242. }
  243. return list;
  244. }
  245. }
  246. }