Browse Source

新增接口

zhouj1203@hotmail.com 2 năm trước cách đây
mục cha
commit
56a5f3d63a

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/ArtEvaluation.cs

@@ -84,6 +84,6 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         public int? type { get; set; } = 0;
         public int? type { get; set; } = 0;
         public string workDesc { get; set; }
         public string workDesc { get; set; }
         public long workEnd { get; set; }
         public long workEnd { get; set; }
-        public List<JsonElement> examInfo { get; set; } = new List<JsonElement>();
+        public JsonElement examInfo { get; set; }
     }
     }
 }
 }

+ 91 - 0
TEAMModelOS/Controllers/Common/AreaController.cs

@@ -509,6 +509,97 @@ namespace TEAMModelOS.Controllers
 
 
         }
         }
 
 
+
+        [ProducesDefaultResponseType]
+        [Authorize(Roles = "IES")]
+        //[AuthToken(Roles = "teacher,admin")]
+        [HttpPost("find-all-art")]
+        public async Task<IActionResult> FindAllArt(JsonElement request)
+        {
+            try
+            {
+                //区级Id
+                if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                var client = _azureCosmos.GetCosmosClient();
+                // List<string> baseIds = await getId(client, id.GetString());
+                List<object> arts = new();
+
+                var query = $"select c.id,c.name,c.type,c.startTime,c.endTime,c.presenter,c.topic,c.address,c.owner,c.school from c order by c.createTime desc";
+
+
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"art-{id}") }))
+                {
+
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            arts.Add(obj.ToObject<object>());
+                        }
+                    }
+                }
+
+                return Ok(new { arts });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},area/find-all-art()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+
+        }
+
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "teacher,admin")]
+        [HttpPost("delete-art")]
+        [Authorize(Roles = "IES")]
+        public async Task<IActionResult> DeleteArt(JsonElement request)
+        {
+            try
+            {
+                //区级活动Id
+                if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                //区级id
+                if (!request.TryGetProperty("areaId", out JsonElement code)) return BadRequest();
+                var client = _azureCosmos.GetCosmosClient();                
+                var response = await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Art-{code}"));
+                List<(string id, string name)> bascId = await getId(client, code.GetString());
+                List<(string id, string name)> ids = new();
+                foreach ((string sId, string name) in bascId)
+                {
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select c.id,c.code from c where c.pId = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Art-{sId}") }))
+                    {
+
+                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                        {
+                            var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                            while (accounts.MoveNext())
+                            {
+                                JsonElement account = accounts.Current;
+                                ids.Add((account.GetProperty("id").GetString(), account.GetProperty("code").GetString()));
+                            }
+                        }
+
+                    }
+                }
+                if (ids.Count > 0)
+                {
+                    foreach ((string s, string c) in ids)
+                    {                      
+                        await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(s.ToString(), new PartitionKey($"{c}"));
+                    }
+                }
+                return Ok(new { id, code = response.Status });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},area/delete-art()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
         [Authorize(Roles = "IES")]
         [Authorize(Roles = "IES")]
         //[AuthToken(Roles = "teacher,admin")]
         //[AuthToken(Roles = "teacher,admin")]