AclAuthorizeService.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using WMS.BZModels;
  8. using WMS.BZModels.Dto.UserCenterManager.AclAuthorizeDtos;
  9. using WMS.BZModels.Models.UserCenterManager;
  10. using WMS.Info;
  11. using WMS.BZSqlSugar;
  12. using WMS.Util;
  13. namespace WMS.BZServices.UserCenterManager
  14. {
  15. public class AclAuthorizeService
  16. {
  17. public const string ALLAuthorize = "7DC7155C4A674050BD591CF74B800958";
  18. public const string IcoAuthorize = "fa fa-align-justify";
  19. private readonly Repository<AclAuthorize> _aclAuthorizeRepository;
  20. private readonly Repository<AclConst> _aclConstRepository;
  21. private readonly ACLUserRelationService _aclUserRelationService;
  22. private readonly AclUserInfoService _aclUserInfoService;
  23. public AclAuthorizeService(Repository<AclAuthorize> aclAuthorizeRepository, Repository<AclConst> aclConstRepository, ACLUserRelationService aclUserRelationService, AclUserInfoService aclUserInfoService)
  24. {
  25. _aclAuthorizeRepository = aclAuthorizeRepository;
  26. _aclConstRepository = aclConstRepository;
  27. _aclUserRelationService = aclUserRelationService;
  28. _aclUserInfoService = aclUserInfoService;
  29. }
  30. /// <summary>
  31. /// 获取按钮列表树形数据(基于WebApp)
  32. /// </summary>
  33. /// <returns></returns>
  34. public List<TreeModel> GetWebAppTree()
  35. {
  36. try
  37. {
  38. List<AclConst> list = _aclConstRepository.Queryable().Where(it => it.AppTypeNum == (int)EAppType.PC).ToList();
  39. List<TreeModel> WebAppTree = new List<TreeModel>();
  40. foreach (var webitem in list)
  41. {
  42. TreeModel node = new TreeModel();
  43. node.id = webitem.Code;
  44. node.text = webitem.Name;
  45. node.value = webitem.Code;
  46. node.showcheck = true;
  47. node.checkstate = 0;
  48. node.isexpand = true;
  49. node.icon = IcoAuthorize;
  50. node.parentId = webitem.PNO;
  51. WebAppTree.Add(node);
  52. }
  53. return WebAppTree.ToTree();
  54. }
  55. catch (Exception ex)
  56. {
  57. throw ex;
  58. }
  59. }
  60. /// <summary>
  61. /// 获取按钮列表树形数据(基于OnLineRFApp)
  62. /// </summary>
  63. /// <returns></returns>
  64. public List<TreeModel> GetOnLineRFTree()
  65. {
  66. List<AclConst> list = _aclConstRepository.Queryable().Where(it => it.AppTypeNum == (int)EAppType.OnLineRF).ToList();
  67. List<TreeModel> OnRFAppTree = new List<TreeModel>();
  68. foreach (var OnRFitem in list)
  69. {
  70. TreeModel node = new TreeModel();
  71. node.id = OnRFitem.Code;
  72. node.text = OnRFitem.Name;
  73. node.value = OnRFitem.Code;
  74. node.showcheck = true;
  75. node.checkstate = 0;
  76. node.isexpand = true;
  77. node.icon = IcoAuthorize;
  78. node.parentId = OnRFitem.PNO;
  79. OnRFAppTree.Add(node);
  80. }
  81. return OnRFAppTree.ToTree();
  82. }
  83. public List<string> GetItemIdList(string objectNo, EACLType eACLType, ACLObjType eACLObjType)
  84. {
  85. return _aclAuthorizeRepository.Queryable().Where(it => it.ObjNO == objectNo && it.AclTypeNum == (int)eACLType && it.ObjTypeNum == (int)eACLObjType).Select(it => it.ItemNO).Distinct().ToList();
  86. }
  87. public void Authorize(AuthorizeInfo authorize)
  88. {
  89. void action()
  90. {
  91. _aclAuthorizeRepository.Deleteable().Where(it => it.ObjNO == authorize.ObjectNo && it.ObjTypeNum == (int)authorize.ObjTypeNum).ExecuteCommand();
  92. if (authorize.WarehouseList != null)
  93. {
  94. var lists = new List<AclAuthorize>();
  95. var WebApplists = new List<AclAuthorize>();
  96. var OnlineRFNolists = new List<AclAuthorize>();
  97. foreach (var item in authorize.WarehouseList)
  98. {
  99. //if (item == ALLAuthorize)
  100. //{
  101. // continue;
  102. //}
  103. //if (item.Contains(BaseWarehouse.WarehouseHead))
  104. //{
  105. // continue;
  106. //}
  107. lists.Add(new AclAuthorize()
  108. {
  109. ObjTypeNum = (int)authorize.ObjTypeNum,
  110. ItemNO = item,
  111. ObjNO = authorize.ObjectNo,
  112. WarehouseNo = item,
  113. AclTypeNum = (int)EACLType.Warehouse
  114. });
  115. if (authorize.WebAppNoList != null)
  116. {
  117. foreach (var webAppitem in authorize.WebAppNoList)
  118. {
  119. WebApplists.Add(new AclAuthorize()
  120. {
  121. ObjTypeNum = (int)authorize.ObjTypeNum,
  122. ItemNO = webAppitem,
  123. ObjNO = authorize.ObjectNo,
  124. WarehouseNo = item,
  125. AclTypeNum = (int)EACLType.WebApp
  126. });
  127. }
  128. }
  129. if (authorize.OnlineRFNoList != null)
  130. {
  131. foreach (var OnlineRFNoitem in authorize.OnlineRFNoList)
  132. {
  133. OnlineRFNolists.Add(new AclAuthorize()
  134. {
  135. ObjTypeNum = (int)authorize.ObjTypeNum,
  136. ItemNO = OnlineRFNoitem,
  137. ObjNO = authorize.ObjectNo,
  138. WarehouseNo = item,
  139. AclTypeNum = (int)EACLType.OnlineRF
  140. });
  141. }
  142. }
  143. }
  144. _aclAuthorizeRepository.Insert(lists);
  145. _aclAuthorizeRepository.Insert(WebApplists);
  146. _aclAuthorizeRepository.Insert(OnlineRFNolists);
  147. }
  148. }
  149. _aclAuthorizeRepository.UseTran(action);
  150. }
  151. public Dictionary<string, WmsAuthorize> GetAuthorize(LoginUserInfo loginUser, string warehouseNO)
  152. {
  153. Dictionary<string, WmsAuthorize> dics = new Dictionary<string, WmsAuthorize>();
  154. if (loginUser.UserType == EUserType.User)
  155. {
  156. var entityuser = _aclUserInfoService.GetEntityByCode(loginUser.UserNo);
  157. if (entityuser != null)
  158. {
  159. var rolegroupIds = _aclUserRelationService.GetObjectIds(Convert.ToInt64(entityuser.Id), 0);
  160. string objectIds = entityuser.Id + (string.IsNullOrEmpty(rolegroupIds) ? "" : ("," + rolegroupIds));
  161. var arr = objectIds.Split(',');
  162. var WarehouseNo = warehouseNO;
  163. if (string.IsNullOrWhiteSpace(warehouseNO) || warehouseNO == "null" || warehouseNO == "undefined")
  164. {
  165. WarehouseNo = entityuser.WarehouseNo;
  166. }
  167. var UserAuthorizeList = _aclAuthorizeRepository.Queryable().Where(o => arr.Contains(o.ObjNO)).ToList();
  168. if (string.IsNullOrWhiteSpace(WarehouseNo))
  169. {
  170. if (UserAuthorizeList.Any())
  171. {
  172. WarehouseNo = UserAuthorizeList.Where(o => o.AclTypeNum == 3).OrderBy(o => o.AddTime).Select(o => o.ItemNO).Distinct().FirstOrDefault("");
  173. }
  174. }
  175. if (string.IsNullOrWhiteSpace(WarehouseNo))
  176. {
  177. return dics;
  178. }
  179. var alllists = WMS.BZModels.Extensions.EnumToListIdDesc<WearHouseList>();
  180. var authWarehouseList = new List<EnumEntity2>();
  181. if(UserAuthorizeList.Count==0 || UserAuthorizeList.Where(o => o.AclTypeNum == 3).Count()==0 )
  182. {
  183. if (warehouseNO != entityuser.WarehouseNo)
  184. WarehouseNo = entityuser.WarehouseNo;
  185. }
  186. authWarehouseList.Insert(0, alllists.FirstOrDefault(item => item.id == WarehouseNo) ?? new EnumEntity2());
  187. UserAuthorizeList.Where(o => o.AclTypeNum == 3 && o.WarehouseNo != WarehouseNo).ToList().ForEach(o =>
  188. {
  189. if (!string.IsNullOrWhiteSpace(o.WarehouseNo))
  190. {
  191. var item = alllists.FirstOrDefault(item => item.id == o.WarehouseNo);
  192. if (item != null)
  193. {
  194. if(!authWarehouseList.Contains(item))
  195. authWarehouseList.Add(item);
  196. }
  197. }
  198. });
  199. UserAuthorizeList.Where(o => arr.Contains(o.ObjNO) && o.WarehouseNo == WarehouseNo).Select(o => new WmsAuthorize
  200. {
  201. UserNO = entityuser.Code,
  202. ACLTypeNum = o.AclTypeNum,
  203. ItemNO = o.ItemNO
  204. }).Distinct().ToList().ForEach(it =>
  205. {
  206. if (!dics.ContainsKey(it.ItemNO))
  207. dics.Add(it.ItemNO, it);
  208. });
  209. dics.Add("authWarehouses", new WmsAuthorize { WarehouseList = authWarehouseList });
  210. //_aclAuthorizeRepository.Queryable().Where(o => arr.Contains(o.ObjNO) && o.WarehouseNo == WarehouseNo).Select(o => new WmsAuthorize
  211. //{
  212. // UserNO = entityuser.Code,
  213. // ACLTypeNum = o.AclTypeNum,
  214. // ItemNO = o.ItemNO
  215. //}).Distinct().ToList().ForEach(it => dics.Add(it.ItemNO, it));
  216. }
  217. }
  218. return dics;
  219. }
  220. }
  221. }