Bladeren bron

修复 任务调度配置会丢失的问题
修复 查询用户信息接口没有考虑租户套餐权限的问题
调整 读取appsettings.CAP.RabbitMq配置改用RabbitMQOptions,删除RabbitMqConfig.cs

zhontai 2 jaren geleden
bovenliggende
commit
e98e8af9b3

+ 1 - 1
build/pkg.props

@@ -1,6 +1,6 @@
 <Project>
   <PropertyGroup>
-    <Version>3.6.0</Version>
+    <Version>3.6.1</Version>
 	<TargetFramework>net7.0</TargetFramework>
 	<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
 	<GenerateDocumentationFile>true</GenerateDocumentationFile>

+ 1 - 1
src/hosts/ZhonTai.Host/Configs/appconfig.json

@@ -38,7 +38,7 @@
       {
         "name": "中台Admin",
         "code": "admin",
-        "version": "v3.6.0",
+        "version": "v3.6.1",
         "description": ""
       }
     ]

+ 25 - 6
src/hosts/ZhonTai.Host/Program.cs

@@ -7,6 +7,7 @@ using ZhonTai;
 using ZhonTai.Admin.Core;
 using ZhonTai.Admin.Core.Configs;
 using ZhonTai.Admin.Core.Consts;
+using ZhonTai.Admin.Core.Db;
 using ZhonTai.Admin.Core.Startup;
 using ZhonTai.Admin.Tools.TaskScheduler;
 using ZhonTai.ApiUI;
