浏览代码

Merge branch 'develop' of http://52.130.252.100:10000/TEAMMODEL/TEAMModelOS into develop

OnePsycho 2 年之前
父节点
当前提交
93f79ba101

+ 58 - 0
TEAMModelBI/Controllers/BINormal/BusinessController.cs

@@ -275,5 +275,63 @@ namespace TEAMModelBI.Controllers.BINormal
             return Ok(new { state = RespondCode.Ok, bizConfig });
         }
 
+        /// <summary>
+        /// 查询所有学校 如果传企业ID则查询与企业没有关联的学校
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-schools")]
+        public async Task<IActionResult> GetSchools(JsonElement jsonElement)
+        {
+            jsonElement.TryGetProperty("id", out JsonElement id);
+            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.Global))
+            {
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
+                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
+            }
+
+            List<OpenSchool> openSchools = new();
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<OpenSchool>(queryText: "select c.id,c.code,c.name,c.picture from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+            {
+                openSchools.Add(item);
+            }
+            BizConfig bizConfig = new();
+            if (!string.IsNullOrEmpty($"id"))
+            {
+                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>();
+                    if (bizConfig.schools.Count > 0)
+                    {
+                        foreach (var item in bizConfig.schools)
+                        {
+                            var temp = openSchools.Find(f => f.id.Equals(item.id));
+                            if (temp != null)
+                                openSchools.Remove(temp);
+                        }
+                    }
+                }
+            }
+
+            return Ok(new { state = RespondCode.Ok , openSchools });
+        }
+
+
+        public record OpenSchool
+        {
+            public string id { get; set; }
+            public string code { get; set; }
+            public string name { get; set; }
+            public string picture { get; set; }
+        }
     }
 }

+ 0 - 38
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -1067,36 +1067,6 @@ namespace TEAMModelBI.Controllers.BISchool
             }
         }
 
-        /// <summary>
-        /// 查询所有学校  第三方开放平台关联学校显示所有学校
-        /// </summary>
-        /// <param name="jsonElement"></param>
-        /// <returns></returns>
-        [HttpPost("get-applyschools")]
-        public async Task<IActionResult> GetApplySchools(JsonElement jsonElement)
-        {
-            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.Global))
-            {
-                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
-                tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
-                blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
-            }
-
-            List<ApplySchool> applySchools = new();
-
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ApplySchool>(queryText: "select c.id,c.code,c.name,c.picture from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
-            {
-                applySchools.Add(item);
-            }
-
-            return Ok(new { state = 200, applySchools });
-        }
-
-
         /// <summary>
         /// 通过学校Id查询详情   数据管理工具——查询工具
         /// </summary>
@@ -2023,14 +1993,6 @@ namespace TEAMModelBI.Controllers.BISchool
 
         #endregion
 
-        public record ApplySchool
-        {
-            public string id { get; set; }
-            public string code { get; set; }
-            public string name { get; set; }
-            public string picture { get; set; }
-        }
-
         /// <summary>
         /// 未加入区域的学校
         /// </summary>

+ 63 - 2
TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

