瀏覽代碼

Merge branch 'develop' of http://52.130.252.100:10000/TEAMMODEL/TEAMModelOS into develop

CrazyIter_Bin 2 年之前
父節點
當前提交
d46a2d2f19

+ 56 - 0
TEAMModelOS/Controllers/Analysis/ClassAnalysisController.cs

@@ -338,6 +338,61 @@ namespace TEAMModelOS.Controllers.Analysis
             }
 
         }
+
+        [ProducesDefaultResponseType]
+        [Authorize(Roles = "IES")]
+        [AuthToken(Roles = "teacher,admin")]
+        [HttpPost("analysis-record-count")]
+        public async Task<IActionResult> analysisRecordCount(JsonElement request)
+        {
+            try
+            {
+                if (!request.TryGetProperty("stime", out JsonElement stime)) return BadRequest();
+                if (!request.TryGetProperty("etime", out JsonElement etime)) return BadRequest();
+                if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                if (!request.TryGetProperty("periodId", out JsonElement pId)) return BadRequest();
+                long st = stime.GetInt64();
+                long et = etime.GetInt64();
+                //获取当前学期所有的课程记录
+                List<LessonRecord> records = new();
+                var client = _azureCosmos.GetCosmosClient();
+                var queryClass = $"select value(c) from c where c.periodId = '{pId}'";
+                string tId = string.Empty;
+                if (request.TryGetProperty("tmdId", out JsonElement tmdId))
+                {
+                    queryClass = $"select value(c) from c where c.tmdid = '{tmdId}' and c.periodId = '{pId}'";
+                    tId = tmdId.GetString();
+                }
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonRecord>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{code}") }))
+                {
+                    records.Add(item);
+                }
+                if (records.Count > 0)
+                {
+                    var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(code.GetString(), new PartitionKey($"Base"));
+                    School sc = new School();
+                    if (response.Status == 200)
+                    {
+                        using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                        sc = json.ToObject<School>();
+                    }
+                    List<(string name, double count)> rc = await getRecordCount(client, records, st, et, code.GetString(), tId, pId.GetString());                                      
+                    var total = rc.Select(x => new { x.name, value = x.count });                                                      
+                    return Ok(new { total });
+                }
+                else
+                {
+                    return Ok(new { code = 404, msg = "暂无课程记录" });
+                }              
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/analysis-record-count()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+
+        }
+
         private List<(string name, int count)> getGroupCount(List<LessonRecord> records)
         {
             List<string> groupIds = new();
@@ -654,6 +709,7 @@ namespace TEAMModelOS.Controllers.Analysis
             return (scount, tcount);
         }
 
+
         private async Task<List<(string time, double count)>> getRecordCount(CosmosClient client, List<LessonRecord> records, long stime, long etime, string code, string tId, string periodId)
         {
             List<(string time, double count)> counts = new();

+ 1 - 1
TEAMModelOS/Controllers/Common/AreaController.cs

@@ -849,7 +849,7 @@ namespace TEAMModelOS.Controllers
                         {
                             t.Key,
                             kno = t.ToList().Select(k => k.kno).ToList()[0],
-                            scores = Math.Round(t.ToList().Select(l => l.score).ToList().Sum() * 1.0 / baseInfo.Count, 2)
+                            scores = Math.Round(t.ToList().Select(l => l.score).ToList().Sum() * 1.0 / artSchools.Count, 2)
                         })
                     })
                 }).FirstOrDefault();