using ProductionSystem_Log; using ProductionSystem_Model.DbModel.System; using ProductionSystem_Model.ViewModel.Response.System; using SqlSugar; using System; using System.Collections.Generic; namespace ProductionSystem_Service { /// /// 菜单角色 /// public class MenuRoleService : DbContext { /// /// 查询所有菜单角色关系 /// /// public ISugarQueryable QueryMenuRoles() { try { return db.Queryable(); } catch (Exception ex) { LogHelper.Error(ex, "执行MenuRoleService下QueryMenuRoles时异常"); return null; } } /// /// 查询有效菜单角色关系 /// /// public ISugarQueryable QueryActiveMenuRoles() { try { return db.Queryable().Where(m => m.IsActive); } catch (Exception ex) { LogHelper.Error(ex, "执行MenuRoleService下QueryActiveMenuRoles时异常"); return null; } } /// /// 根据角色编码查询有效菜单角色关系 /// /// public List QueryActiveMenuRolesByRoleCode(string roleCode) { try { return db.Queryable().Where(m => m.RoleCode == roleCode && m.IsActive).ToList(); } catch (Exception ex) { LogHelper.Error(ex, "执行MenuRoleService下QueryActiveMenuRolesByRoleCode时异常"); return null; } } /// /// 根据角色编码查询有效菜单 /// /// /// public List QueryActiveMenusByRoleCode(string roleCode) { try { return db.Queryable() .InnerJoin((a, b) => a.MenuCode == b.MenuCode && a.IsActive && b.IsActive) .Where((a, b) => a.RoleCode == roleCode) .Select((a, b) => new MenuVM { MenuCode = a.MenuCode, MenuName = b.MenuName, ImgPath = b.MenuImgPath }).ToList(); } catch (Exception ex) { LogHelper.Error(ex, "执行MenuRoleService下QueryActiveMenusByRoleCode时异常"); return null; } } /// /// 新增菜单角色关系 /// /// /// public int AddMenuRole(Sys_Menu_Role sys_Menu_Role) { try { return db.Insertable(sys_Menu_Role).ExecuteCommand(); } catch (Exception ex) { LogHelper.Error(ex, "执行MenuRoleService下AddMenuRole时异常"); return -1; } } /// /// 修改菜单角色关系 /// /// /// public int UpdateMenuRole(Sys_Menu_Role sys_Menu_Role) { try { return db.Updateable(sys_Menu_Role).ExecuteCommand(); } catch (Exception ex) { LogHelper.Error(ex, "执行MenuRoleService下UpdateMenuRole时异常"); return -1; } } /// /// 根据Id集合物理删除菜单角色关系 /// /// /// public int DoDelMenusByIds(List ids) { try { return db.Deleteable().Where(m => ids.Contains(m.Id)).ExecuteCommand(); } catch (Exception ex) { LogHelper.Error(ex, "执行MenuRoleService下DoDelMenusByIds时异常"); return -1; } } } }