소스 검색

修改初始化数据,优化操作日志

zhontai 2 년 전
부모
커밋
75618c8bed

+ 1 - 1
build/pkg.props

@@ -1,6 +1,6 @@
 <Project>
   <PropertyGroup>
-    <Version>2.2.23</Version>
+    <Version>2.3.0</Version>
 	<TargetFramework>net6.0</TargetFramework>
 	<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
 	<GenerateDocumentationFile>true</GenerateDocumentationFile>

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

@@ -30,7 +30,7 @@
       {
         "name": "中台Admin",
         "code": "admin",
-        "version": "v2.2.23",
+        "version": "v2.3.0",
         "description": ""
       }
     ]

+ 3 - 3
src/hosts/ZhonTai.Host/Configs/dbconfig.json

@@ -25,14 +25,14 @@
   "createDbSql": "CREATE DATABASE `admindb` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci'",
 
   //同步结构
-  "syncStructure": true,
+  "syncStructure": false,
   //同步数据
-  "syncData": true,
+  "syncData": false,
 
   //项目初始化不开启生成数据,发布生产环境前,如果开发环境有配置数据需要更新数据包,可以开启生成数据包,使用完记得关闭
   //开启生成数据前先关闭syncStructure syncData createDb
   //生成数据,回写InitData/Admin/*.json
-  "generateData": false,
+  "generateData": true,
 
   //数据库配置 https://github.com/dotnetcore/FreeSql/wiki/入门
   //数据库类型 MySql = 0, SqlServer = 1, PostgreSQL = 2, Oracle = 3, Sqlite = 4, OdbcOracle = 5, OdbcSqlServer = 6, OdbcMySql = 7, OdbcPostgreSQL = 8, Odbc = 9, OdbcDameng = 10, MsAccess = 11, Dameng = 12, OdbcKingbaseES = 13, ShenTong = 14, KingbaseES = 15, Firebird = 16

+ 0 - 91
src/hosts/ZhonTai.Host/InitData/Admin/ad_api.json

@@ -452,16 +452,6 @@
         "description": "",
         "enabled": true,
         "childs": []
-      },
-      {
-        "id": 271618651926603,
-        "parentId": 161227167719495,
-        "label": "查询权限",
-        "path": "/api/admin/permission/get",
-        "httpMethods": "get",
-        "description": "",
-        "enabled": true,
-        "childs": []
       }
     ]
   },
@@ -701,15 +691,6 @@
         "enabled": true,
         "childs": []
       },
-      {
-        "id": 271618651926605,
-        "parentId": 161227167719497,
-        "label": "查询登录用户信息",
-        "path": "/api/admin/user/get-login-user",
-        "httpMethods": "get",
-        "description": "",
-        "childs": []
-      },
       {
         "id": 271618651926606,
         "parentId": 161227167719497,
@@ -1065,16 +1046,6 @@
         "enabled": true,
         "childs": []
       },
-      {
-        "id": 271618651926598,
-        "parentId": 161227167723592,
-        "label": "查询文档",
-        "path": "/api/admin/document/get",
-        "httpMethods": "get",
-        "description": "",
-        "enabled": true,
-        "childs": []
-      },
       {
         "id": 271618651926599,
         "parentId": 161227167723592,
@@ -1176,68 +1147,6 @@
       }
     ]
   },
-  {
-    "id": 174219034701893,
-    "label": "员工管理",
-    "path": "staff",
-    "description": "",
-    "childs": [
-      {
-        "id": 174219034734666,
-        "parentId": 174219034701893,
-        "label": "查询员工",
-        "path": "/api/admin/staff/get",
-        "httpMethods": "get",
-        "description": "",
-        "childs": []
-      },
-      {
-        "id": 174219034734667,
-        "parentId": 174219034701893,
-        "label": "查询员工列表",
-        "path": "/api/admin/staff/get-page",
-        "httpMethods": "post",
-        "description": "",
-        "childs": []
-      },
-      {
-        "id": 174219034734668,
-        "parentId": 174219034701893,
-        "label": "新增员工",
-        "path": "/api/admin/staff/add",
-        "httpMethods": "post",
-        "description": "",
-        "childs": []
-      },
-      {
-        "id": 174219034734669,
-        "parentId": 174219034701893,
-        "label": "修改员工",
-        "path": "/api/admin/staff/update",
-        "httpMethods": "put",
-        "description": "",
-        "childs": []
-      },
-      {
-        "id": 174219034734670,
-        "parentId": 174219034701893,
-        "label": "删除员工",
-        "path": "/api/admin/staff/soft-delete",
-        "httpMethods": "delete",
-        "description": "",
-        "childs": []
-      },
-      {
-        "id": 174219034734671,
-        "parentId": 174219034701893,
-        "label": "批量删除员工",
-        "path": "/api/admin/staff/batch-soft-delete",
-        "httpMethods": "put",
-        "description": "",
-        "childs": []
-      }
-    ]
-  },
   {
     "id": 174219034718277,
     "label": "部门服务",

+ 1 - 12
src/hosts/ZhonTai.Host/InitData/Admin/ad_view.json

@@ -184,23 +184,12 @@
         "cache": true,
         "childs": []
       },
