using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WMS.BZModels; using WMS.BZModels.Dto.UserCenterManager.AclAuthorizeDtos; using WMS.BZModels.Models.UserCenterManager; using WMS.Info; using WMS.BZSqlSugar; using WMS.Util; namespace WMS.BZServices.UserCenterManager { public class AclAuthorizeService { public const string ALLAuthorize = "7DC7155C4A674050BD591CF74B800958"; public const string IcoAuthorize = "fa fa-align-justify"; private readonly Repository _aclAuthorizeRepository; private readonly Repository _aclConstRepository; private readonly ACLUserRelationService _aclUserRelationService; private readonly AclUserInfoService _aclUserInfoService; public AclAuthorizeService(Repository aclAuthorizeRepository, Repository aclConstRepository, ACLUserRelationService aclUserRelationService, AclUserInfoService aclUserInfoService) { _aclAuthorizeRepository = aclAuthorizeRepository; _aclConstRepository = aclConstRepository; _aclUserRelationService = aclUserRelationService; _aclUserInfoService = aclUserInfoService; } /// /// 获取按钮列表树形数据(基于WebApp) /// /// public List GetWebAppTree() { try { List list = _aclConstRepository.Queryable().Where(it => it.AppTypeNum == (int)EAppType.PC).ToList(); List WebAppTree = new List(); foreach (var webitem in list) { TreeModel node = new TreeModel(); node.id = webitem.Code; node.text = webitem.Name; node.value = webitem.Code; node.showcheck = true; node.checkstate = 0; node.isexpand = true; node.icon = IcoAuthorize; node.parentId = webitem.PNO; WebAppTree.Add(node); } return WebAppTree.ToTree(); } catch (Exception ex) { throw ex; } } /// /// 获取按钮列表树形数据(基于OnLineRFApp) /// /// public List GetOnLineRFTree() { List list = _aclConstRepository.Queryable().Where(it => it.AppTypeNum == (int)EAppType.OnLineRF).ToList(); List OnRFAppTree = new List(); foreach (var OnRFitem in list) { TreeModel node = new TreeModel(); node.id = OnRFitem.Code; node.text = OnRFitem.Name; node.value = OnRFitem.Code; node.showcheck = true; node.checkstate = 0; node.isexpand = true; node.icon = IcoAuthorize; node.parentId = OnRFitem.PNO; OnRFAppTree.Add(node); } return OnRFAppTree.ToTree(); } public List GetItemIdList(string objectNo, EACLType eACLType, ACLObjType eACLObjType) { return _aclAuthorizeRepository.Queryable().Where(it => it.ObjNO == objectNo && it.AclTypeNum == (int)eACLType && it.ObjTypeNum == (int)eACLObjType).Select(it => it.ItemNO).Distinct().ToList(); } public void Authorize(AuthorizeInfo authorize) { void action() { _aclAuthorizeRepository.Deleteable().Where(it => it.ObjNO == authorize.ObjectNo && it.ObjTypeNum == (int)authorize.ObjTypeNum).ExecuteCommand(); if (authorize.WarehouseList != null) { var lists = new List(); var WebApplists = new List(); var OnlineRFNolists = new List(); foreach (var item in authorize.WarehouseList) { //if (item == ALLAuthorize) //{ // continue; //} //if (item.Contains(BaseWarehouse.WarehouseHead)) //{ // continue; //} lists.Add(new AclAuthorize() { ObjTypeNum = (int)authorize.ObjTypeNum, ItemNO = item, ObjNO = authorize.ObjectNo, WarehouseNo = item, AclTypeNum = (int)EACLType.Warehouse }); if (authorize.WebAppNoList != null) { foreach (var webAppitem in authorize.WebAppNoList) { WebApplists.Add(new AclAuthorize() { ObjTypeNum = (int)authorize.ObjTypeNum, ItemNO = webAppitem, ObjNO = authorize.ObjectNo, WarehouseNo = item, AclTypeNum = (int)EACLType.WebApp }); } } if (authorize.OnlineRFNoList != null) { foreach (var OnlineRFNoitem in authorize.OnlineRFNoList) { OnlineRFNolists.Add(new AclAuthorize() { ObjTypeNum = (int)authorize.ObjTypeNum, ItemNO = OnlineRFNoitem, ObjNO = authorize.ObjectNo, WarehouseNo = item, AclTypeNum = (int)EACLType.OnlineRF }); } } } _aclAuthorizeRepository.Insert(lists); _aclAuthorizeRepository.Insert(WebApplists); _aclAuthorizeRepository.Insert(OnlineRFNolists); } } _aclAuthorizeRepository.UseTran(action); } public Dictionary GetAuthorize(LoginUserInfo loginUser, string warehouseNO) { Dictionary dics = new Dictionary(); if (loginUser.UserType == EUserType.User) { var entityuser = _aclUserInfoService.GetEntityByCode(loginUser.UserNo); if (entityuser != null) { var rolegroupIds = _aclUserRelationService.GetObjectIds(Convert.ToInt64(entityuser.Id), 0); string objectIds = entityuser.Id + (string.IsNullOrEmpty(rolegroupIds) ? "" : ("," + rolegroupIds)); var arr = objectIds.Split(','); var WarehouseNo = warehouseNO; if (string.IsNullOrWhiteSpace(warehouseNO) || warehouseNO == "null" || warehouseNO == "undefined") { WarehouseNo = entityuser.WarehouseNo; } var UserAuthorizeList = _aclAuthorizeRepository.Queryable().Where(o => arr.Contains(o.ObjNO)).ToList(); if (string.IsNullOrWhiteSpace(WarehouseNo)) { if (UserAuthorizeList.Any()) { WarehouseNo = UserAuthorizeList.Where(o => o.AclTypeNum == 3).OrderBy(o => o.AddTime).Select(o => o.ItemNO).Distinct().FirstOrDefault(""); } } if (string.IsNullOrWhiteSpace(WarehouseNo)) { return dics; } var alllists = WMS.BZModels.Extensions.EnumToListIdDesc(); var authWarehouseList = new List(); if(UserAuthorizeList.Count==0 || UserAuthorizeList.Where(o => o.AclTypeNum == 3).Count()==0 ) { if (warehouseNO != entityuser.WarehouseNo) WarehouseNo = entityuser.WarehouseNo; } authWarehouseList.Insert(0, alllists.FirstOrDefault(item => item.id == WarehouseNo) ?? new EnumEntity2()); UserAuthorizeList.Where(o => o.AclTypeNum == 3 && o.WarehouseNo != WarehouseNo).ToList().ForEach(o => { if (!string.IsNullOrWhiteSpace(o.WarehouseNo)) { var item = alllists.FirstOrDefault(item => item.id == o.WarehouseNo); if (item != null) { if(!authWarehouseList.Contains(item)) authWarehouseList.Add(item); } } }); UserAuthorizeList.Where(o => arr.Contains(o.ObjNO) && o.WarehouseNo == WarehouseNo).Select(o => new WmsAuthorize { UserNO = entityuser.Code, ACLTypeNum = o.AclTypeNum, ItemNO = o.ItemNO }).Distinct().ToList().ForEach(it => { if (!dics.ContainsKey(it.ItemNO)) dics.Add(it.ItemNO, it); }); dics.Add("authWarehouses", new WmsAuthorize { WarehouseList = authWarehouseList }); //_aclAuthorizeRepository.Queryable().Where(o => arr.Contains(o.ObjNO) && o.WarehouseNo == WarehouseNo).Select(o => new WmsAuthorize //{ // UserNO = entityuser.Code, // ACLTypeNum = o.AclTypeNum, // ItemNO = o.ItemNO //}).Distinct().ToList().ForEach(it => dics.Add(it.ItemNO, it)); } } return dics; } } }