Browse Source

优化保存日志多个数据库的问题,和上传文件多个数据库的问题

Li 3 years ago
parent
commit
1e25fc9c72

+ 50 - 14
TEAMModelBI/Controllers/BIAbility/AbilityMgmtController.cs

@@ -18,6 +18,7 @@ using TEAMModelOS.SDK.Extension;
 using TEAMModelBI.Filter;
 using TEAMModelBI.Tool.Extension;
 using TEAMModelBI.Tool.Context;
+using TEAMModelBI.DI.BIAzureStorage;
 
 namespace TEAMModelBI.Controllers.BIAbility
 {
@@ -56,9 +57,14 @@ namespace TEAMModelBI.Controllers.BIAbility
             try
             {
                 if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
+                jsonElement.TryGetProperty("site", out JsonElement site);
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+
                 List<Ability> abilities = new List<Ability>();
                 string sqltxt = "select value(c) from c";
-                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{standard}") }))
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Ability>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{standard}") }))
                 {
                     abilities.Add(item);
                 }
@@ -85,7 +91,11 @@ namespace TEAMModelBI.Controllers.BIAbility
             {
                 if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
                 if (!jsonElement.TryGetProperty("abilityId", out JsonElement abilityId)) return BadRequest();
+                jsonElement.TryGetProperty("site", out JsonElement site);
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
                 Ability ability = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Ability>($"{abilityId}", new PartitionKey($"Ability-{standard}"));
                 return Ok(new { state = 200, ability = ability });
             }
@@ -102,7 +112,7 @@ namespace TEAMModelBI.Controllers.BIAbility
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales")]
         [HttpPost("del-ability")]
         public async Task<IActionResult> DelAbility(JsonElement jsonElement)
         {
@@ -110,6 +120,7 @@ namespace TEAMModelBI.Controllers.BIAbility
             {
                 if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
                 if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                jsonElement.TryGetProperty("site", out JsonElement site);
 
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
 
@@ -118,23 +129,32 @@ namespace TEAMModelBI.Controllers.BIAbility
                     return Ok(new { state = 0,message= "standard 参数异常" });
                 }
 
-                var client = _azureCosmos.GetCosmosClient();
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 List<AbilityTask> syllabus = new List<AbilityTask>();
                 string sql = $"select value(c) from c where c.abilityId='{id}'";
-                var response = await client.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Ability-{standard}"));
-                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{standard}") }))
+                var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Ability-{standard}"));
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AbilityTask>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilityTask-{standard}") }))
                 {
                     syllabus.Add(item);
                 }
                 if (syllabus.IsNotEmpty())
                 {
-                    var sresponse = await client.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(syllabus.Select(x => x.id).ToList(), $"AbilityTask-{standard}");
+                    var sresponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemsStreamAsync(syllabus.Select(x => x.id).ToList(), $"AbilityTask-{standard}");
                 }
 
                 if (response.Status == 200)
                 {
                     //保存操作记录
-                    await _azureStorage.SaveBILog("abilityTask-del", $"{_tmdName}【{_tmdId}】删除册别,删除ID:{id}", _dingDing, httpContext: HttpContext);
+                    //await _azureStorage.SaveBILog("abilityTask-del", $"{_tmdName}【{_tmdId}】删除册别,删除ID:{id}", _dingDing, httpContext: HttpContext);
+                    await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "abilityTask-del", $"{_tmdName}【{_tmdId}】删除册别,删除ID:{id}", _dingDing, httpContext: HttpContext);
 
                     return Ok(new { state = 200 });
                 }
@@ -153,7 +173,7 @@ namespace TEAMModelBI.Controllers.BIAbility
         /// <param name="request"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales")]
         [HttpPost("upd-ability")]
         public async Task<IActionResult> UpdAbility(Ability ability, [FromHeader] string site)
         {
@@ -176,8 +196,14 @@ namespace TEAMModelBI.Controllers.BIAbility
                 else return Ok(new { state = 0, message = "参数异常" });
 
                 var azureClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
+                {
                     azureClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 string tempType = "";
                 //新增册别
                 if (string.IsNullOrEmpty(ability.id))
@@ -227,7 +253,8 @@ namespace TEAMModelBI.Controllers.BIAbility
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog(tempType?.ToString(), stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
+                //await _azureStorage.SaveBILog(tempType?.ToString(), stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, tempType?.ToString(), stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
 
                 return Ok(new { state = 200, Ability = tempAbility });
             }
@@ -244,27 +271,36 @@ namespace TEAMModelBI.Controllers.BIAbility
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales")]
         [HttpPost("upd-currency")]
         public async Task<IActionResult> UpdateCurrency(JsonElement jsonElement) 
         {
             try
             {
                 if (!jsonElement.TryGetProperty("isRequired", out JsonElement isRequired)) return BadRequest(); //是否是必修集合
+                jsonElement.TryGetProperty("site", out JsonElement site);
 
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 var currencys = isRequired.ToObject<List<IsRequired>>();
-
-                foreach (var item in currencys)
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
+                    foreach (var item in currencys)
                 {
-                    var cosmosClient = _azureCosmos.GetCosmosClient();
                     Ability ability = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<Ability>(item.abilityId, new PartitionKey($"Ability-{item.standard}"));
                     ability.currency = item.currency;
                     await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync(ability, ability.id, new PartitionKey(ability.code));
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("ability-update", $"{_tmdName}【{_tmdId}】设置是否必修状态。标准:{currencys[0].standard}", _dingDing, httpContext: HttpContext);
+                //await _azureStorage.SaveBILog("ability-update", $"{_tmdName}【{_tmdId}】设置是否必修状态。标准:{currencys[0].standard}", _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "ability-update", $"{_tmdName}【{_tmdId}】设置是否必修状态。标准:{currencys[0].standard}", _dingDing, httpContext: HttpContext);
 
                 return Ok(new { state = 200, currencys });
             }

+ 25 - 5
TEAMModelBI/Controllers/BIAbility/AbilityTaskMgmtController.cs

@@ -19,6 +19,7 @@ using TEAMModelOS.SDK.Services;
 using TEAMModelBI.Tool.Extension;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelBI.Tool.Context;
+using TEAMModelBI.DI.BIAzureStorage;
 
 namespace TEAMModelBI.Controllers.BIAbility
 {
@@ -58,7 +59,10 @@ namespace TEAMModelBI.Controllers.BIAbility
             {
                 if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
                 if (!jsonElement.TryGetProperty("abilityId", out JsonElement abilityId)) return BadRequest();
+                jsonElement.TryGetProperty("site", out JsonElement site);
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
                 Ability ability = null;
                 List<AbilityTaskTreeNode> abilityTaskTreeNodes = new List<AbilityTaskTreeNode>();//原始数据未排序
                 List<AbilityTaskTreeNode> redtAbilityTaskTreeNodes = new List<AbilityTaskTreeNode>();//排序后的数据
@@ -125,10 +129,16 @@ namespace TEAMModelBI.Controllers.BIAbility
         {
             try
             {
-                var cosmosClient = _azureCosmos.GetCosmosClient();
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
+                {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
 
                 StringBuilder msgBuilder = new StringBuilder($"{_tmdName}【{_tmdId}】");
                 string type = null;
@@ -213,7 +223,8 @@ namespace TEAMModelBI.Controllers.BIAbility
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog(type, msgBuilder?.ToString(), _dingDing, httpContext: HttpContext);
+                //await _azureStorage.SaveBILog(type, msgBuilder?.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, type, msgBuilder?.ToString(), _dingDing, httpContext: HttpContext);
 
                 return Ok(new { state = 200, recordAbilityTask });
             }
@@ -230,7 +241,7 @@ namespace TEAMModelBI.Controllers.BIAbility
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales")]
         [HttpPost("del-abilitytask")]
         public async Task<IActionResult> DelAbilityTask(JsonElement jsonElement) 
         {
@@ -238,16 +249,25 @@ namespace TEAMModelBI.Controllers.BIAbility
             {
                 if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
                 if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                jsonElement.TryGetProperty("site", out JsonElement site);
 
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"AbilityTask-{standard}"));
 
                 string msg = $"{_tmdName}【{_tmdId}】删除册别,删除状态:{response.Status},删除ID:{id}";
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("abilitytask-del", msg, _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("abilitytask-del", msg, _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "abilitytask-del", msg, _dingDing, httpContext: HttpContext);
                 if (response.Status == 204)
                     return Ok(new { state = 200 });
                 else

+ 66 - 15
TEAMModelBI/Controllers/BINormal/AppCompanyController.cs

@@ -9,8 +9,10 @@ using System.Linq;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
+using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.Filter;
 using TEAMModelBI.Models.Extension;
+using TEAMModelBI.Tool.Context;
 using TEAMModelBI.Tool.Extension;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.DI;
@@ -53,8 +55,11 @@ namespace TEAMModelBI.Controllers.BINormal
             jsonElement.TryGetProperty("appId", out JsonElement appId);
             jsonElement.TryGetProperty("eid", out JsonElement eid);
             jsonElement.TryGetProperty("audit", out JsonElement audit);
+            jsonElement.TryGetProperty("site", out JsonElement site);
 
             var cosmosClient = _azureCosmos.GetCosmosClient();
+            if ($"{site}".Equals(BIConst.GlobalSite))
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
             StringBuilder sqlTxt = new($"select c.id,c.pk,c.code,c.name,c.descr,c.picture,c.jwtKey,c.status,c.audit,c.refuseDesc,c.gateways,c.apis,c.webhookDomain,c.webHooks,c.schools from c where c.pk='App'");
             if (!string.IsNullOrEmpty($"{appId}"))
             {
@@ -106,14 +111,22 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="appCompany"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist,company")]
+        [AuthToken(Roles = "admin,rdc,company")]
         [HttpPost("set-info")]
-        public async Task<IActionResult> SetAppInfo(AppCompany appCompany)
+        public async Task<IActionResult> SetAppInfo(AppCompany appCompany, [FromHeader] string site)
         {
             try
             {
-                var cosmosClient = _azureCosmos.GetCosmosClient();
                 var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 StringBuilder stringBuilder = new($"{loginName}【{loginId}】");
                 string type = "";
                 //新建
@@ -144,7 +157,8 @@ namespace TEAMModelBI.Controllers.BINormal
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog(type, stringBuilder.ToString(), _dingDing, httpContext: HttpContext);
+                //await _azureStorage.SaveBILog(type, stringBuilder.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, type, stringBuilder.ToString(), _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200, appCompany });
             }
             catch (Exception e)
@@ -164,8 +178,16 @@ namespace TEAMModelBI.Controllers.BINormal
         public async Task<IActionResult> GetNoAudit(JsonElement jsonElement) 
         {
             if(!jsonElement.TryGetProperty("operate", out JsonElement operate)) return BadRequest();
-
+            jsonElement.TryGetProperty("site", out JsonElement site);
             var cosmosClient = _azureCosmos.GetCosmosClient();
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+            if ($"{site}".Equals(BIConst.GlobalSite))
+            {
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+            }
             StringBuilder sqlTxt = new();
 
             switch (operate.GetString())
@@ -214,17 +236,26 @@ namespace TEAMModelBI.Controllers.BINormal
         /// </summary>
         /// <param name="jsonElement"></param>
         /// <returns></returns>
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("get-apply")]
         public async Task<IActionResult> SetAuditApp(JsonElement jsonElement)
         {
             try
             {
+                var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 if (!jsonElement.TryGetProperty("appIds", out JsonElement appIds)) return BadRequest();
                 if (!jsonElement.TryGetProperty("isAudit", out JsonElement isAudit)) return BadRequest();
                 jsonElement.TryGetProperty("refuseDesc", out JsonElement refuseDesc);
+                jsonElement.TryGetProperty("site", out JsonElement site);
                 var cosmosClient = _azureCosmos.GetCosmosClient();
-                var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite)) 
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 StringBuilder strMsg = new($"{loginName}【{loginId}】");
                 List<AppIdOrCode> idOrCode = appIds.ToObject<List<AppIdOrCode>>();
                 List<AppIdOrCode> haveIds = new();
@@ -262,7 +293,8 @@ namespace TEAMModelBI.Controllers.BINormal
                 else return Ok(new { state = 404, msg = "appIds参数错误" });
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
+                //await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
 
                 if (haveIds.Count > 0)
                     return Ok(new { state = 201, msg = "部分应用审核失败!", haveIds });
@@ -282,18 +314,27 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist,company")]
+        [AuthToken(Roles = "admin,rdc,company")]
         [HttpPost("set-applyapi")]
         public async Task<IActionResult> SetApplyApi(JsonElement jsonElement)
         {
             try
             {
+                var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 if (!jsonElement.TryGetProperty("applyApis", out JsonElement jsApplyApis)) return BadRequest();
                 if (!jsonElement.TryGetProperty("operate", out JsonElement operate)) return BadRequest();
+                jsonElement.TryGetProperty("site", out JsonElement site);
 
-                var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 StringBuilder strMsg = new($"{loginName}【{loginId}】");
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 string bizcode = "";  //消息名称
                 List<string> sendWhom = new();//消息分发给谁   待完善
                 List<ApplyApi> applyApis = jsApplyApis.ToObject<List<ApplyApi>>();
@@ -389,8 +430,8 @@ namespace TEAMModelBI.Controllers.BINormal
                 await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
                 if (haveApi.Count > 0 || noAudit.Count > 0)
                     return Ok(new { state = 201, msg = "部分成功", haveApi, noAudit });
                 else return Ok(new { state = 200 });
@@ -409,19 +450,28 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist,company")]
+        [AuthToken(Roles = "admin,rdc,company")]
         [HttpPost("set-applyschool")]
         public async Task<IActionResult> SetAuditSchool(JsonElement jsonElement)
         {
             try
             {
+                var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 if (!jsonElement.TryGetProperty("appId", out JsonElement appId)) return BadRequest();
                 if (!jsonElement.TryGetProperty("appCode", out JsonElement appCode)) return BadRequest();
                 if (!jsonElement.TryGetProperty("schooCode", out JsonElement schooCode)) return BadRequest();
                 if (!jsonElement.TryGetProperty("operate", out JsonElement operate)) return BadRequest();
+                jsonElement.TryGetProperty("site", out JsonElement site);
 
                 var cosmosClient = _azureCosmos.GetCosmosClient();
-                var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite)) 
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 StringBuilder strMsg = new($"{loginName}【{loginId}】操作:");
                 List<string> haveSchool = new();
                 List<string> sendWhom = new();//消息分发给谁   待完善
@@ -517,7 +567,8 @@ namespace TEAMModelBI.Controllers.BINormal
                 await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
+                //await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
                 if (haveSchool.Count > 0) return Ok(new { state = 201, msg = "已存在学校,无须申请!", haveSchool });
                 else return Ok(new { state = 200 });
             }

+ 19 - 5
TEAMModelBI/Controllers/BINormal/BIOpenApiController.cs

@@ -7,7 +7,9 @@ using System.Collections.Generic;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
+using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.Filter;
+using TEAMModelBI.Tool.Context;
 using TEAMModelBI.Tool.Extension;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.DI;
@@ -39,12 +41,15 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales,company")]
         [HttpPost("get-infos")]
         public async Task<IActionResult> GetOpenApi(JsonElement jsonElement) 
         {
             jsonElement.TryGetProperty("id", out JsonElement id);
+            jsonElement.TryGetProperty("site", out JsonElement site);
             var cosmosClient = _azureCosmos.GetCosmosClient();
+            if ($"{site}".Equals(BIConst.GlobalSite))
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
             StringBuilder sqlTxt = new("select c.id,c.code,c.pk,c.name,c.rw,c.method,c.url,c.descr,c.type,c.descrUrl,c.createTime from c where c.pk='Api' ");
             if (!string.IsNullOrEmpty($"{id}")) 
             {
@@ -87,13 +92,21 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="openApi"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales,company")]
         [HttpPost("set-api")]
-        public async Task<IActionResult> SetOpenApi(BIOpenApi  openApi) 
+        public async Task<IActionResult> SetOpenApi(BIOpenApi openApi, [FromHeader] string site)
         {
             try
             {
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 StringBuilder strMsg = new($"{loginName}【{loginId}】");
                 string type = "";
@@ -123,8 +136,9 @@ namespace TEAMModelBI.Controllers.BINormal
                     else return Ok(new { state = 404, msg = "未找到该id相关的Api信息" });
                 }
                 //保存操作记录
-                await _azureStorage.SaveBILog(type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog(type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
+                
                 return Ok(new { state = 200, openApi });
             }
             catch (Exception e)

+ 18 - 5
TEAMModelBI/Controllers/BINormal/CompanyController.cs

@@ -9,7 +9,9 @@ using System.Net.Http;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
+using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.Filter;
+using TEAMModelBI.Tool.Context;
 using TEAMModelBI.Tool.Extension;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.DI;
@@ -44,12 +46,15 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="jsonElenent"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist,company")]
+        [AuthToken(Roles = "admin,rdc,assist,sales,company")]
         [HttpPost("get-info")]
         public async Task<IActionResult> GetInfo(JsonElement jsonElenent)
         {
             jsonElenent.TryGetProperty("eid", out JsonElement eid);
+            jsonElenent.TryGetProperty("site", out JsonElement site);
             var cosmosClient = _azureCosmos.GetCosmosClient();
+            if ($"{site}".Equals(BIConst.GlobalSite))
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
             List<ReadCompany> companys = new();
             StringBuilder sqlTxt = new("select c.id,c.pk,c.code,c.name,c.credit,c.picture,c.emall,c.mobile,c.password from c");
             if (!string.IsNullOrEmpty($"{eid}"))
@@ -89,15 +94,23 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="appCompany"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist,company")]
+        [AuthToken(Roles = "admin,rdc,assist,sales,company")]
         [HttpPost("set-info")]
-        public async Task<IActionResult> SetCompany(Company company)
+        public async Task<IActionResult> SetCompany(Company company, [FromHeader] string site) 
         {
             try
             {
                 var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 StringBuilder strMsg = new($"{loginName}【{loginId}】");
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 string salt = Utils.CreatSaltString(8);
                 string type = "";
                 //新增企业信息
@@ -156,8 +169,8 @@ namespace TEAMModelBI.Controllers.BINormal
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog(type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog(type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200, company });
             }
             catch (Exception e)

+ 11 - 4
TEAMModelBI/Controllers/BISchool/AreaRelevantController.cs

@@ -7,6 +7,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text.Json;
 using System.Threading.Tasks;
+using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.Filter;
 using TEAMModelBI.Tool.Context;
 using TEAMModelBI.Tool.Extension;
@@ -109,7 +110,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,,rdc,assist")]
+        [AuthToken(Roles = "admin,,rdc")]
         [HttpPost("set-areashiftschool")]
         public async Task<IActionResult> SetAreaShiftSchool(JsonElement jsonElement)
         {
@@ -123,8 +124,14 @@ namespace TEAMModelBI.Controllers.BISchool
 
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 var cosmosClient = _azureCosmos.GetCosmosClient();
-                if ($"{site}".Equals(BIConst.GlobalSite))
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite)) 
+                {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
 
                 School tempSchool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{schoolId}", new PartitionKey("Base"));
                 if (bool.Parse($"{isDefault}") == true)
@@ -161,8 +168,8 @@ namespace TEAMModelBI.Controllers.BISchool
                 School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempSchool, tempSchool.id, new PartitionKey("Base"));
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("school-update", $"{_tmdName}【{_tmdId}】已操作学校({schoolId})移除该区域", _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("school-update", $"{_tmdName}【{_tmdId}】已操作学校({schoolId})移除该区域", _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】已操作学校({schoolId})移除该区域", _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200, school });
             }
             catch (Exception ex)

+ 18 - 11
TEAMModelBI/Controllers/BISchool/BatchAreaController.cs

@@ -21,6 +21,7 @@ using TEAMModelBI.Filter;
 using TEAMModelBI.Tool.Extension;
 using TEAMModelBI.Tool;
 using TEAMModelBI.Tool.Context;
+using TEAMModelBI.DI.BIAzureStorage;
 
 namespace TEAMModelBI.Controllers.BISchool
 {
@@ -152,7 +153,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("batch-area")]
         public async Task<IActionResult> batchArea(JsonElement jsonElement)
         {
@@ -176,18 +177,22 @@ namespace TEAMModelBI.Controllers.BISchool
                 //操作记录实体
                 var tempStandard = !string.IsNullOrEmpty($"{oldStandard}") && !string.IsNullOrEmpty($"{_oldId}") ? $"{oldStandard}" : "standard2";
 
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
+                //var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
                 var cosmosClient = _azureCosmos.GetCosmosClient();//数据库连接
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 var serBusClient = _serviceBus.GetServiceBusClient();
                 var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");//秘钥地址
                 if ($"{site}".Equals(BIConst.GlobalSite))
                 {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("IESLogin");
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
                     //serBusClient = _serviceBus.GetServiceBusClient(BIConst.GlobalSite);  //暂未确定使用默认
                     //activeTask = _configuration.GetValue<string>("GlobalAzure:ServiceBus:ActiveTask");   //暂未确定使用默认
                 }
 
+                var table = tableClient.GetTableReference("IESLogin");
+
                 //查询新的是否存在
                 await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select value(c) from c where c.standard='{standard}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
                 {
@@ -509,8 +514,8 @@ namespace TEAMModelBI.Controllers.BISchool
                 await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200, area = addArea });
             }
             catch (Exception ex)
@@ -526,7 +531,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("cut-standard")]
         public async Task<IActionResult> CutStandard(JsonElement jsonElement)
         {
@@ -542,18 +547,20 @@ namespace TEAMModelBI.Controllers.BISchool
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 //操作记录实体
                 string blobOrTable = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 var serBusClient = _serviceBus.GetServiceBusClient();
                 var activeTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");//秘钥地址
                 if ($"{site}".Equals(BIConst.GlobalSite))
                 {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("IESLogin");
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                     //serBusClient = _serviceBus.GetServiceBusClient(BIConst.GlobalSite);    //暂未确定使用默认 
                     //activeTask = _configuration.GetValue<string>("GlobalAzure:ServiceBus:ActiveTask");  //暂未确定使用默认
                 }
-
+                var table = tableClient.GetTableReference("IESLogin");
                 //保存引用记录
                 await table.SaveOrUpdate<AreaQuoteRecord>(new AreaQuoteRecord() { PartitionKey = "QuoteRecord", RowKey = $"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}", areaId = $"{_oldId}", quoteId = $"{_newId}", quoteName = $"{newName}", standard = $"{_newStandard}" });
 
@@ -754,8 +761,8 @@ namespace TEAMModelBI.Controllers.BISchool
                 await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //发送站内发送消息
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("area-cut", $"{_tmdName}【{_tmdId}】已操作【{_oldStandard}】切换至{_newStandard}微能力点,复制标准:{_newStandard}", _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("area-cut", $"{_tmdName}【{_tmdId}】已操作【{_oldStandard}】切换至{_newStandard}微能力点,复制标准:{_newStandard}", _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "area-cut", $"{_tmdName}【{_tmdId}】已操作【{_oldStandard}】切换至{_newStandard}微能力点,复制标准:{_newStandard}", _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200 });
             }
             catch (Exception ex)

+ 19 - 6
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -27,6 +27,7 @@ using TEAMModelBI.Tool.Extension;
 using TEAMModelBI.Tool;
 using TEAMModelBI.Models;
 using TEAMModelBI.Tool.Context;
+using TEAMModelBI.DI.BIAzureStorage;
 
 namespace TEAMModelBI.Controllers.BISchool
 {
@@ -133,7 +134,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="school"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("batch-school")]
         public async Task<IActionResult> BatchCreateSchool(FoundSchools foundSchools)
         {
@@ -143,8 +144,14 @@ namespace TEAMModelBI.Controllers.BISchool
                 List<BISchool> schools = new List<BISchool>();
                 StringBuilder stringBuilder = new StringBuilder($"{_tmdName}【{_tmdId}】使用批量创校功能:");
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if (foundSchools.site.Equals(BIConst.GlobalSite))
+                {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
 
                 if (foundSchools.biSchools.Count > 0)
                 {
@@ -303,8 +310,8 @@ namespace TEAMModelBI.Controllers.BISchool
                 else return Ok(new { state = 1, message = "创校信息为空" });
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
                 if (schools.Count > 0)
                     return Ok(new { state = 201, message = "已有部分学校批量创建成功;学校已经重复!请检查学校信息!", schools });
                 else
@@ -573,7 +580,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("upd-schoolassist")]
         public async Task<IActionResult> UpdSchoolAssist(JsonElement jsonElement)
         {
@@ -597,9 +604,15 @@ namespace TEAMModelBI.Controllers.BISchool
                 //List<string> periodS = period.ToObject<List<string>>();
                 Dictionary<string, List<Dictionary<string, string>>> haveSchoolManger = new Dictionary<string, List<Dictionary<string, string>>>();
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
 
                 if ($"{site}".Equals(BIConst.GlobalSite))
+                {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
 
                 School tempShool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
                 if (tempShool != null)
@@ -748,8 +761,8 @@ namespace TEAMModelBI.Controllers.BISchool
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{string.Join("|", assistId.ToArray())}", _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{string.Join("|", assistId.ToArray())}", _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{string.Join("|", assistId.ToArray())}", _dingDing, httpContext: HttpContext);
 
                 return Ok(new { state = 200 });
             }

+ 11 - 3
TEAMModelBI/Controllers/BISchool/RoomController.cs

@@ -7,6 +7,7 @@ using System;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
+using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.Filter;
 using TEAMModelBI.Tool.Context;
 using TEAMModelBI.Tool.Extension;
@@ -44,7 +45,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales")]
         [HttpPost("set-bind")]
         public async Task<IActionResult> SetBindProduct(JsonElement jsonElement) 
         {
@@ -58,9 +59,15 @@ namespace TEAMModelBI.Controllers.BISchool
                 var s = string.IsNullOrEmpty($"{serial}") ? null : $"{serial}";
 
                 Room room = new Room();
-                var cosmosClient = _azureCosmos.GetCosmosClient(); 
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
+                {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
 
                 var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{roomId}", new PartitionKey($"{roomCode}"));
                 if (response.Status == 200)
@@ -75,7 +82,8 @@ namespace TEAMModelBI.Controllers.BISchool
                     if (!string.IsNullOrEmpty($"{serial}")) { stringBudeler.Append($"绑定。"); } else { stringBudeler.Append($"解绑。"); }
 
                     //保存操作记录
-                    await _azureStorage.SaveBILog("room-update", $"{_tmdName}【{_tmdId}】将{roomInfo.id}教师和{serial}产品绑定", _dingDing, httpContext: HttpContext);
+                    //await _azureStorage.SaveBILog("room-update", $"{_tmdName}【{_tmdId}】将{roomInfo.id}教师和{serial}产品绑定", _dingDing, httpContext: HttpContext);
+                    await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "room-update", $"{_tmdName}【{_tmdId}】将{roomInfo.id}教师和{serial}产品绑定", _dingDing, httpContext: HttpContext);
                 }
                 else
                 {

+ 49 - 10
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -12,6 +12,7 @@ using System.Net.Http;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
+using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.Filter;
 using TEAMModelBI.Tool;
 using TEAMModelBI.Tool.Context;
@@ -158,7 +159,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,rdc,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales")]
         [HttpPost("set-schooljoinarea")]
         public async Task<IActionResult> SetSchoolJoinArea(JsonElement jsonElement)
         {
@@ -175,8 +176,14 @@ namespace TEAMModelBI.Controllers.BISchool
                 List<string> schoolCodes = _schoolCode.ToObject<List<string>>();
 
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
+                {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
 
                 if (schoolCodes.Count > 0)
                 {
@@ -208,7 +215,8 @@ namespace TEAMModelBI.Controllers.BISchool
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("school-update", $"{_tmdName}【{_tmdId}】操作学校加入区域功能,加入的区域:{standard},学校ID:{string.Join("|", schoolCodes.ToArray())}", _dingDing, httpContext: HttpContext);
+                //await _azureStorage.SaveBILog("school-update", $"{_tmdName}【{_tmdId}】操作学校加入区域功能,加入的区域:{standard},学校ID:{string.Join("|", schoolCodes.ToArray())}", _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】操作学校加入区域功能,加入的区域:{standard},学校ID:{string.Join("|", schoolCodes.ToArray())}", _dingDing, httpContext: HttpContext);
 
                 return Ok(new { state = 200 });
             }
@@ -312,14 +320,22 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="school"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,rdc,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales")]
         [HttpPost("upd-school")]
-        public async Task<IActionResult> UpdSchool(School school)
+        public async Task<IActionResult> UpdSchool(School school, [FromHeader] string site) 
         {
             try
             {
                 School schoolInfo = new School();
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 string _auth = HttpContext.GetXAuth("AuthToken");
                 //var (tmdId, tmdName) = HttpJwtAnalysis.JwtXAuth(_auth, _option);
                 var (tmdId, tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(_auth, _option);
@@ -346,7 +362,8 @@ namespace TEAMModelBI.Controllers.BISchool
                     schoolInfo = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey($"Base"));
 
                     //保存操作记录
-                    await _azureStorage.SaveBILog("school-update", $"{tmdName}【{tmdId}】修改学校信息,学校和ID:{school.name}【{school.id}】", _dingDing, httpContext: HttpContext);
+                    //await _azureStorage.SaveBILog("school-update", $"{tmdName}【{tmdId}】修改学校信息,学校和ID:{school.name}【{school.id}】", _dingDing, httpContext: HttpContext);
+                    await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{tmdName}【{tmdId}】修改学校信息,学校和ID:{school.name}【{school.id}】", _dingDing, httpContext: HttpContext);
                 }
                 else return Ok(new { state = 400, message = "请求错误!" });
 
@@ -515,8 +532,14 @@ namespace TEAMModelBI.Controllers.BISchool
             jsonElement.TryGetProperty("site", out JsonElement site);
 
             var cosmosClient = _azureCosmos.GetCosmosClient();
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
             if ($"{site}".Equals(BIConst.GlobalSite))
+            {
                 cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+            }
 
             SchoolTeacher schoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<SchoolTeacher>($"{_tmdId}", new PartitionKey($"Teacher-{_school}"));
             if (schoolTeacher.roles.IsNotEmpty() && schoolTeacher.roles.Contains("assist"))
@@ -556,7 +579,8 @@ namespace TEAMModelBI.Controllers.BISchool
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("schoolTeacher-add", $"{_tmdName}【{_tmdId}】移交顾问给{newSchoolTeacher.name}【{newSchoolTeacher.id}】", _dingDing, httpContext: HttpContext);
+                //await _azureStorage.SaveBILog("schoolTeacher-add", $"{_tmdName}【{_tmdId}】移交顾问给{newSchoolTeacher.name}【{newSchoolTeacher.id}】", _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-add", $"{_tmdName}【{_tmdId}】移交顾问给{newSchoolTeacher.name}【{newSchoolTeacher.id}】", _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200 });
             }
             else { return Ok(new { status = 201, msg = $"{_tmdName}【{_tmdId}】账号不是顾问" }); }
@@ -568,7 +592,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("set-aistschool")]
         public async Task<IActionResult> SetAssistSchool(JsonElement jsonElement)
         {
@@ -727,8 +751,14 @@ namespace TEAMModelBI.Controllers.BISchool
                 if (!jsonElement.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
                 jsonElement.TryGetProperty("site", out JsonElement site);
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
+                {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
 
                 var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{_adminTmdId}", new PartitionKey($"Teacher-{_schoolId}"));
                 if (response.Status == 200)
@@ -741,7 +771,8 @@ namespace TEAMModelBI.Controllers.BISchool
                         SchoolTeacher st = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey(schoolTeacher.code));
 
                         //保存操作记录
-                        await _azureStorage.SaveBILog("schoolTeacher-update", $"{_tmdName}【{_tmdId}】账户把{_adminTmdName}【{_adminTmdId}】设置学校id为{_schoolId}管理员。", _dingDing, httpContext: HttpContext);
+                        //await _azureStorage.SaveBILog("schoolTeacher-update", $"{_tmdName}【{_tmdId}】账户把{_adminTmdName}【{_adminTmdId}】设置学校id为{_schoolId}管理员。", _dingDing, httpContext: HttpContext);
+                        await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-update", $"{_tmdName}【{_tmdId}】账户把{_adminTmdName}【{_adminTmdId}】设置学校id为{_schoolId}管理员。", _dingDing, httpContext: HttpContext);
                         return Ok(new { state = 200, schoolTeacher = st });
                     }
                     else
@@ -765,7 +796,8 @@ namespace TEAMModelBI.Controllers.BISchool
 
                     schoolTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
                     //保存操作记录
-                    await _azureStorage.SaveBILog("schoolTeacher-add", $"{_tmdName}【{_tmdId}】账户创建{_adminTmdName}【{_adminTmdId}】账户,并设学校管理员。学校ID:{_schoolId}。", _dingDing, httpContext: HttpContext);
+                    //await _azureStorage.SaveBILog("schoolTeacher-add", $"{_tmdName}【{_tmdId}】账户创建{_adminTmdName}【{_adminTmdId}】账户,并设学校管理员。学校ID:{_schoolId}。", _dingDing, httpContext: HttpContext);
+                    await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-add", $"{_tmdName}【{_tmdId}】账户创建{_adminTmdName}【{_adminTmdId}】账户,并设学校管理员。学校ID:{_schoolId}。", _dingDing, httpContext: HttpContext);
                     return Ok(new { status = 200, schoolTeacher });
                 }
             }
@@ -794,8 +826,14 @@ namespace TEAMModelBI.Controllers.BISchool
                 string _auth = HttpContext.GetXAuth("AuthToken");
                 var (tmdId, tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(_auth, _option);
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
+                {
                     cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
                 StringBuilder msg = new();
                 List<DelSchoolRel> delSchoolRels = new();
 
@@ -838,7 +876,8 @@ namespace TEAMModelBI.Controllers.BISchool
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("set-del", msg.ToString(), _dingDing, httpContext: HttpContext);
+                //await _azureStorage.SaveBILog("set-del", msg.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "set-del", msg.ToString(), _dingDing, httpContext: HttpContext);
                 if (delSchoolRels.Count > 0)
                     return Ok(new { state = 201, delSchoolRels });
                 else

+ 1 - 1
TEAMModelBI/Controllers/BIServer/BiServersController.cs

@@ -52,7 +52,7 @@ namespace TEAMModelBI.Controllers.BIServer
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales")]
         [HttpPost("get-coreinfo")]
         public async Task<IActionResult> GetCoreInfo(JsonElement jsonElement)
         {

+ 21 - 2
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -30,6 +30,8 @@ using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Models.Service;
 using TEAMModelOS.SDK.Models.Table;
 
+using static TEAMModelBI.DI.BIAzureStorage.BIAzureStorageBlobExtensions;
+
 //.Net 6新的特性
 using System.Threading;
 using System.Reflection;
@@ -47,6 +49,7 @@ using TEAMModelBI.Tool.CosmosBank;
 using System.Diagnostics;
 using StackExchange.Redis;
 using TEAMModelBI.Tool.Context;
+using TEAMModelBI.DI.BIAzureStorage;
 
 namespace TEAMModelBI.Controllers.BITest
 {
@@ -157,13 +160,29 @@ namespace TEAMModelBI.Controllers.BITest
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "assist")]
+        [AuthToken(Roles = "assist,admin")]
         [HttpPost("set-savebilog")]
         public async Task<IActionResult> SetTestSaveBIlog(JsonElement jsonElement)
         {
+            jsonElement.TryGetProperty("site", out JsonElement site);
+            jsonElement.TryGetProperty("msg", out JsonElement msg);
+
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+            var redisClinet = _azureRedis.GetRedisClient(8);
+            if ($"{site}".Equals(BIConst.GlobalSite))
+            {
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                redisClinet = _azureRedis.GetRedisClient(dbnum: 8, name: BIConst.GlobalSite);
+            }
+
             var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
             await _azureStorage.SaveLog(type: "table-save", msg: "测试保存方法01", dingDing: _dingDing, httpContext: HttpContext); //IES5 日志记录
-            await _azureStorage.SaveBILog("Test-add", $"{_tmdName}【{_tmdId}】删除册别,删除ID:", _dingDing, httpContext: HttpContext);//BI 日志记录
+
+            await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "Test-test", $"{msg}", _dingDing, httpContext: HttpContext);//BI 日志记录
 
             return Ok(new { state = 200 });
         }

+ 9 - 3
TEAMModelBI/Controllers/Core/BlobController.cs

@@ -7,7 +7,9 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Net.Http;
 using System.Threading.Tasks;
+using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.Filter;
+using TEAMModelBI.Tool.Context;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
@@ -50,16 +52,20 @@ namespace TEAMModelBI.Controllers.Core
         /// <param name="file"></param>
         /// <returns></returns>
         [HttpPost("upload-public")]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc,assist,sales")]
         [RequestSizeLimit(102_400_000_00)]//最大10000m左右
-        public async Task<IActionResult> UploadPublic([FromForm] IFormFile file)
+        public async Task<IActionResult> UploadPublic([FromForm] IFormFile file,[FromHeader]string site)
         {
             var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
             string fileExt = FileType.GetExtention(file.FileName).ToLower();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+            if ($"{site}".Equals(BIConst.GlobalSite))
+                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
 
             if (ContentTypeDict.dict.ContainsKey($".{fileExt}"))
             {
-                var url = await _azureStorage.UploadFileByContainer("0-public", file.OpenReadStream(), "school", $"{Guid.NewGuid()}.{fileExt}", false);
+                //var url = await _azureStorage.UploadFileByContainer("0-public", file.OpenReadStream(), "school", $"{Guid.NewGuid()}.{fileExt}", false);
+                var url = await BIAzureStorageBlobExtensions.UploadFileByContainer(blobClient, file.OpenReadStream(), "school", $"{Guid.NewGuid()}.{fileExt}");
                 return Ok(new { url });
             }
             else

+ 4 - 4
TEAMModelBI/Controllers/DingDingStruc/SystemConfigController.cs

@@ -68,7 +68,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("set-config")]
         public async Task<IActionResult> SetConfigJson(JsonElement jsonElement)
         {
@@ -255,7 +255,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("get-allconfig")]
         public async Task<IActionResult> GetAllConfig() 
         {
@@ -318,7 +318,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// <param name="sysConfig"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("set-singleconfig")]
         public async Task<IActionResult> SetSingleConfig(SysConfig sysConfig) 
         {
@@ -375,7 +375,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("cut-site")]
         public async Task<IActionResult> CutSite(JsonElement jsonElement) 
         {

+ 72 - 39
TEAMModelBI/Controllers/DingDingStruc/TableDingDingInfoController.cs

@@ -26,6 +26,7 @@ using TEAMModelBI.Tool.Extension;
 using TEAMModelBI.Models;
 using TEAMModelBI.Tool.CosmosBank;
 using TEAMModelBI.Tool.Context;
+using TEAMModelBI.DI.BIAzureStorage;
 
 namespace TEAMModelBI.Controllers.DingDingStruc
 {
@@ -59,18 +60,21 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// </summary>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("get-dingdingusers")]
         public async Task<IActionResult> GetDingDingUser(JsonElement jsonElement)
         {
             try
             {
                 jsonElement.TryGetProperty("site", out JsonElement site);
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
                 {
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("BIDDUserInfo");
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                 }
+                var table = tableClient.GetTableReference("BIDDUserInfo");                
 
                 string appKey = _configuration["DingDingAuth:appKey"];
                 string appSecret = _configuration["DingDingAuth:appSecret"];
@@ -171,8 +175,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("tabledd-update", $"{_tmdName}【{_tmdId}】从钉钉组织结构更新至Azure Table表【DDUserInfo】中。", _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("tabledd-update", $"{_tmdName}【{_tmdId}】从钉钉组织结构更新至Azure Table表【DDUserInfo】中。", _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{_tmdName}【{_tmdId}】从钉钉组织结构更新至Azure Table表【DDUserInfo】中。", _dingDing, httpContext: HttpContext);
                 var tempddUserInfos = ddUserInfos.GroupBy(c => c.userId).Select(c => c.First()).ToList();//去重
                 //List<DingDingUserInfo> TempdingDingUserInfos = await _azureStorage.SaveOrUpdateAll(dingDingUserInfos);  //只是保存至Table
                 //查询数据的数据 并和钉钉查询的数据对比,找出不同的数据,并删除  待后期测试
@@ -328,18 +332,21 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// </summary>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("set-ddinductionuser")]
         public async Task<IActionResult> SetDingDingInductionUser(JsonElement jsonElement)
         {
             try
             {
                 jsonElement.TryGetProperty("site", out JsonElement site);
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
                 {
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("BIDDUserInfo");
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                 }
+                var table = tableClient.GetTableReference("BIDDUserInfo");
 
                 string appKey = _configuration["DingDingAuth:appKey"];
                 string appSecret = _configuration["DingDingAuth:appSecret"];
@@ -379,8 +386,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                     List<DingDingUserInfo> tempddUserInfos = await table.SaveAll(ddUserInfos);
 
                     //保存操作记录
-                    await _azureStorage.SaveBILog("tabledd-add", $"{_tmdName}【{_tmdId}】添加待入职员工至table数据表中", _dingDing, httpContext: HttpContext);
-
+                    //await _azureStorage.SaveBILog("tabledd-add", $"{_tmdName}【{_tmdId}】添加待入职员工至table数据表中", _dingDing, httpContext: HttpContext);
+                    await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-add", $"{_tmdName}【{_tmdId}】添加待入职员工至table数据表中", _dingDing, httpContext: HttpContext);
                     if (ddUserInfos.Count == tempddUserInfos.Count)
                     {
                         return Ok(new { state = 200, UserInfo = tempddUserInfos });
@@ -408,18 +415,21 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// </summary>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("del-ddquituser")]
         public async Task<IActionResult> DeleteDDQuitUser(JsonElement jsonElement)
         {
             try
             {
                 jsonElement.TryGetProperty("site", out JsonElement site);
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
                 {
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("BIDDUserInfo");
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                 }
+                var table = tableClient.GetTableReference("BIDDUserInfo");           
 
                 string appKey = _configuration["DingDingAuth:appKey"];
                 string appSecret = _configuration["DingDingAuth:appSecret"];
@@ -453,8 +463,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                     }
 
                     //保存操作记录
-                    await _azureStorage.SaveBILog("tabledd-del", $"{_tmdName}【{_tmdId}】从table数据表中删除离职员工", _dingDing, httpContext: HttpContext);
-
+                    //await _azureStorage.SaveBILog("tabledd-del", $"{_tmdName}【{_tmdId}】从table数据表中删除离职员工", _dingDing, httpContext: HttpContext);
+                    await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-del", $"{_tmdName}【{_tmdId}】从table数据表中删除离职员工", _dingDing, httpContext: HttpContext);
                     return Ok(new { state = 200 });
                 }
                 else
@@ -476,7 +486,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("set-rolesper")]
         public async Task<IActionResult> SetPermissions(JsonElement jsonElement)
         {
@@ -489,11 +499,15 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 if (!jsonElement.TryGetProperty("roles", out JsonElement _roles)) return BadRequest();
                 jsonElement.TryGetProperty("site", out JsonElement site);
 
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
                 {
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("BIDDUserInfo");
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                 }
+
+                var table = tableClient.GetTableReference("BIDDUserInfo");
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
 
                 List<DingDingUserInfo> ddUserInfo = new();
@@ -535,8 +549,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 ddUserInfo = await table.UpdateAll<DingDingUserInfo>(ddUserInfo);
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("tabledd-update", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("tabledd-update", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200, ddUserInfo, roles, permissions });
             }
             catch (Exception ex)
@@ -557,16 +571,20 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         {
             try
             {
-                var cosmosCliet = _azureCosmos.GetCosmosClient();
                 if (!jsonElement.TryGetProperty("deptId", out JsonElement deptId)) return BadRequest();
                 jsonElement.TryGetProperty("site", out JsonElement site);
 
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
+                var cosmosCliet = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
                 {
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("BIDDUserInfo");
                     cosmosCliet = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                 };
+
+                var table = tableClient.GetTableReference("BIDDUserInfo");
                 //string divide = _configuration["CustomParam:SiteScope"];
                 string divide = _option.Location;
                 Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", $"{divide}" } };
@@ -703,7 +721,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,assist")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("set-backenbind")]
         public async Task<IActionResult> SetBackenBind(JsonElement jsonElement) 
         {
@@ -714,12 +732,17 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 jsonElement.TryGetProperty("site", out JsonElement site);
 
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
+
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
                 {
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("BIDDUserInfo");
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                 }
 
+                var table = tableClient.GetTableReference("BIDDUserInfo");
+
                 List<DingDingUserInfo> tempddUsers = null;
                 List<DingDingUserInfo> ddUsers = new();
                 StringBuilder tableSql = new();
@@ -777,8 +800,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 if (ddUsers.Count > 0) ddUsers = await table.SaveOrUpdateAll(ddUsers);
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("tabledd-update", $"{_tmdName}【{_tmdId}】操作:绑定钉钉账户[{rowKey}]和醍摩豆账户[{tmdId}]", _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("tabledd-update", $"{_tmdName}【{_tmdId}】操作:绑定钉钉账户[{rowKey}]和醍摩豆账户[{tmdId}]", _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{_tmdName}【{_tmdId}】操作:绑定钉钉账户[{rowKey}]和醍摩豆账户[{tmdId}]", _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200, ddUsers });
             }
             catch (Exception ex)
@@ -794,7 +817,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("set-backend")]
         public async Task<IActionResult> SetBackendAdmin(JsonElement jsonElement)
         {
@@ -805,11 +828,18 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 if (!jsonElement.TryGetProperty("isAdmin", out JsonElement isAdmin)) return BadRequest();
                 jsonElement.TryGetProperty("site", out JsonElement site);
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
+
+
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
                 {
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("BIDDUserInfo");
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                 }
+
+                var table = tableClient.GetTableReference("BIDDUserInfo");
+
                 var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{rowKey}" } });
                 
                 List<DDUserInfo> ddUserInfos = new();
@@ -879,8 +909,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("tabledd-update", msg.ToString(), _dingDing, httpContext: HttpContext);
-
+               //await _azureStorage.SaveBILog("tabledd-update", msg.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", msg.ToString(), _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200, roles });
 
             }
@@ -898,7 +928,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        [AuthToken(Roles = "admin,rdc")]
         [HttpPost("set-tmdadmin")]
         public async Task<IActionResult> SetTmdBackendAdmin(JsonElement jsonElement) 
         {
@@ -912,13 +942,16 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 jsonElement.TryGetProperty("site", out JsonElement site);
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 var cosmosCliet = _azureCosmos.GetCosmosClient();
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
+                
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
                 {
                     cosmosCliet = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("BIDDUserInfo");
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
                 }
-
+                var table = tableClient.GetTableReference("BIDDUserInfo");
 
                 List<DDUserInfo> ddUserInfos = new();
                 List<string> roles = new();//角色列表
@@ -1032,8 +1065,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 }
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("tabledd-update",msg.ToString(), _dingDing, httpContext: HttpContext);
-
+                //await _azureStorage.SaveBILog("tabledd-update",msg.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", msg.ToString(), _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200, ddUserInfos });
             }
             catch (Exception ex)

+ 71 - 10
TEAMModelBI/Controllers/LoginController.cs

@@ -34,6 +34,8 @@ using TEAMModelBI.Models.Extension;
 using TEAMModelOS.SDK;
 using Microsoft.AspNetCore.Hosting;
 using TEAMModelBI.Tool;
+using TEAMModelBI.DI.BIAzureStorage;
+using TEAMModelBI.Tool.Context;
 //using static DingTalk.Api.Response.OapiV2UserGetResponse;
 
 namespace TEAMModelBI.Controllers
@@ -94,6 +96,15 @@ namespace TEAMModelBI.Controllers
                 }
                 //自己传的code
                 if (!jsonElement.TryGetProperty("code", out JsonElement LoginTempCode)) return BadRequest();
+                jsonElement.TryGetProperty("site", out JsonElement site);
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                    Website = BIConst.GlobalSite;
+                }
 
                 //获取access_token
                 IDingTalkClient tokenClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
@@ -197,8 +208,10 @@ namespace TEAMModelBI.Controllers
                             strMsg.Append($"{item.tmdName}【{item.tmdId}】醍摩豆账号和{item.name}【{item.userId}】钉钉账户绑定成功");
 
                             //保存操作记录
-                            await _azureStorage.SaveBILog("tabledd-update", strMsg?.ToString(), _dingDing, httpContext: HttpContext, twebsite: Website, tid: item.tmdId, tname: item.tmdName);
-                            saveInfo.Add(item);
+                            //await _azureStorage.SaveBILog("tabledd-update", strMsg?.ToString(), _dingDing, httpContext: HttpContext, twebsite: Website, tid: item.tmdId, tname: item.tmdName);
+                            await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", strMsg?.ToString(), _dingDing, httpContext: HttpContext, twebsite: Website, tid: item.tmdId, tname: item.tmdName);
+
+                            saveInfo.Add(item);                            
                         }
 
                         List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, item.tmdId);
@@ -282,7 +295,8 @@ namespace TEAMModelBI.Controllers
                     ddUserInfo = await table.Save<DingDingUserInfo>(ddUserInfo);
 
                     //保存操作记录
-                    await _azureStorage.SaveBILog("tabledd-update", $"{ddUserInfo.tmdName}【{ddUserInfo.tmdId}】醍摩豆账号和{ddUserInfo.name}【{ddUserInfo.RowKey}】钉钉账户绑定成功", _dingDing, httpContext: HttpContext, tid: ddUserInfo.tmdId, tname: ddUserInfo.tmdName, twebsite: Website);
+                    //await _azureStorage.SaveBILog("tabledd-update", $"{ddUserInfo.tmdName}【{ddUserInfo.tmdId}】醍摩豆账号和{ddUserInfo.name}【{ddUserInfo.RowKey}】钉钉账户绑定成功", _dingDing, httpContext: HttpContext, tid: ddUserInfo.tmdId, tname: ddUserInfo.tmdName, twebsite: Website);
+                    await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{ddUserInfo.tmdName}【{ddUserInfo.tmdId}】醍摩豆账号和{ddUserInfo.name}【{ddUserInfo.RowKey}】钉钉账户绑定成功", _dingDing, httpContext: HttpContext, tid: ddUserInfo.tmdId, tname: ddUserInfo.tmdName, twebsite: Website);
 
                     roles = !string.IsNullOrEmpty($"{ddUserInfo.roles}") ? new List<string>(ddUserInfo.roles.Split(",")) : new List<string>();
                     permissions = !string.IsNullOrEmpty($"{ddUserInfo.permissions}") ? new List<string>(ddUserInfo.permissions.Split(",")) : new List<string>();
@@ -319,8 +333,17 @@ namespace TEAMModelBI.Controllers
                 if (!jsonElement.TryGetProperty("rowKey", out JsonElement userId)) return BadRequest();
                 jsonElement.TryGetProperty("id_token", out JsonElement idtoken);
                 jsonElement.TryGetProperty("mobile", out JsonElement mobile);
-
+                jsonElement.TryGetProperty("site", out JsonElement site);
                 string Website = "China";
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                    Website = BIConst.GlobalSite;
+                }
+
                 HttpClient httpClient = _http.CreateClient();
                 string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
                 var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
@@ -378,7 +401,8 @@ namespace TEAMModelBI.Controllers
                         roles = !string.IsNullOrEmpty($"{itemUser.roles}") ? new List<string>(itemUser.roles.Split(",")) : new List<string>();
 
                         //保存操作记录
-                        await _azureStorage.SaveBILog("tabledd-update", $"{itemUser.tmdName}【{itemUser.tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
+                        //await _azureStorage.SaveBILog("tabledd-update", $"{itemUser.tmdName}【{itemUser.tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
+                        await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{itemUser.tmdName}【{itemUser.tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
 
                         id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, itemUser.tmdId?.ToString(), itemUser.tmdName?.ToString(), itemUser.picture?.ToString(), _option.JwtSecretKey, scope: "assist", webSite: Website, isex: false, itemUser.userId?.ToString(), itemUser.name?.ToString(), itemUser.avatar?.ToString(), roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire: 3);
                     }
@@ -412,8 +436,18 @@ namespace TEAMModelBI.Controllers
                 if (!jsonElement.TryGetProperty("mobile", out JsonElement moile)) return BadRequest();
                 if (!jsonElement.TryGetProperty("partitionKey", out JsonElement partitionKey)) return BadRequest();
                 if (!jsonElement.TryGetProperty("rowKey", out JsonElement userId)) return BadRequest();
+                
+                jsonElement.TryGetProperty("site", out JsonElement site); 
                 string Website = "China";
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                    Website = BIConst.GlobalSite;
+                }
+                var table = tableClient.GetTableReference("BIDDUserInfo");
                 var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "userId", $"{userId}" } });
 
                 List<string> roles = new();//角色列表
@@ -462,7 +496,8 @@ namespace TEAMModelBI.Controllers
                                 ddUserInfos = await table.UpdateAll<DingDingUserInfo>(ddUserInfos);
 
                                 //保存操作记录
-                                await _azureStorage.SaveBILog("tabledd-update", $"{tmdName}【{tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
+                                //await _azureStorage.SaveBILog("tabledd-update", $"{tmdName}【{tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
+                                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{tmdName}【{tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
                             }
                             else return Ok(new { state = 400, message = "该手机没有注册醍摩豆账号信息" });
                         }
@@ -494,10 +529,21 @@ namespace TEAMModelBI.Controllers
         {
             if (!jsonElement.TryGetProperty("account", out JsonElement accout)) return BadRequest();
             if (!jsonElement.TryGetProperty("password", out JsonElement password)) return BadRequest();
+            jsonElement.TryGetProperty("site", out JsonElement site);
 
             string Website = "China";
-            StringBuilder sqlTxt = new($"select value(c) from c");
             var cosmosClient = _azureCosmos.GetCosmosClient();
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+            if ($"{site}".Equals(BIConst.GlobalSite))
+            {
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                Website = BIConst.GlobalSite;
+            }
+
+            StringBuilder sqlTxt = new($"select value(c) from c");
             var temps = $"{accout}".Contains($"@");
             if (temps)
                 sqlTxt.Append($" where c.emall='{accout}'");
@@ -526,7 +572,8 @@ namespace TEAMModelBI.Controllers
             else return Ok(new { state = 404 });
 
             //保存操作记录
-            await _azureStorage.SaveBILog("tabledd-update", $"{company.name}【{company.id}】登录商务智能开放平台", _dingDing, tid: company.id, tname: company.name, twebsite: "BI", httpContext: HttpContext);
+            //await _azureStorage.SaveBILog("tabledd-update", $"{company.name}【{company.id}】登录商务智能开放平台", _dingDing, tid: company.id, tname: company.name, twebsite: "BI", httpContext: HttpContext);
+            await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{company.name}【{company.id}】登录商务智能开放平台", _dingDing, tid: company.id, tname: company.name, twebsite: Website?.ToString(), httpContext: HttpContext);
 
             return Ok(new { error = 200, id_token, company });
         }
@@ -543,8 +590,20 @@ namespace TEAMModelBI.Controllers
             if (!jsonElement.TryGetProperty("credit", out JsonElement credit)) return BadRequest();
             if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
             if (!jsonElement.TryGetProperty("password", out JsonElement password)) return BadRequest();
+            jsonElement.TryGetProperty("site", out JsonElement site);
 
+            string Website = "China";
             var cosmosClient = _azureCosmos.GetCosmosClient();
+            var tableClient = _azureStorage.GetCloudTableClient();
+            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+            if ($"{site}".Equals(BIConst.GlobalSite))
+            {
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                Website = BIConst.GlobalSite;
+            }
+
             string salt = Utils.CreatSaltString(8);
 
             string sqltxt = $"select value(c) from c where c.mobile='{mobile}'";
@@ -582,7 +641,9 @@ namespace TEAMModelBI.Controllers
             company = await cosmosClient.GetContainer("TEAMModelOS", "Normal").CreateItemAsync<Company>(company, new PartitionKey("Company"));
 
             //保存操作记录
-            await _azureStorage.SaveBILog("tabledd-update", $"{company.name}【{company.id}】注册商务智能开放平台", _dingDing, tid: company.id, tname: company.name, twebsite: "BI", httpContext: HttpContext);
+            //await _azureStorage.SaveBILog("tabledd-update", $"{company.name}【{company.id}】注册商务智能开放平台", _dingDing, tid: company.id, tname: company.name, twebsite: "BI", httpContext: HttpContext);
+            await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{company.name}【{company.id}】注册商务智能开放平台", _dingDing, tid: company.id, tname: company.name, twebsite: Website?.ToString(), httpContext: HttpContext);
+
 
             return Ok(new { state = 200, company });
         }

+ 11 - 3
TEAMModelBI/Controllers/OperateRecord/OperateLogController.cs

@@ -16,6 +16,7 @@ using TEAMModelBI.Filter;
 using TEAMModelBI.Tool.Extension;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelBI.Tool.Context;
+using TEAMModelBI.DI.BIAzureStorage;
 
 namespace TEAMModelBI.Controllers.OperateRecord
 {
@@ -121,13 +122,20 @@ namespace TEAMModelBI.Controllers.OperateRecord
                     tableStrWhere.Append($"time ge {startDate}L and time le {endDate}L ");
                     operateStr.Append($"删除的时间戳,开始——结束时间戳:{startDate}-{endDate}");
                 }
-                var table = _azureStorage.GetCloudTableClient().GetTableReference("BIOptLog");
+                var tableClient = _azureStorage.GetCloudTableClient();
+                var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 if ($"{site}".Equals(BIConst.GlobalSite))
-                    table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("BIOptLog");
+                {
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
+                }
+
+                var table = tableClient.GetTableReference("BIOptLog");
                 var temp = await table.DeleteStringWhere<BIOptLog>(rowKey: tableStrWhere.ToString());
 
                 //保存操作记录
-                await _azureStorage.SaveBILog("operatelog-del", operateStr?.ToString(), _dingDing, httpContext: HttpContext);
+                //await _azureStorage.SaveBILog("operatelog-del", operateStr?.ToString(), _dingDing, httpContext: HttpContext);
+                await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "operatelog-del", operateStr?.ToString(), _dingDing, httpContext: HttpContext);
 
                 if (temp.Count > 0)
                 {

+ 161 - 2
TEAMModelBI/DI/BIAzureStorage/BIAzureStorageBlobExtensions.cs

@@ -1,6 +1,165 @@
-namespace TEAMModelBI.DI.BIAzureStorage
+using Azure.Storage.Blobs;
+using Azure.Storage.Blobs.Models;
+using HTEXLib.COMM.Helpers;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Azure.Cosmos.Table;
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models.Table;
+
+namespace TEAMModelBI.DI.BIAzureStorage
 {
-    public class BIAzureStorageBlobExtensions
+    public static class BIAzureStorageBlobExtensions
     {
+        /// <summary>
+        /// 系统管理员 资源,题目关联,htex关联,学习活动学生上传文件关联,基本信息关联,教室平面图关联,评测冷数据关联
+        /// "system": [ "res", "item", "htex", "task", "info", "room", "exam" ],
+        /// 资源,题目关联,htex关联,学习活动学生上传文件关联,基本信息关联,教室平面图关联,评测冷数据关联
+        /// "school": [ "res", "item", "htex", "task", "info", "room", "exam" ],
+        /// 资源,题目关联,htex关联,学习活动关联,教师基本信息关联
+        /// "teacher": [ "res", "item", "htex", "task", "info" ],
+        /// 答案及学习活动上传的文件,学生基本信息关联
+        ///"student": [ "stu/{studentId}/ans", "stu/{studentId}/task" ]
+        /// </summary>
+        /// <param name="name">容器名称</param>
+        /// <param name="json">文件内容的流</param>
+        /// <param name="folder">业务文件夹</param>
+        /// <param name="fileName">文件名</param>
+        /// <param name="contentTypeDefault">是否存放文件后缀对应的contentType</param>
+        /// <returns></returns>
+        public static async Task<string> UploadFileByContainer(BlobContainerClient blobContainer, string json, string root, string blobpath, bool contentTypeDefault = true)
+        {
+            // string groupName =folder;
+            //BlobContainerClient blobContainer1 = azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName);            
+
+            var blockBlob = blobContainer.GetBlobClient($"{root}/{blobpath}");
+            string content_type = "application/octet-stream";
+            if (!contentTypeDefault)
+            {
+                string fileext = blobpath.Substring(blobpath.LastIndexOf(".") > 0 ? blobpath.LastIndexOf(".") : 0);
+                ContentTypeDict.dict.TryGetValue(fileext, out string contenttype);
+                if (!string.IsNullOrEmpty(contenttype))
+                {
+                    content_type = contenttype;
+                }
+            }
+            byte[] bytes = System.Text.Encoding.Default.GetBytes(json);
+            Stream streamBlob = new MemoryStream(bytes);
+            await blockBlob.UploadAsync(streamBlob, true);
+            blockBlob.SetHttpHeaders(new BlobHttpHeaders { ContentType = content_type });
+
+            return blockBlob.Uri.ToString();
+        }
+
+
+        /// <summary>
+        /// 系统管理员 资源,题目关联,htex关联,学习活动学生上传文件关联,基本信息关联,教室平面图关联,评测冷数据关联
+        /// "system": [ "res", "item", "htex", "task", "info", "room", "exam" ],
+        /// 资源,题目关联,htex关联,学习活动学生上传文件关联,基本信息关联,教室平面图关联,评测冷数据关联
+        /// "school": [ "res", "item", "htex", "task", "info", "room", "exam" ],
+        /// 资源,题目关联,htex关联,学习活动关联,教师基本信息关联
+        /// "teacher": [ "res", "item", "htex", "task", "info" ],
+        /// 答案及学习活动上传的文件,学生基本信息关联
+        ///"student": [ "stu/{studentId}/ans", "stu/{studentId}/task" ]
+        /// </summary>
+        /// <param name="blobContainer">Blob连接信息</param>
+        /// <param name="stream">文件内容的流</param>
+        /// <param name="root">跟目录</param>
+        /// <param name="blobpath">路径</param>
+        /// <param name="contentTypeDefault">是否存放文件后缀对应的contentType</param>
+        /// <returns></returns>
+        public static async Task<string> UploadFileByContainer(BlobContainerClient blobContainer, Stream stream, string root, string blobpath, bool contentTypeDefault = true)
+        {
+            //BlobContainerClient blobContainer = azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName); 
+            //if (clientName != null) 
+            //{
+            //    blobContainer = azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", ""),name:clientName); //blobClient.GetContainerReference(groupName); 
+            //}
+            Uri url = blobContainer.Uri;
+            var blockBlob = blobContainer.GetBlobClient($"{root}/{blobpath}");
+            string content_type = "application/octet-stream";
+            if (!contentTypeDefault)
+            {
+                string fileext = blobpath.Substring(blobpath.LastIndexOf(".") > 0 ? blobpath.LastIndexOf(".") : 0);
+                ContentTypeDict.dict.TryGetValue(fileext, out string contenttype);
+                if (!string.IsNullOrEmpty(contenttype))
+                {
+                    content_type = contenttype;
+                }
+            }
+            await blockBlob.UploadAsync(stream, true);
+            blockBlob.SetHttpHeaders(new BlobHttpHeaders { ContentType = content_type });
+            return blockBlob.Uri.ToString();
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="azureStorage"></param>
+        /// <param name="type"></param>
+        /// <param name="msg"></param>
+        /// <param name="dingDing"></param>
+        /// <param name="scope"></param>
+        /// <param name="option"></param>
+        /// <param name="httpContext"></param>
+        /// <returns></returns>
+
+        /// <summary>
+        /// BI保存操作记录
+        /// </summary>
+        /// <param name="blobContainer">Blob连接信息</param>
+        /// <param name="tableClient">table连接信息</param>
+        /// <param name="type">日志类型</param>
+        /// <param name="msg">日志内容</param>
+        /// <param name="dingDing"></param>
+        /// <param name="tid">账户ID</param>
+        /// <param name="tname">账户名称</param>
+        /// <param name="twebsite">站点</param>
+        /// <param name="scope">范围</param>
+        /// <param name="option"></param>
+        /// <param name="httpContext"></param>
+        /// <returns></returns>
+        public static async Task SaveBILog(BlobContainerClient blobContainer, CloudTableClient tableClient, string type, string msg, DingDing dingDing,  string tid = null, string tname = null, string twebsite = null, string scope = null, Option option = null, HttpContext httpContext = null)
+        {
+            var table = tableClient.GetTableReference("BIOptLog");
+            BIOptLog biLog = new() { RowKey = Guid.NewGuid().ToString() };
+            try
+            {
+                object id = null, name = null, ddid = null, ddname = null, website = null;
+                httpContext?.Items.TryGetValue("ID", out id);
+                httpContext?.Items.TryGetValue("Name", out name);
+                httpContext?.Items.TryGetValue("DDId", out ddid);
+                httpContext?.Items.TryGetValue("DDName", out ddname);
+                httpContext?.Items.TryGetValue("Website", out website);
+                string site = twebsite != null ? twebsite : $"{website}";
+                biLog.tmdId = id != null ? $"{id}" : tid;
+                biLog.name = name != null ? $"{name}" : tname;
+                biLog.PartitionKey = type != null ? $"{site}-Log-{type}" : $"{site}-Log-Default";
+                biLog.platform = site != null ? site : "Default";
+                biLog.msg = msg;
+                biLog.type = type;
+                biLog.scope = scope;
+                string host = httpContext?.Request?.Host.Value;
+                host = !string.IsNullOrWhiteSpace($"{host}") ? $"{host}" : option?.Location != null ? $"{host}" : "Default";
+                biLog.url = $"{host}{httpContext?.Request.Path}";
+                if (!string.IsNullOrWhiteSpace(msg) && msg.Length > 255)
+                {
+                    biLog.saveMod = 1;
+                    biLog.jsonfile = $"/0-public/BIOptLog/{biLog.PartitionKey}-{biLog.RowKey}.json";
+                    await UploadFileByContainer(blobContainer,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($"BI日志保存失败:{ex.Message}\n{ex.StackTrace},,{biLog.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
+            }
+        }
     }
 }