|  |  | 
 |  |  | using WIDESEA_Model.Models; | 
 |  |  | using WIDESEA_Model.Models.System; | 
 |  |  | using WIDESEA_SystemRepository; | 
 |  |  | using WIDESEA_Core.Helper; | 
 |  |  | using WIDESEA_Core.HostedService; | 
 |  |  |  | 
 |  |  | namespace WIDESEA_SystemService | 
 |  |  | { | 
 |  |  | 
 |  |  |             _RoleAuthRepository = roleAuthRepository; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         public override WebResponseContent AddData(SaveModel saveModel) | 
 |  |  |         { | 
 |  |  |             string authorityScope = saveModel.MainData["authorityScope"].ToString() ?? ""; | 
 |  |  |             Sys_Role role = saveModel.MainData.DicToModel<Sys_Role>(); | 
 |  |  |             if (BaseDal.QueryFirst(x => x.RoleName == role.RoleName) != null) | 
 |  |  |             { | 
 |  |  |                 return WebResponseContent.Instance.Error($"è§è²åéå¤"); | 
 |  |  |             } | 
 |  |  |             List<Dt_Warehouse> warehouses = BaseDal.Db.Queryable<Dt_Warehouse>().Where(x => true).ToList(); | 
 |  |  |             List<Sys_RoleDataPermission> roleDataPermissions = new List<Sys_RoleDataPermission>(); | 
 |  |  |             if (!string.IsNullOrEmpty(authorityScope)) | 
 |  |  |             { | 
 |  |  |                 string[] scopes = authorityScope.Split(','); | 
 |  |  |                 foreach (string scope in scopes) | 
 |  |  |                 { | 
 |  |  |                     Dt_Warehouse? warehouse = warehouses.FirstOrDefault(x => x.WarehouseId == Convert.ToInt32(scope)); | 
 |  |  |                     if (warehouse != null) | 
 |  |  |                     { | 
 |  |  |                         roleDataPermissions.Add(new Sys_RoleDataPermission | 
 |  |  |                         { | 
 |  |  |                             WarehouseId = warehouse.WarehouseId, | 
 |  |  |                             WarehouseName = warehouse.WarehouseName, | 
 |  |  |                             RoleName = role.RoleName | 
 |  |  |                         }); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             int roleId = BaseDal.AddData(role); | 
 |  |  |             if (roleDataPermissions.Count > 0) | 
 |  |  |             { | 
 |  |  |                 roleDataPermissions.ForEach(x => { x.RoleId = roleId; }); | 
 |  |  |                 BaseDal.Db.Insertable(roleDataPermissions).ExecuteCommand(); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             PermissionDataHostService.UserRoles = PermissionDataHostService.GetUserRoles(Db); | 
 |  |  |  | 
 |  |  |             return WebResponseContent.Instance.OK(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         public override WebResponseContent UpdateData(SaveModel saveModel) | 
 |  |  |         { | 
 |  |  |             string authorityScope = saveModel.MainData["authorityScope"].ToString() ?? ""; | 
 |  |  |             Sys_Role role = saveModel.MainData.DicToModel<Sys_Role>(); | 
 |  |  |             if (BaseDal.QueryFirst(x => x.RoleId == role.RoleId) == null) | 
 |  |  |             { | 
 |  |  |                 return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥æ°æ®"); | 
 |  |  |             } | 
 |  |  |             List<Dt_Warehouse> warehouses = BaseDal.Db.Queryable<Dt_Warehouse>().Where(x => true).ToList(); | 
 |  |  |  | 
 |  |  |             List<Sys_RoleDataPermission> oldDatas = BaseDal.Db.Queryable<Sys_RoleDataPermission>().Where(x => x.RoleId == role.RoleId).ToList(); | 
 |  |  |             List<Sys_RoleDataPermission> roleDataPermissions = new List<Sys_RoleDataPermission>(); | 
 |  |  |             if (!string.IsNullOrEmpty(authorityScope)) | 
 |  |  |             { | 
 |  |  |                 string[] scopes = authorityScope.Split(','); | 
 |  |  |                 foreach (string scope in scopes) | 
 |  |  |                 { | 
 |  |  |                     Sys_RoleDataPermission? oldData = oldDatas.FirstOrDefault(x => x.WarehouseId == Convert.ToInt32(scope)); | 
 |  |  |                     if (oldData == null) | 
 |  |  |                     { | 
 |  |  |                         Dt_Warehouse? warehouse = warehouses.FirstOrDefault(x => x.WarehouseId == Convert.ToInt32(scope)); | 
 |  |  |                         if (warehouse != null) | 
 |  |  |                         { | 
 |  |  |                             roleDataPermissions.Add(new Sys_RoleDataPermission | 
 |  |  |                             { | 
 |  |  |                                 WarehouseId = warehouse.WarehouseId, | 
 |  |  |                                 WarehouseName = warehouse.WarehouseName, | 
 |  |  |                                 RoleName = role.RoleName | 
 |  |  |                             }); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                     else | 
 |  |  |                     { | 
 |  |  |                         oldDatas.Remove(oldData); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             roleDataPermissions.ForEach(x => { x.RoleId = role.RoleId; }); | 
 |  |  |             BaseDal.Db.Insertable(roleDataPermissions).ExecuteCommand(); | 
 |  |  |             BaseDal.Db.Deleteable(oldDatas).ExecuteCommand(); | 
 |  |  |  | 
 |  |  |             PermissionDataHostService.UserRoles = PermissionDataHostService.GetUserRoles(Db); | 
 |  |  |  | 
 |  |  |             return WebResponseContent.Instance.OK(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         public List<int> GetAllChildrenRoleId(int roleId) | 
 |  |  |         { | 
 |  |  |             return GetAllChildren(roleId).Select(x => x.Id).ToList(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         public List<RoleNodes> GetAllChildren(int roleId) | 
 |  |  |         { | 
 |  |  |             if (roleId <= 0) return new List<RoleNodes>() { }; | 
 |  |  | 
 |  |  |             return list; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         public  List<RoleNodes> GetAllRoleId() | 
 |  |  |         public List<RoleNodes> GetAllRoleId() | 
 |  |  |         { | 
 |  |  |             List<RoleNodes> roles = BaseDal.QueryData().Select(s => new RoleNodes() { Id = s.RoleId, ParentId = s.ParentId, RoleName = s.RoleName }).ToList(); | 
 |  |  |  | 
 |  |  | 
 |  |  |             //è·åç¨æ·æé | 
 |  |  |             List<Permissions> permissions = _MenuRepository.GetPermissions(roleId); | 
 |  |  |             //æéç¨æ·æéæ¥è¯¢ææçèåä¿¡æ¯ | 
 |  |  |             List<MenuDTO> menus =  _MenuService.GetUserMenuList(roleId); | 
 |  |  |             List<MenuDTO> menus = _MenuService.GetUserMenuList(roleId); | 
 |  |  |             //è·åå½åç¨æ·æéå¦:(Add,Search)对åºçæ¾ç¤ºææ¬ä¿¡æ¯å¦:Addï¼æ·»å ï¼Search:æ¥è¯¢ | 
 |  |  |             var data = menus.Select(x => new | 
 |  |  |             { | 
 |  |  | 
 |  |  |             List<MenuDTO> menus = _MenuService.GetUserMenuListPDA(roleId); | 
 |  |  |  | 
 |  |  |             //è·åå½åç¨æ·æéå¦:(Add,Search)对åºçæ¾ç¤ºææ¬ä¿¡æ¯å¦:Addï¼æ·»å ï¼Search:æ¥è¯¢ | 
 |  |  |             var data = menus.Where(x => x.MenuType==1).Select(x => new | 
 |  |  |             var data = menus.Where(x => x.MenuType == 1).Select(x => new | 
 |  |  |             { | 
 |  |  |                 Id = x.MenuId, | 
 |  |  |                 Pid = x.ParentId, | 
 |  |  | 
 |  |  |  | 
 |  |  |                 int addCount = updateAuths.Where(x => x.AuthId <= 0).Count(); | 
 |  |  |                 int updateCount = updateAuths.Where(x => x.AuthId > 0).Count(); | 
 |  |  |                  | 
 |  |  |  | 
 |  |  |                 string _version = DateTime.Now.ToString("yyyyMMddHHMMssfff"); | 
 |  |  |  | 
 |  |  |  |