LEIYI hace 3 meses
padre
commit
b1ac66b510

+ 1 - 1
OASystem/OASystem.Api/Controllers/AuthController.cs

@@ -80,7 +80,7 @@ namespace OASystem.API.Controllers
         /// <returns></returns>
         [Route("login")]
         [HttpPost]
-        //[ApiLog]
+        [ApiLog("Login",OperationEnum.Login)]
         [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
         public async Task<IActionResult> LoginAsync(LoginDto dto)
         {

+ 9 - 6
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -483,23 +483,26 @@ namespace OASystem.API.Controllers
                     sqlWhere += string.Format(@"And (ssd.Name Like '%{0}%' Or TeamName Like '%{1}%' Or ClientName Like '%{2}%' Or  ClientName Like '%{3}%' Or su.CnName  Like '%{4}%')",
                        tj, tj, tj, tj, tj);
                 }
-                if (dto.Rank > 0) sqlWhere += string.Format("And gdi.TeamLevSId = {0}", dto.Rank);
+
+                if (int.TryParse(dto.Rank,out int rankId))
+                {
+                    if (rankId > 0) sqlWhere += string.Format("And gdi.TeamLevSId = {0}", rankId);
+                }
+
+                
                 string sqlWhere1 = string.Empty;
                 if (!string.IsNullOrEmpty(dto.Department) && !dto.Department.Equals("全部"))
                 {
                     sqlWhere1 = string.Format("Where Department = '{0}'", dto.Department);
                 }
 
-
-
-
                 string sql = string.Format(@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,Department,
                                              	TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
                                              	VisitDate,VisitDays,VisitPNumber,JietuanOperatorId,
                                              	JietuanOperator,IsSure,CreateTime,IsBid
                                              	From (
                                              	Select row_number() over(order by gdi.CreateTime Desc) as Row_Number,
-                                                CASE WHEN gdi.JietuanOperator = 4 OR gdi.JietuanOperator = 21 THEN '管理员'
+                                                CASE WHEN gdi.JietuanOperator = 4 OR gdi.JietuanOperator = 21 THEN '国交部'
                                                 ELSE (Select DepName FROM OA2023DB.dbo.Sys_Department WHERE Id = su.DepId) END AS 'Department',
                                              	gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
                                              	ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
@@ -510,7 +513,7 @@ namespace OASystem.API.Controllers
                                              	Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
                                              	Left Join Sys_Users su On gdi.JietuanOperator = su.Id
                                              	Where gdi.IsDel = 0 {0}
-                                             ) temp{1}", sqlWhere, sqlWhere1);
+                                             ) temp {1}", sqlWhere, sqlWhere1);
 
                 RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
                 var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync

+ 0 - 79
OASystem/OASystem.Api/Filters/RecordAPIOperationFilter.cs

@@ -1,79 +0,0 @@
-using Microsoft.AspNetCore.Mvc.Filters;
-
-namespace OASystem.API.Filters
-{
-    public class RecordAPIOperationFilter : IActionFilter, IResultFilter
-    {
-       private string _requestParam { get; set; }
-       private string _requestMethod { get; set; }
-
-        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
-        {
-            // 启用请求体缓冲
-            context.HttpContext.Request.EnableBuffering();
-
-            _requestMethod = context.HttpContext.Request.Method.ToUpper();
-
-            // 读取请求体
-            if (_requestMethod == "POST" && context.HttpContext.Request.ContentType?.Contains("application/json") == true)
-            {
-                using (var reader = new StreamReader(context.HttpContext.Request.Body))
-                {
-                    var body = await reader.ReadToEndAsync();
-                    // 重置请求体流的位置,以便后续处理
-                    context.HttpContext.Request.Body.Position = 0;
-
-                    if (!string.IsNullOrEmpty(body))
-                    {
-                        using (var jsonReader = new JsonTextReader(new StringReader(body)))
-                        {
-                            // 解析JSON内容
-                            var json = new JsonSerializer().Deserialize<Dictionary<string, object>>(jsonReader);
-                            if (json != null)
-                            {
-                                // 验证指定参数是否存在
-                                if (json.ContainsKey("specifiedKey"))
-                                {
-                                    var specifiedValue = json["specifiedKey"];
-                                    Console.WriteLine($"Specified Value: {specifiedValue}");
-                                }
-                                else
-                                {
-                                    Console.WriteLine("Specified Key does not exist in the request body.");
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-
-            // 继续执行Action
-            await next();
-        }
-
-        public void OnResultExecuting(ResultExecutingContext context)
-        {
-            // 获取返回结果
-            if (context.Result is ObjectResult objectResult)
-            {
-                Console.WriteLine("Response Result: " +objectResult.Value);
-            }
-        }
-
-        public void OnResultExecuted(ResultExecutedContext context)
-        {
-            // 结果生成后的逻辑
-        }
-
-        public void OnActionExecuting(ActionExecutingContext context)
-        {
-            throw new NotImplementedException();
-        }
-
-        public void OnActionExecuted(ActionExecutedContext context)
-        {
-            throw new NotImplementedException();
-        }
-    }
-}
-

+ 25 - 13
OASystem/OASystem.Api/Middlewares/RecordAPIOperationMiddleware.cs

@@ -38,11 +38,11 @@ namespace OASystem.API.Middlewares
 
             // 检查控制器方法是否使用了自定义属性
             var endpoint = context.GetEndpoint();
-            if (endpoint?.Metadata?.GetMetadata<ApiLogAttribute>() != null)
+            var apiLogAttribute = endpoint?.Metadata?.GetMetadata<ApiLogAttribute>();
+            if (apiLogAttribute != null)
             {
-                var logInfo = new Crm_TableOperationRecord();
-                logInfo.ActionName = context.Request.Path;
-                logInfo.UpdatePreData = requestBodyText;
+                var startTime = DateTime.UtcNow;
+
                 // 保存原始响应体流
                 var originalResponseBody = context.Response.Body;
 
@@ -53,22 +53,34 @@ namespace OASystem.API.Middlewares
                 // 调用下一个中间件
                 await _next(context);
 
-                // 重置响应体流的位置
-                responseMemoryStream.Position = 0;
-
                 // 读取响应体内容
                 var responseBodyText = await new StreamReader(responseMemoryStream).ReadToEndAsync();
 
+                // 重置响应体流的位置
+                responseMemoryStream.Position = 0;
                 // 将响应体内容写回原始响应体流
                 await responseMemoryStream.CopyToAsync(originalResponseBody);
-
-                logInfo.UpdateBefData = responseBodyText;
-
-               
-
+                // 记录请求结束时间
+                var endTime = DateTime.UtcNow;
+                // 计算耗时
+                var duration = (long)(endTime - startTime).TotalMilliseconds;
+
+                int portType = 1;
+
+                var logInfo = new Crm_TableOperationRecord() {
+                    TableName = apiLogAttribute.TableName,
+                    PortType = portType,
+                    OperationItem = apiLogAttribute.OperationEnum,
+                    DataId = apiLogAttribute.DataId,
+                    RequestUrl = context.Request.Path,
+                    RequestParam = requestBodyText,
+                    ReturnResult = responseBodyText,
+                    Elapsed = duration,
+                    Status = context.Response.StatusCode.ToString(),
+
+                };
 
                 // 存储到数据库
-                //_sqlSugar.ChangeDatabase(DBEnum.OA2023DB);
                 await  _sqlSugar.Insertable(logInfo).ExecuteCommandAsync();
             }
             else

+ 3 - 3
OASystem/OASystem.Api/OAMethodLib/GeneralMethod.cs

@@ -68,10 +68,10 @@ namespace OASystem.API.OAMethodLib
             //    .Where(u => u.IsDel == 0)
             //    .Select((u, d) => new GroupOpAffiliationBranchView { value = userIds.Contains(u.Id) ? "国交部" : d.DepName, text = userIds.Contains(u.Id) ? "国交部" : d.DepName })
             //    .ToList();
+            //userDepDatas.Insert(0, new GroupOpAffiliationBranchView() { text = "公司", value = "公司" });
             userDepDatas.Insert(0, new GroupOpAffiliationBranchView() { text = "全部", value = "全部" });
-            userDepDatas.Insert(0, new GroupOpAffiliationBranchView() { text = "管理员", value = "全部" });
-            userDepDatas.Insert(0, new GroupOpAffiliationBranchView() { text = "市场部", value = "市场部" });
-            userDepDatas.Insert(0, new GroupOpAffiliationBranchView() { text = "国交部", value = "国交部" });
+            userDepDatas.Insert(1, new GroupOpAffiliationBranchView() { text = "国交部", value = "国交部" });
+            userDepDatas.Insert(2, new GroupOpAffiliationBranchView() { text = "市场部", value = "市场部" });
 
             return userDepDatas;
         }

+ 2 - 5
OASystem/OASystem.Api/appsettings.json

@@ -9,11 +9,8 @@
   },
   "NoLoginAuth": [
     "高媛媛",
-    "符志超",
-    "杨千莹",
-    "喻思霖",
-    "张倩",
-    "雷怡"
+    "王珊珊",
+    "孟晓祥"
   ],
   //记录相关api接口
   "RecordApiPathName": [

+ 29 - 1
OASystem/OASystem.Domain/Attributes/ApiLogAttribute.cs

@@ -1,4 +1,5 @@
-using System;
+using OASystem.Domain.Enums;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -12,5 +13,32 @@ namespace OASystem.Domain.Attributes
     [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
     public class ApiLogAttribute : Attribute
     {
+        /// <summary>
+        /// 记录操作表名
+        /// </summary>
+        public string TableName { get; set; }
+
+        /// <summary>
+        /// 操作权限
+        /// </summary>
+        public OperationEnum OperationEnum { get; set; }
+
+        /// <summary>
+        /// 操作数据Id
+        /// </summary>
+        public int DataId { get; set; } = 0;
+
+        /// <summary>
+        /// 记录操作日志
+        /// </summary>
+        /// <param name="tableName">表名称</param>
+        /// <param name="operationEnum">操作类型</param>
+        /// <param name="dataId">DataId Defualt 0</param>
+        public ApiLogAttribute(string tableName, OperationEnum operationEnum, int dataId = 0)
+        {
+            TableName = tableName;
+            OperationEnum = operationEnum;
+            DataId = dataId;
+        }
     }
 }

+ 1 - 1
OASystem/OASystem.Domain/Dtos/Groups/GroupListDto.cs

@@ -37,7 +37,7 @@ namespace OASystem.Domain.Dtos.Groups
         public string? SearchCriteria { get; set; }
 
         public string Department { get; set; }
-        public int Rank { get; set; }
+        public string Rank { get; set; }
 
     }
 

+ 5 - 16
OASystem/OASystem.Domain/Entities/Customer/Crm_TableOperationRecord.cs

@@ -28,7 +28,7 @@ namespace OASystem.Domain.Entities.Customer
 
         /// <summary>
         /// 操作项目
-        /// 0 未操作 1浏览列表 2 浏览详情 3 添加 4 修改 5 删除 6 审核 7 上传 8 下载
+        /// 0 未操作 1浏览列表 2 浏览详情 3 添加 4 修改 5 删除 6 审核 7 上传 8 下载 9 Login
         /// </summary>
         [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         public OperationEnum OperationItem { get; set; } = OperationEnum.NoOperation;
@@ -39,17 +39,6 @@ namespace OASystem.Domain.Entities.Customer
         [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         public int DataId { get; set; } = 0;
 
-        /// <summary>
-        /// 模块名称
-        /// </summary>
-        public string? ControllerName { get; set; }
-
-        /// <summary>
-        /// 方法名称
-        ///</summary>
-        public string? ActionName { get; set; }
-
-
         /// <summary>
         /// 执行状态
         /// </summary>
@@ -80,10 +69,10 @@ namespace OASystem.Domain.Entities.Customer
         /// </summary>
         public long? Elapsed { get; set; }
 
-        ///// <summary>
-        ///// 请求地址
-        ///// </summary>
-        //public string? RequestUrl { get; set; }
+        /// <summary>
+        /// 请求地址
+        /// </summary>
+        public string? RequestUrl { get; set; }
 
         /// <summary>
         /// 请求参数