refactor: 重构服务基类增加用户服务
This commit is contained in:
parent
0b1a110b22
commit
33054356d0
|
@ -1,6 +1,6 @@
|
|||
using BootstrapAdmin.DataAccess.EFCore;
|
||||
using BootstrapAdmin.DataAccess.EFCore.Services;
|
||||
using BootstrapAdmin.DataAccess.Core;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapBlazor.Components;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using BootstrapAdmin.DataAccess.Core;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
|
||||
namespace BootstrapAdmin.DataAccess.EFCore.Services
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using BootstrapAdmin.DataAccess.Core;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.DataAccess.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using BootstrapAdmin.DataAccess.Core;
|
||||
using BootstrapAdmin.DataAccess.PetaPoco;
|
||||
using BootstrapAdmin.DataAccess.PetaPoco;
|
||||
using BootstrapAdmin.DataAccess.PetaPoco.Services;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapBlazor.Components;
|
||||
using BootstrapBlazor.DataAcces.PetaPoco.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
@ -35,6 +35,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
|
||||
services.AddSingleton<INavigations, NavigationsService>();
|
||||
services.AddSingleton<IDicts, DictsService>();
|
||||
services.AddSingleton<IUsers, UsersService>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
using PetaPoco;
|
||||
|
||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
||||
{
|
||||
abstract class BaseDatabase
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
protected IDatabase? Database { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,8 +1,14 @@
|
|||
using BootstrapAdmin.DataAccess.Core;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using PetaPoco;
|
||||
|
||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
||||
{
|
||||
class DictsService : IDicts
|
||||
class DictsService : BaseDatabase, IDicts
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
public DictsService(IDatabase db) => Database = db;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using BootstrapAdmin.DataAccess.Core;
|
||||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using PetaPoco;
|
||||
|
||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
||||
|
@ -7,10 +7,8 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class NavigationsService : INavigations
|
||||
class NavigationsService : BaseDatabase, INavigations
|
||||
{
|
||||
private IDatabase Database { get; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
using BootstrapAdmin.Web.Core;
|
||||
using PetaPoco;
|
||||
|
||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
||||
{
|
||||
class UsersService : BaseDatabase, IUsers
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
public UsersService(IDatabase db) => Database = db;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public List<string> GetApps(string userName) => Database.Fetch<string>($"select d.Code from Dicts d inner join RoleApp ra on d.Code = ra.AppId inner join (select r.Id from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @0 union select r.Id from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @0) r on ra.RoleId = r.ID union select Code from Dicts where Category = @1 and exists(select r.ID from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @0 and r.RoleName = @2 union select r.ID from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @0 and r.RoleName = @2)", userName, "应用程序", "Administrators");
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public List<string> GetRoles(string userName) => Database.Fetch<string>($"select r.RoleName from Roles r inner join UserRole ur on r.ID=ur.RoleID inner join Users u on ur.UserID = u.ID and u.UserName = @0 union select r.RoleName from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID and u.UserName=@0", userName);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace BootstrapAdmin.DataAccess.Core
|
||||
namespace BootstrapAdmin.Web.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Dict 字典表接口
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using BootstrapAdmin.DataAccess.Models;
|
||||
|
||||
namespace BootstrapAdmin.DataAccess.Core
|
||||
namespace BootstrapAdmin.Web.Core
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
namespace BootstrapAdmin.Web.Core
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface IUsers
|
||||
{
|
||||
/// <summary>
|
||||
/// 通过用户名获取角色列表
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
List<string> GetRoles(string userName);
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户名获得授权 App 集合
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
List<string> GetApps(string userName);
|
||||
}
|
||||
}
|
|
@ -1,21 +1,30 @@
|
|||
using Bootstrap.Security.Blazor;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
|
||||
namespace BootstrapAdmin.Web.Services
|
||||
{
|
||||
class AdminService : IBootstrapAdminService
|
||||
{
|
||||
private IUsers User { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
public AdminService(IUsers user) => User = user;
|
||||
|
||||
/// <summary>
|
||||
/// 通过当前登录用户名获取角色集合方法
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> GetRolesByUserName(string userName) => new List<string>() { "Administrators" };
|
||||
public List<string> GetRoles(string userName) => User.GetRoles(userName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 通过当前登录用户名获取授权 App 集合方法
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> GetAppsByUserName(string userName) => new List<string>() { "BA" };
|
||||
public List<string> GetApps(string userName) => User.GetApps(userName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
/// <param name="configuration"></param>
|
||||
public BootstrapAppContext(IConfiguration configuration)
|
||||
{
|
||||
AppId = configuration.GetValue("AppId", "demo");
|
||||
AppId = configuration.GetValue("AppId", "BA");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using BootstrapAdmin.DataAccess.Core;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.Web.Extensions;
|
||||
|
||||
namespace BootstrapAdmin.Web.Shared
|
||||
|
|
Loading…
Reference in New Issue