zhouj1203@hotmail.com 2 年之前
父節點
當前提交
a88d2ec65b
共有 2 個文件被更改,包括 64 次插入2 次删除
  1. 62 2
      TEAMModelOS.FunctionV4/CosmosDB/TriggerExam.cs
  2. 2 0
      TEAMModelOS.SDK/Models/Cosmos/Student/ErrorItems.cs

+ 62 - 2
TEAMModelOS.FunctionV4/CosmosDB/TriggerExam.cs

@@ -1450,6 +1450,61 @@ namespace TEAMModelOS.FunctionV4
                         urls.Add(ne["url"].ToString());
                     }                   
                 }
+                string code = string.Empty;
+                string pk = string.Empty;
+                string table = "School";
+                if (info.scope.Equals("school"))
+                {
+                    code = $"ErrorItems-{info.school}";
+                    pk = $"Item-{info.school}";                    
+                }
+                else
+                {
+                    code = "ErrorItems";
+                    pk = $"Item-{info.creatorId}";
+                    table = "Teacher";
+                }
+                // 获取整体的题目ID集合
+               /* List<string> ids = new();
+                List<(string id, string pid, int level, string type)> itemInfos = new();
+                foreach (string url in urls) {
+                    string id = url.Replace(".json", "");
+                    BlobDownloadResult index_item_json;
+                    if (info.scope.Equals("school"))
+                    {
+                        index_item_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
+                    }
+                    else
+                    {
+                        index_item_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
+                    }
+                    JObject keys = JObject.Parse(index_item_json.Content.ToString());
+                    string type =  keys["exercise"].Value<string>("type");
+                    int level = keys["exercise"].Value<int>("level");
+                    string pid = keys.Value<string>("pid");
+                    itemInfos.Add((id,pid,level,type));
+                }*/
+
+
+                /*await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, table).GetItemQueryStreamIterator(
+                                    queryText: $"select c.id,c.pid,c.level,c.type from c where c.id in ({string.Join(",", ids.Select(o => $"'{o}'"))})", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{pk}") }))
+                {
+                    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;
+                            string pid = "";
+                            if (account.TryGetProperty("pid",out JsonElement element)) {
+                                pid = element.GetString();
+                            }
+                            itemInfos.Add((account.GetProperty("id").GetString(), pid, account.GetProperty("level").GetInt32(), account.GetProperty("type").GetString()));
+                        }
+                    }
+                }*/
+
                 double[] point = StringHelper.ListTodouble(result.paper.point);
                 double[,] res = StringHelper.ListToDouble(result.studentScores);
                 var cdm = new ClouDASMatrix(res, point);
@@ -1457,12 +1512,13 @@ namespace TEAMModelOS.FunctionV4
                 var ss = cdm.StriveTopic;
                 int n = 0;
                 List<Task<ItemResponse<ErrorItems>>> task_error = new();
+                
                 foreach (var sIds in result.studentIds)
                 {
                     ErrorItems error = new()
                     {
                         ttl = -1,
-                        code = "ErrorItems",
+                        code = code,
                         id = Guid.NewGuid().ToString(),
                         stuId = sIds,
                         school = info.school,
@@ -1475,9 +1531,13 @@ namespace TEAMModelOS.FunctionV4
                     {
                         Items items = new()
                         {
-                            id = urls[item-1].Replace(".json", ""),
+                            id = urls[item - 1].Replace(".json", ""),
                             blob = info.papers[no].blob
+                           
                         };
+                      /*  items.level = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().level;
+                        items.type = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().type;
+                        items.pId = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().pid;*/
                         error.its.Add(items);
                     }
                     n++;

+ 2 - 0
TEAMModelOS.SDK/Models/Cosmos/Student/ErrorItems.cs

@@ -26,6 +26,8 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Student
         public string id { get; set; }
         //所属blob
         public string blob { get; set; }
+        public int level { get; set; }
+        public string type { get; set; }
         //如果是小题则会存在大题ID
         public string pId { get; set; }     
         //熟练度 后续扩展