Prechádzať zdrojové kódy

更改错误的exam的type类型

CrazyIter_Bin 4 rokov pred
rodič
commit
9c28f9b2bd

+ 2 - 2
TEAMModelFunction/TriggerExam.cs

@@ -139,7 +139,7 @@ namespace TEAMModelFunction
                                 pk = "Activity",
                                 id = info.id,
                                 code = $"Activity-{x}",
-                                type = "survey",
+                                type = "exam",
                                 name = info.name,
                                 startTime = info.startTime,
                                 endTime = info.endTime,
@@ -160,7 +160,7 @@ namespace TEAMModelFunction
                                 pk = "Activity",
                                 id = info.id,
                                 code = $"Activity-{info.school}-{x.id}",
-                                type = "survey",
+                                type = "exam",
                                 name = info.name,
                                 startTime = info.startTime,
                                 endTime = info.endTime,

+ 25 - 1
TEAMModelOS/Controllers/School/StudentCommonController.cs

@@ -10,6 +10,7 @@ using TEAMModelOS.Filter;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models.Cosmos;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.Services.Common;
 
 namespace TEAMModelOS.Controllers
@@ -52,6 +53,29 @@ namespace TEAMModelOS.Controllers
             (List<ActivityData> datas, string continuationTokenSchool,string continuationTokenTeacher) = await ActivityStudentService.FindAsStu( request, id,  school, _azureCosmos,_azureRedis);
             return Ok(new { datas, continuationTokenSchool,continuationTokenTeacher });
         }
-        
+
+        /// <summary>
+        /// 查询活动所有活动类型的列表,学生端
+        /// </summary>
+        /// <param name="request">
+        ///加入的班级信息                      ?classes:[{"classid":"S-C-00001","scope":"school"},{"classid":"P-C-00004","scope":"private"}]
+        ///活动类型                            ?"type":"vote"/"exam"/"homework"/"learn"/"survey"" // vote投票 survey问卷 exam评测 learn学习活动 homework作业活动
+        ///时间筛选范围开始时间 默认30天之前   ?"stime":1608274766154  
+        ///时间筛选范围结束时间 默认当前时间   ?"etime":1608274766666 
+        ///是否展示列表的 Tips                 ? "tips":true/false
+        ///每页大小     ?"count":10/null/Undefined  
+        ///分页Token    ?"continuationToken":Undefined/null/"[{\"token\":\"+RID:~omxMAP3ipcSEEwAAAAAAAA==#RT:2#TRC:20#ISV:2#IEO:65551#QCF:1#FPC:AYQTAAAAAAAAiRMAAAAAAAA=\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}]"
+        /// 当前状态    ?"progress":Undefined/null/"" 表示两种状态都要查询/ "going"/"finish" 表示查询进行中/ 或者已完成 学生端只能查询正在进行或已经结束 going 已发布|finish 已结束  
+        /// </param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("stu-activity")]
+        // [AuthToken(Roles = "student")]
+        public async Task<IActionResult> StuActivity(JsonElement request)
+        {
+            var (id, name, pic, school) = HttpContext.GetAuthTokenInfo();
+            (List<StuActivity> datas, string continuationToken) = await ActivityStudentService.FindActivity(request, id, school, _azureCosmos, _azureRedis);
+            return Ok(new { datas, continuationToken });
+        }
     }
 }

+ 138 - 0
TEAMModelOS/Services/Common/ActivityStudentService.cs

@@ -12,6 +12,7 @@ using System.Text;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
 using StackExchange.Redis;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 
 namespace TEAMModelOS.Services.Common
 {
@@ -128,6 +129,9 @@ namespace TEAMModelOS.Services.Common
             }
             return msgid;
         }
+
+      
+
         public static async Task<byte> VoteIng(Vote vote, RedisValue value, byte msgid, Dictionary<string, int> option, string Field, long curr, AzureRedisFactory _azureRedis,string userid,string times,string endpoint)
         {
             if (!value.IsNullOrEmpty)
@@ -222,7 +226,141 @@ namespace TEAMModelOS.Services.Common
             int week = ((day + 7) / 7) + 1;
             return week;
         }
