⚡优化codefirst
This commit is contained in:
parent
02e1000bb0
commit
cf8dfc0d19
@ -2,7 +2,6 @@ using Infrastructure;
|
|||||||
using Infrastructure.Extensions;
|
using Infrastructure.Extensions;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using SqlSugar.IOC;
|
using SqlSugar.IOC;
|
||||||
using System.Security.Principal;
|
|
||||||
using ZR.Model;
|
using ZR.Model;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
|
|
||||||
@ -125,20 +124,19 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
|
|
||||||
SqlDiffLog log = new()
|
SqlDiffLog log = new()
|
||||||
{
|
{
|
||||||
AfterData = pars,
|
BeforeData = pars,
|
||||||
BusinessData = data,
|
BusinessData = data.ToString(),
|
||||||
DiffType = diffType.ToString(),
|
DiffType = diffType.ToString(),
|
||||||
Sql = sql,
|
Sql = sql,
|
||||||
TableName = item.TableName,
|
TableName = item.TableName,
|
||||||
UserName = name,
|
UserName = name,
|
||||||
AddTime = DateTime.Now
|
AddTime = DateTime.Now,
|
||||||
|
ConfigId = configId
|
||||||
};
|
};
|
||||||
//logger.WithProperty("title", data).Info(pars);
|
//logger.WithProperty("title", data).Info(pars);
|
||||||
db.GetConnectionScope(configId).Insertable(log).ExecuteReturnSnowflakeId();
|
db.GetConnectionScope(0).Insertable(log).ExecuteReturnSnowflakeId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Write logic
|
|
||||||
};
|
};
|
||||||
db.GetConnectionScope(configId).CurrentConnectionConfig.MoreSettings = new ConnMoreSettings()
|
db.GetConnectionScope(configId).CurrentConnectionConfig.MoreSettings = new ConnMoreSettings()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -23,8 +23,7 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
//var entityes = AssemblyUtils.GetAllTypes().Where(p => !p.IsAbstract && p != baseType && p.GetCustomAttribute<SugarTable>() != null).ToArray();
|
//var entityes = AssemblyUtils.GetAllTypes().Where(p => !p.IsAbstract && p != baseType && p.GetCustomAttribute<SugarTable>() != null).ToArray();
|
||||||
//db.CodeFirst.InitTables(entityes);
|
//db.CodeFirst.InitTables(entityes);
|
||||||
|
|
||||||
//23个表,建议先使用下面方法初始化表,方便排查问题
|
//24个表,建议先使用下面方法初始化表,方便排查问题
|
||||||
db.CodeFirst.InitTables(typeof(SqlDiffLog));
|
|
||||||
db.CodeFirst.InitTables(typeof(SysUser));
|
db.CodeFirst.InitTables(typeof(SysUser));
|
||||||
db.CodeFirst.InitTables(typeof(SysRole));
|
db.CodeFirst.InitTables(typeof(SysRole));
|
||||||
db.CodeFirst.InitTables(typeof(SysDept));
|
db.CodeFirst.InitTables(typeof(SysDept));
|
||||||
@ -48,6 +47,7 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
db.CodeFirst.InitTables(typeof(ArticleCategory));
|
db.CodeFirst.InitTables(typeof(ArticleCategory));
|
||||||
db.CodeFirst.InitTables(typeof(SysDictData));
|
db.CodeFirst.InitTables(typeof(SysDictData));
|
||||||
db.CodeFirst.InitTables(typeof(SysDictType));
|
db.CodeFirst.InitTables(typeof(SysDictType));
|
||||||
|
db.CodeFirst.InitTables(typeof(SqlDiffLog));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
using SqlSugar;
|
namespace ZR.Model.System
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace ZR.Model.System
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文章表
|
/// 文章表
|
||||||
|
|||||||
@ -1,21 +1,51 @@
|
|||||||
namespace ZR.Model.System
|
namespace ZR.Model.System
|
||||||
{
|
{
|
||||||
[SugarTable("SqlDiffLog")]
|
[SugarTable("SqlDiffLog", "数据差异日志")]
|
||||||
|
[Tenant("0")]
|
||||||
public class SqlDiffLog
|
public class SqlDiffLog
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 主键
|
||||||
|
/// </summary>
|
||||||
[SugarColumn(IsPrimaryKey = true)]
|
[SugarColumn(IsPrimaryKey = true)]
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
public long PId { get; set; }
|
public long PId { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 表名
|
||||||
|
/// </summary>
|
||||||
public string TableName { get; set; }
|
public string TableName { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 业务数据内容
|
||||||
|
/// </summary>
|
||||||
[SugarColumn(Length = 4000)]
|
[SugarColumn(Length = 4000)]
|
||||||
public object BusinessData { get; set; }
|
public string BusinessData { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 差异类型insert,update,delete
|
||||||
|
/// </summary>
|
||||||
public string DiffType { get; set; }
|
public string DiffType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 执行sql语句
|
||||||
|
/// </summary>
|
||||||
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
|
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
|
||||||
public string Sql { get; set; }
|
public string Sql { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 变更前数据
|
||||||
|
/// </summary>
|
||||||
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
|
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
|
||||||
public string BeforeData { get; set; }
|
public string BeforeData { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 变更后数据
|
||||||
|
/// </summary>
|
||||||
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
|
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
|
||||||
public string AfterData { get; set; }
|
public string AfterData { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 操作用户名
|
||||||
|
/// </summary>
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
public DateTime AddTime { get; set; }
|
public DateTime AddTime { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 数据库配置id
|
||||||
|
/// </summary>
|
||||||
|
public string ConfigId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
using SqlSugar;
|
namespace ZR.Model.System
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace ZR.Model.System
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 部门表
|
/// 部门表
|
||||||
@ -13,7 +10,8 @@ namespace ZR.Model.System
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 部门ID
|
/// 部门ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
public long DeptId { get; set; }
|
public long DeptId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -58,13 +56,13 @@ namespace ZR.Model.System
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 部门状态:0正常,1停用
|
/// 部门状态:0正常,1停用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(Length = 1, DefaultValue = "0")]
|
[SugarColumn(DefaultValue = "0")]
|
||||||
public int Status { get; set; }
|
public int Status { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除标志(0代表存在 2代表删除)
|
/// 删除标志(0代表存在 2代表删除)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(Length = 1, DefaultValue = "0")]
|
[SugarColumn(DefaultValue = "0")]
|
||||||
public int DelFlag { get; set; }
|
public int DelFlag { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user