chore: 增加接口类工程

This commit is contained in:
Argo-Tianyi 2021-12-11 10:21:35 +08:00
parent 16d3d52005
commit f4ba67baf9
23 changed files with 248 additions and 68 deletions

View File

@ -5,6 +5,7 @@
"src\\blazor\\admin\\BootstrapAdmin.DataAccess.EFCore\\BootstrapAdmin.DataAccess.EFCore.csproj",
"src\\blazor\\admin\\BootstrapAdmin.DataAccess.Models\\BootstrapAdmin.DataAccess.Models.csproj",
"src\\blazor\\admin\\BootstrapAdmin.DataAccess\\BootstrapAdmin.DataAccess.csproj",
"src\\blazor\\admin\\BootstrapAdmin.Web.Interface\\BootstrapAdmin.Web.Interface.csproj",
"src\\blazor\\admin\\BootstrapAdmin.Web\\BootstrapAdmin.Web.csproj",
"src\\mvc\\admin\\Bootstrap.Admin\\Bootstrap.Admin.csproj",
"src\\mvc\\admin\\Bootstrap.DataAccess\\Bootstrap.DataAccess.csproj"

View File

@ -151,6 +151,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapAdmin.DataAccess.E
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapAdmin.DataAccess.Models", "src\blazor\admin\BootstrapAdmin.DataAccess.Models\BootstrapAdmin.DataAccess.Models.csproj", "{7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapAdmin.Web.Interface", "src\blazor\admin\BootstrapAdmin.Web.Interface\BootstrapAdmin.Web.Interface.csproj", "{C57CE871-FBC9-44B7-996B-E8D3449EDAD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -209,6 +211,10 @@ Global
{7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}.Release|Any CPU.Build.0 = Release|Any CPU
{C57CE871-FBC9-44B7-996B-E8D3449EDAD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C57CE871-FBC9-44B7-996B-E8D3449EDAD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C57CE871-FBC9-44B7-996B-E8D3449EDAD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C57CE871-FBC9-44B7-996B-E8D3449EDAD4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -244,6 +250,7 @@ Global
{1C04A3C2-DF68-4716-BA69-259CEC6E2311} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C}
{D8ED2DF7-F7E1-4DE7-B097-D0BEE51D58E9} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C}
{7E3861AB-F797-4A9F-B7CE-0E35751FFCD9} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C}
{C57CE871-FBC9-44B7-996B-E8D3449EDAD4} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {221EAE38-5F75-4391-9A48-E462A9F3B8FC}

View File

@ -1,9 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BootstrapAdmin.Web.Interface\BootstrapAdmin.Web.Interface.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,59 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>BootstrapAdmin.DataAccess.EFCore</name>
</assembly>
<members>
<member name="T:BootstrapAdmin.DataAccess.EFCore.BootstrapAdminContext">
<summary>
</summary>
</member>
<member name="M:BootstrapAdmin.DataAccess.EFCore.BootstrapAdminContext.#ctor(Microsoft.EntityFrameworkCore.DbContextOptions{BootstrapAdmin.DataAccess.EFCore.BootstrapAdminContext})">
<summary>
构造函数
</summary>
<param name="options"></param>
</member>
<member name="P:BootstrapAdmin.DataAccess.EFCore.BootstrapAdminContext.Dicts">
<summary>
</summary>
</member>
<member name="P:BootstrapAdmin.DataAccess.EFCore.BootstrapAdminContext.Navigations">
<summary>
</summary>
</member>
<member name="T:BootstrapAdmin.DataAccess.EFCore.Services.NavigationsService">
<summary>
</summary>
</member>
<member name="M:BootstrapAdmin.DataAccess.EFCore.Services.NavigationsService.#ctor(Microsoft.EntityFrameworkCore.IDbContextFactory{BootstrapAdmin.DataAccess.EFCore.BootstrapAdminContext})">
<summary>
</summary>
<param name="factory"></param>
</member>
<member name="M:BootstrapAdmin.DataAccess.EFCore.Services.NavigationsService.RetrieveAllMenus(System.String)">
<summary>
获得指定用户名可访问的所有菜单集合
</summary>
<param name="userName">当前用户名</param>
<returns>未层次化的菜单集合</returns>
</member>
<member name="T:Microsoft.Extensions.DependencyInjection.ServicesExtensions">
<summary>
</summary>
</member>
<member name="M:Microsoft.Extensions.DependencyInjection.ServicesExtensions.AddEFCoreDataAccessServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary>
</summary>
<param name="services"></param>
<returns></returns>
</member>
</members>
</doc>

