123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- 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<AclAuthorize> _aclAuthorizeRepository;
- private readonly Repository<AclConst> _aclConstRepository;
- private readonly ACLUserRelationService _aclUserRelationService;
- private readonly AclUserInfoService _aclUserInfoService;
- public AclAuthorizeService(Repository<AclAuthorize> aclAuthorizeRepository, Repository<AclConst> aclConstRepository, ACLUserRelationService aclUserRelationService, AclUserInfoService aclUserInfoService)
- {
- _aclAuthorizeRepository = aclAuthorizeRepository;
- _aclConstRepository = aclConstRepository;
- _aclUserRelationService = aclUserRelationService;
- _aclUserInfoService = aclUserInfoService;
- }
- /// <summary>
- /// 获取按钮列表树形数据(基于WebApp)
- /// </summary>
- /// <returns></returns>
- public List<TreeModel> GetWebAppTree()
- {
- try
- {
- List<AclConst> list = _aclConstRepository.Queryable().Where(it => it.AppTypeNum == (int)EAppType.PC).ToList();
- List<TreeModel> WebAppTree = new List<TreeModel>();
- 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;
- }
- }
- /// <summary>
- /// 获取按钮列表树形数据(基于OnLineRFApp)
- /// </summary>
- /// <returns></returns>
- public List<TreeModel> GetOnLineRFTree()
- {
- List<AclConst> list = _aclConstRepository.Queryable().Where(it => it.AppTypeNum == (int)EAppType.OnLineRF).ToList();
- List<TreeModel> OnRFAppTree = new List<TreeModel>();
- 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<string> 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<AclAuthorize>();
- var WebApplists = new List<AclAuthorize>();
- var OnlineRFNolists = new List<AclAuthorize>();
- 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<string, WmsAuthorize> GetAuthorize(LoginUserInfo loginUser, string warehouseNO)
- {
- Dictionary<string, WmsAuthorize> dics = new Dictionary<string, WmsAuthorize>();
- 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<WearHouseList>();
- var authWarehouseList = new List<EnumEntity2>();
- 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;
- }
- }
- }
|