¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Concurrent; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.System; |
| | | using WIDESEA_ISystemRepository; |
| | | using WIDESEA_ISystemService; |
| | | using WIDESEA_Model; |
| | | using WIDESEA_Model.Models; |
| | | |
| | | namespace WIDESEA_SystemService |
| | | { |
| | | public class Sys_MenuService : ServiceBase<Sys_Menu, ISys_MenuRepository>, ISys_MenuService |
| | | { |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | |
| | | public ISys_MenuRepository Repository => BaseDal; |
| | | |
| | | public Sys_MenuService(ISys_MenuRepository BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åå½åç¨æ·ææèå䏿é |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public object GetCurrentMenuActionList() |
| | | { |
| | | object obj = GetMenuActionList(App.User.RoleId); |
| | | if (obj is IEnumerable<object> list) |
| | | { |
| | | if (list.Any()) |
| | | { |
| | | return obj; |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error("æªè·åå°èåä¿¡æ¯"); |
| | | } |
| | | } |
| | | return obj; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è§è²IDè·åèå䏿é |
| | | /// </summary> |
| | | /// <param name="roleId"></param> |
| | | /// <returns></returns> |
| | | public object GetMenuActionList(int roleId) |
| | | { |
| | | if (App.User.IsRoleIdSuperAdmin(roleId)) |
| | | { |
| | | return BaseDal.GetSuperAdminMenu(); |
| | | } |
| | | return BaseDal.GetMenuByRoleId(roleId); |
| | | } |
| | | |
| | | |
| | | public List<MenuDTO> GetUserMenuList(int roleId) |
| | | { |
| | | if (App.User.IsRoleIdSuperAdmin(roleId)) |
| | | { |
| | | return BaseDal.GetAllMenu(); |
| | | } |
| | | List<int> menuIds = BaseDal.GetPermissions(roleId).Select(x => x.MenuId).ToList(); |
| | | return BaseDal.GetAllMenu().Where(x => menuIds.Contains(x.MenuId)).ToList(); |
| | | } |
| | | |
| | | public List<MenuDTO> GetUserMenuListPDA(int roleId) |
| | | { |
| | | if (App.User.IsRoleIdSuperAdmin(roleId)) |
| | | { |
| | | return BaseDal.GetAllMenuPDA(); |
| | | } |
| | | List<int> menuIds = BaseDal.GetPermissions(roleId).Select(x => x.MenuId).ToList(); |
| | | return BaseDal.GetAllMenuPDA().Where(x => menuIds.Contains(x.MenuId)).ToList(); |
| | | } |
| | | |
| | | public List<ActionDTO> GetActions(int menuId, List<ActionDTO> menuActions, List<Permissions> permissions, int roleId) |
| | | { |
| | | if (App.User.IsRoleIdSuperAdmin(roleId)) |
| | | { |
| | | return menuActions; |
| | | } |
| | | |
| | | return menuActions.Where(p => permissions |
| | | .Exists(w => menuId == w.MenuId |
| | | && w.UserAuthArr.Contains(p.Value))) |
| | | .ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç¼è¾ä¿®æ¹èåæ¶,è·åææèå |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public object GetMenu() |
| | | { |
| | | if (App.User.IsRoleIdSuperAdmin(App.User.RoleId)) |
| | | { |
| | | List<int> menuIds = BaseDal.QueryData().Select(x => x.MenuId).ToList(); |
| | | return BaseDal.GetMenu(menuIds); |
| | | } |
| | | else |
| | | { |
| | | List<int> menuIds = BaseDal.GetPermissions(App.User.RoleId).Select(x => x.MenuId).ToList(); |
| | | return BaseDal.GetMenu(menuIds); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç¼è¾èåæ¶ï¼è·åèåä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="menuId"></param> |
| | | /// <returns></returns> |
| | | public object GetTreeItem(int menuId) |
| | | { |
| | | return BaseDal.GetTreeItem(menuId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ°å»ºæç¼è¾èå |
| | | /// </summary> |
| | | /// <param name="menu"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent Save(Sys_Menu menu) |
| | | { |
| | | WebResponseContent webResponse = new WebResponseContent(); |
| | | if (menu == null) return webResponse.Error("没æè·åå°æäº¤çåæ°"); |
| | | if (menu.MenuId > 0 && menu.MenuId == menu.ParentId) return webResponse.Error("ç¶çº§IDä¸è½æ¯å½åèåçID"); |
| | | try |
| | | { |
| | | //webResponse = menu.ValidationEntity(x => new { x.MenuName, x.TableName }); |
| | | //if (!webResponse.Status) return webResponse; |
| | | if (menu.TableName != "/" && menu.TableName != ".") |
| | | { |
| | | // 2022.03.26å¢ç§»å¨ç«¯å èåç±»å夿 |
| | | Sys_Menu sysMenu = BaseDal.QueryFirst(x => x.TableName == menu.TableName); |
| | | if (sysMenu != null) |
| | | { |
| | | if (sysMenu.MenuType == menu.MenuType) |
| | | { |
| | | if ((menu.MenuId > 0 && sysMenu.MenuId != menu.MenuId) |
| | | || menu.MenuId <= 0) |
| | | { |
| | | return webResponse.Error($"è§å¾/表åã{menu.TableName}ã已被å
¶ä»èå使ç¨"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | bool _changed = false; |
| | | if (menu.MenuId <= 0) |
| | | { |
| | | int id = BaseDal.AddData(menu); |
| | | menu.MenuId = id; |
| | | } |
| | | else |
| | | { |
| | | //2020.05.07æ°å¢ç¦æ¢éæ©ä¸çº§è§è²ä¸ºèªå·± |
| | | if (menu.MenuId == menu.ParentId) |
| | | { |
| | | return webResponse.Error($"ç¶çº§idä¸è½ä¸ºèªå·±"); |
| | | } |
| | | if (BaseDal.QueryFirst(x => x.ParentId == menu.MenuId && menu.ParentId == x.MenuId) != null) |
| | | { |
| | | return webResponse.Error($"ä¸è½éæ©æ¤ç¶çº§idï¼éæ©çç¶çº§idä¸å½åèåå½¢æä¾èµå
³ç³»"); |
| | | } |
| | | |
| | | _changed = BaseDal.QueryData(c => c.MenuId == menu.MenuId).Select(s => s.Auth).FirstOrDefault() != menu.Auth; |
| | | |
| | | BaseDal.UpdateData(menu); |
| | | } |
| | | webResponse.OK("ä¿åæå", menu); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | webResponse.Error(ex.Message); |
| | | } |
| | | return webResponse; |
| | | |
| | | } |
| | | |
| | | public WebResponseContent DelMenu(int menuId) |
| | | { |
| | | WebResponseContent webResponse = new WebResponseContent(); |
| | | if(BaseDal.QueryFirst(x=>x.ParentId == menuId) != null) |
| | | { |
| | | return webResponse = WebResponseContent.Instance.Error("å½åèååå¨åèå,请å
å é¤åèå!"); |
| | | } |
| | | BaseDal.DeleteDataById(menuId); |
| | | |
| | | return webResponse = WebResponseContent.Instance.OK("å 餿å"); |
| | | } |
| | | } |
| | | } |