zhouj1203@hotmail.com 1 tahun lalu
induk
melakukan
b01946ffca
1 mengubah file dengan 30 tambahan dan 38 penghapusan
  1. 30 38
      TEAMModelOS.FunctionV4/CosmosDB/TriggerExam.cs

+ 30 - 38
TEAMModelOS.FunctionV4/CosmosDB/TriggerExam.cs

@@ -34,6 +34,7 @@ using Microsoft.Extensions.Configuration;
 using DocumentFormat.OpenXml.EMMA;
 using Microsoft.Extensions.Options;
 using TEAMModelOS.Models;
+using Microsoft.AspNetCore.Razor.TagHelpers;
 
 namespace TEAMModelOS.FunctionV4
 {
@@ -1547,8 +1548,22 @@ namespace TEAMModelOS.FunctionV4
             await examRecordCount(info, subject, _dingDing, no, result, examClassResults, _azureCosmos);
             await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
             List<ErrorItems> errorItems = new();
+            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";
+            }
             string sqlqueryText = $"select value(c) from c where c.activityId = '{info.id}'and c.subjectId = '{info.subjects[no].id}' and c.stuId in ({string.Join(",", result.studentIds.Select(x => $"'{x}'"))})";
-            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<ErrorItems>(queryText: sqlqueryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ErrorItems") }))
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<ErrorItems>(queryText: sqlqueryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
             {
                 errorItems.Add(item);
             }
@@ -1572,6 +1587,14 @@ namespace TEAMModelOS.FunctionV4
                     //BlobDownloadResult index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
                     JObject jo = JObject.Parse(index_json.Content.ToString());
                     JArray array = jo.Value<JArray>("slides");
+                    List<string> attachments = new List<string>();
+                    if (info.qamode == 1) {
+                        attachments = jo.Value<JArray>("attachments")?.ToObject<List<string>>();
+                        if (attachments.Count == 0)
+                        {
+                            return;
+                        }
+                    }
                     List<string> urls = new();
                     foreach (var ne in array)
                     {
@@ -1580,20 +1603,7 @@ 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, List<string> knows)> itemInfos = new();
@@ -1616,27 +1626,7 @@ namespace TEAMModelOS.FunctionV4
                         string pid = keys.Value<string>("pid");
                         itemInfos.Add((id, pid, level, type, knowledge));
                     }
-
-
-                    /*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);*/
@@ -1730,8 +1720,10 @@ namespace TEAMModelOS.FunctionV4
                     htc.DefaultRequestHeaders.Add("x-functions-key", accessKey);
                     string paramJson = JsonConvert.SerializeObject(errors);
                     var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
-                    await htc.PostAsync(connect, content);
-                    await task_error.TaskPage(10);
+                    var response =  await htc.PostAsync(connect, content);
+                    if ((int)response.StatusCode == 200) {
+                        await task_error.TaskPage(10);
+                    }                  
                 }
             } catch (Exception e) {
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测错题异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);