105040 Update 注释
This commit is contained in:
parent
dc2f90e66b
commit
873d7bbd01
|
|
@ -6,12 +6,25 @@ namespace LFlow.Base;
|
|||
/// </summary>
|
||||
public class App
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务集合
|
||||
/// </summary>
|
||||
internal static IServiceCollection? services;
|
||||
/// <summary>
|
||||
/// 服务提供者
|
||||
/// </summary>
|
||||
private static IServiceProvider? ServiceProvider => services?.BuildServiceProvider();
|
||||
/// <summary>
|
||||
/// 获取服务
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static T? GetService<T>()
|
||||
{
|
||||
return ServiceProvider!.GetService<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 子服务程序集
|
||||
/// </summary>
|
||||
public static List<Assembly> SubServiceAssembly = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,28 @@
|
|||
程序对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:LFlow.Base.App.services">
|
||||
<summary>
|
||||
服务集合
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:LFlow.Base.App.ServiceProvider">
|
||||
<summary>
|
||||
服务提供者
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.App.GetService``1">
|
||||
<summary>
|
||||
获取服务
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="F:LFlow.Base.App.SubServiceAssembly">
|
||||
<summary>
|
||||
子服务程序集
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:LFlow.Base.Default.DefaultCurdRepo`2">
|
||||
<summary>
|
||||
默认的增删改查仓储
|
||||
|
|
@ -16,6 +38,17 @@
|
|||
<typeparam name="T"></typeparam>
|
||||
<typeparam name="K"></typeparam>
|
||||
</member>
|
||||
<member name="F:LFlow.Base.Default.DefaultCurdRepo`2._client">
|
||||
<summary>
|
||||
数据库连接客户端
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Default.DefaultCurdRepo`2.#ctor(SqlSugar.ISqlSugarClient)">
|
||||
<summary>
|
||||
构造函数
|
||||
</summary>
|
||||
<param name="client"></param>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Default.DefaultCurdRepo`2.DeleteById(`1)">
|
||||
<summary>
|
||||
根据ID删除对象
|
||||
|
|
@ -68,6 +101,45 @@
|
|||
</summary>
|
||||
<example> Route("api/[controller]/[action]") ApiController </example>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Interfaces.BaseController.Success``1(``0)">
|
||||
<summary>
|
||||
成功返回
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="data"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Interfaces.BaseController.Success``1(``0,System.Int32,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
成功返回(分页)
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="data"></param>
|
||||
<param name="totalCount"></param>
|
||||
<param name="pageIndex"></param>
|
||||
<param name="pageSize"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Interfaces.BaseController.Fail``1(``0,System.String,System.Int32)">
|
||||
<summary>
|
||||
失败返回
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="data"></param>
|
||||
<param name="errorMsg"></param>
|
||||
<param name="errCode"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Interfaces.BaseController.PagedFail``1(``0,System.String,System.Int32)">
|
||||
<summary>
|
||||
失败返回(分页)
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="data"></param>
|
||||
<param name="errorMsg"></param>
|
||||
<param name="errCode"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:LFlow.Base.Interfaces.IController">
|
||||
<summary>
|
||||
控制器接口
|
||||
|
|
@ -93,6 +165,12 @@
|
|||
模块接口
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Interfaces.IModule.ConfigureModule(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
|
||||
<summary>
|
||||
配置模块
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
</member>
|
||||
<member name="T:LFlow.Base.Interfaces.IRepo`2">
|
||||
<summary>
|
||||
通用的仓库对象接口
|
||||
|
|
@ -119,6 +197,7 @@
|
|||
保存与更新
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<param name="isUpdate"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Interfaces.IRepo`2.GetAll(System.Int32,System.Int32,System.Int32@)">
|
||||
|
|
@ -127,6 +206,7 @@
|
|||
</summary>
|
||||
<param name="pageIndex"></param>
|
||||
<param name="pageSize"></param>
|
||||
<param name="pageTotal"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Interfaces.IRepo`2.Search(`0)">
|
||||
|
|
@ -146,14 +226,35 @@
|
|||
<member name="T:LFlow.Base.Interfaces.IService">
|
||||
<summary>
|
||||
服务接口
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:LFlow.Base.Program">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Program.Main(System.String[])">
|
||||
<summary>
|
||||
入口
|
||||
</summary>
|
||||
<param name="args"></param>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Program.ConfigureSqlSugar(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
|
||||
<summary>
|
||||
配置SqlSugar
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Program.LoadSubService(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
|
||||
<summary>
|
||||
从子文件夹中加载DLL
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Program.ConfigDllLoader">
|
||||
<summary>
|
||||
配置DLL加载器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:LFlow.Base.Utils.ApiExplorerGroupPerVersionConvention">
|
||||
<summary>
|
||||
控制器模型约定
|
||||
|
|
@ -171,6 +272,88 @@
|
|||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
</member>
|
||||
<member name="P:LFlow.Base.Utils.ApiResult`1.Data">
|
||||
<summary>
|
||||
数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.ApiResult`1.#ctor">
|
||||
<summary>
|
||||
构造函数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.ApiResult`1.#ctor(System.Boolean,System.String,System.Int32,`0)">
|
||||
<summary>
|
||||
构造函数
|
||||
</summary>
|
||||
<param name="success"></param>
|
||||
<param name="message"></param>
|
||||
<param name="code"></param>
|
||||
<param name="data"></param>
|
||||
</member>
|
||||
<member name="P:LFlow.Base.Utils.ApiResult`1.Success">
|
||||
<summary>
|
||||
是否成功
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:LFlow.Base.Utils.ApiResult`1.Message">
|
||||
<summary>
|
||||
消息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:LFlow.Base.Utils.ApiResult`1.Code">
|
||||
<summary>
|
||||
状态码
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.ApiResult`1.SuccessResult(`0,System.String,System.Int32)">
|
||||
<summary>
|
||||
成功返回
|
||||
</summary>
|
||||
<param name="data"></param>
|
||||
<param name="message"></param>
|
||||
<param name="code"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.ApiResult`1.FailResult(System.String,System.Int32)">
|
||||
<summary>
|
||||
失败返回
|
||||
</summary>
|
||||
<param name="message"></param>
|
||||
<param name="code"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:LFlow.Base.Utils.CodeFirst">
|
||||
<summary>
|
||||
CodeFirst
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:LFlow.Base.Utils.CodeFirst._types">
|
||||
<summary>
|
||||
类型集合
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.CodeFirst.AddType(System.Type)">
|
||||
<summary>
|
||||
添加类型
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.CodeFirst.InitTable">
|
||||
<summary>
|
||||
初始化表
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.CodeFirst.InitDBSeed">
|
||||
<summary>
|
||||
初始化数据库种子
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:LFlow.Base.Utils.Mapper">
|
||||
<summary>
|
||||
映射器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.Mapper.Map``1(System.Object)">
|
||||
<summary>
|
||||
将一个对象映射到另一个对象
|
||||
|
|
@ -179,6 +362,19 @@
|
|||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.Mapper.MapTo``1(LFlow.Base.Interfaces.IDataModel)">
|
||||
<summary>
|
||||
将一个数据模型映射到另一个对象
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="model"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:LFlow.Base.Utils.ObjectToWhereExp">
|
||||
<summary>
|
||||
对象转换为where条件
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.ObjectToWhereExp.ToWhereExp(LFlow.Base.Interfaces.IModel)">
|
||||
<summary>
|
||||
将IModel对象转换为where条件
|
||||
|
|
@ -192,6 +388,68 @@
|
|||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
</member>
|
||||
<member name="P:LFlow.Base.Utils.PagedApiResult`1.Data">
|
||||
<summary>
|
||||
数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:LFlow.Base.Utils.PagedApiResult`1.TotalCount">
|
||||
<summary>
|
||||
总行数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:LFlow.Base.Utils.PagedApiResult`1.PageIndex">
|
||||
<summary>
|
||||
当前页
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:LFlow.Base.Utils.PagedApiResult`1.PageSize">
|
||||
<summary>
|
||||
每页行数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.PagedApiResult`1.#ctor">
|
||||
<summary>
|
||||
构造函数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.PagedApiResult`1.#ctor(System.Boolean,System.String,System.Int32,`0,System.Int32,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
构造函数
|
||||
</summary>
|
||||
<param name="success"></param>
|
||||
<param name="message"></param>
|
||||
<param name="code"></param>
|
||||
<param name="data"></param>
|
||||
<param name="totalCount"></param>
|
||||
<param name="pageIndex"></param>
|
||||
<param name="pageSize"></param>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.PagedApiResult`1.SuccessResult(`0,System.Int32,System.Int32,System.Int32,System.String,System.Int32)">
|
||||
<summary>
|
||||
成功返回
|
||||
</summary>
|
||||
<param name="data"></param>
|
||||
<param name="totalCount"></param>
|
||||
<param name="pageIndex"></param>
|
||||
<param name="pageSize"></param>
|
||||
<param name="message"></param>
|
||||
<param name="code"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.PagedApiResult`1.FailResult(System.String,System.Int32)">
|
||||
<summary>
|
||||
失败返回
|
||||
</summary>
|
||||
<param name="message"></param>
|
||||
<param name="errCode"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:LFlow.Base.Utils.RegisterModule">
|
||||
<summary>
|
||||
注册模块
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:LFlow.Base.Utils.RegisterModule.RegisterAllModel(System.Collections.Generic.List{System.Type},Microsoft.Extensions.DependencyInjection.IServiceCollection)">
|
||||
<summary>
|
||||
注册所有模型
|
||||
|
|
|
|||
|
|
@ -10,7 +10,14 @@ namespace LFlow.Base.Default;
|
|||
/// <typeparam name="K"></typeparam>
|
||||
public abstract class DefaultCurdRepo<T, K> : IRepo<T, K> where T : class, IDataModel, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据库连接客户端
|
||||
/// </summary>
|
||||
private readonly ISqlSugarClient _client;
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
public DefaultCurdRepo(ISqlSugarClient client)
|
||||
{
|
||||
_client = client;
|
||||
|
|
|
|||
|
|
@ -11,19 +11,49 @@ namespace LFlow.Base.Interfaces;
|
|||
[ApiController]
|
||||
public abstract class BaseController : ControllerBase, IController
|
||||
{
|
||||
/// <summary>
|
||||
/// 成功返回
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual ApiResult<T> Success<T>(T? data) where T : class, new()
|
||||
{
|
||||
return ApiResult<T>.SuccessResult(data);
|
||||
}
|
||||
/// <summary>
|
||||
/// 成功返回(分页)
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="totalCount"></param>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual PagedApiResult<T> Success<T>(T? data, int totalCount, int pageIndex, int pageSize) where T : class, new()
|
||||
{
|
||||
return PagedApiResult<T>.SuccessResult(data, totalCount, pageIndex, pageSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 失败返回
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="errorMsg"></param>
|
||||
/// <param name="errCode"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual ApiResult<T> Fail<T>(T? data, string errorMsg, int errCode) where T : class, new()
|
||||
{
|
||||
return ApiResult<T>.FailResult(errorMsg, errCode);
|
||||
}
|
||||
/// <summary>
|
||||
/// 失败返回(分页)
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="errorMsg"></param>
|
||||
/// <param name="errCode"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual PagedApiResult<T>? PagedFail<T>(T? data, string errorMsg, int errCode) where T : class, new()
|
||||
{
|
||||
return PagedApiResult<T>.FailResult(errorMsg, errCode);
|
||||
|
|
|
|||
|
|
@ -6,5 +6,9 @@ namespace LFlow.Base.Interfaces;
|
|||
/// </summary>
|
||||
public interface IModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置模块
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
void ConfigureModule(IServiceCollection services);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public interface IRepo<T, K> where T : IDataModel
|
|||
/// 保存与更新
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="isUpdate"></param>
|
||||
/// <returns></returns>
|
||||
T SaveOrUpdate(T entity, bool isUpdate);
|
||||
/// <summary>
|
||||
|
|
@ -30,6 +31,7 @@ public interface IRepo<T, K> where T : IDataModel
|
|||
/// </summary>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="pageTotal"></param>
|
||||
/// <returns></returns>
|
||||
List<T> GetAll(int pageIndex, int pageSize, ref int pageTotal);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
namespace LFlow.Base.Interfaces;
|
||||
/// <summary>
|
||||
/// ·þÎñ½Ó¿Ú
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// 服务接口
|
||||
/// </summary>
|
||||
public interface IService//<T> where T : class, IModel, new()
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,15 @@ using SqlSugar;
|
|||
using System.Reflection;
|
||||
|
||||
namespace LFlow.Base;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class Program
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 入口
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
|
|
@ -47,8 +53,10 @@ public static class Program
|
|||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
builder.Services.AddResponseCompression();
|
||||
|
||||
Log.Logger.Information("ConfigureSqlSugar");
|
||||
|
||||
builder.Services.ConfigureSqlSugar();
|
||||
|
||||
builder.Services.AddControllers(c =>
|
||||
|
|
@ -87,6 +95,8 @@ public static class Program
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// 配置跨域策略
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
|
|
@ -149,7 +159,7 @@ public static class Program
|
|||
}
|
||||
// 在启动后调用Sqlsugar进行CodeFirst
|
||||
// 挂载启动后事件
|
||||
app.Services.GetRequiredService<IHostApplicationLifetime>().ApplicationStarted.Register(async () =>
|
||||
app.Services.GetRequiredService<IHostApplicationLifetime>().ApplicationStarted.Register(() =>
|
||||
{
|
||||
Log.Logger.Information("ApplicationStarted");
|
||||
CodeFirst.InitTable();
|
||||
|
|
@ -170,6 +180,10 @@ public static class Program
|
|||
app.Run();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置SqlSugar
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public static void ConfigureSqlSugar(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<ISqlSugarClient>(s =>
|
||||
|
|
@ -260,6 +274,9 @@ public static class Program
|
|||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置DLL加载器
|
||||
/// </summary>
|
||||
public static void ConfigDllLoader()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
|
||||
|
|
|
|||
|
|
@ -7,15 +7,26 @@
|
|||
[Serializable]
|
||||
public class ApiResult<T> where T : class, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据
|
||||
/// </summary>
|
||||
public T? Data
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public ApiResult()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="success"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
public ApiResult(bool success, string message, int code, T? data)
|
||||
{
|
||||
Success = success;
|
||||
|
|
@ -23,26 +34,44 @@ public class ApiResult<T> where T : class, new()
|
|||
Code = code;
|
||||
Data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否成功
|
||||
/// </summary>
|
||||
public bool Success
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息
|
||||
/// </summary>
|
||||
public string? Message
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 状态码
|
||||
/// </summary>
|
||||
public int? Code
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 成功返回
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public static ApiResult<T> SuccessResult(T? data, string message = "操作成功", int code = 200)
|
||||
{
|
||||
return new ApiResult<T>(true, message, code, data);
|
||||
}
|
||||
/// <summary>
|
||||
/// 失败返回
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public static ApiResult<T> FailResult(string message = "操作失败", int code = 500)
|
||||
{
|
||||
return new ApiResult<T>(false, message, code, default);
|
||||
|
|
|
|||
|
|
@ -2,15 +2,27 @@ using SqlSugar;
|
|||
using System.Collections.Concurrent;
|
||||
|
||||
namespace LFlow.Base.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// CodeFirst
|
||||
/// </summary>
|
||||
public static class CodeFirst
|
||||
{
|
||||
// 线程安全的类型列表
|
||||
private static readonly ConcurrentBag<Type> _types = new();
|
||||
|
||||
/// <summary>
|
||||
/// 类型集合
|
||||
/// </summary>
|
||||
private static readonly ConcurrentBag<Type> _types = [];
|
||||
/// <summary>
|
||||
/// 添加类型
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
public static void AddType(Type type)
|
||||
{
|
||||
_types.Add(type);
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化表
|
||||
/// </summary>
|
||||
internal static void InitTable()
|
||||
{
|
||||
var logger = App.GetService<Serilog.ILogger>()!;
|
||||
|
|
@ -22,6 +34,9 @@ public static class CodeFirst
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化数据库种子
|
||||
/// </summary>
|
||||
internal static void InitDBSeed()
|
||||
{
|
||||
//TODO: Seed data
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ using LFlow.Base.Interfaces;
|
|||
using Mapster;
|
||||
|
||||
namespace LFlow.Base.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// 映射器
|
||||
/// </summary>
|
||||
public static class Mapper
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -19,6 +21,12 @@ public static class Mapper
|
|||
}
|
||||
return source.Adapt<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 将一个数据模型映射到另一个对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public static T? MapTo<T>(this IDataModel model)
|
||||
{
|
||||
if (model == null)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
using LFlow.Base.Interfaces;
|
||||
|
||||
namespace LFlow.Base.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// 对象转换为where条件
|
||||
/// </summary>
|
||||
public static class ObjectToWhereExp
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -7,29 +7,51 @@
|
|||
[Serializable]
|
||||
public class PagedApiResult<T> : ApiResult<T> where T : class, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据
|
||||
/// </summary>
|
||||
public new T? Data
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 总行数
|
||||
/// </summary>
|
||||
public int TotalCount
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前页
|
||||
/// </summary>
|
||||
public int PageIndex
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每页行数
|
||||
/// </summary>
|
||||
public int PageSize
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public PagedApiResult()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="success"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="totalCount"></param>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
public PagedApiResult(bool success, string message, int code, T? data, int totalCount, int pageIndex, int pageSize)
|
||||
{
|
||||
Success = success;
|
||||
|
|
@ -40,10 +62,26 @@ public class PagedApiResult<T> : ApiResult<T> where T : class, new()
|
|||
PageIndex = pageIndex;
|
||||
PageSize = pageSize;
|
||||
}
|
||||
/// <summary>
|
||||
/// 成功返回
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="totalCount"></param>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public static PagedApiResult<T> SuccessResult(T? data, int totalCount, int pageIndex, int pageSize, string message = "操作成功", int code = 200)
|
||||
{
|
||||
return new PagedApiResult<T>(true, message, code, data, totalCount, pageIndex, pageSize);
|
||||
}
|
||||
/// <summary>
|
||||
/// 失败返回
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="errCode"></param>
|
||||
/// <returns></returns>
|
||||
public static new PagedApiResult<T>? FailResult(string message = "操作失败", int errCode = 500)
|
||||
{
|
||||
return new PagedApiResult<T>(false, message, errCode, null, 0, 0, 0);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
namespace LFlow.Base.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// 注册模块
|
||||
/// </summary>
|
||||
public static class RegisterModule
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace LFlow.InternalEventBus
|
|||
/// <returns></returns>
|
||||
public static async Task PublishAsync(string eventName, object data)
|
||||
{
|
||||
Task.Factory.StartNew(() => Publish(eventName, data));
|
||||
await Task.Factory.StartNew(() => Publish(eventName, data));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,34 @@
|
|||
{
|
||||
var controllerName = context.GetRouteData()?.Values["controller"]?.ToString();
|
||||
var actionName = context.GetRouteData()?.Values["action"]?.ToString();
|
||||
|
||||
using (_logger?.BeginScope("LoggingMiddleware"))
|
||||
var requestId = context.Request.Headers["X-Request-Id"].ToString();
|
||||
if (string.IsNullOrEmpty(requestId))
|
||||
{
|
||||
_logger?.LogInformation($"Controller: {controllerName} / Action : {actionName}");
|
||||
_logger?.LogInformation("Router Data {@routerData}", context.GetRouteData());
|
||||
await next();
|
||||
requestId = Guid.NewGuid().ToString();
|
||||
context.Request.Headers.Append("X-Request-Id", requestId);
|
||||
}
|
||||
using (_logger?.BeginScope(requestId))
|
||||
{
|
||||
_logger?.LogInformation("Request Id: {requestId}", requestId);
|
||||
_logger?.LogInformation("Controller: {controllerName} / Action : {actionName}", controllerName, actionName);
|
||||
// _logger?.LogInformation("Router Data {@routerData}", context.GetRouteData());
|
||||
try
|
||||
{
|
||||
await next();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, "An error occurred while processing the request. Request Id: {requestId}", requestId);
|
||||
//await context.Response.WriteAsync(JsonConvert.SerializeObject(ApiResult<object>.FailResult("无权限!", 100501)));
|
||||
// _logger?.LogInformation("Response {@response}", context.Response);
|
||||
}
|
||||
}
|
||||
if (!context.Response.Headers.ContainsKey("X-Request-Id"))
|
||||
{
|
||||
|
||||
}
|
||||
// context.Response.Headers.Append("X-Request-Id", requestId);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,20 @@ using LFlow.OnlineManegement.Service;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LFlow.OnlineManegement.Controller;
|
||||
/// <summary>
|
||||
/// 在线用户管理
|
||||
/// </summary>
|
||||
/// <param name="service"></param>
|
||||
public class OnlineManagementController(IOnlineManagementService service) : BaseController
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有在线用户
|
||||
/// </summary>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public PagedApiResult<List<OnlineDto>> ListAll(int pageIndex, int pageSize)
|
||||
{
|
||||
|
|
@ -18,7 +30,11 @@ public class OnlineManagementController(IOnlineManagementService service) : Base
|
|||
}
|
||||
return Success(result, dataTotal, pageIndex, pageSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册在线用户
|
||||
/// </summary>
|
||||
/// <param name="onlineInfo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ApiResult<OnlineDto> OnlineRegistered(OnlineDto onlineInfo)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,13 +10,22 @@ namespace LFlow.Permission.Controller
|
|||
/// <summary>
|
||||
/// 权限控制
|
||||
/// </summary>
|
||||
/// <param name="service"></param>
|
||||
/// <param name="logger"></param>
|
||||
public class PermissionController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 权限服务
|
||||
/// </summary>
|
||||
private IPermissionService service;
|
||||
/// <summary>
|
||||
/// 日志
|
||||
/// </summary>
|
||||
private ILogger logger;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="service"></param>
|
||||
/// <param name="logger"></param>
|
||||
public PermissionController(IPermissionService service, ILogger logger)
|
||||
|
||||
{
|
||||
|
|
@ -41,11 +50,26 @@ namespace LFlow.Permission.Controller
|
|||
TotalCount = total
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加程序权限
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<ApiResult<List<PermissionDto>>> GetProgPermissions()
|
||||
{
|
||||
var result = await service.GetPermissions();
|
||||
return Success(result);
|
||||
}
|
||||
/// <summary>
|
||||
/// Test method to throw an exception
|
||||
/// </summary>
|
||||
/// <returns>ApiResult with an error message</returns>
|
||||
[HttpGet]
|
||||
public Task<ApiResult<object>> TestException()
|
||||
{
|
||||
// var a = 0 / 1;
|
||||
throw new Exception("Test exception");
|
||||
// return Task.FromResult(Success((object)"Success"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,5 +52,13 @@ namespace LFlow.Permission.Model
|
|||
get;
|
||||
set;
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否公开
|
||||
/// </summary>
|
||||
public bool IsPublic
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,15 @@ namespace LFlow.Permission.Model
|
|||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否公开
|
||||
/// </summary>
|
||||
public bool IsPublic
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
using System.Net.Sockets;
|
||||
using LFlow.Base;
|
||||
using LFlow.Base.Utils;
|
||||
using LFlow.Middleware;
|
||||
using LFlow.Permission.Service;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace LFlow.Permission;
|
||||
|
||||
/// <summary>
|
||||
/// 权限中间件
|
||||
/// </summary>
|
||||
public class PermissionMiddleware : ILFlowMiddleware
|
||||
{
|
||||
/// <summary>
|
||||
/// 优先级
|
||||
/// </summary>
|
||||
public int Priority => 2;
|
||||
|
||||
/// <summary>
|
||||
/// 执行入口
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="next"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task RunAsync(HttpContext context, Func<Task> next)
|
||||
{
|
||||
var progName = context.GetRouteData()?.Values["controller"]?.ToString();
|
||||
var progAction = context.GetRouteData()?.Values["action"]?.ToString();
|
||||
if (progName != null)
|
||||
{
|
||||
var service = App.GetService<IPermissionService>();
|
||||
var progPermission = service != null ? await service.GetProgPerminssionListAsync(progName) : null;
|
||||
var currentPermission = progPermission?.FirstOrDefault(p => p.PermissionAction == progAction);
|
||||
if (currentPermission == null || currentPermission!.IsPublic)
|
||||
{
|
||||
await next();
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO 从缓存中根据Token获取用户信息,并判断是否有权限
|
||||
await context.Response.WriteAsync(JsonConvert.SerializeObject(ApiResult<object>.FailResult("无权限!", 100501)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -6,19 +6,24 @@ using Serilog;
|
|||
using System.Reflection;
|
||||
|
||||
namespace LFlow.Permission;
|
||||
|
||||
/// <summary>
|
||||
/// 权限模块
|
||||
/// </summary>
|
||||
public class PermissionModule : IModule
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 配置模块
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public void ConfigureModule(IServiceCollection services)
|
||||
{
|
||||
CodeFirst.AddType(typeof(PermissionModel));
|
||||
var assembly = Assembly.GetAssembly(typeof(PermissionModule))!;
|
||||
var types = assembly.GetTypes().ToList();
|
||||
RegisterModule.RegisterAllService(types, services);
|
||||
RegisterModule.RegisterAllRepo(types, services);
|
||||
types.RegisterAllService(services);
|
||||
types.RegisterAllRepo(services);
|
||||
//RegisterModule.RegisterAllModel(types, services);
|
||||
services.AddControllers().AddApplicationPart(assembly);
|
||||
Log.Logger?.Information("UserManegementModule ConfigureModule done");
|
||||
Log.Logger?.Information("UserManagementModule ConfigureModule done");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ namespace LFlow.UserManagement.Controller
|
|||
{
|
||||
public class UserManagementController(IUserManagementService service, ILogger logger) : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ApiResult<UserDto>? Login(UserDto user)
|
||||
{
|
||||
|
|
@ -20,6 +25,11 @@ namespace LFlow.UserManagement.Controller
|
|||
}
|
||||
return Success(loginedUser);
|
||||
}
|
||||
/// <summary>
|
||||
/// 注册
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ApiResult<UserDto> Register(UserDto user)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,18 +7,25 @@ using System.Reflection;
|
|||
|
||||
namespace LFlow.UserManagement
|
||||
{
|
||||
public class UserManegementModule : IModule
|
||||
/// <summary>
|
||||
/// 用户管理模块
|
||||
/// </summary>
|
||||
public class UserManagementModule : IModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置模块
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public void ConfigureModule(IServiceCollection services)
|
||||
{
|
||||
CodeFirst.AddType(typeof(UserModel));
|
||||
var assembly = Assembly.GetAssembly(typeof(UserManegementModule))!;
|
||||
var assembly = Assembly.GetAssembly(typeof(UserManagementModule))!;
|
||||
var types = assembly.GetTypes().ToList();
|
||||
RegisterModule.RegisterAllService(types, services);
|
||||
RegisterModule.RegisterAllRepo(types, services);
|
||||
types.RegisterAllService(services);
|
||||
types.RegisterAllRepo(services);
|
||||
//RegisterModule.RegisterAllModel(types, services);
|
||||
services.AddControllers().AddApplicationPart(assembly);
|
||||
Log.Logger?.Information("UserManegementModule ConfigureModule done");
|
||||
Log.Logger?.Information("UserManagementModule ConfigureModule done");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,20 +7,32 @@ using Serilog;
|
|||
|
||||
namespace LFlow.UserManagement
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户管理中间件
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
public class UserMiddleware(ILogger logger) : ILFlowMiddleware
|
||||
{
|
||||
/// <summary>
|
||||
/// 优先级
|
||||
/// </summary>
|
||||
public int Priority => 1;
|
||||
/// <summary>
|
||||
/// 执行入口
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="next"></param>
|
||||
public async Task RunAsync(Microsoft.AspNetCore.Http.HttpContext context, Func<Task> next)
|
||||
{
|
||||
// Do something before
|
||||
var progController = context.GetRouteData()?.Values["controller"]?.ToString();
|
||||
var progAction = context.GetRouteData()?.Values["action"]?.ToString();
|
||||
if (progAction != "ListAll")
|
||||
// var progController = context.GetRouteData()?.Values["controller"]?.ToString();
|
||||
// var progAction = context.GetRouteData()?.Values["action"]?.ToString();
|
||||
// if (progAction != "ListAll")
|
||||
await next();
|
||||
else
|
||||
{
|
||||
await context.Response.WriteAsync(JsonConvert.SerializeObject(ApiResult<object>.FailResult("无权限!", 100501)));
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// await context.Response.WriteAsync(JsonConvert.SerializeObject(ApiResult<object>.FailResult("无权限!", 100501)));
|
||||
// }
|
||||
// Do something after
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue