Browse Source

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

OnePsycho 4 năm trước cách đây
mục cha
commit
e4335bc207
1 tập tin đã thay đổi với 163 bổ sung97 xóa
  1. 163 97
      TEAMModelOS/Controllers/Analysis/AchievementController.cs

+ 163 - 97
TEAMModelOS/Controllers/Analysis/AchievementController.cs

@@ -3578,107 +3578,112 @@ namespace TEAMModelOS.Controllers.Analysis
         //}
 
 
-        //[HttpPost("import")]
-        //public async Task<IActionResult> importIES3(JsonElement request)
-        //{
-        //    获取评测的ID
-        //            if (!request.TryGetProperty("exam", out JsonElement exam)) return BadRequest();
-        //    if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
-        //    try
-        //    {
-        //        var client = _azureCosmos.GetCosmosClient();
-        //        ExamDto examDtos = new ExamDto();
-        //        examDtos = exam.ToObject<ExamDto>();
-        //        ExamInfo info = new ExamInfo();
-        //        info.code = info.pk + "-hbcn";
-        //        info.progress = "pending";
-        //        info.id = examDtos.id;
-        //        info.name = examDtos.name;
-        //        info.grades = examDtos.grades;
-        //        info.subjects = examDtos.subjects;
-        //        info.period = examDtos.period;
-        //        examDtos.targetClasses.ForEach(e =>
-        //        {
-        //            info.classes.Add(e.id);
-        //        });
-        //        examDtos.papers.ForEach(p =>
-        //        {
-        //            PaperSimple simple = new PaperSimple();
-        //            simple.id = p.id;
-        //            simple.name = p.name;
-        //            p.points.ForEach(po =>
-        //            {
-        //                simple.point.Add(double.Parse(po));
-        //            });
-        //            p.answers.ForEach(an =>
-        //            {
-        //                List<string> ans = new List<string>();
-        //                if (an.Length > 1)
-        //                {
-        //                    char[] aa = an.ToCharArray();
-        //                    foreach (char a in aa)
-        //                    {
-        //                        switch (a)
-        //                        {
-        //                            case '1':
-        //                                ans.Add("A");
-        //                                break;
-        //                            case '2':
-        //                                ans.Add("B");
-        //                                break;
-        //                            case '3':
-        //                                ans.Add("C");
-        //                                break;
-        //                            case '4':
-        //                                ans.Add("D");
-        //                                break;
-        //                            default:
-        //                                ans.Add("");
-        //                                break;
-        //                        }
-        //                    }
-        //                }
-        //                else
-        //                {
-        //                    switch (an)
-        //                    {
-        //                        case "1":
-        //                            ans.Add("A");
-        //                            break;
-        //                        case "2":
-        //                            ans.Add("B");
-        //                            break;
-        //                        case "3":
-        //                            ans.Add("C");
-        //                            break;
-        //                        case "4":
-        //                            ans.Add("D");
-        //                            break;
-        //                        default:
-        //                            ans.Add("");
-        //                            break;
-        //                    }
-
-        //                }
-        //                simple.answers.Add(ans);
-        //            });
-        //            info.papers.Add(simple);
-        //        });
-        //        await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(info, new PartitionKey("Exam-hbcn"));
-        //        return Ok(new { info });
-        //    }
-        //    catch (Exception e)
-        //    {
-        //        await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/scoring()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
-        //        return BadRequest();
-        //    }
-        //}
+        [HttpPost("import")]
+        public async Task<IActionResult> importIES3(JsonElement request)
+        {
+            //获取评测的ID
+            if (!request.TryGetProperty("exam", out JsonElement exam)) return BadRequest();
+            if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                ExamDto examDtos = new ExamDto();
+                examDtos = exam.ToObject<ExamDto>();
+                ExamInfo info = new ExamInfo();
+                info.code = info.pk +"-"+ code;
+                info.progress = "pending";
+                info.id = examDtos.id;
+                info.name = examDtos.name;
+                info.grades = examDtos.grades;
+                info.subjects = examDtos.subjects;
+                info.period = examDtos.period;
+                examDtos.targetClasses.ForEach(e =>
+                {
+                    info.classes.Add(e.id);
+                });
+                examDtos.papers.ForEach(p =>
+                {
+                    PaperSimple simple = new PaperSimple
+                    {
+                        id = p.id,
+                        name = p.name
+                    };
+                    p.points.ForEach(po =>
+                    {
+                        simple.point.Add(double.Parse(po));
+                    });
+                    //List<List<string>> answers = new List<List<string>>();
+                    p.answers.ForEach(an =>
+                    {
+                        List<string> ans = new List<string>();
+                        if (an.Length > 1)
+                        {
+                            char[] aa = an.ToCharArray();
+                            foreach (char a in aa)
+                            {
+                                switch (a)
+                                {
+                                    case '1':
+                                        ans.Add("A");
+                                        break;
+                                    case '2':
+                                        ans.Add("B");
+                                        break;
+                                    case '3':
+                                        ans.Add("C");
+                                        break;
+                                    case '4':
+                                        ans.Add("D");
+                                        break;
+                                    default:
+                                        ans.Add("");
+                                        break;
+                                }
+                               // answers.Add(ans);
+                            }
+                        }
+                        else
+                        {
+                            switch (an)
+                            {
+                                case "1":
+                                    ans.Add("A");
+                                    break;
+                                case "2":
+                                    ans.Add("B");
+                                    break;
+                                case "3":
+                                    ans.Add("C");
+                                    break;
+                                case "4":
+                                    ans.Add("D");
+                                    break;
+                                default:
+                                    ans.Add("");
+                                    break;
+                            }
+                            //answers.Add(ans);
+                        }
+                        simple.answers.Add(ans);
+                    });
+                    info.papers.Add(simple);
+                });
+                await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(info, new PartitionKey($"Exam-{code}"));
+                return Ok(new { info });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/import()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
         [HttpPost("importResult")]
         public async Task<IActionResult> importClassResult(JsonElement request)
         {
             //获取评测的ID
             if (!request.TryGetProperty("classResult", out JsonElement classResult)) return BadRequest();
             if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
+            if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
             try
             {
                 var client = _azureCosmos.GetCosmosClient();
@@ -3687,7 +3692,7 @@ namespace TEAMModelOS.Controllers.Analysis
                 //获取本次评测所有班级作答结果
                 List<ExamClassResult> examClassResults = new List<ExamClassResult>();
                 var queryClass = $"select value(c) from c where c.examId =  '{id}'";
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ExamClassResult-hbcn") }))
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
                 {
                     examClassResults.Add(item);
 
@@ -3822,7 +3827,68 @@ namespace TEAMModelOS.Controllers.Analysis
                 return BadRequest();
             }
         }
-    }
+
+        //获取学校简易基础信息
+        [HttpPost("getSchoolInfo")]
+        public async Task<IActionResult> getInfoSchool(JsonElement request)
+        {
+            if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                List<object> info = new List<object>();
+                var query = $"select c.period,c.id,c.campuses from c where c.id = '{code}'";
+                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base")}))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            info.Add(obj.ToObject<object>());
+                        }
+                    }
+                }
+                return Ok(new { info });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/getSchoolInfo()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+
+        //获取学校某学段班级信息
+        [HttpPost("getClassInfo")]
+        public async Task<IActionResult> getClassInfo(JsonElement request)
+        {
+            if (!request.TryGetProperty("periodId", out JsonElement periodId)) return BadRequest();
+            if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                List<object> classInfo = new List<object>();
+                var query = $"select c.id,c.name from c where c.periodId = '{periodId}'";
+                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{code}") }))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            classInfo.Add(obj.ToObject<object>());
+                        }
+                    }
+                }
+                return Ok(new { classInfo });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/getClassInfo()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+    }   
 }
 //private List<Dictionary<string, dynamic>> getKnowledgePoint(List<ExamResult> examResults, ExamInfo info)
 //{