Przeglądaj źródła

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

OnePsycho 3 lat temu
rodzic
commit
65a36a206c

+ 5 - 5
TEAMModelOS/ClientApp/src/components/student-web/EventView/EventContentTypeTemplate/Vote.vue

@@ -268,19 +268,19 @@
             getVoteType() {
                 if(this.voteInfo != undefined) {
                     if(this.voteInfo.times == "once") {
-                        return "单次"
+                        return this.$t("studentWeb.vote.type.once")
                     }
                     else if(this.voteInfo.times == "day") {
-                        return "每日"
+                        return this.$t("studentWeb.vote.type.day")
                     }
                     else if(this.voteInfo.times == "week") {
-                        return "每周"
+                        return this.$t("studentWeb.vote.type.week")
                     }
                     else if(this.voteInfo.times == "month") {
-                        return "每月"
+                        return this.$t("studentWeb.vote.type.month")
                     }
                     else if(this.voteInfo.times == "year") {
-                        return "每年"
+                        return this.$t("studentWeb.vote.type.year")
                     }
                 }
             },

+ 7 - 0
TEAMModelOS/ClientApp/src/locale/lang/en-US/studentWeb.js

@@ -256,6 +256,13 @@ export default {
         delOk: "删除",
         delCancel: "取消",
         delSuccess: "删除成功",
+        type: {
+            once: "单次",
+            day: "每日",
+            week: "每周",
+            month: "每月",
+            year: "每年",
+        },
     },
     homework: {
         homeworkUpload: 'Assignment Upload Area',

+ 7 - 0
TEAMModelOS/ClientApp/src/locale/lang/zh-CN/studentWeb.js

@@ -256,6 +256,13 @@ export default {
         delOk: "删除",
         delCancel: "取消",
         delSuccess: "删除成功",
+        type: {
+            once: "单次",
+            day: "每日",
+            week: "每周",
+            month: "每月",
+            year: "每年",
+        },
     },
     homework: {
         homeworkUpload: '作业上传区',

+ 7 - 0
TEAMModelOS/ClientApp/src/locale/lang/zh-TW/studentWeb.js

@@ -256,6 +256,13 @@ export default {
         delOk: "删除",
         delCancel: "取消",
         delSuccess: "删除成功",
+        type: {
+            once: "單次",
+            day: "每日",
+            week: "每週",
+            month: "每月",
+            year: "每年",
+        },
     },
     homework: {
         homeworkUpload: '作業上傳區',

+ 74 - 20
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -606,7 +606,7 @@ namespace TEAMModelOS.Controllers
         /// <param name="request"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "Teacher")]
+        [AuthToken(Roles = "student,teacher")]
         [HttpPost("upsert-record")]
         public async Task<IActionResult> upsertRecord(JsonElement request)
         {
@@ -615,7 +615,7 @@ namespace TEAMModelOS.Controllers
             //学校编码
             //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("studentId", out JsonElement studentId)) return BadRequest();
             if (!request.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
             if (!request.TryGetProperty("classIds", out JsonElement classId)) return BadRequest();
             if (!request.TryGetProperty("multipleRule", out JsonElement multipleRule)) return BadRequest();
@@ -624,6 +624,7 @@ namespace TEAMModelOS.Controllers
             //根据不同评测的类型返回对应的编码
             if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
             if (!request.TryGetProperty("scode", out JsonElement scode)) return BadRequest();
+            var (userId, _, _, school) = HttpContext.GetAuthTokenInfo();
             try
             {
                 List<string> ids = new List<string>();
@@ -636,14 +637,14 @@ namespace TEAMModelOS.Controllers
                 {
                     //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}'",
+                    queryText: $"select c.classId as id from c where c.classId = '{cId}' and c.id = '{userId}'",
                     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()) 
+                            while (accounts.MoveNext())
                             {
                                 JsonElement account = accounts.Current;
                                 cIds.Add(account.GetProperty("id").GetString());
@@ -654,7 +655,7 @@ namespace TEAMModelOS.Controllers
                     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}' or array_contains(c.tmids,'{studentId}')) and A0.schoolId = '{info.school}'",
+                        queryText: $"select c.id from c join A0 in c.students where c.id = '{cId}' and (A0.id = '{userId}' or array_contains(c.tmids,'{userId}')) and A0.schoolId = '{info.school}'",
                         requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList") }))
                         {
                             using var json = await JsonDocument.ParseAsync(item.ContentStream);
@@ -673,7 +674,7 @@ namespace TEAMModelOS.Controllers
                     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}'",
+                       queryText: $"select c.id from c join A0 in c.students where c.id = '{cId}' and A0.id = '{userId}'",
                        requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList-{info.school}") }))
                         {
                             using var json = await JsonDocument.ParseAsync(item.ContentStream);
@@ -689,11 +690,7 @@ namespace TEAMModelOS.Controllers
                             }
                         }
                     }
-                   /* 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(",", cIds.Select(o => $"'{o}'"))})",
@@ -736,7 +733,7 @@ namespace TEAMModelOS.Controllers
                 List<Task<string>> tasks = new List<Task<string>>();
                 foreach (ExamClassResult result in examClassResults)
                 {
-                    int index = result.studentIds.IndexOf(studentId.ToString());
+                    int index = result.studentIds.IndexOf(userId.ToString());
                     //存放客观题作答详情
                     if (result.ans.Count == 0)
                     {
@@ -756,12 +753,20 @@ namespace TEAMModelOS.Controllers
                     if (index == -1)
                     {
                         List<double> ansPoint = new List<double>();
+                        List<List<string>> anc = new List<List<string>>();
+                        List<List<Details>> mark = new List<List<Details>>();
                         foreach (List<string> num in standard)
                         {
-                            //ans.Add(new List<string>());
+                            List<string> newAns = new List<string>();
+                            foreach (string san in num) {
+                                newAns.Add(san);
+                            }
+                            anc.Add(newAns);
                             ansPoint.Add(-1);
+                            mark.Add(new List<Details>());
                         }
-                        result.studentIds.Add(studentId.ToString());
+                        result.ans.Add(anc);
+                        result.studentIds.Add(userId.ToString());
                         result.studentScores.Add(ansPoint);
                         result.studentAnswers.Add(new List<string>());
                         result.sum.Add(0);
@@ -773,13 +778,13 @@ namespace TEAMModelOS.Controllers
                                 flagCount++;
                         }
                     }    */
-                    int newIndex = result.studentIds.IndexOf(studentId.ToString());
+                    int newIndex = result.studentIds.IndexOf(userId.ToString());
                     /*                    if (flagCount != standard.Count)
                                         {*/
                     StringBuilder builder = new StringBuilder();
                     builder.Append(result.examId).Append("/");
                     builder.Append(result.subjectId).Append("/");
-                    builder.Append(studentId).Append("/");
+                    builder.Append(userId).Append("/");
                     builder.Append("ans.json");
                     /*string FileName = result.examId + "/" + result.subjectId + "/" + studentId;
                     string blob = FileName + "/" + "ans.json";*/
@@ -798,7 +803,7 @@ namespace TEAMModelOS.Controllers
                         //算分处理
                         if (sc > 0)
                         {
-                            result.ans[index][i] = ans[i];
+                            result.ans[newIndex][i] = ans[i];
                             if (ac == sc && sc == 1)
                             {
                                 foreach (string right in ans[i])
@@ -929,7 +934,7 @@ namespace TEAMModelOS.Controllers
                     }
                     if (flag)
                     {
-                        ExamInfo exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{scode}"));
+                        //ExamInfo exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{scode}"));
                         result.progress = true;
                         /*//标记单科单班总得分
                         double score = 0;
@@ -946,20 +951,69 @@ namespace TEAMModelOS.Controllers
                         }
                         result.standard = Math.Round(scount > 0 ? Math.Pow(powSum / scount, 0.5) : 0, 2);
                         result.average = scount > 0 ? Math.Round(score / scount, 2) : 0;*/
-                        exam.subjects.ForEach(s =>
+                        info.subjects.ForEach(s =>
                         {
                             if (s.id.Equals(subjectId.ToString()))
                             {
                                 s.classCount += 1;
                             }
                         });
-                        await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{scode}"));
+                        await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(info, id.ToString(), new PartitionKey($"{scode}"));
+                        try {
+                            if (string.IsNullOrEmpty(school))
+                            {
+                                StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{userId}"));
+                                activity.taskStatus = 1;
+                                await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
+                            }
+                            else
+                            {
+                                StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{info.school}-{userId}"));
+                                activity.taskStatus = 1;
+                                await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
+                            }
+                        } catch (CosmosException e) {
+                            if (e.Status == 404) {
+                                StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{userId}"));
+                                activity.taskStatus = 1;
+                                await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
+                            }
+                        }                        
+                    }
+                    else
+                    {
+                        try
+                        {
+                            if (string.IsNullOrEmpty(school))
+                            {
+                                StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{userId}"));
+                                activity.taskStatus = 0;
+                                await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
+                            }
+                            else
+                            {
+                                StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{info.school}-{userId}"));
+                                activity.taskStatus = 1;
+                                await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
+                            }
+                        }
+                        catch (CosmosException e)
+                        {
+                            if (e.Status == 404)
+                            {
+                                StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{userId}"));
+                                activity.taskStatus = 0;
+                                await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
+                            }
+                        }
+
                     }
                     result.sum[newIndex] = result.studentScores[newIndex].Sum();
                     classResult = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
                 }
                 await Task.WhenAll(tasks);
 
+
                 return Ok(new { classResult });
             }
             catch (Exception e)