mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Synchronization code
This commit is contained in:
parent
57c854c9e7
commit
385c3d15ec
@ -20,6 +20,7 @@ namespace SqlSugar
|
||||
public Action<string, SugarParameter[]> OnLogExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.OnLogExecuted = value; } }
|
||||
public Func<string, SugarParameter[], KeyValuePair<string, SugarParameter[]>> OnExecutingChangeSql { set { this.Context.CurrentConnectionConfig.AopEvents.OnExecutingChangeSql = value; } }
|
||||
public virtual Action<object, DataFilterModel> DataExecuting { set { this.Context.CurrentConnectionConfig.AopEvents.DataExecuting = value; } }
|
||||
public Action<object, DataFilterModel> DataChangesExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.DataChangesExecuted = value; } }
|
||||
public virtual Action<object, DataAfterModel> DataExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.DataExecuted = value; } }
|
||||
}
|
||||
}
|
||||
|
@ -708,6 +708,7 @@ namespace SqlSugar
|
||||
if (this.RemoveCacheFunc != null) {
|
||||
this.RemoveCacheFunc();
|
||||
}
|
||||
DataChangesAop(this.DeleteObjects);
|
||||
}
|
||||
|
||||
private void Before(string sql)
|
||||
@ -769,5 +770,25 @@ namespace SqlSugar
|
||||
dataEvent(deleteObj,model);
|
||||
}
|
||||
}
|
||||
private void DataChangesAop(List<T> deleteObjs)
|
||||
{
|
||||
var dataEvent = this.Context.CurrentConnectionConfig.AopEvents?.DataChangesExecuted;
|
||||
if(dataEvent != null&&deleteObjs != null)
|
||||
{
|
||||
foreach (var deleteObj in deleteObjs)
|
||||
{
|
||||
if (deleteObj != null)
|
||||
{
|
||||
var model = new DataFilterModel()
|
||||
{
|
||||
OperationType = DataFilterType.DeleteByObject,
|
||||
EntityValue = deleteObj,
|
||||
EntityColumnInfo = this.EntityInfo.Columns.FirstOrDefault()
|
||||
};
|
||||
dataEvent(deleteObj, model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,6 +224,40 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
private void DataChangeAop(T [] items)
|
||||
{
|
||||
|
||||
var dataEvent = this.Context.CurrentConnectionConfig.AopEvents?.DataChangesExecuted;
|
||||
if (dataEvent != null)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item != null&& !(item is Dictionary<string,object>))
|
||||
{
|
||||
foreach (var columnInfo in this.EntityInfo.Columns)
|
||||
{
|
||||
if (columnInfo.ForOwnsOnePropertyInfo != null)
|
||||
{
|
||||
var data = columnInfo.ForOwnsOnePropertyInfo.GetValue(item, null);
|
||||
if (data != null)
|
||||
{
|
||||
dataEvent(columnInfo.PropertyInfo.GetValue(data, null), new DataFilterModel() { OperationType = DataFilterType.InsertByObject, EntityValue = item, EntityColumnInfo = columnInfo });
|
||||
}
|
||||
}
|
||||
else if (columnInfo.PropertyInfo.Name == "Item" && columnInfo.IsIgnore)
|
||||
{
|
||||
//class index
|
||||
}
|
||||
else
|
||||
{
|
||||
dataEvent(columnInfo.PropertyInfo.GetValue(item, null), new DataFilterModel() { OperationType = DataFilterType.InsertByObject, EntityValue = item, EntityColumnInfo = columnInfo });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetInsertItemByDic(int i, T item, List<DbColumnInfo> insertItem)
|
||||
{
|
||||
foreach (var column in (item as Dictionary<string, object>).OrderBy(it=>it.Key))
|
||||
@ -455,6 +489,7 @@ namespace SqlSugar
|
||||
{
|
||||
this.RemoveCacheFunc();
|
||||
}
|
||||
DataChangeAop(this.InsertObjs);
|
||||
}
|
||||
protected void Before(string sql)
|
||||
{
|
||||
|
@ -292,6 +292,39 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
private void DataChangesAop(T [] items)
|
||||
{
|
||||
var dataEvent = this.Context.CurrentConnectionConfig.AopEvents?.DataChangesExecuted;
|
||||
if (dataEvent != null)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
foreach (var columnInfo in this.EntityInfo.Columns)
|
||||
{
|
||||
if (columnInfo.ForOwnsOnePropertyInfo != null)
|
||||
{
|
||||
var data = columnInfo.ForOwnsOnePropertyInfo.GetValue(item, null);
|
||||
if (data != null)
|
||||
{
|
||||
dataEvent(columnInfo.PropertyInfo.GetValue(data, null), new DataFilterModel() { OperationType = DataFilterType.UpdateByObject, EntityValue = item, EntityColumnInfo = columnInfo });
|
||||
}
|
||||
}
|
||||
else if (columnInfo.PropertyInfo.Name == "Item" && columnInfo.IsIgnore)
|
||||
{
|
||||
//class index
|
||||
}
|
||||
else
|
||||
{
|
||||
dataEvent(columnInfo.PropertyInfo.GetValue(item, null), new DataFilterModel() { OperationType = DataFilterType.UpdateByObject, EntityValue = item, EntityColumnInfo = columnInfo });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckTranscodeing(bool checkIsJson = true)
|
||||
{
|
||||
if (this.EntityInfo.Columns.Any(it => it.IsTranscoding))
|
||||
@ -670,6 +703,8 @@ namespace SqlSugar
|
||||
{
|
||||
this.RemoveCacheFunc();
|
||||
}
|
||||
|
||||
DataChangesAop(this.UpdateObjs);
|
||||
}
|
||||
private string _ExecuteCommandWithOptLock(T updateData,ref object oldVerValue)
|
||||
{
|
||||
|
@ -183,7 +183,7 @@ namespace SqlSugar
|
||||
return 0;
|
||||
}
|
||||
var result = await this.Ado.ExecuteCommandAsync(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray());
|
||||
After(sql);
|
||||
After(sql);
|
||||
return result;
|
||||
}
|
||||
public Task<bool> ExecuteCommandHasChangeAsync(CancellationToken token)
|
||||
|
@ -92,6 +92,7 @@ namespace SqlSugar
|
||||
public Action<string, SugarParameter[]> OnLogExecuted { get; set; }
|
||||
public Func<string, SugarParameter[], KeyValuePair<string, SugarParameter[]>> OnExecutingChangeSql { get; set; }
|
||||
public Action<object, DataFilterModel> DataExecuting { get; set; }
|
||||
public Action<object, DataFilterModel> DataChangesExecuted { get; set; }
|
||||
public Action<object, DataAfterModel> DataExecuted { get; set; }
|
||||
}
|
||||
public class ConfigureExternalServices
|
||||
|
Loading…
Reference in New Issue
Block a user