Browse Source

滚动翻页相关调整

zhouj1203@hotmail.com 3 years ago
parent
commit
c949bc3b95

+ 1 - 0
TEAMModelOS.SDK/Models/Service/FixDataService.cs

@@ -604,6 +604,7 @@ namespace TEAMModelOS.SDK.Models.Service
                     item.updateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                     taskInfo.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(item, item.id, new PartitionKey(item.code)));
                 }
+                //TODO 数据量过大的时候暂未处理
                 await Task.WhenAll(taskInfo);
             }
             catch (Exception ex)

+ 1 - 1
TEAMModelOS/Controllers/Analysis/AnalysisController.cs

@@ -618,7 +618,7 @@ namespace TEAMModelOS.Controllers.Analysis
             }
             catch (Exception ex)
             {
-                //await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/process()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/process()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
             }
 
             var sub = examResults.Select(e => new

+ 87 - 14
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -428,7 +428,7 @@ namespace TEAMModelOS.Controllers
             try
             {
                 if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
-                var client = _azureCosmos.GetCosmosClient();               
+                var client = _azureCosmos.GetCosmosClient();
                 var query = $"select c.id,c.name,c.code,c.period,c.startTime,c.endTime,c.stuCount,c.type,c.progress,c.examType,c.createTime,c.source, c.subjects, c.grades,c.owner, c.scope,c.classes, c.stuLists, c.sRate,c.lostStu,c.sStatus,c.qamode,c.school from c where (c.status<>404 or IS_DEFINED(c.status) = false)";
                 if (requert.TryGetProperty("classIds", out JsonElement classIds))
                 {
@@ -452,13 +452,6 @@ namespace TEAMModelOS.Controllers
 
                 string continuationToken = string.Empty;
                 string token = default;
-                //是否需要进行分页查询,默认不分页
-                bool iscontinuation = false;
-                if (requert.TryGetProperty("token", out JsonElement token_1))
-                {
-                    token = token_1.GetString();
-                    iscontinuation = true;
-                };
                 //默认不指定返回大小
                 int? topcout = null;
                 if (requert.TryGetProperty("count", out JsonElement jcount))
@@ -468,7 +461,22 @@ namespace TEAMModelOS.Controllers
                         topcout = data;
                     }
                 }
+                //是否需要进行分页查询,默认不分页
+                bool iscontinuation = false;
+                if (topcout != null && topcout.Value > 0)
+                {
+                    iscontinuation = true;
+                }
+                //如果指定了返回大小
+                if (requert.TryGetProperty("token", out JsonElement token_1))
+                {
+                    //指定了cancellationToken continuationSchool
+                    if (!token_1.ValueKind.Equals(JsonValueKind.Null) && token_1.ValueKind.Equals(JsonValueKind.String))
+                    {
+                        continuationToken = token_1.GetString();
 
+                    }
+                }              
                 List<ExamInfo> examInfo = new List<ExamInfo>();
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: query, continuationToken: token, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Exam-{code}") }))
                 {
@@ -488,8 +496,8 @@ namespace TEAMModelOS.Controllers
                         break;
                     }
 
-                }               
-                return Ok(new { examInfo, token = continuationToken});
+                }
+                return Ok(new { examInfo, token = continuationToken });
             }
             catch (Exception e)
             {
@@ -607,7 +615,7 @@ namespace TEAMModelOS.Controllers
                 }
 
                 List<ExamInfo> examInfo = new List<ExamInfo>();
-                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: query, continuationToken: token, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout}))
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: query, continuationToken: token, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout }))
                 {
 
                     using var json = await JsonDocument.ParseAsync(item.ContentStream);
@@ -625,7 +633,7 @@ namespace TEAMModelOS.Controllers
                         break;
                     }
 
-                }               
+                }
                 return Ok(new { examInfo, token = continuationToken, year });
             }
             catch (Exception e)
@@ -1463,7 +1471,7 @@ namespace TEAMModelOS.Controllers
             if (!requert.TryGetProperty("code", out JsonElement school)) return BadRequest();
             if (!requert.TryGetProperty("scode", out JsonElement scode)) return BadRequest();
             try
-            {              
+            {
                 var client = _azureCosmos.GetCosmosClient();
                 var query = $"select c.id,c.code,c.school,c.creatorId,c.progress,A0.id paperId,A0.code paperCode,A0.name paperName,A0.knowledge,A0.point,A0.field,A0.multipleRule,A0.scope,A0.blob,A0.time from c join A0 in c.papers where c.id ='{id}'";
                 List<PaperSimple> papers = new List<PaperSimple>();
@@ -1771,7 +1779,7 @@ namespace TEAMModelOS.Controllers
                 {
                     //初始化认知层次得分
                     double score = 0;
-                    double allScore = 0;                  
+                    double allScore = 0;
                     int count = 0;
                     foreach (ExamClassResult result in answers)
                     {
@@ -3034,6 +3042,71 @@ namespace TEAMModelOS.Controllers
             return Ok(new { sc });
         }
 
+
+        //处理仲裁卷内容
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "teacher,admin")]
+        [HttpPost("score")]
+        //[Authorize(Roles = "IES")]
+        public async Task<IActionResult> score(JsonElement requert)
+        {
+            if (!requert.TryGetProperty("courseId", out JsonElement courseId)) return BadRequest();
+            if (!requert.TryGetProperty("cId", out JsonElement cId)) return BadRequest();
+            if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
+            var client = _azureCosmos.GetCosmosClient();
+            List<(string eId, string cId,string cname,List<string> sIds,List<double> sum)> classResults = new();
+            List<string> eIds = new();
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(
+                queryText: $"select c.examId as eId,c.info.id as cId,c.info.name as cName,c.studentIds,c.sum from c where c.subjectId = '{courseId}' and c.info.id = '{cId}'",
+                requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{code}") }))
+            {
+                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;
+                        List<string> sIds = account.GetProperty("studentIds").ToObject<List<string>>();
+                        List<double> sum = account.GetProperty("sum").ToObject<List<double>>();
+                        eIds.Add(account.GetProperty("eId").GetString());
+                        classResults.Add((account.GetProperty("eId").GetString(), account.GetProperty("cId").GetString(), account.GetProperty("cName").GetString(), sIds, sum));
+                    }
+                }
+            }
+            List<(string id, string name, List<Custom> eType, string scope)> exam = new();
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(
+                   queryText: $"select c.id,c.name,c.examType,c.scope from c where c.id in ({string.Join(",", eIds.Select(o => $"'{o}'"))})"))
+            {
+                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;
+                        List<Custom> eType = new();
+                        if (requert.TryGetProperty("examType", out JsonElement examType)) {
+                            eType = examType.ToObject<List<Custom>>();
+                        }                            
+                        exam.Add((account.GetProperty("id").GetString(), account.GetProperty("name").GetString(), eType, account.GetProperty("scope").GetString()));
+                    }
+                }
+            }
+
+            var scores = classResults.Select(x => new {
+                examId = x.eId,
+                examName = exam.Where(e => e.id.Equals(x.eId)).FirstOrDefault().name,
+                scope = exam.Where(e => e.id.Equals(x.eId)).FirstOrDefault().scope,
+                eType = exam.Where(e => e.id.Equals(x.eId)).FirstOrDefault().eType,
+                classId = x.cId,
+                cname = x.cname,
+                studentIds = x.sIds,
+                sum = x.sum
+            });
+            return Ok(new { scores });
+        }
+
         //阅卷信息统计
         [ProducesDefaultResponseType]
         [Authorize(Roles = "IES")]