-      {
-        "id": 336556164280389,
-        "parentId": 161227168313413,
-        "name": "Staff",
-        "label": "员工管理",
-        "path": "admin/staff",
-        "description": "",
-        "enabled": true,
-        "cache": true,
-        "childs": []
-      },
       {
         "id": 336556164300869,
         "parentId": 161227168313413,
         "name": "Task",
         "label": "任务管理",
-        "path": "admin/task",
+        "path": "admin/task/index",
         "description": "",
         "enabled": true,
         "cache": true,

+ 1 - 1
src/platform/ZhonTai.Admin/Core/Entities/Entity.cs

@@ -25,7 +25,7 @@ public class Entity<TKey> : IEntity<TKey>
     [Description("主键Id")]
     [Snowflake]
     [Column(Position = 1, IsIdentity = false, IsPrimary = true)]
-    [JsonProperty(Order = -2)]
+    [JsonProperty(Order = -30)]
     public virtual TKey Id { get; set; }
 }
 

+ 2 - 0
src/platform/ZhonTai.Admin/Core/Entities/EntityTenant.cs

@@ -1,4 +1,5 @@
 using FreeSql.DataAnnotations;
+using Newtonsoft.Json;
 using System.ComponentModel;
 
 namespace ZhonTai.Admin.Core.Entities;
@@ -13,6 +14,7 @@ public class EntityTenant<TKey> : EntityBase, ITenant
     /// </summary>
     [Description("租户Id")]
     [Column(Position = 2, CanUpdate = false)]
+    [JsonProperty(Order = -20)]
     public long? TenantId { get; set; }
 }
 

+ 3 - 0
src/platform/ZhonTai.Admin/Core/Entities/EntityTenantWithData.cs

@@ -1,4 +1,6 @@
 using FreeSql.DataAnnotations;
+using Newtonsoft.Json;
+using Org.BouncyCastle.Asn1.X509;
 using System.ComponentModel;
 
 namespace ZhonTai.Admin.Core.Entities;
@@ -13,6 +15,7 @@ public class EntityTenantWithData<TKey> : EntityBase, ITenant, IData
     /// </summary>
     [Description("租户Id")]
     [Column(Position = 2, CanUpdate = false)]
+    [JsonProperty(Order = -20)]
     public long? TenantId { get; set; }
 
     /// <summary>

+ 11 - 5
src/platform/ZhonTai.Admin/Core/Filters/ControllerExceptionFilter.cs

@@ -5,6 +5,7 @@ using Microsoft.Extensions.Hosting;
 using Microsoft.Extensions.Logging;
 using System.Threading.Tasks;
 using ZhonTai.Admin.Core.Dto;
+using ZhonTai.Admin.Core.Exceptions;
 using ZhonTai.Common.Extensions;
 
 namespace ZhonTai.Admin.Core.Filters;
@@ -28,18 +29,23 @@ public class ControllerExceptionFilter : IExceptionFilter, IAsyncExceptionFilter
         if (context.ExceptionHandled == false)
         {
             string message;
+            var appException = context.Exception is AppException;
             if (_env.IsProduction())
             {
-                message = Enums.StatusCodes.Status500InternalServerError.ToDescription();
+                message = appException ? context.Exception.Message : Enums.StatusCodes.Status500InternalServerError.ToDescription();
             }
             else
             {
                 message = context.Exception.Message;
             }
 
-            _logger.LogError(context.Exception, "");
+            if (!appException)
+            {
+                _logger.LogError(context.Exception, "");
+            }
+            
             var data = ResultOutput.NotOk(message);
-            context.Result = new InternalServerErrorResult(data);
+            context.Result = new InternalServerErrorResult(data, appException);
         }
 
         context.ExceptionHandled = true;
