Procházet zdrojové kódy

Merge branch 'develop5.0-tmd' of http://106.12.23.251:10000/TEAMMODEL/TEAMModelOS into develop5.0-tmd

liqk před 3 roky
rodič
revize
8ec832184f
1 změnil soubory, kde provedl 71 přidání a 8 odebrání
  1. 71 8
      TEAMModelOS/Controllers/Common/ExamController.cs

+ 71 - 8
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -612,7 +612,8 @@ namespace TEAMModelOS.Controllers
         {
 
             if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
-            //if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
+            //学校编码
+            //if (!request.TryGetProperty("school", out JsonElement school)) return BadRequest();            
             if (!request.TryGetProperty("answer", out JsonElement answer)) return BadRequest();
             if (!request.TryGetProperty("studentId", out JsonElement studentId)) return BadRequest();
             if (!request.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
@@ -621,17 +622,79 @@ namespace TEAMModelOS.Controllers
             //if (!request.TryGetProperty("answers ", out JsonElement tandardAnswer)) return BadRequest();
             if (!request.TryGetProperty("paperId", out JsonElement paperId)) return BadRequest();
             //根据不同评测的类型返回对应的编码
-            if (!request.TryGetProperty("code", out JsonElement school)) return BadRequest();
+            if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
             if (!request.TryGetProperty("scode", out JsonElement scode)) return BadRequest();
             try
             {
                 List<string> ids = new List<string>();
                 ids = classId.ToObject<List<string>>();
                 var client = _azureCosmos.GetCosmosClient();
+                ExamInfo info = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.GetString(), new PartitionKey($"{scode}"));
+                //确定当前学生所在班级且该班级参与该活动
+                List<string> cIds = new();
+                foreach (string cId in ids)
+                {
+                    List<string> stus = new List<string>();
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(
+                    queryText: $"select c.classId as id from c where c.classId = '{cId}' and c.id = '{studentId}'",
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{info.school}") }))
+                    {
+                        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;
+                                stus.Add(account.GetProperty("id").GetString());
+                            }
+                        }
+                    }
+                    if (info.scope.Equals("private"))
+                    {
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(
+                        queryText: $"select c.id from c join A0 in c.students where c.id = '{cId}' and (A0.id = '{studentId}' and A0.schoolId = '{info.school}'or array_contains(c.tmids,'{studentId}'))",
+                        requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList") }))
+                        {
+                            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;
+                                    stus.Add(account.GetProperty("id").GetString());
+                                }
+                            }
+                        }
+                    }
+                    else
+                    {
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(
+                       queryText: $"select c.id from c join A0 in c.students where c.id = '{cId}' and A0.id = '{studentId}'",
+                       requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList-{info.school}") }))
+                        {
+                            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;
+                                    stus.Add(account.GetProperty("id").GetString());
+                                }
+                            }
+                        }
+                    }
+                    if(stus.Count > 0)
+                    {
+                        cIds.Add(cId);
+                    }
+                }                
                 List<ExamClassResult> examClassResults = new List<ExamClassResult>();
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(
-                    queryText: $"select value(c) from c where c.examId = '{id}' and c.subjectId = '{subjectId}' and c.info.id in ({string.Join(",", ids.Select(o => $"'{o}'"))})",
-                    requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{school}") }))
+                    queryText: $"select value(c) from c where c.examId = '{id}' and c.subjectId = '{subjectId}' and c.info.id in ({string.Join(",", cIds.Select(o => $"'{o}'"))})",
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
                 {
                     using var json = await JsonDocument.ParseAsync(item.ContentStream);
                     if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
@@ -717,7 +780,7 @@ namespace TEAMModelOS.Controllers
                     builder.Append("ans.json");
                     /*string FileName = result.examId + "/" + result.subjectId + "/" + studentId;
                     string blob = FileName + "/" + "ans.json";*/
-                    tasks.Add(_azureStorage.UploadFileByContainer(school.ToString(), ans.ToJsonString(), "exam", builder.ToString(), false));
+                    tasks.Add(_azureStorage.UploadFileByContainer(code.ToString(), ans.ToJsonString(), "exam", builder.ToString(), false));
                     result.studentAnswers[newIndex].Add(builder.ToString());
                     //}                  
                     //List<(int index ,string content, double count)> acount = new List<(int index,string content, double count)>();
@@ -1612,11 +1675,11 @@ namespace TEAMModelOS.Controllers
                         //item.scores.Where(x => x.tmdId.Equals(tId.GetString())).SelectMany(p => p.sc, (p, d) => new { });
                         if (scc.Count > 0)
                         {
-                            sc.Add(new { sc = scc.FirstOrDefault(),blob = blob.FirstOrDefault(), item.ssc });
+                            sc.Add(new { sc = scc.FirstOrDefault(), blob = blob.FirstOrDefault(), item.ssc });
                         }
                         else
                         {
-                            sc.Add(new { sc = ss.scores[indexScore], blob="",item.ssc });
+                            sc.Add(new { sc = ss.scores[indexScore], blob = "", item.ssc });
                         }
                         indexScore++;
                         //sc.Add(item.scores.Where(x => x.tmdId.Equals(tId.GetString())).Select(c => c.sc).FirstOrDefault());
@@ -2153,7 +2216,7 @@ namespace TEAMModelOS.Controllers
                                     foreach (Info info in items)
                                     {
                                         info.sc = ssc[number];
-                                        info.mark = marks.Count > 0 ? marks[number]:"";
+                                        info.mark = marks.Count > 0 ? marks[number] : "";
                                     }
                                 }
                                 else