Sfoglia il codice sorgente

优化API操作日志记录和客户资料表操作记录

在 `MarketCustomerResourcesController.cs` 文件中,添加了 `using OASystem.Domain.Attributes;` 引用,并在多个方法上添加了 `[ApiLog("Crm_NewClientData", OperationEnum.*)]` 属性,用于记录 API 操作日志。注释掉了多个调用 `GeneralMethod.NewClientOperationRecord` 方法的代码,这些代码用于记录客户资料表的操作记录。

在 `RecordAPIOperationMiddleware.cs` 文件中,增加了对 `operationUserId` 和 `deleteUserId` 参数的处理,并修改了关于操作类型的判断逻辑,增加了对新增和编辑操作的处理。

在 `NewClientDataRepository.cs` 文件中,注释掉了批量添加客户资料表操作记录的代码。
LEIYI 3 mesi fa
parent
commit
202a776a44

+ 27 - 25
OASystem/OASystem.Api/Controllers/MarketCustomerResourcesController.cs

@@ -10,6 +10,7 @@ using System.Collections;
 using System.Data;
 using System.Diagnostics;
 using System.Linq;
+using OASystem.Domain.Attributes;
 
 namespace OASystem.API.Controllers
 {
@@ -65,6 +66,7 @@ namespace OASystem.API.Controllers
         /// </summary>
         /// <returns></returns>
         [HttpPost]
+        [ApiLog("Crm_NewClientData", OperationEnum.List)]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
         {
@@ -83,7 +85,7 @@ namespace OASystem.API.Controllers
                 if (resultData.Code == 0)
                 {
                     #region 客户资料表操作记录
-                    await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.NoOperation, dto.OperationUserId, 0, "");
+                    //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.NoOperation, dto.OperationUserId, 0, "");
                     #endregion
 
                     jw = JsonView(true, resultData.Msg, resultData.Data);
@@ -107,6 +109,7 @@ namespace OASystem.API.Controllers
         /// </summary>
         /// <returns></returns>
         [HttpPost]
+        [ApiLog("Crm_NewClientData", OperationEnum.Details)]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> PostNewClientDataDetails(NewClientDataDetailsDto dto)
         {
@@ -128,7 +131,7 @@ namespace OASystem.API.Controllers
                 if (resultData.Code == 0)
                 {
                     #region 客户资料表操作记录
-                    await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
+                    //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
                     #endregion
                     jw = JsonView(true, "查询成功!", resultData.Data);
                 }
@@ -151,6 +154,7 @@ namespace OASystem.API.Controllers
         /// <param name="dto"></param>
         /// <returns></returns>
         [HttpPost]
+        [ApiLog("Crm_NewClientData", OperationEnum.NoOperation)]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
         {
@@ -175,15 +179,14 @@ namespace OASystem.API.Controllers
                     return Ok(JsonView(false, result.Msg));
                 }
                 #region 客户资料操作记录
-                OperationEnum operationEnum = OperationEnum.NoOperation;
-                if (dto.Status == 1)
-                {
-                    operationEnum = OperationEnum.Add;
-                    dto.Id = Convert.ToInt32(result.Data);
-                }
-                else if (dto.Status == 2) operationEnum = OperationEnum.Edit;
-
-                await GeneralMethod.NewClientOperationRecord(dto.PortType, operationEnum, dto.CreateUserId, dto.Id, "");
+                //OperationEnum operationEnum = OperationEnum.NoOperation;
+                //if (dto.Status == 1)
+                //{
+                //    operationEnum = OperationEnum.Add;
+                //    dto.Id = Convert.ToInt32(result.Data);
+                //}
+                //else if (dto.Status == 2) operationEnum = OperationEnum.Edit;
+                //await GeneralMethod.NewClientOperationRecord(dto.PortType, operationEnum, dto.CreateUserId, dto.Id, "");
                 #endregion
 
                 return Ok(JsonView(true, result.Msg + "Id:" + dto.Id));
@@ -200,6 +203,7 @@ namespace OASystem.API.Controllers
         /// <param name="dto"></param>
         /// <returns></returns>
         [HttpPost]
+        [ApiLog("Crm_NewClientData", OperationEnum.Del)]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> NewClientDel(DelBaseDto dto)
         {
@@ -226,7 +230,7 @@ namespace OASystem.API.Controllers
             }
 
             #region 客户资料表操作记录
-            await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Del, dto.DeleteUserId, dto.Id, "");
+            //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Del, dto.DeleteUserId, dto.Id, "");
             #endregion
 
             return Ok(JsonView(true, "删除成功!"));
@@ -238,6 +242,7 @@ namespace OASystem.API.Controllers
         /// <param name="dto"></param>
         /// <returns></returns>
         [HttpPost]
+        [ApiLog("Crm_NewClientData", OperationEnum.Details)]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> QuerySelectAndSingleData(QuerySingleDto dto)
         {
@@ -246,7 +251,7 @@ namespace OASystem.API.Controllers
             if (result.Code == 0)
             {
                 #region 客户资料表操作记录
-                await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
+                //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
                 #endregion
 
                 jw = JsonView(true, result.Msg, result.Data);
@@ -300,6 +305,7 @@ namespace OASystem.API.Controllers
         /// <param name="dto"></param>
         /// <returns></returns>
         [HttpPost]
+        [ApiLog("Crm_NewClientData", OperationEnum.BatchAssignment)]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> PostBatchAssignment(BatchAssignmentDto dto)
         {
@@ -569,6 +575,7 @@ namespace OASystem.API.Controllers
         /// <param name="dto"></param>
         /// <returns></returns>
         [HttpPost]
+        [ApiLog("Crm_NewClientData", OperationEnum.Download)]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> NewClientDataExcelDownload(NewClientDataExcelDownloadDto dto)
         {
@@ -601,14 +608,13 @@ namespace OASystem.API.Controllers
 
                 #region 客户资料表操作记录
                 var respose = JsonView(true, "成功", url);
-                var paramData = new
-                {
-                    APIName = @"MarketCustomerResources/NewClientDataExcelDownload",
-                    RequestParam = dto,
-                    ResposeParam = respose
-                };
-
-                await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Download, dto.OperationUserId, 0, JsonConvert.SerializeObject(paramData));
+                //var paramData = new
+                //{
+                //    APIName = @"MarketCustomerResources/NewClientDataExcelDownload",
+                //    RequestParam = dto,
+                //    ResposeParam = respose
+                //};
+                //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Download, dto.OperationUserId, 0, JsonConvert.SerializeObject(paramData));
                 #endregion
 
                 return Ok(respose);
@@ -619,8 +625,6 @@ namespace OASystem.API.Controllers
 
         }
 
-
-
         #region 修改数据
         //[HttpPost]
         //public IActionResult SynchronizationData()
@@ -828,8 +832,6 @@ namespace OASystem.API.Controllers
 
         #endregion
 
-
-
         /// <summary>
         /// 客户资料 操作记录记录查询
         /// </summary>

+ 21 - 6
OASystem/OASystem.Api/Middlewares/RecordAPIOperationMiddleware.cs

@@ -59,7 +59,8 @@ namespace OASystem.API.Middlewares
 
                     if (!string.IsNullOrEmpty(requestBodyText))
                     {
-                        object param1 = string.Empty, param2 = string.Empty, param3 = string.Empty, param4 = string.Empty, param5 = string.Empty, param6 = string.Empty;
+                        object param1 = string.Empty, param2 = string.Empty, param3 = string.Empty, param4 = string.Empty,
+                               param5 = string.Empty, param6 = string.Empty, param7 = string.Empty, param8 = string.Empty;
                         var requestBodyJson = JsonConvert.DeserializeObject<Dictionary<string, object>>(requestBodyText);
                         bool exists1 = requestBodyJson.TryGetValue("portType", out param1);
                         bool exists2 = requestBodyJson.TryGetValue("userId", out param2);
@@ -67,6 +68,8 @@ namespace OASystem.API.Middlewares
                         bool exists4 = requestBodyJson.TryGetValue("createUserId", out param4);
                         bool exists5 = requestBodyJson.TryGetValue("id", out param5);
                         bool exists6 = requestBodyJson.TryGetValue("status", out param6);
+                        bool exists7 = requestBodyJson.TryGetValue("operationUserId", out param7);
+                        bool exists8 = requestBodyJson.TryGetValue("deleteUserId", out param8); 
 
                         if (exists1) int.TryParse(param1.ToString(), out portType);
 
@@ -84,9 +87,11 @@ namespace OASystem.API.Middlewares
                             }
                             else
                             {
-                                if (exists2) if (int.TryParse(param2.ToString(), out userId)) { }
-                                else if (exists3) if (int.TryParse(param3.ToString(), out userId)) { }
-                                else if (exists4) if (int.TryParse(param4.ToString(), out userId)) { }
+                                if (exists2) int.TryParse(param2.ToString(), out userId);
+                                else if (exists3) int.TryParse(param3.ToString(), out userId);
+                                else if (exists4) int.TryParse(param4.ToString(), out userId);
+                                else if (exists7) int.TryParse(param7.ToString(), out userId);
+                                else if (exists8) int.TryParse(param8.ToString(), out userId);
                             }
                         }
                         //编辑前数据查询;
@@ -96,12 +101,22 @@ namespace OASystem.API.Middlewares
                         if (param6Bool)
                         {
                             //  2 修改 
-                            if (status == 2) updatePreData = await TableInfoToJson(apiLogAttribute.TableName, id);
+                            if (status == 1) apiLogAttribute.OperationEnum = OperationEnum.Add;
+                            else if (status == 2)
+                            {
+                                apiLogAttribute.OperationEnum = OperationEnum.Edit;
+                                updatePreData = await TableInfoToJson(apiLogAttribute.TableName, id);
+                            }
                         }
                         else if (param5Bool)
                         {
                             //  id > 0 修改 
-                            if (id > 0) updatePreData = await TableInfoToJson(apiLogAttribute.TableName, id);
+                            if (id < 1) apiLogAttribute.OperationEnum = OperationEnum.Add;
+                            else if (id > 0)
+                            {
+                                apiLogAttribute.OperationEnum = OperationEnum.Edit;
+                                updatePreData = await TableInfoToJson(apiLogAttribute.TableName, id);
+                            }
                         }
                     }
                 }

+ 0 - 1
OASystem/OASystem.Api/OAMethodLib/GeneralMethod.cs

@@ -5135,7 +5135,6 @@ namespace OASystem.API.OAMethodLib
 
         #endregion
 
-
         #region aspose
 
         /// <summary>

+ 19 - 20
OASystem/OASystem.Infrastructure/Repositories/CRM/NewClientDataRepository.cs

@@ -1347,27 +1347,26 @@ namespace OASystem.Infrastructure.Repositories.CRM
                 {
                     #region 客户资料表操作记录 批量添加
 
-                    List<Crm_TableOperationRecord> _TableOperationRecords = new List<Crm_TableOperationRecord>();
+                    //List<Crm_TableOperationRecord> _TableOperationRecords = new List<Crm_TableOperationRecord>();
 
-                    foreach (var item in _ClientDataAndUsers)
-                    {
-                        _TableOperationRecords.Add(
-                            new Crm_TableOperationRecord() { 
-                                TableName = "Crm_TableOperationRecord",
-                                PortType = dto.PortType,
-                                OperationItem = OperationEnum.BatchAssignment,
-                                DataId = item.NewClientDataId,
-                                CreateUserId = dto.UserId,
-                                CreateTime = DateTime.Now,
-                                Remark = "",
-                                IsDel = 0
-                            });
-                    }
-
-                    if (_TableOperationRecords.Count > 0)
-                    {
-                        await _sqlSugar.Insertable(_TableOperationRecords).ExecuteCommandAsync();
-                    }
+                    //foreach (var item in _ClientDataAndUsers)
+                    //{
+                    //    _TableOperationRecords.Add(
+                    //        new Crm_TableOperationRecord() { 
+                    //            TableName = "Crm_TableOperationRecord",
+                    //            PortType = dto.PortType,
+                    //            OperationItem = OperationEnum.BatchAssignment,
+                    //            DataId = item.NewClientDataId,
+                    //            CreateUserId = dto.UserId,
+                    //            CreateTime = DateTime.Now,
+                    //            Remark = "",
+                    //            IsDel = 0
+                    //        });
+                    //}
+                    //if (_TableOperationRecords.Count > 0)
+                    //{
+                    //    await _sqlSugar.Insertable(_TableOperationRecords).ExecuteCommandAsync();
+                    //}
 
                     #endregion