Files
glz 8ed012bba8 refactor: 重构项目基础架构与实体体系
- 替换原有自定义生命周期接口为通用基础服务体系
- 将所有实体基类替换为带雪花ID的SqlSugarBaseEntity
- 迁移DTO到Models项目并统一管理
- 移除冗余的Repository层实现,改用通用基础服务
- 添加Yitter.IdGenerator雪花ID生成支持
- 重构SqlSugar数据库上下文与依赖注入配置
- 新增微信用户、用户勋章、背包等实体与配套服务
- 整理分页查询与结果封装类
- 优化WebApi控制器结构
2026-06-02 14:10:43 +08:00

52 lines
2.0 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Builder;
using QYZH.InteractiveMagazine.Repository.Core;
using Serilog;
using SqlSugar;
using SqlSugar.IOC;
namespace QYZH.InteractiveMagazine.Repository.Core
{
/// <summary>
/// sql sugar 管理器
/// </summary>
public static class SqlSugarManager
{
/// <summary>
/// 获基础信息库对象 用IOC这块代码不能写到IOC里面
/// </summary>
public static void InitSqlSugarDb(this WebApplicationBuilder builder, IocConfig config)
{
builder.Services.AddSqlSugar(config);
//配置参数
SugarIocServices.ConfigurationSugar(db =>
{
db.Aop.OnLogExecuting = (sql, pars) =>
{
//var param = db.GetConnectionScope(0).Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value));
Log.Information($"【sql语句】{UtilMethods.GetSqlString((DbType)config.DbType, sql, pars)}\n");
};
db.Aop.OnError = (ex) =>
{
string sql = $"【错误SQL】{UtilMethods.GetSqlString((DbType)config.DbType, ex.Sql, (SugarParameter[])ex.Parametres)}\r\n";
Log.Error(ex, $"{sql}\r\n{ex.Message}\r\n{ex.StackTrace}");
};
//SQL执行完
db.Aop.OnLogExecuted = (sql, pars) =>
{
//执行完了可以输出SQL执行时间 (OnLogExecutedDelegate)
};
db.SetDefaultValue().SetQueryFilter(GetAssemblyNames());//.CreateClassFile("C:\\Model");
});
}
private static string GetAssemblyNames()
{
string friendlyName = AppDomain.CurrentDomain.FriendlyName;
string[] source = friendlyName.Split('.');
string assemblyNames = string.Join(".", source.Take(source.Count() - 1)) + ".Models";
return assemblyNames;
}
}
}