diff --git a/Admin.NET/Admin.NET.Core/Service/Enum/SysEnumService.cs b/Admin.NET/Admin.NET.Core/Service/Enum/SysEnumService.cs index 0a76b4a3..a541826c 100644 --- a/Admin.NET/Admin.NET.Core/Service/Enum/SysEnumService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Enum/SysEnumService.cs @@ -123,30 +123,54 @@ public class SysEnumService : IDynamicApiController, ITransient var newEnumType = enumTypeList.Where(u => !updatedEnumCodes.Contains(u.TypeName)).ToList(); var (newDictTypes, newDictDatas) = GetNewSysDicts(newEnumType); + // 若是sqlite、pg、mysql、sqlserver则采用批量处理 + bool useBulk = _db.CurrentConnectionConfig.DbType == SqlSugar.DbType.Sqlite + || _db.CurrentConnectionConfig.DbType == SqlSugar.DbType.PostgreSQL + || _db.CurrentConnectionConfig.DbType == SqlSugar.DbType.MySql + || _db.CurrentConnectionConfig.DbType == SqlSugar.DbType.MySqlConnector + || _db.CurrentConnectionConfig.DbType == SqlSugar.DbType.SqlServer; + // 执行数据库操作 if (updatedDictTypes.Count > 0) - await _db.Updateable(updatedDictTypes).ExecuteCommandAsync(); + { + if (useBulk) await _db.Fastest().PageSize(300).BulkMergeAsync(updatedDictTypes); + else await _db.Updateable(updatedDictTypes).ExecuteCommandAsync(); + } if (updatedDictDatas.Count > 0) - await _db.Updateable(updatedDictDatas).ExecuteCommandAsync(); + { + if (useBulk) await _db.Fastest().PageSize(300).BulkMergeAsync(updatedDictDatas); + else await _db.Updateable(updatedDictDatas).ExecuteCommandAsync(); + } if (newSysDictDatas.Count > 0) { - // 达梦:用db.Insertable(newDictTypes).ExecuteCommandAsync(stoppingToken);插入400条以上会内容溢出错误,所以改用逐条插入 - // 达梦:不支持storageable2.BulkUpdateAsync 功能 - foreach (var dd in newSysDictDatas) - await _db.Insertable(dd).ExecuteCommandAsync(); + if (useBulk) await _db.Fastest().PageSize(300).BulkMergeAsync(newSysDictDatas); + else + { + // 达梦:用db.Insertable(newSysDictDatas).ExecuteCommandAsync(stoppingToken);插入400条以上会内容溢出错误,所以改用逐条插入 + // 达梦:不支持storageable2.BulkUpdateAsync 功能 + foreach (var dd in newSysDictDatas) + await _db.Insertable(dd).ExecuteCommandAsync(); + } } if (newDictTypes.Count > 0) - await _db.Insertable(newDictTypes).ExecuteCommandAsync(); + { + if (useBulk) await _db.Fastest().PageSize(300).BulkMergeAsync(newDictTypes); + else await _db.Insertable(newDictTypes).ExecuteCommandAsync(); + } if (newDictDatas.Count > 0) { - // 达梦:用db.Insertable(newDictTypes).ExecuteCommandAsync(stoppingToken);插入400条以上会内容溢出错误,所以改用逐条插入 - // 达梦:不支持storageable2.BulkUpdateAsync 功能 - foreach (var dd in newDictDatas) - await _db.Insertable(dd).ExecuteCommandAsync(); + if (useBulk) await _db.Fastest().PageSize(300).BulkMergeAsync(newDictDatas); + else + { + // 达梦:用db.Insertable(newDictDatas).ExecuteCommandAsync(stoppingToken);插入400条以上会内容溢出错误,所以改用逐条插入 + // 达梦:不支持storageable2.BulkUpdateAsync 功能 + foreach (var dd in newDictDatas) + await _db.Insertable(dd).ExecuteCommandAsync(); + } } }