Эх сурвалжийг харах

修复发布生成单个文件无法运行的问题
新增套餐服务查询套餐租户分页接口

zhontai 2 жил өмнө
parent
commit
0a5a8a381b

+ 1 - 5
src/hosts/ZhonTai.Host/Program.cs

@@ -1,9 +1,7 @@
 using FreeScheduler;
 using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.DependencyModel;
 using Microsoft.Extensions.Hosting;
 using Savorboard.CAP.InMemoryMessageQueue;
-using System.Linq;
 using System.Reflection;
 using ZhonTai;
 using ZhonTai.Admin.Core;
@@ -23,9 +21,7 @@ new HostApp(new HostAppOptions
 
         //添加cap事件总线
         var appConfig = ConfigHelper.Get<AppConfig>("appconfig", context.Environment.EnvironmentName);
-        Assembly[] assemblies = DependencyContext.Default.RuntimeLibraries
-            .Where(a => appConfig.AssemblyNames.Contains(a.Name))
-            .Select(o => Assembly.Load(new AssemblyName(o.Name))).ToArray();
+        Assembly[] assemblies = AssemblyHelper.GetAssemblyList(appConfig.AssemblyNames);
 
         //var dbConfig = ConfigHelper.Get<DbConfig>("dbconfig", context.Environment.EnvironmentName);
         //var rabbitMQ = context.Configuration.GetSection("CAP:RabbitMq").Get<RabbitMqConfig>();

+ 8 - 16
src/platform/ZhonTai.Admin/Core/Db/DbHelper.cs

@@ -1,5 +1,4 @@
-using Microsoft.Extensions.DependencyModel;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
@@ -79,15 +78,12 @@ public class DbHelper
         {
             return null;
         }
-
-        Assembly[]  assemblies = DependencyContext.Default.RuntimeLibraries
-            .Where(a => assemblyNames.Contains(a.Name))
-            .Select(o => Assembly.Load(new AssemblyName(o.Name))).ToArray();
-
+ 
         var entityTypes = new List<Type>();
 
-        foreach (var assembly in assemblies)
+        foreach (var assemblyName in assemblyNames)
         {
+            var assembly = Assembly.Load(assemblyName);
             foreach (Type type in assembly.GetExportedTypes())
             {
                 foreach (Attribute attribute in type.GetCustomAttributes())
@@ -372,9 +368,7 @@ public class DbHelper
                     db.Aop.CurdBefore += SyncDataCurdBefore;
                 }
 
-                Assembly[] assemblies = DependencyContext.Default.RuntimeLibraries
-                .Where(a => dbConfig.AssemblyNames.Contains(a.Name))
-                .Select(o => Assembly.Load(new AssemblyName(o.Name))).ToArray();
+                Assembly[] assemblies = AssemblyHelper.GetAssemblyList(dbConfig.AssemblyNames);
 
                 List<ISyncData> syncDatas = assemblies.Select(assembly => assembly.GetTypes()
                 .Where(x => typeof(ISyncData).GetTypeInfo().IsAssignableFrom(x.GetTypeInfo()) && x.GetTypeInfo().IsClass && !x.GetTypeInfo().IsAbstract))
@@ -417,9 +411,7 @@ public class DbHelper
 
             if (dbConfig.AssemblyNames?.Length > 0)
             {
-                Assembly[] assemblies = DependencyContext.Default.RuntimeLibraries
-               .Where(a => dbConfig.AssemblyNames.Contains(a.Name))
-               .Select(o => Assembly.Load(new AssemblyName(o.Name))).ToArray();
+                Assembly[] assemblies = AssemblyHelper.GetAssemblyList(dbConfig.AssemblyNames);
 
                 List<IGenerateData> generateDatas = assemblies.Select(assembly => assembly.GetTypes()
                 .Where(x => typeof(IGenerateData).GetTypeInfo().IsAssignableFrom(x.GetTypeInfo()) && x.GetTypeInfo().IsClass && !x.GetTypeInfo().IsAbstract))
@@ -456,7 +448,7 @@ public class DbHelper
     )
     {
         //注册数据库
-        var idelTiem = dbConfig.IdleTime.HasValue && dbConfig.IdleTime.Value > 0 ? TimeSpan.FromMinutes(dbConfig.IdleTime.Value) : TimeSpan.MaxValue;
+        var idelTime = dbConfig.IdleTime.HasValue && dbConfig.IdleTime.Value > 0 ? TimeSpan.FromMinutes(dbConfig.IdleTime.Value) : TimeSpan.MaxValue;
         freeSqlCloud.Register(dbConfig.Key, () =>
         {
             //创建数据库
@@ -606,7 +598,7 @@ public class DbHelper
             #endregion 监听Curd操作
 
             return fsql;
-        }, idelTiem);
+        }, idelTime);
 
         //执行注册数据库
         var fsql = freeSqlCloud.Use(dbConfig.Key);

+ 1 - 13
src/platform/ZhonTai.Admin/Core/HostApp.cs

@@ -10,7 +10,6 @@ using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.DependencyInjection.Extensions;
 using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.DependencyModel;
 using Microsoft.IdentityModel.Tokens;
 using Microsoft.OpenApi.Models;
 using Newtonsoft.Json;
@@ -227,13 +226,7 @@ public class HostApp
         services.Configure<UploadConfig>(uploadConfig);
 
         //程序集
-        Assembly[] assemblies = null;
-        if(appConfig.AssemblyNames?.Length > 0)
-        {
-            assemblies = DependencyContext.Default.RuntimeLibraries
-            .Where(a => appConfig.AssemblyNames.Contains(a.Name))
-            .Select(o => Assembly.Load(new AssemblyName(o.Name))).ToArray();
-        }
+        Assembly[] assemblies = AssemblyHelper.GetAssemblyList(appConfig.AssemblyNames);
 
         #region Mapster 映射配置
         services.AddScoped<IMapper>(sp => new Mapper());
@@ -610,11 +603,6 @@ public class HostApp
         //动态api
         services.AddDynamicApi(options =>
         {
-            Assembly[] assemblies = DependencyContext.Default.RuntimeLibraries
-            .Where(a => a.Name.EndsWith("Service"))
-            .Select(o => Assembly.Load(new AssemblyName(o.Name))).ToArray();
-            options.AddAssemblyOptions(assemblies);
-
             options.FormatResult = appConfig.DynamicApi.FormatResult;
             options.FormatResultType = typeof(ResultOutput<>);
 

+ 2 - 4
src/platform/ZhonTai.Admin/Core/RegisterModules/RegisterModule.cs

@@ -5,12 +5,12 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
 using Module = Autofac.Module;
-using Microsoft.Extensions.DependencyModel;
 using ZhonTai.Admin.Core.Configs;
 using ZhonTai.Admin.Core.Db.Transaction;
 using ZhonTai.Admin.Core.Attributes;
 using ZhonTai.Admin.Core.Repositories;
 using Microsoft.AspNetCore.Identity;
+using ZhonTai.Common.Helpers;
 
 namespace ZhonTai.Admin.Core.RegisterModules;
 
@@ -41,9 +41,7 @@ public class RegisterModule : Module
         if(_appConfig.AssemblyNames?.Length > 0)
         {
             //程序集
-            Assembly[] assemblies = DependencyContext.Default.RuntimeLibraries
-                .Where(a => _appConfig.AssemblyNames.Contains(a.Name))
-                .Select(o => Assembly.Load(new AssemblyName(o.Name))).ToArray();
+            Assembly[] assemblies = AssemblyHelper.GetAssemblyList(_appConfig.AssemblyNames);
 
             var nonRegisterIOCAttribute = typeof(NonRegisterIOCAttribute);
             var iRegisterIOCType = typeof(IRegisterIOC);

+ 2 - 4
src/platform/ZhonTai.Admin/Core/RegisterModules/SingleInstanceModule.cs

@@ -1,9 +1,9 @@
 using Autofac;
-using Microsoft.Extensions.DependencyModel;
 using System.Linq;
 using System.Reflection;
 using ZhonTai.Admin.Core.Attributes;
 using ZhonTai.Admin.Core.Configs;
+using ZhonTai.Common.Helpers;
 using Module = Autofac.Module;
 
 namespace ZhonTai.Admin.Core.RegisterModules;
@@ -26,9 +26,7 @@ public class SingleInstanceModule : Module
         if(_appConfig.AssemblyNames?.Length > 0)
         {
             // 获得要注入的程序集
-            Assembly[] assemblies = DependencyContext.Default.RuntimeLibraries
-                .Where(a => _appConfig.AssemblyNames.Contains(a.Name))
-                .Select(o => Assembly.Load(new AssemblyName(o.Name))).ToArray();
+            Assembly[] assemblies = AssemblyHelper.GetAssemblyList(_appConfig.AssemblyNames);
 
             //无接口注入单例
             builder.RegisterAssemblyTypes(assemblies)

+ 3 - 5
src/platform/ZhonTai.Admin/Services/Cache/CacheService.cs

@@ -1,5 +1,4 @@
-using Microsoft.Extensions.DependencyModel;
-using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -11,6 +10,7 @@ using ZhonTai.Admin.Core.Configs;
 using ZhonTai.DynamicApi;
 using ZhonTai.DynamicApi.Attributes;
 using ZhonTai.Admin.Core.Consts;
+using ZhonTai.Common.Helpers;
 
 namespace ZhonTai.Admin.Services.Cache;
 
@@ -34,9 +34,7 @@ public class CacheService : BaseService, ICacheService, IDynamicApi
         var list = new List<dynamic>();
 
         var appConfig = LazyGetRequiredService<AppConfig>();
-        Assembly[] assemblies = DependencyContext.Default.RuntimeLibraries
-            .Where(a => appConfig.AssemblyNames.Contains(a.Name))
-            .Select(o => Assembly.Load(new AssemblyName(o.Name))).ToArray();
+        Assembly[] assemblies = AssemblyHelper.GetAssemblyList(appConfig.AssemblyNames);
 
         foreach (Assembly assembly in assemblies)
         {

+ 13 - 1
src/platform/ZhonTai.Admin/Services/Pkg/Dto/PkgGetListOutput.cs

@@ -1,4 +1,6 @@
-namespace ZhonTai.Admin.Services.Pkg.Dto;
+using System;
+
+namespace ZhonTai.Admin.Services.Pkg.Dto;
 
 public class PkgGetListOutput
 {
@@ -31,4 +33,14 @@ public class PkgGetListOutput
     /// 描述
     /// </summary>
     public string Description { get; set; }
+
+    /// <summary>
+    /// 启用
+    /// </summary>
+    public bool Enabled { get; set; }
+
+    /// <summary>
+    /// 创建时间
+    /// </summary>
+    public DateTime? CreatedTime { get; set; }
 }

+ 5 - 0
src/platform/ZhonTai.Admin/Services/Pkg/Dto/PkgGetPageOutput.cs

@@ -24,6 +24,11 @@ public class PkgGetPageOutput
     /// </summary>
     public string Description { get; set; }
 
+    /// <summary>
+    /// 排序
+    /// </summary>
+    public int Sort { get; set; }
+
     /// <summary>
     /// 启用
     /// </summary>

+ 39 - 6
src/platform/ZhonTai.Admin/Services/Pkg/PkgService.cs

@@ -14,6 +14,7 @@ using ZhonTai.Admin.Domain.Tenant;
 using System.Collections.Generic;
 using ZhonTai.Admin.Domain.RolePermission;
 using ZhonTai.Admin.Domain.User;
+using ZhonTai.Admin.Domain.Org;
 
 namespace ZhonTai.Admin.Services.Pkg;
 
@@ -96,16 +97,48 @@ public class PkgService : BaseService, IDynamicApi
     /// <returns></returns>
     public async Task<List<PkgGetPkgTenantListOutput>> GetPkgTenantListAsync([FromQuery] PkgGetPkgTenantListInput input)
     {
-        var list = await _tenantRepository.Select.From<TenantPkgEntity>()
-            .InnerJoin(a => a.t2.TenantId == a.t1.Id)
-            .Where(a => a.t2.PkgId == input.PkgId)
-            .WhereIf(input.TenantName.NotNull(), a => a.t1.Org.Name.Contains(input.TenantName))
-            .OrderByDescending(a => a.t1.Id)
-            .ToListAsync(a=> new PkgGetPkgTenantListOutput { Id = a.t1.Id, Name = a.t1.Org.Name, Code = a.t1.Org.Code });
+        using var _ = _tenantRepository.DataFilter.Disable(FilterNames.Tenant);
+
+        var list = await _tenantRepository.Select.From<TenantPkgEntity, OrgEntity>((s, b, c) => s
+            .InnerJoin(a => a.Id == b.TenantId)
+            .InnerJoin(a => a.OrgId == c.Id))
+            .Where((a, b, c) => b.PkgId == input.PkgId)
+            .WhereIf(input.TenantName.NotNull(), (a, b, c) => c.Name.Contains(input.TenantName))
+            .OrderByDescending((a, b, c) => b.Id)
+            .ToListAsync((a, b, c) => new PkgGetPkgTenantListOutput { Id = a.Id, Name = c.Name, Code = c.Code });
 
         return list;
     }
 
+    /// <summary>
+    /// 查询套餐租户分页
+    /// </summary>
+    /// <param name="input"></param>
+    /// <returns></returns>
+    [HttpPost]
+    public async Task<PageOutput<PkgGetPkgTenantListOutput>> GetPkgTenantPageAsync(PageInput<PkgGetPkgTenantListInput> input)
+    {
+        using var _ = _tenantRepository.DataFilter.Disable(FilterNames.Tenant);
+
+        var list = await _tenantRepository.Select.From<TenantPkgEntity, OrgEntity>((s, b, c) => s
+            .InnerJoin(a => a.Id == b.TenantId)
+            .InnerJoin(a => a.OrgId == c.Id))
+            .Where((a, b, c) => b.PkgId == input.Filter.PkgId)
+            .WhereIf(input.Filter.TenantName.NotNull(), (a, b, c) => c.Name.Contains(input.Filter.TenantName))
+            .Count(out var total)
+            .OrderByDescending((a, b, c) => b.Id)
+            .Page(input.CurrentPage, input.PageSize)
+            .ToListAsync((a, b, c) => new PkgGetPkgTenantListOutput { Id = a.Id, Name = c.Name, Code = c.Code });
+
+        var data = new PageOutput<PkgGetPkgTenantListOutput>()
+        {
+            List = list,
+            Total = total
+        };
+
+        return data;
+    }
+
     /// <summary>
     /// 查询套餐权限列表
     /// </summary>

+ 27 - 26
src/platform/ZhonTai.Admin/Services/Tenant/TenantService.cs

@@ -25,6 +25,7 @@ using System.Collections.Generic;
 using System.Security.Policy;
 using System.Xml.Linq;
 using Yitter.IdGenerator;
+using ZhonTai.Admin.Repositories;
 
 namespace ZhonTai.Admin.Services.Tenant;
 
@@ -82,34 +83,34 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
     [HttpPost]
     public async Task<PageOutput<TenantListOutput>> GetPageAsync(PageInput<TenantGetPageDto> input)
     {
-        using (_tenantRepository.DataFilter.Disable(FilterNames.Tenant))
-        {
-            var key = input.Filter?.Name;
-
-            var list = await _tenantRepository.Select
-            .WhereDynamicFilter(input.DynamicFilter)
-            .WhereIf(key.NotNull(), a => a.Org.Name.Contains(key))
-            .Count(out var total)
-            .OrderByDescending(true, a => a.Id)
-            .Page(input.CurrentPage, input.PageSize)
-            .ToListAsync(a => new TenantListOutput
-            {
-                Name = a.Org.Name,
-                Code = a.Org.Code,
-                UserName = a.User.UserName,
-                RealName = a.User.Name,
-                Phone = a.User.Mobile,
-                Email = a.User.Email,
-            });
+        using var _ = _tenantRepository.DataFilter.Disable(FilterNames.Tenant);
 
-            var data = new PageOutput<TenantListOutput>()
-            {
-                List = list,
-                Total = total
-            };
 
-            return data;
-        }
+        var key = input.Filter?.Name;
+
+        var list = await _tenantRepository.Select
+        .WhereDynamicFilter(input.DynamicFilter)
+        .WhereIf(key.NotNull(), a => a.Org.Name.Contains(key))
+        .Count(out var total)
+        .OrderByDescending(true, a => a.Id)
+        .Page(input.CurrentPage, input.PageSize)
+        .ToListAsync(a => new TenantListOutput
+        {
+            Name = a.Org.Name,
+            Code = a.Org.Code,
+            UserName = a.User.UserName,
+            RealName = a.User.Name,
+            Phone = a.User.Mobile,
+            Email = a.User.Email,
+        });
+
+        var data = new PageOutput<TenantListOutput>()
+        {
+            List = list,
+            Total = total
+        };
+
+        return data;
     }
 
     /// <summary>

+ 22 - 0
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -6031,6 +6031,16 @@
             描述
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Services.Pkg.Dto.PkgGetListOutput.Enabled">
+            <summary>
+            启用
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Pkg.Dto.PkgGetListOutput.CreatedTime">
+            <summary>
+            创建时间
+            </summary>
+        </member>
         <member name="P:ZhonTai.Admin.Services.Pkg.Dto.PkgGetPageDto.Name">
             <summary>
             名称
@@ -6056,6 +6066,11 @@
             说明
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Services.Pkg.Dto.PkgGetPageOutput.Sort">
+            <summary>
+            排序
+            </summary>
+        </member>
         <member name="P:ZhonTai.Admin.Services.Pkg.Dto.PkgGetPageOutput.Enabled">
             <summary>
             启用
@@ -6134,6 +6149,13 @@
             <param name="input"></param>
             <returns></returns>
         </member>
+        <member name="M:ZhonTai.Admin.Services.Pkg.PkgService.GetPkgTenantPageAsync(ZhonTai.Admin.Core.Dto.PageInput{ZhonTai.Admin.Services.Pkg.Dto.PkgGetPkgTenantListInput})">
+            <summary>
+            查询套餐租户分页
+            </summary>
+            <param name="input"></param>
+            <returns></returns>
+        </member>
         <member name="M:ZhonTai.Admin.Services.Pkg.PkgService.GetPkgPermissionList(System.Int64)">
             <summary>
             查询套餐权限列表

+ 36 - 0
src/platform/ZhonTai.Common/Helpers/AssemblyHelper.cs

@@ -0,0 +1,36 @@
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace ZhonTai.Common.Helpers;
+
+/// <summary>
+/// 程序集帮助类
+/// </summary>
+public class AssemblyHelper
+{
+    /// <summary>
+    /// 根据程序集名称列表获取程序集列表
+    /// </summary>
+    /// <param name="assemblyNames"></param>
+    /// <returns></returns>
+    public static Assembly[] GetAssemblyList(string[] assemblyNames)
+    {
+        List<Assembly> assemblies = new();
+
+        if (!(assemblyNames?.Length > 0))
+        {
+            return assemblies.ToArray();
+        }
+
+        foreach (var assemblyName in assemblyNames)
+        {
+            var assembly = Assembly.Load(assemblyName);
+            if (assembly != null)
+            {
+                assemblies.Add(assembly);
+            }
+        }
+
+        return assemblies.ToArray();
+    }
+}

+ 12 - 0
src/platform/ZhonTai.Common/ZhonTai.Common.xml

@@ -239,6 +239,18 @@
             G字节
             </summary>
         </member>
+        <member name="T:ZhonTai.Common.Helpers.AssemblyHelper">
+            <summary>
+            程序集帮助类
+            </summary>
+        </member>
+        <member name="M:ZhonTai.Common.Helpers.AssemblyHelper.GetAssemblyList(System.String[])">
+            <summary>
+            根据程序集名称列表获取程序集列表
+            </summary>
+            <param name="assemblyNames"></param>
+            <returns></returns>
+        </member>
         <member name="T:ZhonTai.Common.Helpers.ConfigHelper">
             <summary>
             配置帮助类