zhouj1203@hotmail.com hace 3 años
padre
commit
7f52bf26ac

+ 27 - 2
TEAMModelOS.SDK/Models/Service/Common/ActivityStudentService.cs

@@ -382,7 +382,32 @@ namespace TEAMModelOS.SDK.Services
                     stimesql = $" and  c.startTime >= {data}  ";
                 }
             }
-           
+
+            string source = "";
+            //评测类型
+            if (request.TryGetProperty("source", out JsonElement sc))
+            {
+
+                    stimesql = $" and  c.source = '{sc}'  ";
+                
+            }
+            string owner = "";
+            //评测来源
+            if (request.TryGetProperty("owner", out JsonElement element))
+            {
+
+                stimesql = $" and  c.owner = '{element}'  ";
+
+            }
+            string name = "";
+            //评测来源
+            if (request.TryGetProperty("name", out JsonElement jsonElement))
+            {
+
+                stimesql = $" and  c.name = '{jsonElement}'  ";
+
+            }
+
             //默认当前时间,  未开始的不能查询
             var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             string etimesql = $" and c.startTime <= {etimestamp}   ";
@@ -454,7 +479,7 @@ namespace TEAMModelOS.SDK.Services
                 containerId = "Student";
                 PartitionKey = $"Activity-{id}";
             }
-            string querySchool = $" SELECT distinct  value c   FROM c   {joinSqlSubjects}  where c.pk='Activity' {stimesql}  {etimesql}      {typesql}  {andSqlSubjects}  ";
+            string querySchool = $" SELECT distinct  value c   FROM c   {joinSqlSubjects}  where c.pk='Activity' {stimesql}  {etimesql}      {typesql}  {andSqlSubjects} {source} {owner} {name} ";
             //查询数据归属学校的
             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, containerId).GetItemQueryStreamIterator(querySchool, continuationToken: continuationToken,
                 requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey(PartitionKey) }))

+ 31 - 13
TEAMModelOS/Controllers/Student/StudentCommonController.cs

@@ -69,17 +69,14 @@ namespace TEAMModelOS.Controllers
             //if (!HttpContext.Items.TryGetValue("Scope", out object _scope)) return BadRequest();
             (List<StuActivity> datas, string continuationToken) = await ActivityStudentService.FindActivity(request, id, school, _azureCosmos, _azureRedis);
             List<(string id, string scope, string name, string source, List<string> cIds, int qamode, string createId, Dictionary<string, JsonElement> ext,long time,string owner)> eIds = new();
-            List<(string id, string scope, string name, List<string> cIds, string createId,long time)> wIds = new();
+          //List<(string id, string scope, string name, List<string> cIds, string createId,long time)> wIds = new();
             foreach (var data in datas)
             {
                 if (data.type.Equals("Exam"))
                 {
                     eIds.Add((data.id, data.scope, data.name, data.source, data.classIds, data.qamode, data.creatorId, data.ext,data.createTime,data.owner));
                 }
-                if (data.type.Equals("Homework"))
-                {
-                    wIds.Add((data.id, data.scope, data.name, data.classIds, data.creatorId,data.createTime));
-                }
+                
             }
             var client = _azureCosmos.GetCosmosClient();
             List<(string eId, string sub, string cId, string cname, List<string> sIds, List<double> sum)> classResults = await getExamClassResult(eIds,client);
@@ -96,9 +93,29 @@ namespace TEAMModelOS.Controllers
                 e.owner,
                 result = classResults.Where(c => c.eId == e.id).Select(s => new { s.sub, s.cId, s.cname, s.sum, s.sIds })
             });
-            var result = exam.Where(e => e.result.Any());
-
+            var result = exam.Where(e => e.result.Any());           
+            return Ok(new { result, continuationToken });
+        }
 
+        [ProducesDefaultResponseType]
+        [HttpPost("stu-hw-score")]
+        [Authorize(Roles = "IES")]
+        [AuthToken(Roles = "teacher,student,admin")]
+        public async Task<IActionResult> StuHwScore(JsonElement request)
+        {
+            var (id, name, pic, school) = HttpContext.GetAuthTokenInfo();
+            //if (!HttpContext.Items.TryGetValue("Scope", out object _scope)) return BadRequest();
+            (List<StuActivity> datas, string continuationToken) = await ActivityStudentService.FindActivity(request, id, school, _azureCosmos, _azureRedis);
+            //List<(string id, string scope, string name, string source, List<string> cIds, int qamode, string createId, Dictionary<string, JsonElement> ext, long time, string owner)> eIds = new();
+            List<(string id, string scope, string name, List<string> cIds, string createId, long time)> wIds = new();
+            foreach (var data in datas)
+            {             
+                if (data.type.Equals("Homework"))
+                {
+                    wIds.Add((data.id, data.scope, data.name, data.classIds, data.creatorId, data.createTime));
+                }
+            }
+            var client = _azureCosmos.GetCosmosClient();           
             string partitionKey = String.Empty;
             if (string.IsNullOrWhiteSpace(id))
             {
@@ -115,7 +132,7 @@ namespace TEAMModelOS.Controllers
             {
                 partitionKey = $"HomeworkRecord-{school}-{id}";
             }
-            List<(string id,double score, List<HomeworkComment> comments)> work = new();
+            List<(string id, double score, List<HomeworkComment> comments)> work = new();
             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(
                 queryText: $"select c.id,c.score,c.comments from c where c.id in ({string.Join(",", wIds.Select(o => $"'{o.id}'"))})",
                 requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(partitionKey) }))
@@ -132,29 +149,30 @@ namespace TEAMModelOS.Controllers
                         if (account.TryGetProperty("score", out JsonElement score))
                         {
                             sc = score.GetDouble();
-                            if (sc == -1) {
+                            if (sc == -1)
+                            {
                                 sc = 0;
                             }
                         }
                         if (account.TryGetProperty("comments", out JsonElement comments))
                         {
-                            hc = comments.ToObject<List<HomeworkComment>>();                           
+                            hc = comments.ToObject<List<HomeworkComment>>();
                         }
 
                         work.Add((account.GetProperty("id").GetString(), sc, hc));
                     }
                 }
             }
-            var works = wIds.Select(w => new { 
+            var works = wIds.Select(w => new {
                 w.id,
                 w.name,
                 w.cIds,
                 w.createId,
                 w.time,
-                score = work.Where(x => x.id == w.id ).Select(s => new { s.score,s.comments})
+                score = work.Where(x => x.id == w.id).Select(s => new { s.score, s.comments })
             });
 
-            return Ok(new { result, works, continuationToken });
+            return Ok(new {works, continuationToken });
         }
 
         private async Task<List<(string eId, string sub, string cId, string cname, List<string> sIds, List<double> sum)>> getExamClassResult(List<(string id, string scope, string name, string source, List<string> cIds, int qamode, string createId, Dictionary<string, JsonElement> ext, long time, string owner)> eIds, CosmosClient client) {