@@ -54,8 +60,8 @@ public class ControllerExceptionFilter : IExceptionFilter, IAsyncExceptionFilter
 
 public class InternalServerErrorResult : ObjectResult
 {
-    public InternalServerErrorResult(object value) : base(value)
+    public InternalServerErrorResult(object value, bool appException) : base(value)
     {
-        StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError;
+        StatusCode = appException ? Microsoft.AspNetCore.Http.StatusCodes.Status200OK : Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError;
     }
 }

+ 4 - 4
src/platform/ZhonTai.Admin/Core/Filters/FormatResultFilter.cs

@@ -15,9 +15,9 @@ public class FormatResultFilter : IAsyncActionFilter
 {
     public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
     {
-        var actionExecutionContext = await next();
+        var actionExecutedContext = await next();
         
-        if (actionExecutionContext.Exception != null)
+        if (actionExecutedContext.Exception != null)
         {
             return;
         }
@@ -27,7 +27,7 @@ public class FormatResultFilter : IAsyncActionFilter
             return;
         }
 
-        IActionResult result = actionExecutionContext.Result;
+        IActionResult result = actionExecutedContext.Result;
         
         var formatResult = result switch
         {
@@ -62,6 +62,6 @@ public class FormatResultFilter : IAsyncActionFilter
             _ => null,
         };
 
-        actionExecutionContext.Result = new JsonResult(new ResultOutput<dynamic>().Ok(data));
+        actionExecutedContext.Result = new JsonResult(new ResultOutput<dynamic>().Ok(data));
     }
 }

+ 6 - 4
src/platform/ZhonTai.Admin/Core/HostApp.cs

@@ -429,13 +429,15 @@ public class HostApp
             {
                 options.Filters.Add<ValidatePermissionAttribute>();
             }
-            if (appConfig.Log.Operation)
+            //在具有较高的 Order 值的筛选器之前运行 before 代码
+            //在具有较高的 Order 值的筛选器之后运行 after 代码
+            if (appConfig.DynamicApi.FormatResult)
             {
-                options.Filters.Add<ControllerLogFilter>();
+                options.Filters.Add<FormatResultFilter>(20);
             }
-            if (appConfig.DynamicApi.FormatResult)
+            if (appConfig.Log.Operation)
             {
-                options.Filters.Add<FormatResultFilter>();
+                options.Filters.Add<ControllerLogFilter>(10);
             }
 
             //禁止去除ActionAsync后缀

+ 4 - 7
src/platform/ZhonTai.Admin/Core/Logs/LogHandler.cs

@@ -2,15 +2,11 @@
 using System.Diagnostics;
 using System.Linq;
 using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc.Filters;
 using Microsoft.Extensions.Logging;
-using ZhonTai.Admin.Core.Dto;
 using ZhonTai.Admin.Services.OprationLog;
 using ZhonTai.Admin.Services.OprationLog.Dto;
 
-//using Newtonsoft.Json;
-
 namespace ZhonTai.Admin.Core.Logs;
 
 /// <summary>
@@ -49,15 +45,16 @@ public class LogHandler : ILogHandler
         {
             var input = new OprationLogAddInput
             {
+                Status = true,
                 ApiMethod = context.HttpContext.Request.Method.ToLower(),
                 ApiPath = context.ActionDescriptor.AttributeRouteInfo.Template.ToLower(),
                 ElapsedMilliseconds = sw.ElapsedMilliseconds
             };
 
-            if (actionExecutedContext.Result is ObjectResult result && result.Value is IResultOutput res)
+            if (actionExecutedContext.Exception != null)
             {
-                input.Status = res?.Success;
-                input.Msg = res?.Msg;
+                input.Status = false;
+                input.Msg = actionExecutedContext.Exception.Message;
             }
 
             input.ApiLabel = _apiHelper.GetApis().FirstOrDefault(a => a.Path == input.ApiPath)?.Label;

+ 0 - 1
src/platform/ZhonTai.Admin/Services/Auth/AuthService.cs

@@ -4,7 +4,6 @@ using System.Linq;
 using System.Text;
 using System.Security.Claims;
 using System.Threading.Tasks;
-using StackExchange.Profiling;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Cors;
 using Microsoft.AspNetCore.Mvc;