View File

@ -0,0 +1,37 @@
using BootstrapAdmin.DataAccess.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BootstrapAdmin.DataAccess.EFCore
{
/// <summary>
///
/// </summary>
public class BootstrapAdminContext : DbContext
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="options"></param>
public BootstrapAdminContext(DbContextOptions<BootstrapAdminContext> options) : base(options)
{
}
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<Dicts>? Dicts { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<Navigations>? Navigations { get; set; }
}
}

View File

@ -1,7 +0,0 @@
namespace BootstrapAdmin.DataAccess.EFCore
{
public class Class1
{
}
}

View File

@ -0,0 +1,35 @@
using BootstrapAdmin.DataAccess.EFCore;
using BootstrapAdmin.DataAccess.EFCore.Services;
using BootstrapAdmin.DataAccess.Interface;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
///
/// </summary>
public static class ServicesExtensions
{
/// <summary>
///
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddEFCoreDataAccessServices(this IServiceCollection services)
{
services.AddDbContextFactory<BootstrapAdminContext>((provider, option) =>
{
//TODO: 后期改造成自定适配
var configuration = provider.GetRequiredService<IConfiguration>();
var connString = configuration.GetConnectionString("bb");
option.UseSqlite(connString);
});
services.TryAddSingleton<INavigations, NavigationsService>();
services.TryAddSingleton<IDicts, DictsService>();
return services;
}
}
}

View File

@ -0,0 +1,8 @@
using BootstrapAdmin.DataAccess.Interface;
namespace BootstrapAdmin.DataAccess.EFCore.Services
{
class DictsService : IDicts
{
}
}

View File

@ -0,0 +1,33 @@
using BootstrapAdmin.DataAccess.EFCore;
using BootstrapAdmin.DataAccess.Interface;
using BootstrapAdmin.DataAccess.Models;
using Microsoft.EntityFrameworkCore;
namespace BootstrapAdmin.DataAccess.EFCore.Services
{
/// <summary>
///
/// </summary>
class NavigationsService : INavigations
{
private IDbContextFactory<BootstrapAdminContext> DbFactory { get; set; }
/// <summary>
///
/// </summary>
/// <param name="factory"></param>
public NavigationsService(IDbContextFactory<BootstrapAdminContext> factory) => DbFactory = factory;
/// <summary>
/// 获得指定用户名可访问的所有菜单集合
/// </summary>
/// <param name="userName">当前用户名</param>
/// <returns>未层次化的菜单集合</returns>
public List<Navigations> RetrieveAllMenus(string userName)
{
using var context = DbFactory.CreateDbContext();
//return context..Fetch<Models.Navigations>($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" });
return new List<Navigations>();
}
}
}

View File

@ -1,9 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -1,11 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
@ -14,11 +8,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BootstrapAdmin.DataAccess.Models\BootstrapAdmin.DataAccess.Models.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="System.Diagnostics.CodeAnalysis" />
<ProjectReference Include="..\BootstrapAdmin.Web.Interface\BootstrapAdmin.Web.Interface.csproj" />
</ItemGroup>
</Project>

View File

@ -9,29 +9,13 @@
</summary>
</member>
<member name="M:Microsoft.Extensions.DependencyInjection.ServicesExtensions.AddDataAccessServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<member name="M:Microsoft.Extensions.DependencyInjection.ServicesExtensions.AddPetaPocoDataAccessServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary>
</summary>
<param name="services"></param>
<returns></returns>
</member>
<member name="T:BootstrapAdmin.DataAccess.Services.IDicts">
<summary>
Dict 字典表接口
</summary>
</member>
<member name="T:BootstrapAdmin.DataAccess.Services.INavigations">
<summary>
</summary>
</member>
<member name="M:BootstrapAdmin.DataAccess.Services.INavigations.RetrieveAllMenus(System.String)">
<summary>
</summary>
<returns></returns>
</member>
<member name="T:BootstrapAdmin.DataAccess.Services.NavigationsService">
<summary>