@@ -14,6 +15,26 @@ using ZhonTai.Common.Helpers;
 
 new HostApp(new HostAppOptions
 {
+    //配置FreeSql
+    ConfigureFreeSql = (freeSql, dbConfig) =>
+    {
+        if(dbConfig.Key == DbKeys.AppDb)
+        {
+            freeSql.SyncSchedulerStructure(dbConfig, (fsql) =>
+            {
+                fsql.CodeFirst
+                .ConfigEntity<TaskInfo>(a =>
+                {
+                    a.Name("app_task");
+                })
+                .ConfigEntity<TaskLog>(a =>
+                {
+                    a.Name("app_task_log");
+                });
+            });
+        }
+    },
+
 	//配置后置服务
 	ConfigurePostServices = context =>
 	{
@@ -24,14 +45,14 @@ new HostApp(new HostAppOptions
         Assembly[] assemblies = AssemblyHelper.GetAssemblyList(appConfig.AssemblyNames);
 
         //var dbConfig = ConfigHelper.Get<DbConfig>("dbconfig", context.Environment.EnvironmentName);
-        //var rabbitMQ = context.Configuration.GetSection("CAP:RabbitMq").Get<RabbitMqConfig>();
+        //var rabbitMQ = context.Configuration.GetSection("CAP:RabbitMq").Get<RabbitMQOptions>();
         context.Services.AddCap(config =>
         {
             config.UseInMemoryStorage();
             config.UseInMemoryMessageQueue();
 
-            //<PackageReference Include="DotNetCore.CAP.MySql" Version="7.1.0" />
-            //<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="7.1.0" />
+            //<PackageReference Include="DotNetCore.CAP.MySql" Version="7.1.1" />
+            //<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="7.1.1" />
 
             //config.UseMySql(dbConfig.ConnectionString);
             //config.UseRabbitMQ(mqConfig => {
@@ -50,12 +71,10 @@ new HostApp(new HostAppOptions
             options.ConfigureFreeSql = freeSql =>
             {
                 freeSql.CodeFirst
-                //配置任务表
                 .ConfigEntity<TaskInfo>(a =>
                 {
                     a.Name("app_task");
                 })
-                //配置任务日志表
                 .ConfigEntity<TaskLog>(a =>
                 {
                     a.Name("app_task_log");
@@ -63,7 +82,7 @@ new HostApp(new HostAppOptions
             };
 
             //模块任务处理器
-            options.TaskHandler = new TaskHandler(options.FreeSql);
+            options.TaskHandler = new CloudTaskHandler(options.FreeSqlCloud, DbKeys.AppDb);
         });
     },
 

+ 2 - 2
src/hosts/ZhonTai.Host/ZhonTai.Host.csproj

@@ -34,8 +34,8 @@
 	</ItemGroup>
 
 	<ItemGroup>
-		<PackageReference Include="DotNetCore.CAP.Dashboard" Version="7.1.0" />
-		<PackageReference Include="DotNetCore.CAP.InMemoryStorage" Version="7.1.0" />
+		<PackageReference Include="DotNetCore.CAP.Dashboard" Version="7.1.1" />
+		<PackageReference Include="DotNetCore.CAP.InMemoryStorage" Version="7.1.1" />
 		<PackageReference Include="Savorboard.CAP.InMemoryMessageQueue" Version="7.0.0" />
 		<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.3" />
 	</ItemGroup>

+ 0 - 27
src/platform/ZhonTai.Admin/Core/Configs/RabbitMqConfig.cs

@@ -1,27 +0,0 @@
-namespace ZhonTai.Admin.Core.Configs;
-
-/// <summary>
-/// RabbitMq配置
-/// </summary>
-public class RabbitMqConfig
-{
-    /// <summary>
-    /// 主机IP或Url地址
-    /// </summary>
-    public string HostName { get; set; } = string.Empty;
-
-    /// <summary>
-    /// 端口号
-    /// </summary>
-    public int Port { get; set; } = 5672;
-
-    /// <summary>
-    /// 用户名
-    /// </summary>
-    public string UserName { get; set; } = string.Empty;
-
-    /// <summary>
-    ///  密码
-    /// </summary>
-    public string Password { get; set; } = string.Empty;
-}

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

@@ -471,7 +471,7 @@ public class DbHelper
                 freeSqlBuilder.UseSlave(slaveList).UseSlaveWeight(slaveWeightList);
             }
 
-            hostAppOptions?.ConfigureFreeSqlBuilder?.Invoke(freeSqlBuilder);
+            hostAppOptions?.ConfigureFreeSqlBuilder?.Invoke(freeSqlBuilder, dbConfig);
 
             #region 监听所有命令
 
@@ -543,7 +543,7 @@ public class DbHelper
             //配置实体
             ConfigEntity(fsql, appConfig, dbConfig);
 
-            hostAppOptions?.ConfigureFreeSql?.Invoke(fsql);
+            hostAppOptions?.ConfigureFreeSql?.Invoke(fsql, dbConfig);
 
             #region 初始化数据库
 

+ 41 - 0
src/platform/ZhonTai.Admin/Core/Db/FreeSqlDbContextExtensions.cs

@@ -1,6 +1,9 @@
 using System;
 using ZhonTai.Admin.Core.Repositories;
 using System.Linq.Expressions;
+using ZhonTai.Admin.Tools.TaskScheduler;
+using FreeScheduler;
+using ZhonTai.Admin.Core.Configs;
 
 namespace ZhonTai.Admin.Core.Db;
 
@@ -30,4 +33,42 @@ public static class FreeSqlDbContextExtensions
     {
         return new RepositoryBase<TEntity, long>(that, filter);
     }
+
+    /// <summary>
+    /// 同步调度结构
+    /// </summary>
+    /// <param name="that"></param>
+    /// <param name="dbConfig"></param>
+    /// <param name="configureFreeSql"></param>
+    public static void SyncSchedulerStructure(this IFreeSql that, DbConfig dbConfig, Action<IFreeSql> configureFreeSql = null)
+    {
+        that.CodeFirst
+        .ConfigEntity<TaskInfo>(a =>
+        {
+            a.Name("ad_task");
+            a.Property(b => b.Id).IsPrimary(true);
+            a.Property(b => b.Body).StringLength(-1);
+            a.Property(b => b.Interval).MapType(typeof(int));
+            a.Property(b => b.IntervalArgument).StringLength(1024);
+            a.Property(b => b.Status).MapType(typeof(int));
+            a.Property(b => b.CreateTime).ServerTime(DateTimeKind.Local);
+            a.Property(b => b.LastRunTime).ServerTime(DateTimeKind.Local);
+        })
+        .ConfigEntity<TaskLog>(a =>
+        {
+            a.Name("ad_task_log");
+            a.Property(b => b.Exception).StringLength(-1);
+            a.Property(b => b.Remark).StringLength(-1);
+            a.Property(b => b.CreateTime).ServerTime(DateTimeKind.Local);
+        });
+
+        configureFreeSql?.Invoke(that);
+
+        if (dbConfig.SyncStructure)
+        {
+            that.CodeFirst.SyncStructure<TaskInfo>();
+            that.CodeFirst.SyncStructure<TaskLog>();
+        }
+        
+    }
 }

+ 5 - 4
src/platform/ZhonTai.Admin/Core/Startup/HostAppOptions.cs

@@ -3,6 +3,7 @@ using FreeSql;
 using Microsoft.Extensions.DependencyInjection;
 using System;
 using Yitter.IdGenerator;
+using ZhonTai.Admin.Core.Configs;
 using ZhonTai.DynamicApi;
 
 namespace ZhonTai.Admin.Core.Startup;
@@ -53,14 +54,14 @@ public class HostAppOptions
     public Action<HostAppMiddlewareContext> ConfigurePostMiddleware { get; set; }
 
     /// <summary>
-    /// 配置主库FreeSql构建器
+    /// 配置FreeSql构建器
     /// </summary>
-    public Action<FreeSqlBuilder> ConfigureFreeSqlBuilder { get; set; }
+    public Action<FreeSqlBuilder, DbConfig> ConfigureFreeSqlBuilder { get; set; }
 
     /// <summary>
-    /// 配置主库FreeSql
+    /// 配置FreeSql
     /// </summary>
-    public Action<IFreeSql> ConfigureFreeSql { get; set; }
+    public Action<IFreeSql, DbConfig> ConfigureFreeSql { get; set; }
 
     /// <summary>
     /// 配置动态Api

+ 8 - 4
src/platform/ZhonTai.Admin/Services/Auth/AuthService.cs

@@ -157,9 +157,7 @@ public class AuthService : BaseService, IAuthService, IDynamicApi
                        db.Select<TenantPermissionEntity>()
                        .Where(b => b.PermissionId == a.Id && b.TenantId == User.TenantId)
                        .Any()
-
                        ||
-
                        db.Select<TenantPkgEntity, PkgPermissionEntity>()
                        .Where((b, c) => b.PkgId == c.PkgId && b.TenantId == User.TenantId && c.PermissionId == a.Id)
                        .Any()
@@ -218,9 +216,7 @@ public class AuthService : BaseService, IAuthService, IDynamicApi
                        db.Select<TenantPermissionEntity>()
                        .Where(b => b.PermissionId == a.Id && b.TenantId == User.TenantId)
                        .Any()
-
                        ||
-
                        db.Select<TenantPkgEntity, PkgPermissionEntity>()
                        .Where((b, c) => b.PkgId == c.PkgId && b.TenantId == User.TenantId && c.PermissionId == a.Id)
                        .Any()
@@ -276,12 +272,20 @@ public class AuthService : BaseService, IAuthService, IDynamicApi
                        db.Select<TenantPermissionEntity>()
                        .Where(b => b.PermissionId == a.Id && b.TenantId == User.TenantId)
                        .Any()
+                       ||
+                       db.Select<TenantPkgEntity, PkgPermissionEntity>()
+                       .Where((b, c) => b.PkgId == c.PkgId && b.TenantId == User.TenantId && c.PermissionId == a.Id)
+                       .Any()
                    );
 
                     dotSelect = dotSelect.Where(a =>
                        db.Select<TenantPermissionEntity>()
                        .Where(b => b.PermissionId == a.Id && b.TenantId == User.TenantId)
                        .Any()
+                       ||
+                       db.Select<TenantPkgEntity, PkgPermissionEntity>()
+                       .Where((b, c) => b.PkgId == c.PkgId && b.TenantId == User.TenantId && c.PermissionId == a.Id)
+                       .Any()
                     );
                 }
                 else

+ 37 - 0
src/platform/ZhonTai.Admin/Tools/TaskScheduler/CloudTaskHandler.cs

@@ -0,0 +1,37 @@
+using FreeScheduler;
+using FreeSql;
+using System.Collections.Generic;
+
+namespace ZhonTai.Admin.Tools.TaskScheduler;
+
+public class CloudTaskHandler : ITaskHandler
+{
+    readonly FreeSqlCloud _fsqlc;
+    readonly string _dbKey;
+    private IFreeSql _fsql => _fsqlc.Use(_dbKey);
+    public CloudTaskHandler(FreeSqlCloud fsqlc, string dbKey)
+    {
+        _fsqlc = fsqlc;
+        _dbKey = dbKey;
+    }
+
+    public IEnumerable<TaskInfo> LoadAll() => _fsql.Select<TaskInfo>().Where(a => a.Status == TaskStatus.Running && (a.Round < 0 || a.CurrentRound < a.Round)).ToList();
+    public TaskInfo Load(string id) => _fsql.Select<TaskInfo>().Where(a => a.Id == id).First();
+    public void OnAdd(TaskInfo task) => _fsql.Insert<TaskInfo>().NoneParameter().AppendData(task).ExecuteAffrows();
+    public void OnRemove(TaskInfo task) => _fsql.Delete<TaskInfo>().Where(a => a.Id == task.Id).ExecuteAffrows();
+    public void OnExecuted(Scheduler scheduler, TaskInfo task, TaskLog result)
+    {
+        _fsql.Transaction(() =>
+        {
+            _fsql.Update<TaskInfo>().NoneParameter().SetSource(task)
+                .UpdateColumns(a => new { a.CurrentRound, a.ErrorTimes, a.LastRunTime, a.Status })
+                .ExecuteAffrows();
+            _fsql.Insert<TaskLog>().NoneParameter().AppendData(result).ExecuteAffrows();
+        });
+    }
+
+    public virtual void OnExecuting(Scheduler scheduler, TaskInfo task)
+    {
+
+    }
+}

+ 6 - 0
src/platform/ZhonTai.Admin/Tools/TaskScheduler/TaskSchedulerOptions.cs

@@ -1,4 +1,5 @@
 using FreeScheduler;
+using FreeSql;
 using System;
 using ZhonTai.Admin.Core.Consts;
 
@@ -19,6 +20,11 @@ public class TaskSchedulerOptions
     /// </summary>
     public IFreeSql FreeSql { get; set; }
 
+    /// <summary>
+    /// 多库实例
+    /// </summary>
+    public FreeSqlCloud FreeSqlCloud { get; set; }
+
     /// <summary>
     /// 配置FreeSql
     /// </summary>

+ 3 - 27
src/platform/ZhonTai.Admin/Tools/TaskScheduler/TaskSchedulerServiceExtensions.cs

@@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
 using System;
 using ZhonTai.Admin.Core.Configs;
 using ZhonTai.Admin.Core.Consts;
+using ZhonTai.Admin.Core.Db;
 
 namespace ZhonTai.Admin.Tools.TaskScheduler;
 
@@ -33,40 +34,15 @@ public static class TaskSchedulerServiceExtensions
         ServiceProvider = services.BuildServiceProvider();
         var options = new TaskSchedulerOptions()
         {
+            FreeSqlCloud = ServiceProvider.GetService<FreeSqlCloud>(),
             FreeSql = ServiceProvider.GetService<FreeSqlCloud>().Use(dbKey)
         };
         configureOptions?.Invoke(options);
 
         var freeSql = options.FreeSql;
 
-        freeSql.CodeFirst
-        .ConfigEntity<TaskInfo>(a =>
-        {
-            a.Name("ad_task");
-            a.Property(b => b.Id).IsPrimary(true);
-            a.Property(b => b.Body).StringLength(-1);
-            a.Property(b => b.Interval).MapType(typeof(int));
-            a.Property(b => b.IntervalArgument).StringLength(1024);
-            a.Property(b => b.Status).MapType(typeof(int));
-            a.Property(b => b.CreateTime).ServerTime(DateTimeKind.Local);
-            a.Property(b => b.LastRunTime).ServerTime(DateTimeKind.Local);
-        })
-        .ConfigEntity<TaskLog>(a =>
-        {
-            a.Name("ad_task_log");
-            a.Property(b => b.Exception).StringLength(-1);
-            a.Property(b => b.Remark).StringLength(-1);
-            a.Property(b => b.CreateTime).ServerTime(DateTimeKind.Local);
-        });
-
-        options.ConfigureFreeSql?.Invoke(freeSql);
-
         var dbConfig = ServiceProvider.GetService<DbConfig>();
-        if (dbConfig.SyncStructure)
-        {
-            freeSql.CodeFirst.SyncStructure<TaskInfo>();
-            freeSql.CodeFirst.SyncStructure<TaskLog>();
-        }
+        freeSql.SyncSchedulerStructure(dbConfig, options.ConfigureFreeSql);
 
         if (options.TaskHandler != null && options.CustomTaskHandler == null)
         {

+ 2 - 2
src/platform/ZhonTai.Admin/ZhonTai.Admin.csproj

@@ -14,7 +14,7 @@
 		<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
 		<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.1" />
 		<PackageReference Include="Castle.Core.AsyncInterceptor" Version="2.1.0" />
-		<PackageReference Include="DotNetCore.CAP" Version="7.1.0" />
+		<PackageReference Include="DotNetCore.CAP" Version="7.1.1" />
 		<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
 		<PackageReference Include="FreeRedis" Version="1.0.8" />
 		<PackageReference Include="FreeRedis.DistributedCache" Version="1.0.5" />
@@ -33,7 +33,7 @@
 		<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.1.9" />
 		<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
 		<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
-		<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.27.0" />
+		<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.28.1" />
 		<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
 		<PackageReference Include="UAParser" Version="3.1.47" />
 		<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />

+ 15 - 27
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -870,31 +870,6 @@
             OSS配置列表
             </summary>
         </member>
-        <member name="T:ZhonTai.Admin.Core.Configs.RabbitMqConfig">
-            <summary>
-            RabbitMq配置
-            </summary>
-        </member>
-        <member name="P:ZhonTai.Admin.Core.Configs.RabbitMqConfig.HostName">
-            <summary>
-            主机IP或Url地址
-            </summary>
-        </member>
-        <member name="P:ZhonTai.Admin.Core.Configs.RabbitMqConfig.Port">
-            <summary>
-            端口号
-            </summary>
-        </member>
-        <member name="P:ZhonTai.Admin.Core.Configs.RabbitMqConfig.UserName">
-            <summary>
-            用户名
-            </summary>
-        </member>
-        <member name="P:ZhonTai.Admin.Core.Configs.RabbitMqConfig.Password">
-            <summary>
-             密码
-            </summary>
-        </member>
         <member name="T:ZhonTai.Admin.Core.Configs.UploadConfig">
             <summary>
             上传配置
@@ -1197,6 +1172,14 @@
             <param name="filter">数据过滤 + 验证</param>
             <returns></returns>
         </member>
+        <member name="M:ZhonTai.Admin.Core.Db.FreeSqlDbContextExtensions.SyncSchedulerStructure(IFreeSql,ZhonTai.Admin.Core.Configs.DbConfig,System.Action{IFreeSql})">
+            <summary>
+            同步调度结构
+            </summary>
+            <param name="that"></param>
+            <param name="dbConfig"></param>
+            <param name="configureFreeSql"></param>
+        </member>
         <member name="M:ZhonTai.Admin.Core.Db.Transaction.TransactionAsyncInterceptor.InterceptSynchronous(Castle.DynamicProxy.IInvocation)">
             <summary>
             拦截同步执行的方法
@@ -2062,12 +2045,12 @@
         </member>
         <member name="P:ZhonTai.Admin.Core.Startup.HostAppOptions.ConfigureFreeSqlBuilder">
             <summary>
-            配置主库FreeSql构建器
+            配置FreeSql构建器
             </summary>
         </member>
         <member name="P:ZhonTai.Admin.Core.Startup.HostAppOptions.ConfigureFreeSql">
             <summary>
-            配置主库FreeSql
+            配置FreeSql
             </summary>
         </member>
         <member name="P:ZhonTai.Admin.Core.Startup.HostAppOptions.ConfigureDynamicApi">
@@ -7932,6 +7915,11 @@
             数据库实例
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Tools.TaskScheduler.TaskSchedulerOptions.FreeSqlCloud">
+            <summary>
+            多库实例
+            </summary>
+        </member>
         <member name="P:ZhonTai.Admin.Tools.TaskScheduler.TaskSchedulerOptions.ConfigureFreeSql">
             <summary>
             配置FreeSql