|
@@ -0,0 +1,94 @@
|
|
|
+using Azure.Cosmos;
|
|
|
+using HTEXLib.COMM.Helpers;
|
|
|
+using HTEXLib.DOCX.Models;
|
|
|
+using Microsoft.Azure.Functions.Worker;
|
|
|
+using Microsoft.Azure.Functions.Worker.Http;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Net;
|
|
|
+using System.Text;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+
|
|
|
+namespace TEAMModelOS.FunctionV4.HttpTrigger
|
|
|
+{
|
|
|
+ public class IESHttpTrigger
|
|
|
+ {
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ private readonly AzureRedisFactory _azureRedis;
|
|
|
+ public IESHttpTrigger(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage
|
|
|
+ , AzureRedisFactory azureRedis)
|
|
|
+ {
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _azureRedis = azureRedis;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 数据推送接口
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="req"></param>
|
|
|
+ /// <param name="log"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Function("KnowledgeChange")]
|
|
|
+ public async Task<HttpResponseData> KnowledgeChange([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<OldNew> 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<OldNew>>();
|
|
|
+ }
|
|
|
+ if (old_new.IsNotEmpty() && !string.IsNullOrWhiteSpace(school))
|
|
|
+ {
|
|
|
+ foreach (var on in old_new)
|
|
|
+ {
|
|
|
+ List<ItemInfo> items = new List<ItemInfo>();
|
|
|
+ string sql = $"select value(c) from c where array_contains(c.knowledge,'{on._old}') ";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>
|
|
|
+ (queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{_school}") }))
|
|
|
+ {
|
|
|
+ items.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ items.ForEach(item => {
|
|
|
+ //修改知识点
|
|
|
+ if (!string.IsNullOrEmpty(on._new))
|
|
|
+ {
|
|
|
+ for (int i = 0; i < item.knowledge.Count; i++)
|
|
|
+ {
|
|
|
+ if (item.knowledge[i].Equals(on._old))
|
|
|
+ {
|
|
|
+ item.knowledge[i] = on._new;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //表示删除知识点
|
|
|
+ item.knowledge.RemoveAll(x => x.Equals(on._old));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|