View File

@ -1,4 +1,5 @@
using BootstrapAdmin.DataAccess.Services;
using BootstrapAdmin.DataAccess.Interface;
using BootstrapAdmin.DataAccess.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection.Extensions;
using PetaPoco;
@ -16,7 +17,7 @@ namespace Microsoft.Extensions.DependencyInjection
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddDataAccessServices(this IServiceCollection services)
public static IServiceCollection AddPetaPocoDataAccessServices(this IServiceCollection services)
{
services.TryAddSingleton<IDatabase>(provider =>
{

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BootstrapAdmin.DataAccess.Interface;
namespace BootstrapAdmin.DataAccess.Services
{

View File

@ -1,4 +1,5 @@
using BootstrapAdmin.DataAccess.Models;
using BootstrapAdmin.DataAccess.Interface;
using BootstrapAdmin.DataAccess.Models;
using PetaPoco;
namespace BootstrapAdmin.DataAccess.Services
@ -8,13 +9,13 @@ namespace BootstrapAdmin.DataAccess.Services
/// </summary>
class NavigationsService : INavigations
{
private IDatabase _db;
private IDatabase Database { get; set; }
/// <summary>
///
/// </summary>
/// <param name="db"></param>
public NavigationsService(IDatabase db) => _db = db;
public NavigationsService(IDatabase db) => Database = db;
/// <summary>
/// 获得指定用户名可访问的所有菜单集合
@ -23,8 +24,8 @@ namespace BootstrapAdmin.DataAccess.Services
/// <returns>未层次化的菜单集合</returns>
public List<Navigations> RetrieveAllMenus(string userName)
{
var order = _db.Provider.EscapeSqlIdentifier("Order");
return _db.Fetch<Models.Navigations>($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" });
var order = Database.Provider.EscapeSqlIdentifier("Order");
return Database.Fetch<Models.Navigations>($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" });
}
}
}

View File

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\BootstrapAdmin.DataAccess.Models\BootstrapAdmin.DataAccess.Models.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,24 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>BootstrapAdmin.Web.Interface</name>
</assembly>
<members>
<member name="T:BootstrapAdmin.DataAccess.Interface.IDicts">
<summary>
Dict 字典表接口
</summary>
</member>
<member name="T:BootstrapAdmin.DataAccess.Interface.INavigations">
<summary>
</summary>
</member>
<member name="M:BootstrapAdmin.DataAccess.Interface.INavigations.RetrieveAllMenus(System.String)">
<summary>
</summary>
<returns></returns>
</member>
</members>
</doc>

View File

@ -1,4 +1,4 @@
namespace BootstrapAdmin.DataAccess.Services
namespace BootstrapAdmin.DataAccess.Interface
{
/// <summary>
/// Dict 字典表接口

View File

@ -1,6 +1,6 @@
using BootstrapAdmin.DataAccess.Models;
namespace BootstrapAdmin.DataAccess.Services
namespace BootstrapAdmin.DataAccess.Interface
{
/// <summary>
///

View File

@ -1,10 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BootstrapBlazor" Version="6.1.1-beta01" />
</ItemGroup>
@ -16,7 +11,6 @@
<ItemGroup>
<Using Include="BootstrapBlazor.Components" />
<Using Include="Microsoft.AspNetCore.Components" />
<Using Include="System.Diagnostics.CodeAnalysis" />
</ItemGroup>
</Project>

View File

@ -69,7 +69,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddSingleton<BootstrapAppContext>();
// 增加数据服务
services.AddDataAccessServices();
services.AddPetaPocoDataAccessServices();
return services;
}

View File

@ -1,4 +1,4 @@
using BootstrapAdmin.DataAccess.Services;
using BootstrapAdmin.DataAccess.Interface;
using BootstrapAdmin.Web.Extensions;
namespace BootstrapAdmin.Web.Shared

View File

@ -0,0 +1,14 @@
<Project>
<Import Project="..\..\Directory.Build.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Diagnostics.CodeAnalysis" />
</ItemGroup>
</Project>