Przeglądaj źródła

解决token为null 的问题

zhouj1203@hotmail.com 3 lat temu
rodzic
commit
b208eb554f

+ 16 - 54
TEAMModelOS.SDK/Models/Service/Common/ActivityStudentService.cs

@@ -400,7 +400,7 @@ namespace TEAMModelOS.SDK.Services
 
                 source = $" and  c.source = '{sc}'  ";
 
-            }         
+            }
             string owner = "";
             //评测来源
             if (request.TryGetProperty("owner", out JsonElement element))
@@ -431,7 +431,7 @@ namespace TEAMModelOS.SDK.Services
                     typesql = $" and c.type='{type}' ";
                 }
             }
-            string continuationToken = default;
+            string token = default;
             //默认不指定返回大小
             int? topcout = null;
             if (request.TryGetProperty("count", out JsonElement jcount))
@@ -448,12 +448,12 @@ namespace TEAMModelOS.SDK.Services
                 iscontinuation = true;
             }
             //如果指定了返回大小
-            if (request.TryGetProperty("continuationToken", out JsonElement token))
+            if (request.TryGetProperty("continuationToken", out JsonElement token_1))
             {
                 //指定了cancellationToken continuationSchool
-                if (!token.ValueKind.Equals(JsonValueKind.Null) && token.ValueKind.Equals(JsonValueKind.String))
+                if (!token_1.ValueKind.Equals(JsonValueKind.Null) && token_1.ValueKind.Equals(JsonValueKind.String))
                 {
-                    continuationToken = token.GetString();
+                    token = token_1.GetString();
 
                 }
             }
@@ -489,9 +489,9 @@ 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} {source} {owner} {name} order by c.createTime desc";
+            string querySchool = $" SELECT  value c   FROM c   {joinSqlSubjects}  where c.pk='Activity' {stimesql}  {etimesql}  {typesql}  {andSqlSubjects} {source} {owner} {name} order by c.createTime desc";
             //查询数据归属学校的
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, containerId).GetItemQueryStreamIterator(querySchool, continuationToken: continuationToken,
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, containerId).GetItemQueryStreamIterator(querySchool, continuationToken: token,
                 requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey(PartitionKey) }))
             {
                 using var json = await JsonDocument.ParseAsync(item.ContentStream);
@@ -500,55 +500,17 @@ namespace TEAMModelOS.SDK.Services
                     foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
                     {
                         datas.Add(obj.ToObject<StuActivity>());
-                    }
-                    //如果需要分页则跳出
-                    if (iscontinuation)
-                    {
-                        continuationToken = item.GetContinuationToken();
-                        break;
-                    }
+                    }                   
+                }
+                //如果需要分页则跳出
+                if (iscontinuation)
+                {
+                    token = item.GetContinuationToken();
+                    break;
                 }
             }
-            /* List<(string id, HashSet<string> name)> cn = new(); 
-             foreach (StuActivity activity in datas) {
-                 var cIds = activity.classIds;
-                 HashSet<string> name = new HashSet<string>();
-                 if (cIds.ToList().Count > 0)
-                 {
-                     List<GroupListDto> groups = await GroupListService.GetGroupListListids(client, _dingDing, cIds.ToList(), school);
-                     foreach (GroupListDto dto in groups)
-                     {
-                         name.Add(dto.name);
-                     }
-                     cn.Add((activity.id, name));
-                 }
-             }
-
-             //string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.leader ";
-
-             datas.Select(item => new {
-                 item.name,
-                 item.classIds,
-                 cName = cn.Where(c =>c.id.Equals(item.id)).FirstOrDefault().name,
-                 item.code,
-                 item.createTime,
-                 item.creatorId,
-                 item.id,
-                 item.owner,
-                 item.endTime,
-                 item.startTime,
-                 item.pk,
-                 item.sStatus,
-                 item.school,
-                 item.scode,
-                 item.scope,
-                 item.source,
-                 item.subjects,
-                 item.taskStatus,
-                 item.type
-
-             });*/
-            return (datas, continuationToken);
+            List<StuActivity> results = datas.Where((x, i) => datas.FindIndex(z => z.id == x.id && z.code == x.code) == i).ToList();
+            return (results, token);
         }
 
 

+ 5 - 2
TEAMModelOS/Controllers/Student/StudentCommonController.cs

@@ -62,8 +62,8 @@ namespace TEAMModelOS.Controllers
 
         [ProducesDefaultResponseType]
         [HttpPost("stu-score")]
-        [Authorize(Roles = "IES")]
-        [AuthToken(Roles = "teacher,student,admin")]
+/*        [Authorize(Roles = "IES")]
+        [AuthToken(Roles = "teacher,student,admin")]*/
         public async Task<IActionResult> StuScore(JsonElement request)
         {
             var (id, name, pic, school) = HttpContext.GetAuthTokenInfo();
@@ -75,6 +75,9 @@ namespace TEAMModelOS.Controllers
             {
                 eIds.Add((data.id, data.scope, data.name, data.source, data.classIds, data.qamode, data.creatorId, data.ext, data.createTime, data.owner));
             }
+            if (eIds.Count() == 0) {
+                return Ok(new { code = 404, msg = "暂无数据" });
+            }
             var client = _azureCosmos.GetCosmosClient();
             List<(string eId, string sub, string cId, string cname, List<string> sIds, List<double> sum)> classResults = await getExamClassResult(eIds, client);
             var exam = eIds.Select(e => new