@@ -70,6 +70,67 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             return response;
 
 
+        }
+        /// <summary>
+        /// 数据推送接口
+        /// </summary>
+        /// <param name="req"></param>
+        /// <param name="log"></param>
+        /// <returns></returns>
+        [Function("lesson-tag-change")]
+        public async Task<HttpResponseData> LessonTagChange([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req) {
+            var response = req.CreateResponse(HttpStatusCode.OK);
+            string data = await new StreamReader(req.Body).ReadToEndAsync();
+            var json = JsonDocument.Parse(data).RootElement;
+            List<TagOldNew> old_new = null;
+            string school = null;
+            if (json.TryGetProperty("school", out JsonElement _school))
+            {
+                school = _school.GetString();
+            }
+            if (json.TryGetProperty("old_new", out JsonElement _old_new))
+            {
+                old_new = _old_new.ToObject<List<TagOldNew>>();
+            }
+            if (old_new.IsNotEmpty() && !string.IsNullOrWhiteSpace(school))
+            {
+                foreach (var on in old_new)
+                {
+                    List<LessonRecord> lessonRecords = new List<LessonRecord>();
+                    string sql = $"select value(c) from c    where array_contains(c.category,'{on._old}') ";
+                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonRecord>
+                        (queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{_school}") }))
+                    {
+                        lessonRecords.Add(item);
+                    }
+
+                    lessonRecords.ForEach(item =>
+                    {
+                        //修改标签
+                        if (!string.IsNullOrWhiteSpace(on._new))
+                        {
+                            for (int i = 0; i < item.category.Count; i++)
+                            {
+                                if (item.category[i].Equals(on._old))
+                                {
+                                    item.category[i] = on._new;
+                                }
+                            }
+                        }
+                        else
+                        {
+                            //表示删除标签
+                            item.category.RemoveAll(x => x.Equals(on._old));
+                        }
+                    });
+                    foreach (var item in lessonRecords)
+                    {
+                        await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
+                    }
+                }
+            }
+            await response.WriteAsJsonAsync(new { data = json });
+            return response;
         }
         /// <summary>
         /// 数据推送接口
@@ -83,7 +144,7 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             var response = req.CreateResponse(HttpStatusCode.OK);
             string data = await new StreamReader(req.Body).ReadToEndAsync();
             var json = JsonDocument.Parse(data).RootElement;
-            List<OldNew> old_new = null;
+            List<TagOldNew> old_new = null;
             string school = null;
             if (json.TryGetProperty("school", out JsonElement _school))
             {
@@ -91,7 +152,7 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             }
             if (json.TryGetProperty("old_new", out JsonElement _old_new))
             {
-                old_new = _old_new.ToObject<List<OldNew>>();
+                old_new = _old_new.ToObject<List<TagOldNew>>();
             }
             if (old_new.IsNotEmpty() && !string.IsNullOrWhiteSpace(school))
             {

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/School/Knowledge.cs

@@ -39,7 +39,7 @@ namespace TEAMModelOS.SDK.Models
         public List<Block> blocks { get; set; } = new List<Block>();
 
     }
-    public class OldNew
+    public class TagOldNew
     {
         [Required(ErrorMessage = "_old 必须设置")]
         public string _old { get; set; }

+ 2 - 2
TEAMModelOS/Controllers/School/KnowledgesController.cs

@@ -122,10 +122,10 @@ namespace TEAMModelOS.Controllers
         {
             if (!json.TryGetProperty("school", out JsonElement school)) return BadRequest();
             Knowledge knowledge = json.GetProperty("knowledge").ToObject<Knowledge>();
-            List<OldNew> old_new = null;
+            List<TagOldNew> old_new = null;
             if (json.TryGetProperty("old_new", out JsonElement _old_new))
             {
-                old_new = _old_new.ToObject<List<OldNew>>();
+                old_new = _old_new.ToObject<List<TagOldNew>>();
             }
             ValidResult validResult = knowledge.Valid();
             if (!validResult.isVaild)

+ 24 - 3
TEAMModelOS/Controllers/School/SchoolSettingController.cs

@@ -15,6 +15,8 @@ using Microsoft.Extensions.Options;
 using Microsoft.Extensions.Configuration;
 using TEAMModelOS.Filter;
 using Microsoft.AspNetCore.Authorization;
+using HTEXLib.COMM.Helpers;
+using System.Linq;
 
 namespace TEAMModelOS.Controllers
 {
@@ -30,8 +32,9 @@ namespace TEAMModelOS.Controllers
         private readonly AzureRedisFactory _azureRedis;
         private readonly DingDing _dingDing;
         private readonly Option _option;
-        private readonly IConfiguration _configuration;
-        public SchoolSettingController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration)
+        private readonly IConfiguration _configuration; 
+        private readonly HttpTrigger _httpTrigger;
+        public SchoolSettingController(HttpTrigger httpTrigger, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration)
         {
             _azureCosmos = azureCosmos;
             _azureStorage = azureStorage;
@@ -39,6 +42,7 @@ namespace TEAMModelOS.Controllers
             _dingDing = dingDing;
             _option = option?.Value;
             _configuration = configuration;
+            _httpTrigger = httpTrigger;
         }
 
         /*
@@ -138,6 +142,23 @@ namespace TEAMModelOS.Controllers
                 case bool when $"{_opt}".Equals("UpsertLessonTag", StringComparison.OrdinalIgnoreCase) && (json.TryGetProperty("lessonTag", out JsonElement _lessonTag)):
                     HashSet <string> lessonTag = _lessonTag.ToObject<HashSet<string>>();
                     setting.lessonTag = lessonTag;
+                    List<TagOldNew> old_new = null;
+                    if (json.TryGetProperty("old_new", out JsonElement _old_new))
+                    {
+                        old_new = _old_new.ToObject<List<TagOldNew>>();
+                    }
+                    //处理标签删除的问题。
+                    if (old_new.IsNotEmpty()  && lessonTag != null)
+                    {
+                        try
+                        {
+                            _ = _httpTrigger.RequestHttpTrigger(new { old_new = old_new, school = $"{_school}" }, _option.Location, "lesson-tag-change");
+                        }
+                        catch (Exception ex)
+                        {
+                            //暂不处理
+                        }
+                    }
                     break;
                 case bool when $"{_opt}".Equals("UpsertLessonSetting", StringComparison.OrdinalIgnoreCase) && (json.TryGetProperty("lessonSetting", out JsonElement _lessonSetting)):
                     LessonSetting lessonSetting = _lessonSetting.ToObject<LessonSetting>();
@@ -145,7 +166,7 @@ namespace TEAMModelOS.Controllers
                     break;
                 default: break;
             }
-            await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<SchoolSetting>(setting, partitionKey: new Azure.Cosmos.PartitionKey("SchoolSetting"));
+            await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolSetting>(setting,setting.id, partitionKey: new Azure.Cosmos.PartitionKey("SchoolSetting"));
             return Ok(new { setting });
         }
     }