Sfoglia il codice sorgente

添加授权记录

Li 2 anni fa
parent
commit
397a07e6a1
1 ha cambiato i file con 20 aggiunte e 3 eliminazioni
  1. 20 3
      TEAMModelBI/Controllers/BITable/IES5OAuthController.cs

+ 20 - 3
TEAMModelBI/Controllers/BITable/IES5OAuthController.cs

@@ -1,4 +1,5 @@
 using Azure.Cosmos;
+using Azure.Storage.Blobs;
 using DocumentFormat.OpenXml.Spreadsheet;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
@@ -8,9 +9,12 @@ using System.Collections.Generic;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
+using TEAMModelBI.Filter;
+using TEAMModelBI.Tool.Extension;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.Context.Constant;
 using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Table;
 
@@ -69,11 +73,17 @@ namespace TEAMModelBI.Controllers.BITable
         /// </summary>
         /// <param name="oAuthShow"></param>
         /// <returns></returns>
+        [AuthToken(Roles = "admin,rdc,sales")]
         [HttpPost("set-oauthshow")]
         public async Task<IActionResult> UpOAuthShow(OAuthShow oAuthShow)
         {
             var table = _azureStorage.GetCloudTableClient().GetTableReference("IESOAuth");
+
+            var (_tmdId, _tmdName, _, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
             var cosmosClinet = _azureCosmos.GetCosmosClient();
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+            StringBuilder msg = new($"{_tmdName}[{_tmdId}]");
             List<OAuthShow> oAuthShows = new();
             List<OAuthShow> queryOs = new();
             ArtSetting artSetting = new();
@@ -81,7 +91,7 @@ namespace TEAMModelBI.Controllers.BITable
             {
                 string osSql = $" PartitionKey eq 'OAuthShow' and RowKey eq '{oAuthShow.RowKey}'";
                 queryOs = await table.QueryWhereString<OAuthShow>(osSql);
-
+                msg.Append($"修改RowKy为{oAuthShow.RowKey}授权信息");
                 if (queryOs.Count > 0)
                 {
                     foreach (var item in queryOs)
@@ -106,11 +116,12 @@ namespace TEAMModelBI.Controllers.BITable
                     oAuthShow.PartitionKey = "OAuthShow";
                     oAuthShow.Status = 1;
                     oAuthShow.RowKey = $"{oAuthShow.Type}-{oAuthShow.Domain}-{oAuthShow.Code}";
+
+                    msg.Append($"添加RowKy为{oAuthShow.RowKey}授权信息");
                     oAuthShow = await table.SaveOrUpdate<OAuthShow>(oAuthShow);
                     oAuthShows.Add(oAuthShow);
                     if (oAuthShow.Type.Equals("art")) 
                     {
-
                         var isExist = await cosmosClinet.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{oAuthShow.Code}", new PartitionKey("ArtSetting"));
                         if (isExist.Status != 200)
                         {
@@ -119,13 +130,19 @@ namespace TEAMModelBI.Controllers.BITable
                             artSetting = await cosmosClinet.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync<ArtSetting>(artSetting, new PartitionKey("ArtSetting"));
                         }
                         else
-                            return Ok(new { state = RespondCode.Created, msg ="已授权,区级艺术设置文件已存在!" });
+                        {
+                            //保存操作记录
+                            await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-add", msg.ToString(), _dingDing, httpContext: HttpContext);
+                            return Ok(new { state = RespondCode.Created, msg = "已授权,区级艺术设置文件已存在!" });
+                        }
                     }
                 }
                 else
                     return Ok(new { state = RespondCode.Conflict, msg = "已存在该授权。" });
             }
 
+            //保存操作记录
+            await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-add", msg.ToString(), _dingDing, httpContext: HttpContext);
             return Ok(new { state = RespondCode.Ok, oAuthShows });
         }