Explorar el Código

Merge branch 'develop' into liqk/develop

liqk hace 2 años
padre
commit
4e94d6b8ab

+ 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 string workDesc { get; set; }
         public long workEnd { get; set; }
-        public JsonElement examInfo { get; set; }
+        public string infoId { get; set; }
     }
 }

+ 32 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/ArtExam.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.Common
+{
+    public  class ArtExam : CosmosEntity
+    {
+        public ArtExam()
+        {
+            pk = "ArtExam";
+        }
+        public string infoId { get; set; }
+        public string activityId { get; set; }
+        public string schoolId { get; set; }
+        public string name { get; set; }
+        public string blob { get; set; }
+        public int count { get; set; }
+        public string periodId { get; set; }
+        public string periodName { get; set; }
+        public List<string> periodTypes { get; set; } = new List<string>();
+        public string subjectId { get; set; }
+        public string subjectBindId { get; set; }
+        public long createTime { get; set; }
+        public List<string> gradeIds { get; set; } = new List<string>();
+
+
+    }
+}

+ 27 - 3
TEAMModelOS/Controllers/Common/AreaController.cs

@@ -387,14 +387,16 @@ namespace TEAMModelOS.Controllers
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "teacher,admin")]
         [HttpPost("save-art")]
-        [Authorize(Roles = "IES")]
+        //[Authorize(Roles = "IES")]
         public async Task<IActionResult> SaveArt(JsonElement request)
         {
             try
             {
                 if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
                 if (!request.TryGetProperty("art", out JsonElement art)) return BadRequest();
+                if (!request.TryGetProperty("artExam", out JsonElement artExam)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
+                List<ArtExam> am = artExam.ToObject<List<ArtExam>>();
                 var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
                 //获取区级以下所有学校编码和基础信息
                 List<string> baseIds = new();
@@ -425,7 +427,12 @@ namespace TEAMModelOS.Controllers
                 if (string.IsNullOrEmpty(areaArt.id))
                 {
                     areaArt.id = Guid.NewGuid().ToString();
-                }                
+                }
+                foreach (var aExam in am) {
+                    aExam.id = Guid.NewGuid().ToString();
+                    aExam.activityId = areaArt.id;
+                    await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(aExam, new PartitionKey("{ArtExam}"));
+                }
                 foreach (string scId in baseIds)
                 {
                     ArtEvaluation ae = art.ToObject<ArtEvaluation>();
@@ -562,8 +569,25 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
                 //区级id
                 if (!request.TryGetProperty("areaId", out JsonElement code)) return BadRequest();
-                var client = _azureCosmos.GetCosmosClient();                
+                var client = _azureCosmos.GetCosmosClient();
+                List<string> ide = new();
                 var response = await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Art-{code}"));
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select c.id,c.code from c where c.activityId = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ArtExam") }))
+                {
+
+                    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;
+                            ide.Add(account.GetProperty("id").GetString());
+                        }
+                    }
+
+                }
+                await client.GetContainer("TEAMModelOS", "Common").DeleteItemsAsync<ArtExam>(ide, "ArtExam");
                 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)