소스 검색

优化保存BI保存操作记录公共方法

Li 3 년 전
부모
커밋
2660677134
2개의 변경된 파일24개의 추가작업 그리고 27개의 파일을 삭제
  1. 1 1
      TEAMModelBI/Controllers/OperateRecord/OperateLogController.cs
  2. 23 26
      TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs

+ 1 - 1
TEAMModelBI/Controllers/OperateRecord/OperateLogController.cs

@@ -48,7 +48,7 @@ namespace TEAMModelBI.Controllers.OperateRecord
                 jsonElement.TryGetProperty("endDate", out JsonElement endDate);
                 jsonElement.TryGetProperty("platform", out JsonElement platform);
 
-                List<BIOptLog> operateLogs = null;
+                List<BIOptLog> operateLogs = new();
                 StringBuilder tableSql = new StringBuilder();
 
                 if (!string.IsNullOrEmpty($"{single}"))

+ 23 - 26
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs

@@ -403,49 +403,46 @@ namespace TEAMModelOS.SDK.DI
         /// <param name="msg"></param>
         /// <param name="dingDing"></param>
         /// <param name="scope"></param>
-        /// <param name="bizId"></param>
         /// <param name="option"></param>
         /// <param name="httpContext"></param>
         /// <returns></returns>
-        public static async Task SaveBILog(this AzureStorageFactory azureStorage, string type, string msg, DingDing dingDing, string scope = null, string bizId = null, Option option = null, HttpContext httpContext = null)
+        public static async Task SaveBILog(this AzureStorageFactory azureStorage, string type, string msg, DingDing dingDing, string scope = null, Option option = null, HttpContext httpContext = null)
         {
-            var table = azureStorage.GetCloudTableClient().GetTableReference("OptLog");
-            OptLog log = new() { RowKey = Guid.NewGuid().ToString() };
+            var table = azureStorage.GetCloudTableClient().GetTableReference("BIOptLog");
+            BIOptLog biLog = new() { RowKey = Guid.NewGuid().ToString() };
             try
             {
-                object id = null, school = null, name = null, website = null;
+                object id = null, name = null, ddid = null, ddname = null, school = null, website = null;
                 httpContext?.Items.TryGetValue("ID", out id);
-                httpContext?.Items.TryGetValue("School", out school);
                 httpContext?.Items.TryGetValue("Name", out name);
+                httpContext?.Items.TryGetValue("DDId", out ddid);
+                httpContext?.Items.TryGetValue("DDName", out ddname);
+                httpContext?.Items.TryGetValue("School", out school);
                 httpContext?.Items.TryGetValue("Website", out website);
-                log.tmdId = id != null ? $"{id}" : log.tmdId;
-                log.name = name != null ? $"{name}" : log.name;
+                biLog.tmdId = id != null ? $"{id}" : biLog.tmdId;
+                biLog.name = name != null ? $"{name}" : biLog.name;
+                biLog.school = school != null ? $"{school}" : biLog.school;
+                biLog.PartitionKey = type != null ? $"{website}-Log-{type}" : $"{website}-Log-Default";
+                biLog.platform = website != null ? $"{website}" : "Default";
+                biLog.msg = msg;
+                biLog.type = type;
+                biLog.scope = scope;
                 string host = httpContext?.Request?.Host.Value;
-                log.school = school != null ? $"{school}" : log.school;
-                log.PartitionKey = type != null ? $"Log-{type}" : "Log-Default";
-                log.RowKey = bizId != null ? bizId : log.RowKey;
-                log.platform = website != null ? $"{website}" : "Default";
-                log.msg = msg;
-                log.type = type;
-                log.scope = scope;
                 host = !string.IsNullOrWhiteSpace($"{host}") ? $"{host}" : option?.Location != null ? $"{host}" : "Default";
-                log.url = $"{host}{httpContext?.Request.Path}";
+                biLog.url = $"{host}{httpContext?.Request.Path}";
                 if (!string.IsNullOrWhiteSpace(msg) && msg.Length > 255)
                 {
-                    log.saveMod = 1;
-                    log.jsonfile = $"/0-public/optlog/{log.RowKey}-{log.PartitionKey}.json";
-                    await azureStorage.UploadFileByContainer("0-public", log.ToJsonString(), "optlog", $"{log.RowKey}-{log.PartitionKey}.json");
-                    log.msg = null;
-                    await table.SaveOrUpdate<OptLog>(log);
-                }
-                else
-                {
-                    await table.SaveOrUpdate<OptLog>(log);
+                    biLog.saveMod = 1;
+                    biLog.jsonfile = $"/0-public/BIOptLog/{biLog.PartitionKey}-{biLog.RowKey}.json";
+                    await azureStorage.UploadFileByContainer("0-public", biLog.ToJsonString(), "BIOptLog", $"{biLog.PartitionKey}-{biLog.RowKey}.json");
+                    biLog.msg = null;
+                    await table.SaveOrUpdate<BIOptLog>(biLog);
                 }
+                else await table.SaveOrUpdate<BIOptLog>(biLog);
             }
             catch (Exception ex)
             {
-                _ = dingDing.SendBotMsg($"日志保存失败:{ex.Message},{ex.StackTrace},{log.ToJsonString()}", GroupNames.成都开发測試群組);
+                _ = dingDing.SendBotMsg($"BI日志保存失败:{ex.Message},{ex.StackTrace},{biLog.ToJsonString()}", GroupNames.成都开发測試群組);
             }
         }
     }