枚举转字典时,对sqlite、pg、mysql、sqlserver采用批量处理

This commit is contained in:
FunCoder 2025-04-16 09:43:42 +08:00
parent 0dd6bb2967
commit febb2f360c

View File

@ -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<SysDictType>().PageSize(300).BulkMergeAsync(updatedDictTypes);
else await _db.Updateable(updatedDictTypes).ExecuteCommandAsync();
}
if (updatedDictDatas.Count > 0)
await _db.Updateable(updatedDictDatas).ExecuteCommandAsync();
{
if (useBulk) await _db.Fastest<SysDictData>().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<SysDictData>().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<SysDictType>().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<SysDictData>().PageSize(300).BulkMergeAsync(newDictDatas);
else
{
// 达梦用db.Insertable(newDictDatas).ExecuteCommandAsync(stoppingToken)插入400条以上会内容溢出错误所以改用逐条插入
// 达梦不支持storageable2.BulkUpdateAsync 功能
foreach (var dd in newDictDatas)
await _db.Insertable(dd).ExecuteCommandAsync();
}
}
}