瀏覽代碼

处理评测查询

zhouj1203@hotmail.com 3 年之前
父節點
當前提交
cb352e3c91
共有 1 個文件被更改,包括 28 次插入33 次删除
  1. 28 33
      TEAMModelOS/Controllers/Common/ExamController.cs

+ 28 - 33
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -1141,7 +1141,7 @@ namespace TEAMModelOS.Controllers
                             {
                                 try
                                 {
-                                    /*var response = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Activity-{result.school}-{s.id}"));
+                                    var response = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Activity-{result.school}-{s.id}"));
                                     if (response.Status == 200)
                                     {
                                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
@@ -1172,10 +1172,10 @@ namespace TEAMModelOS.Controllers
                                             activity.sStatus = 1;
                                             tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}")));
                                         }
-                                    }*/
-                                    StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{result.scIds[index]}-{s.id}"));
+                                    }
+                                    /*StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{result.scIds[index]}-{s.id}"));
                                     activity.sStatus = 1;
-                                    await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{result.scIds[index]}-{s.id}"));
+                                    await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{result.scIds[index]}-{s.id}"));*/
 
                                 }
                                 catch (Exception ex)
@@ -1265,13 +1265,13 @@ namespace TEAMModelOS.Controllers
         public async Task<IActionResult> findSummaryRecord(JsonElement requert)
         {
             //var (id, school) = HttpContext.GetAuthTokenInfo();
+            if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
+            //if (!requert.TryGetProperty("code", out JsonElement school_code)) return BadRequest();
+            if (!requert.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
+            if (!requert.TryGetProperty("code", out JsonElement school_code)) return BadRequest();
+            if (!requert.TryGetProperty("classId", out JsonElement classId)) return BadRequest();
             try
-            {
-                if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
-                //if (!requert.TryGetProperty("code", out JsonElement school_code)) return BadRequest();
-                if (!requert.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
-                if (!requert.TryGetProperty("code", out JsonElement school_code)) return BadRequest();
-                if (!requert.TryGetProperty("classId", out JsonElement classId)) return BadRequest();
+            {              
                 // 如果只有学生id则返回学生参加过的考试 只返回相关摘要信息
                 var client = _azureCosmos.GetCosmosClient();
                 var (_, _, _, school) = HttpContext.GetAuthTokenInfo();
@@ -1284,46 +1284,41 @@ namespace TEAMModelOS.Controllers
                     examClassResults.Add(item);
                 }
                 List<string> ids = new();
-                List<string> codes = new();
+                //List<string> codes = new();
                 foreach (ExamClassResult result in examClassResults)
                 {
                     ids.AddRange(result.studentIds);
-                    codes.AddRange(result.scIds);
+                    //codes.AddRange(result.scIds);
                 }
                 ///获取真实的名称 
                 List<ufo> ufos = new();
                 List<string> delIds = new();
-                List<ufo> students = new List<ufo>();
+                //List<ufo> students = new List<ufo>();
                 if (ids.Count > 0)
                 {
                     List<string> sIds = new();
                     List<string> tIds = new();
-                    foreach (var s in ids)
+                    List<ufo> students = new List<ufo>();
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select distinct c.id,c.name from c where c.id in ({string.Join(",", ids.Select(o => $"'{o}'"))}) and c.pk = 'Base'",requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school}") }))
                     {
-                        int index = ids.IndexOf(s);
-                        string code = codes[index];
-                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select distinct c.id,c.name from c where c.id = '{s}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{code}") }))
+                        using var stuJson = await JsonDocument.ParseAsync(item.ContentStream);
+                        if (stuJson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                         {
-                            using var stuJson = await JsonDocument.ParseAsync(item.ContentStream);
-                            if (stuJson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                            var accounts = stuJson.RootElement.GetProperty("Documents").EnumerateArray();
+                            while (accounts.MoveNext())
                             {
-                                var accounts = stuJson.RootElement.GetProperty("Documents").EnumerateArray();
-                                while (accounts.MoveNext())
+                                JsonElement account = accounts.Current;
+                                ufo fo = new()
                                 {
-                                    JsonElement account = accounts.Current;
-                                    ufo fo = new()
-                                    {
-                                        id = account.GetProperty("id").GetString(),
-                                        name = account.GetProperty("name").GetString(),
-                                        //schoolId = account.GetProperty("schoolId").GetString(),
-                                        type = 2
-                                    };
-                                    students.Add(fo);
-                                }
+                                    id = account.GetProperty("id").GetString(),
+                                    name = account.GetProperty("name").GetString(),
+                                    //schoolId = account.GetProperty("schoolId").GetString(),
+                                    type = 2
+                                };
+                                students.Add(fo);
                             }
                         }
                     }
-
                     if (students.Count > 0)
                     {
                         ufos.AddRange(students);
@@ -1431,7 +1426,7 @@ namespace TEAMModelOS.Controllers
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},exam/findSummaryRecord()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},exam/findSummaryRecord()\n{ex.Message}\n{ex.StackTrace}\n{id.GetString()}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }