Sfoglia il codice sorgente

feat: 增加字典租户隔离

喵你个旺呀 1 anno fa
parent
commit
ae8eeff90c

+ 7 - 13
Admin.NET/Admin.NET.Core/Job/EnumToDictJob.cs

@@ -37,7 +37,7 @@ public class EnumToDictJob : IJob
         // 校验枚举类命名规范,字典相关功能中需要通过后缀判断是否为枚举类型
         Console.ForegroundColor = ConsoleColor.Red;
         foreach (var dictType in sysDictTypeList.Where(x => !x.Code.EndsWith("Enum")))
-            Console.WriteLine($"【{DateTime.Now}】系统枚举转换字典的枚举类名称必须以Enum结尾: {dictType.Code} ({dictType.Name}-{dictType.Remark})");
+            Console.WriteLine($"【{DateTime.Now}】系统枚举转换字典的枚举类名称必须以Enum结尾: {dictType.Code} ({dictType.Name})");
         sysDictTypeList = sysDictTypeList.Where(x => x.Code.EndsWith("Enum")).ToList();
 
         await SyncEnumToDictInfoAsync(db, sysDictTypeList);
@@ -50,8 +50,8 @@ public class EnumToDictJob : IJob
                 .SplitUpdate(it => it.Any())
                 .SplitInsert(_ => true)
                 .ToStorageAsync();
-            await storageable1.AsInsertable.ExecuteCommandAsync(stoppingToken);
-            await storageable1.AsUpdateable.ExecuteCommandAsync(stoppingToken);
+            await storageable1.BulkCopyAsync();
+            await storageable1.BulkUpdateAsync();
 
             Console.WriteLine($"【{DateTime.Now}】系统枚举类转字典类型数据: 插入{storageable1.InsertList.Count}条, 更新{storageable1.UpdateList.Count}条, 共{storageable1.TotalList.Count}条。");
 
@@ -60,14 +60,8 @@ public class EnumToDictJob : IJob
                 .SplitUpdate(it => it.Any())
                 .SplitInsert(_ => true)
                 .ToStorageAsync();
-            await storageable2.AsInsertable.ExecuteCommandAsync(stoppingToken);
-            await storageable2.AsUpdateable.UpdateColumns(u => new
-            {
-                u.Label,
-                u.Name,
-                u.Value,
-                u.TenantId
-            }).ExecuteCommandAsync(stoppingToken);
+            await storageable2.BulkCopyAsync();
+            await storageable2.BulkUpdateAsync(nameof(SysDictData.Label), nameof(SysDictData.Value), nameof(SysDictData.Name), nameof(SysDictData.TenantId));
 
             Console.WriteLine($"【{DateTime.Now}】系统枚举项转字典值数据: 插入{storageable2.InsertList.Count}条, 更新{storageable2.UpdateList.Count}条, 共{storageable2.TotalList.Count}条。");
 
