😎恢复枚举转字典入库模式(兼容达梦和oracle)

This commit is contained in:
zuohuaijun 2025-04-10 03:01:35 +08:00
parent 986de8e331
commit 6b2adaf13b
2 changed files with 22 additions and 13 deletions

View File

@ -123,22 +123,31 @@ public class SysEnumService : IDynamicApiController, ITransient
var newEnumType = enumTypeList.Where(u => !updatedEnumCodes.Contains(u.TypeName)).ToList(); var newEnumType = enumTypeList.Where(u => !updatedEnumCodes.Contains(u.TypeName)).ToList();
var (newDictTypes, newDictDatas) = GetNewSysDicts(newEnumType); var (newDictTypes, newDictDatas) = GetNewSysDicts(newEnumType);
// 需要更新的字典类型 // 执行数据库操作
if (updatedDictTypes.Count > 0) if (updatedDictTypes.Count > 0)
await _db.Fastest<SysDictType>().PageSize(300).BulkMergeAsync(updatedDictTypes); await _db.Updateable(updatedDictTypes).ExecuteCommandAsync();
// 需要更新的字典数据
if (updatedDictDatas.Count > 0) if (updatedDictDatas.Count > 0)
await _db.Fastest<SysDictData>().PageSize(300).BulkMergeAsync(updatedDictDatas); await _db.Updateable(updatedDictDatas).ExecuteCommandAsync();
// 需要新增的字典数据
if (newSysDictDatas.Count > 0) if (newSysDictDatas.Count > 0)
await _db.Fastest<SysDictData>().PageSize(300).BulkMergeAsync(newSysDictDatas); {
// 需要新增的字典类型 // 达梦用db.Insertable(newDictTypes).ExecuteCommandAsync(stoppingToken)插入400条以上会内容溢出错误所以改用逐条插入
// 达梦不支持storageable2.BulkUpdateAsync 功能
foreach (var dd in newSysDictDatas)
await _db.Insertable(dd).ExecuteCommandAsync();
}
if (newDictTypes.Count > 0) if (newDictTypes.Count > 0)
await _db.Fastest<SysDictType>().PageSize(300).BulkMergeAsync(newDictTypes); await _db.Insertable(newDictTypes).ExecuteCommandAsync();
// 需要新增的字典数据
if (newDictDatas.Count > 0) if (newDictDatas.Count > 0)
await _db.Fastest<SysDictData>().PageSize(300).BulkMergeAsync(newDictDatas); {
// 达梦用db.Insertable(newDictTypes).ExecuteCommandAsync(stoppingToken)插入400条以上会内容溢出错误所以改用逐条插入
// 达梦不支持storageable2.BulkUpdateAsync 功能
foreach (var dd in newDictDatas)
await _db.Insertable(dd).ExecuteCommandAsync();
}
} }
/// <summary> /// <summary>

View File

@ -187,8 +187,8 @@ public class SysRegionService : IDynamicApiController, ITransient
var html = await _httpRemoteService.GetAsStringAsync("http://xzqh.mca.gov.cn/map"); var html = await _httpRemoteService.GetAsStringAsync("http://xzqh.mca.gov.cn/map");
var municipalityList = new List<string> { "北京", "天津", "上海", "重庆" }; var municipalityList = new List<string> { "北京", "天津", "上海", "重庆" };
var aa = Regex.Match(html, @"(?<=var json = )(\[\{.*?\}\])(?=;)").Value; var proJson = Regex.Match(html, @"(?<=var json = )(\[\{.*?\}\])(?=;)").Value;
dynamic provList = Clay.Parse(aa); dynamic provList = Clay.Parse(proJson);
var list = new List<SysRegion>(); var list = new List<SysRegion>();
foreach (var proItem in provList) foreach (var proItem in provList)