|
|
@@ -33,15 +33,21 @@ public class EnumToDictJob : IJob
|
|
|
|
|
|
using var serviceScope = _scopeFactory.CreateScope();
|
|
|
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().CopyNew();
|
|
|
+
|
|
|
+ var sysEnumService = serviceScope.ServiceProvider.GetRequiredService<SysEnumService>();
|
|
|
+ var sysDictTypeList = GetDictByEnumType(sysEnumService.GetEnumTypeList());
|
|
|
+
|
|
|
+ // 校验枚举类命名规范,字典相关功能中需要通过后缀判断是否为枚举类型
|
|
|
+ foreach (var dictType in sysDictTypeList.Where(x => !x.Code.EndsWith("Enum"))) Log.Warning($"系统枚举转换字典的枚举类名称必须以Enum结尾: {dictType.Code} ({dictType.Name})");
|
|
|
+ sysDictTypeList = sysDictTypeList.Where(x => x.Code.EndsWith("Enum")).ToList();
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
await db.BeginTranAsync();
|
|
|
-
|
|
|
- var sysEnumService = serviceScope.ServiceProvider.GetRequiredService<SysEnumService>();
|
|
|
- var sysDictTypeList = GetDictByEnumType(sysEnumService.GetEnumTypeList());
|
|
|
var storageable1 = await db.Storageable(sysDictTypeList)
|
|
|
+ .WhereColumns(it => new { it.Code })
|
|
|
+ .SplitInsert(it => !it.Any())
|
|
|
.SplitUpdate(it => it.Any())
|
|
|
- .SplitInsert(_ => true)
|
|
|
.ToStorageAsync();
|
|
|
await storageable1.BulkCopyAsync();
|
|
|
await storageable1.BulkUpdateAsync();
|
|
|
@@ -49,8 +55,9 @@ public class EnumToDictJob : IJob
|
|
|
Log.Information($"系统枚举类转字典类型数据: 共{storageable1.TotalList.Count}条");
|
|
|
|
|
|
var storageable2 = await db.Storageable(sysDictTypeList.SelectMany(x => x.Children).ToList())
|
|
|
+ .WhereColumns(it => new { it.DictTypeId, it.Code })
|
|
|
+ .SplitInsert(it => !it.Any())
|
|
|
.SplitUpdate(it => it.Any())
|
|
|
- .SplitInsert(_ => true)
|
|
|
.ToStorageAsync();
|
|
|
await storageable2.BulkCopyAsync();
|
|
|
await storageable2.BulkUpdateAsync();
|
|
|
@@ -74,6 +81,7 @@ public class EnumToDictJob : IJob
|
|
|
/// <returns></returns>
|
|
|
private List<SysDictType> GetDictByEnumType(List<EnumTypeOutput> enumTypeList)
|
|
|
{
|
|
|
+ var orderNo = 1;
|
|
|
var list = new List<SysDictType>();
|
|
|
foreach (var type in enumTypeList)
|
|
|
{
|
|
|
@@ -86,7 +94,7 @@ public class EnumToDictJob : IJob
|
|
|
};
|
|
|
dictType.Children = type.EnumEntities.Select(x => new SysDictData
|
|
|
{
|
|
|
- Id = dictType.Id + x.Value + OrderOffset,
|
|
|
+ Id = dictType.Id + orderNo++,
|
|
|
DictTypeId = dictType.Id,
|
|
|
Name = x.Name,
|
|
|
Value = x.Describe,
|