@@ -124,10 +118,10 @@ public class EnumToDictJob : IJob
         {
             var dictType = new SysDictType
             {
-                Id = 900000000000 + CommonUtil.GetFixedHashCode(type.TypeFullName),
+                Id = 900000000000 + CommonUtil.GetFixedHashCode(type.TypeName),
                 Code = type.TypeName,
                 Name = type.TypeDescribe,
-                Remark = type.TypeFullName,
+                Remark = type.TypeRemark,
                 TenantId = SqlSugarConst.DefaultTenantId
             };
             dictType.Children = type.EnumEntities.Select(x => new SysDictData

+ 1 - 1
Admin.NET/Admin.NET.Core/Service/Dict/Dto/DictDataInput.cs

@@ -21,7 +21,7 @@ public class PageDictDataInput : BasePageInput
     /// 字典文本
     /// </summary>
     public string Label { get; set; }
-
+    
     /// <summary>
     /// 租户Id
     /// </summary>

+ 1 - 1
Admin.NET/Admin.NET.Core/Service/Dict/Dto/DictTypeInput.cs

@@ -21,7 +21,7 @@ public class PageDictTypeInput : BasePageInput
     /// 编码
     /// </summary>
     public string Code { get; set; }
-
+    
     /// <summary>
     /// 租户Id
     /// </summary>

+ 4 - 4
Admin.NET/Admin.NET.Core/Service/Dict/SysDictDataService.cs

@@ -38,7 +38,7 @@ public class SysDictDataService : IDynamicApiController, ITransient
             .Where(u => u.DictTypeId == input.DictTypeId)
             .WhereIF(!_userManager.SuperAdmin, u => ids.Contains(u.TenantId.Value))
             .WhereIF(!string.IsNullOrEmpty(input.Label?.Trim()), u => u.Value.Contains(input.Label))
-            .WhereIF(_userManager.SuperAdmin && input.TenantId > 0, u => u.TenantId == input.TenantId)
+            .WhereIF(_userManager.SuperAdmin && input.TenantId > 0, u => u.TenantId ==  input.TenantId)
             .OrderBy(u => new { u.OrderNo, Code = u.Value })
             .ToPagedListAsync(input.Page, input.PageSize);
     }
@@ -148,7 +148,7 @@ public class SysDictDataService : IDynamicApiController, ITransient
     [NonAction]
     public async Task<List<SysDictData>> GetDictDataListByDictTypeId(long dictTypeId)
     {
-        var dictType = await App.GetService<SysDictTypeService>().GetDetail(new DictTypeInput { Id = dictTypeId });
+        var dictType = await App.GetService<SysDictTypeService>().GetDetail(new DictTypeInput { Id= dictTypeId });
         var dictDataList = _sysCacheService.Get<List<SysDictData>>($"{CacheConst.KeyDict}{dictTypeId}");
 
         if (dictDataList == null)
@@ -199,7 +199,7 @@ public class SysDictDataService : IDynamicApiController, ITransient
             .OrderBy((u, a) => new { a.OrderNo, Code = a.Value })
             .Select((u, a) => a).ToListAsync();
     }
-
+    
     /// <summary>
     /// 获取租户Id列表
     /// </summary>
@@ -214,7 +214,7 @@ public class SysDictDataService : IDynamicApiController, ITransient
     [NonAction]
     public ISugarQueryable<SysDictData> GetSysDictDataQueryable()
     {
-        var ids = GetTenantIdList();
+        var ids = GetTenantIdList(); 
         return _sysDictDataRep.AsQueryable().ClearFilter().WhereIF(!_userManager.SuperAdmin, u => ids.Contains(u.TenantId.Value));
     }
 

+ 4 - 4
Admin.NET/Admin.NET.Core/Service/Dict/SysDictTypeService.cs

@@ -37,7 +37,7 @@ public class SysDictTypeService : IDynamicApiController, ITransient
     {
         return await _sysDictTypeRep.AsQueryable()
             .WhereIF(!_userManager.SuperAdmin, u => !SqlFunc.EndsWith(SqlFunc.ToLower(u.Code), nameof(Enum).ToLower()))
-            .WhereIF(_userManager.SuperAdmin && input.TenantId > 0, u => u.TenantId == input.TenantId)
+            .WhereIF(_userManager.SuperAdmin && input.TenantId > 0, u => u.TenantId ==  input.TenantId)
             .WhereIF(!string.IsNullOrEmpty(input.Code?.Trim()), u => u.Code.Contains(input.Code))
             .WhereIF(!string.IsNullOrEmpty(input.Name?.Trim()), u => u.Name.Contains(input.Name))
             .OrderBy(u => new { u.OrderNo, u.Code })
@@ -164,7 +164,7 @@ public class SysDictTypeService : IDynamicApiController, ITransient
             .ToListAsync();
         return ds.OrderBy(u => u.OrderNo).GroupBy(u => u.TypeCode).ToDictionary(u => u.Key, u => u);
     }
-
+    
     /// <summary>
     /// 获取SysDictData表查询实例
     /// </summary>
@@ -173,9 +173,9 @@ public class SysDictTypeService : IDynamicApiController, ITransient
     public ISugarQueryable<SysDictType> GetSysDictDataQueryable()
     {
         var ids = GetTenantIdList();
-        return _sysDictTypeRep.AsQueryable().ClearFilter().WhereIF(!_userManager.SuperAdmin, u => ids.Contains(u.TenantId.Value));
+        return _sysDictTypeRep.AsQueryable().WhereIF(!_userManager.SuperAdmin, u => ids.Contains(u.TenantId.Value));
     }
-
+    
     /// <summary>
     /// 获取租户Id列表
     /// </summary>

+ 1 - 1
Web/src/api-services/models/add-pos-input.ts

@@ -98,7 +98,7 @@ export interface AddPosInput {
      */
     status?: StatusEnum;
     /**
-     * 在职人
+     * 在职人
      * @type {Array<SysUser>}
      * @memberof AddPosInput
      */

+ 6 - 0
Web/src/api-services/models/page-dict-data-input.ts

@@ -79,4 +79,10 @@ export interface PageDictDataInput {
      * @memberof PageDictDataInput
      */
     label?: string | null;
+    /**
+     * 租户Id
+     * @type {number}
+     * @memberof PageDictDataInput
+     */
+    tenantId?: number;
 }

+ 1 - 1
Web/src/api-services/models/sys-pos.ts

@@ -104,7 +104,7 @@ export interface SysPos {
      */
     status?: StatusEnum;
     /**
-     * 在职人
+     * 在职人
      * @type {Array<SysUser>}
      * @memberof SysPos
      */

+ 1 - 1
Web/src/api-services/models/update-pos-input.ts

@@ -98,7 +98,7 @@ export interface UpdatePosInput {
      */
     status?: StatusEnum;
     /**
-     * 在职人
+     * 在职人
      * @type {Array<SysUser>}
      * @memberof UpdatePosInput
      */