Quellcode durchsuchen

优化第三方平台信息接口

Li vor 2 Jahren
Ursprung
Commit
46e62e7a7b

+ 7 - 56
TEAMModelBI/Controllers/BINormal/BusinessController.cs

@@ -225,14 +225,14 @@ namespace TEAMModelBI.Controllers.BINormal
                 blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
             }
 
-            StringBuilder strMsg = new();
-            if (string.IsNullOrEmpty("add"))
+            StringBuilder strMsg = new($"{tmdName}[{tmdId}]给");
+            if ($"{type}".Equals("add"))
             {
-                strMsg.Append($"关联企业ID:{id},学校列表:");
+                strMsg.Append($"企业关联学校;学校信息列表:");
             }
-            else if (string.IsNullOrEmpty("del"))
+            else if ($"{type}".Equals("del"))
             {
-                strMsg.Append("移除企业学校信息,学校列表:");
+                strMsg.Append("企业移除学校,学校信息列表:");
             }
             else { return Ok(new { state = RespondCode.ParamsError, msg = "类型错误" }); }
             List<BizSchool> noBizSc = new();
@@ -245,7 +245,7 @@ namespace TEAMModelBI.Controllers.BINormal
                 foreach (var item in bizSchool)
                 {
                     var temp = bizConfig.schools.Find(f => f.id.Equals(item.id));
-                    if (string.IsNullOrEmpty("add"))
+                    if ($"{type}".Equals("add"))
                     {
                         if (temp == null)
                         {
@@ -255,7 +255,7 @@ namespace TEAMModelBI.Controllers.BINormal
                         else
                             noBizSc.Add(temp);
                     }
-                    else if (string.IsNullOrEmpty("del"))
+                    else if ($"{type}".Equals("del"))
                     {
                         if (temp != null)
                         {
@@ -275,54 +275,5 @@ namespace TEAMModelBI.Controllers.BINormal
             return Ok(new { state = RespondCode.Ok, bizConfig });
         }
 
-        /// <summary>
-        /// 删除企业关联学校
-        /// </summary>
-        /// <param name="jsonElement"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin,rdc,assist")]
-        [HttpPost("del-school")]
-        public async Task<IActionResult> DelSchool(JsonElement jsonElement)
-        {
-            if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
-            if (!jsonElement.TryGetProperty("schools", out JsonElement _schools)) return BadRequest();
-            jsonElement.TryGetProperty("site", out JsonElement site);
-            var (tmdId, tmdName, pic, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
-
-            List<BizSchool> bizSchool = _schools.ToObject<List<BizSchool>>();
-            var cosmosClient = _azureCosmos.GetCosmosClient();
-            var tableClient = _azureStorage.GetCloudTableClient();
-            var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
-            if ($"{site}".Equals(BIConst.Global))
-            {
-                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
-                tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
-                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
-            }
-
-            StringBuilder strMsg = new($"{tmdName}[{tmdId}]关联企业ID:{id},学校列表:");
-
-            BizConfig bizConfig = new();
-            var response = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync($"{id}", new PartitionKey("BizConfig"));
-            if (response.Status == RespondCode.Ok)
-            {
-                using var json = await JsonDocument.ParseAsync(response.ContentStream);
-                bizConfig = json.ToObject<BizConfig>();
-                foreach (var item in bizSchool)
-                {
-                    var temp = bizConfig.schools.Find(f => f.id.Equals(item.id));
-                }
-                bizConfig = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<BizConfig>(bizConfig, bizConfig.id, new PartitionKey("BizConfig"));
-            }
-            else return Ok(new { state = RespondCode.NotFound, msg = "未找到该企业" });
-
-            //保存操作记录
-            await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "bizconfig-addSchool", strMsg.ToString(), _dingDing, httpContext: HttpContext);
-
-            return Ok(new { state = RespondCode.Ok, bizConfig });
-        }
-
-
     }
 }

+ 21 - 16
TEAMModelBI/Controllers/BINormal/BusinessUsersController.cs

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Options;
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
@@ -89,13 +90,14 @@ namespace TEAMModelBI.Controllers.BINormal
             string type = "";
             if (string.IsNullOrEmpty(bizUsers.id))
             {
+
                 bizUsers.id = Guid.NewGuid().ToString();
                 bizUsers.code = "BizUsers";
                 bizUsers.name = string.IsNullOrEmpty(bizUsers.name)? bizUsers.mobile.ToString(): bizUsers.name;
 
                 bizUsers.salt = salt;
                 bizUsers.pwd = string.IsNullOrEmpty(bizUsers.pwd) ? Utils.HashedPassword(bizUsers.mobile.ToString(), salt) : Utils.HashedPassword(bizUsers.pwd, salt);
-
+                
                 bizUsers = await cosmosClient.GetContainer("TEAMModelOS", "Normal").CreateItemAsync<BizUsers>(bizUsers, new PartitionKey("BizUsers"));
                 strMsg.Append($"{bizUsers.name}【{bizUsers.id}】新增第三方用户信息基础信息。");
                 type = "bizuser-add";
@@ -111,7 +113,7 @@ namespace TEAMModelBI.Controllers.BINormal
                     bizUsers.pk = "Business";
                     bizUsers.code = "BizUsers";
                     bizUsers.ttl = -1;
-
+                    bizUsers.relation = tempbizUsers.relation;
                     bizUsers.salt = tempbizUsers.salt;
                     bizUsers.pwd = tempbizUsers.pwd;
                     bizUsers = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<BizUsers>(bizUsers, bizUsers.id, new PartitionKey("BizUsers"));
@@ -153,7 +155,7 @@ namespace TEAMModelBI.Controllers.BINormal
             BizUsers bizUsers = new();
             StringBuilder strMsg = new($"{tmdName}[{tmdId}]操作:");
             string salt = Utils.CreatSaltString(8);
-            var response = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync($"{id}", new PartitionKey("BizConfig"));
+            var response = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync($"{id}", new PartitionKey("BizUsers"));
             if (response.Status == 200)
             {
                 using var json = await JsonDocument.ParseAsync(response.ContentStream);
@@ -163,7 +165,7 @@ namespace TEAMModelBI.Controllers.BINormal
 
                 strMsg.Append($"重置{bizUsers.name}【{bizUsers.id}】的密码,重置成功!");
                 bizUsers = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<BizUsers>(bizUsers, bizUsers.id, new PartitionKey("BizUsers"));
-            }
+            }else return Ok(new { state = RespondCode.NotFound, msg="未找到该用户信息" });
 
             //保存操作记录
             await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "bizuser-reset", strMsg.ToString(), _dingDing, httpContext: HttpContext);