+        public static async Task<(List<StuActivity> datas, string continuationToken)> FindActivity(JsonElement request, string id, string school, AzureCosmosFactory _azureCosmos, AzureRedisFactory azureRedis)
+        {
+            if (string.IsNullOrWhiteSpace(id))
+            {
+                id = request.GetProperty("userid").GetString();
+            }
+            if (string.IsNullOrWhiteSpace(school))
+            {
+                school = request.GetProperty("school").GetString();
+            }
+            //开始时间,默认最近三十天
+            var stimestamp = DateTimeOffset.UtcNow.AddDays(-30).ToUnixTimeMilliseconds();
+            if (request.TryGetProperty("stime", out JsonElement stime))
+            {
+                if (!stime.ValueKind.Equals(JsonValueKind.Undefined) && !stime.ValueKind.Equals(JsonValueKind.Null) && stime.TryGetInt64(out long data))
+                {
+                    stimestamp = data;
+                }
+            }
+            string stimesql = $" c.startTime >= {stimestamp}  ";
+            //默认当前时间,  未开始的不能查询
+            var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+            string etimesql = $" and c.startTime <= {etimestamp}   ";
+           
+            var typesql = "";
+            if (request.TryGetProperty("type", out JsonElement type))
+            {
 
+                if (!type.ValueKind.Equals(JsonValueKind.Undefined) && !type.ValueKind.Equals(JsonValueKind.Null) && type.ValueKind.Equals(JsonValueKind.String))
+                {
+                    typesql = $" and c.type='{type}' ";
+                }
+            }
+            string continuationToken = null;
+            //默认不指定返回大小
+            int? topcout = null;
+            if (request.TryGetProperty("count", out JsonElement jcount))
+            {
+                if (!jcount.ValueKind.Equals(JsonValueKind.Undefined) && !jcount.ValueKind.Equals(JsonValueKind.Null) && jcount.TryGetInt32(out int data))
+                {
+                    topcout = data;
+                }
+            }
+            //是否需要进行分页查询,默认不分页
+            bool iscontinuation = false;
+            if (topcout != null && topcout.Value > 0)
+            {
+                iscontinuation = true;
+            }
+            //如果指定了返回大小
+            if (request.TryGetProperty("continuationToken", out JsonElement token))
+            {
+                //指定了cancellationToken continuationSchool
+                if (!token.ValueKind.Equals(JsonValueKind.Null) && token.ValueKind.Equals(JsonValueKind.String))
+                {
+                    continuationToken = token.GetString();
+
+                }
+            }
+            ////个人tmdid
+            //string joinSqlTmdids = $"join A0 in c.tmdids";
+            //string andSqlTmdids = $"   A0 in('{id}')";
+            ////班级
+            //string joinSqlClasses = "";
+            //string andSqlClasses = "";
+            //List<string> classes = null;
+            //if (request.TryGetProperty("classes", out JsonElement jclasses))
+            //{
+            //    if (jclasses.ValueKind is JsonValueKind.Array)
+            //    {
+            //        classes = jclasses.ToObject<List<string>>();
+            //        if (classes.IsNotEmpty())
+            //        {
+            //            joinSqlClasses = " join A1 in c.classes ";
+            //            List<string> sqlList = new List<string>();
+            //            classes.ForEach(x => { sqlList.Add($" '{x}' "); });
+            //            string sql = string.Join(" , ", sqlList);
+            //            andSqlClasses = $"   A1 in ({sql}) ";
+            //        }
+            //    }
+            //}
+            //string tgSql = "";
+            //if (!string.IsNullOrWhiteSpace(joinSqlClasses))
+            //{
+            //    tgSql = $" and ({andSqlTmdids} or  {andSqlClasses } )";
+            //}
+            //else
+            //{
+            //    tgSql = $" and {andSqlTmdids}";
+            //}
+            //科目
+            string joinSqlSubjects = "";
+            string andSqlSubjects = "";
+            if (request.TryGetProperty("subjects", out JsonElement jsubjects))
+            {
+                if (jsubjects.ValueKind is JsonValueKind.Array)
+                {
+                    List<string> subjects = jsubjects.ToObject<List<string>>();
+                    if (subjects.IsNotEmpty())
+                    {
+                        joinSqlSubjects = " join A2 in c.subjects ";
+                        List<string> sqlList = new List<string>();
+                        subjects.ForEach(x => { sqlList.Add($" '{x}' "); });
+                        string sql = string.Join(" , ", sqlList);
+                        andSqlSubjects = $" and A2 in ({sql}) ";
+                    }
+                }
+            }
+            List<StuActivity> datas = new List<StuActivity>();
+            var client = _azureCosmos.GetCosmosClient();
+            if (!string.IsNullOrWhiteSpace(school))
+            {
+                string querySchool = $" SELECT distinct  value c   FROM c   {joinSqlSubjects}  where {stimesql}  {etimesql} and c.pk='Activity'   {typesql}  {andSqlSubjects}  ";
+
+                //查询数据归属学校的
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryStreamIterator(querySchool, continuationToken: continuationToken, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Activity-{school}-{id}") }))
+                {
+                    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())
+                        {
+                            datas.Add(obj.ToObject<StuActivity>());
+                        }
+                        //如果需要分页则跳出
+                        if (iscontinuation)
+                        {
+                            continuationToken = item.GetContinuationToken();
+                            break;
+                        }
+                    }
+                }
+            }
+            return (datas, continuationToken);
+        }
 
         /// <summary>
         /// 学生端查询