zhouj1203@hotmail.com 2 years ago
parent
commit
e352ae0886

+ 5 - 29
TEAMModelOS.FunctionV4/CosmosDB/TriggerArt.cs

@@ -243,7 +243,7 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
                             {
                                 if (art.owner.Equals("area") && string.IsNullOrEmpty(art.pId))
                                 {
-                                    List<(string id, string code, List<Tasks> settings)> artSchools = new();
+                                   /* List<(string id, string code, List<Tasks> settings)> artSchools = new();
                                     string ql = $"select c.id,c.school,c.settings,c.classes from c where  c.pk = 'Art' and c.pId = '{art.id}'";
                                     await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: ql))
                                     {
@@ -291,13 +291,13 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
 
                                     }
                                     art.pass = 1;
-                                    await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ArtEvaluation>(art, art.id, new PartitionKey(art.code));
+                                    await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ArtEvaluation>(art, art.id, new PartitionKey(art.code));*/
                                 }
                                 else
                                 {
                                     //获取当前艺术评价相关评测ID目前暂时排除区级发布的评测信息
 
-                                    List<(string eId, string sId)> ids = new();
+                                    /*List<(string eId, string sId)> ids = new();
                                     var examId = art.settings.SelectMany(x => x.task).Where(c => c.type == 1).Select(z => new { z.acId, z.subject }).ToList();
                                     examId.ForEach(x =>
                                     {
@@ -326,7 +326,7 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
                                     art.miss.Add(stus.Count);
                                     //art.miss = stus.Count;
                                     art.pass = 1;
-                                    await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ArtEvaluation>(art, art.id, new PartitionKey(art.code));
+                                    await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ArtEvaluation>(art, art.id, new PartitionKey(art.code));*/
                                 }
                             }
                             List<StudentArtResult> studentArtResults = new();
@@ -362,30 +362,6 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
             }
 
         }
-        public static async Task<List<(string code, string subject, List<string> stus)>> getLostAsync(List<(string eId, string sId)> examIds, CosmosClient client, string code)
-        {
-            List<(string code, string sub, List<string> stu)> stuInfo = new();
-            if (examIds.Any())
-            {
-                string examSql = $"select c.id,c.school,c.lostStu from c where c.id in ({string.Join(",", examIds.Select(o => $"'{o.eId}'"))})";
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: examSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Exam-{code}") }))
-                {
-                    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;
-                            List<string> lostStu = account.GetProperty("lostStu").ToObject<List<string>>();
-                            string id = account.GetProperty("id").GetString();
-                            string sub = examIds.Where(c => c.eId.Equals(id)).FirstOrDefault().sId;
-                            stuInfo.Add((account.GetProperty("school").GetString(), sub, lostStu));
-                        }
-                    }
-                }
-            }
-            return stuInfo;
-        }
+        
     }
 }

+ 63 - 0
TEAMModelOS/Controllers/Common/ArtController.cs

@@ -712,6 +712,43 @@ namespace TEAMModelOS.Controllers.Common
                 if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
                 ArtEvaluation art = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ArtEvaluation>(id.GetString(), new PartitionKey($"Art-{code}"));
+
+                if (art.owner.Equals("area") && string.IsNullOrEmpty(art.pId))
+                {
+
+                }
+                else {
+                    List<(string eId, string sId)> ids = new();
+                    var examId = art.settings.SelectMany(x => x.task).Where(c => c.type == 1).Select(z => new { z.acId, z.subject }).ToList();
+                    examId.ForEach(x =>
+                    {
+                        ids.Add((x.acId, x.subject));
+                    });
+                    List<(string scode, string sub, List<string> stu)> stuInfo = await getLostAsync(ids, client, art.school);
+                    List<string> stus = new();
+                    foreach (var (scode, sub, stu) in stuInfo)
+                    {
+                        if (stus.Count == 0)
+                        {
+                            stus = stus.Union(stu).ToList();
+                        }
+                        else
+                        {
+                            stus = stus.Intersect(stu).ToList();
+                        }
+                        LostStudent lostStudent = new()
+                        {
+                            code = scode,
+                            subject = sub,
+                            stu = stu.Count
+                        };
+                        art.lost.Add(lostStudent);
+                    }
+                    art.miss.Add(stus.Count);
+                }
+                //art.miss = stus.Count;
+                //art.pass = 1;
+                //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ArtEvaluation>(art, art.id, new PartitionKey(art.code));
                 ArtMusic music = new();
                 ArtExam ae = new();
                 if (art != null)
@@ -850,6 +887,32 @@ namespace TEAMModelOS.Controllers.Common
 
         }
 
+        public static async Task<List<(string code, string subject, List<string> stus)>> getLostAsync(List<(string eId, string sId)> examIds, CosmosClient client, string code)
+        {
+            List<(string code, string sub, List<string> stu)> stuInfo = new();
+            if (examIds.Any())
+            {
+                string examSql = $"select c.id,c.school,c.lostStu from c where c.id in ({string.Join(",", examIds.Select(o => $"'{o.eId}'"))})";
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: examSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Exam-{code}") }))
+                {
+                    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;
+                            List<string> lostStu = account.GetProperty("lostStu").ToObject<List<string>>();
+                            string id = account.GetProperty("id").GetString();
+                            string sub = examIds.Where(c => c.eId.Equals(id)).FirstOrDefault().sId;
+                            stuInfo.Add((account.GetProperty("school").GetString(), sub, lostStu));
+                        }
+                    }
+                }
+            }
+            return stuInfo;
+        }
+
         [ProducesDefaultResponseType]
         [Authorize(Roles = "IES")]
         [AuthToken(Roles = "teacher,admin,student")]