@@ -182,6 +184,7 @@ namespace TEAMModelBI.Controllers.BINormal
         {
             if(!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
             if (!jsonElement.TryGetProperty("bizs", out JsonElement _bizs)) return BadRequest();
+            if (!jsonElement.TryGetProperty("type", out JsonElement type)) return BadRequest();
             jsonElement.TryGetProperty("site", out JsonElement site);
             var (tmdId, tmdName, pic, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
 
@@ -197,14 +200,14 @@ namespace TEAMModelBI.Controllers.BINormal
                 blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
             }
 
-            StringBuilder strMsg = new($"{tmdName}[{tmdId}]");
-            if (string.IsNullOrEmpty("add"))
+            StringBuilder strMsg = new($"{tmdName}[{tmdId}]");
+            if ($"{type}".Equals("add"))
             {
-                strMsg.Append($"关联企业ID:{id},学校列表:");
+                strMsg.Append($"用户【{id}】关联企业信息:添加企业:");
             }
-            else if (string.IsNullOrEmpty("del"))
+            else if ($"{type}".Equals("del"))
             {
-                strMsg.Append("移除企业学校信息,学校列表:");
+                strMsg.Append($"用户【{id}】移除企业信息,移除企业:");
             }
             else { return Ok(new { state = RespondCode.ParamsError, msg = "类型错误" }); }
 
@@ -218,24 +221,26 @@ namespace TEAMModelBI.Controllers.BINormal
                 bizUsers = json.ToObject<BizUsers>();
                 foreach (var item in bizRels)
                 {
-                    var temp = bizUsers.relation.Find(f => f.bizId.Equals(item.bizId));
-                    if (string.IsNullOrEmpty("add"))
+                    var temp = bizUsers.relation.Find(f => f.bizId == item.bizId);
+                    if ($"{type}".Equals("add"))
                     {
-                        if (temp == null)
+                        if (temp != null)
+                            noBizRel.Add(item);
+                        else
                         {
                             bizUsers.relation.Add(item);
                             strMsg.Append($"{item.name}[{item.bizId}]|");
                         }
-                        else
-                            noBizRel.Add(temp);
                     }
-                    else if (string.IsNullOrEmpty("del"))
+                    else if ($"{type}".Equals("del"))
                     {
                         if (temp != null)
                         {
-                            bizUsers.relation.Remove(temp);
+                            bizUsers.relation.Add(item);
                             strMsg.Append($"{item.name}[{item.bizId}]|");
                         }
+                        else
+                            noBizRel.Add(item);
                     }
                 }
 

+ 2 - 2
TEAMModelBI/Controllers/LoginController.cs

@@ -793,7 +793,7 @@ namespace TEAMModelBI.Controllers
                         openid_token = JwtAuthExtension.CreateBizLoginAuthToken(_option.HostName, businessUsers.id?.ToString(), businessUsers.name?.ToString(), businessUsers.picture?.ToString(), $"{_option.Location}-Open", _option.JwtSecretKey, expire: 3);
 
                         await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{businessUsers.name}【{businessUsers.id}】登录开放平台", _dingDing, tid: businessUsers.id, tname: businessUsers.name, twebsite: "Open", httpContext: HttpContext);
-                    };
+                    }
                 }
             }
             else return Ok(new { state = RespondCode.NotFound, msg = "未找到该用户!" });
@@ -851,7 +851,7 @@ namespace TEAMModelBI.Controllers
                     id = Guid.NewGuid().ToString(),
                     code = "BizUsers",
                     name = string.IsNullOrEmpty($"{name}") ? $"{mobile}" : $"{name}",
-                    mobile = mobile.GetInt32(),
+                    mobile = mobile.GetInt64(),
                     salt = salt,
                     pwd = string.IsNullOrEmpty($"{pwd}") ? Utils.HashedPassword($"{mobile}", salt) : Utils.HashedPassword($"{pwd}", salt),
                 };

+ 2 - 2
TEAMModelOS.SDK/Models/Cosmos/BI/BINormal/BizConfig.cs

@@ -42,7 +42,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI.BINormal
         /// <summary>
         /// 企业开放的学校列表
         /// </summary>
-        public List<BizSchool> schools { get; set; }
+        public List<BizSchool> schools { get; set; } = new List<BizSchool>();
 
         /// <summary>
         /// 企业邮箱
@@ -118,7 +118,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI.BINormal
         /// <summary>
         /// 企业关联信息
         /// </summary>
-        public List<BizRel> relation { get; set; }
+        public List<BizRel> relation { get; set; } = new List<BizRel>();
 
         /// <summary>
         /// 密码生成秘钥