瀏覽代碼

编写学生查询课程列表接口。

CrazyIter_Bin 4 年之前
父節點
當前提交
fc4a96d7a3

+ 5 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/StuCourse.cs

@@ -4,6 +4,11 @@ using System.Text;
 
 namespace TEAMModelOS.SDK.Models.Cosmos.Common
 {
+    /// <summary>
+    /*
+     * 
+     */
+    /// </summary>
     public class StuCourse :CosmosEntity
     {
         /// <summary>

+ 76 - 64
TEAMModelOS/Controllers/School/CourseController.cs

@@ -207,48 +207,59 @@ namespace TEAMModelOS.Controllers
                     {
                         odlStus.Add(item);
                     }
-                    if (stuList.students.IsNotEmpty()) {
-                       
-                        if (odlStus.Count > 0 && odlStus[0].students.IsNotEmpty())
+                    if (odlStus.Count > 0) 
+                    {
+                        if (stuList.students.IsNotEmpty())
                         {
-                            StuList oldStu = odlStus[0];
-                            foreach (var stu in stuList.students) {
-                                bool flag = false;
-                                //判断新增名单成员不在已经存在的名单
-                                foreach (var old in oldStu.students) {
-                                    if (old.id == stu.id && old.code == stu.code) {
-                                        flag = true;
+
+                            if (  odlStus[0].students.IsNotEmpty())
+                            {
+                                StuList oldStu = odlStus[0];
+                                foreach (var stu in stuList.students)
+                                {
+                                    bool flag = false;
+                                    //判断新增名单成员不在已经存在的名单
+                                    foreach (var old in oldStu.students)
+                                    {
+                                        if (old.id == stu.id && old.code == stu.code)
+                                        {
+                                            flag = true;
+                                        }
+                                    }
+                                    if (flag == false)
+                                    {
+                                        change.stujoin.Add(stu);
                                     }
                                 }
-                                if (flag == false) {
-                                    change.stujoin.Add(stu);
-                                } 
                             }
                         }
-                    }
-                    if (stuList.tmids.IsNotEmpty()) {
-                        if (odlStus.Count > 0 && odlStus[0].tmids.IsNotEmpty()) {
-                            StuList oldStu = odlStus[0];
-                            foreach (var tmdid in stuList.tmids) {
-                                bool flag = false;
-                                //判断新增名单成员不在已经存在的名单
-                                foreach (var old in oldStu.tmids)
+                        if (stuList.tmids.IsNotEmpty())
+                        {
+                            if (  odlStus[0].tmids.IsNotEmpty())
+                            {
+                                StuList oldStu = odlStus[0];
+                                foreach (var tmdid in stuList.tmids)
                                 {
-                                    if (old==tmdid)
+                                    bool flag = false;
+                                    //判断新增名单成员不在已经存在的名单
+                                    foreach (var old in oldStu.tmids)
                                     {
-                                        flag = true;
+                                        if (old == tmdid)
+                                        {
+                                            flag = true;
+                                        }
+                                    }
+                                    if (flag == false)
+                                    {
+                                        change.tmdjoin.Add(tmdid);
                                     }
-                                }
-                                if (flag == false)
-                                {
-                                    change.tmdjoin.Add(tmdid);
                                 }
                             }
                         }
+                        var messageChange = new ServiceBusMessage(change.ToJsonString());
+                        messageChange.ApplicationProperties.Add("name", "StuList");
+                        await _serviceBus.GetServiceBusClient().SendMessageAsync("active-task", messageChange);
                     }
-                    var messageChange = new ServiceBusMessage(change.ToJsonString());
-                    messageChange.ApplicationProperties.Add("name", "StuList");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync("active-task", messageChange);
                     stuList = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync(stuList, new PartitionKey($"StuList-{originCode}"));
                 }
                 else
@@ -265,56 +276,58 @@ namespace TEAMModelOS.Controllers
                     {
                         odlStus.Add(item);
                     }
-                    if (stuList.students.IsNotEmpty())
-                    {
-
-                        if (odlStus.Count > 0 && odlStus[0].students.IsNotEmpty())
+                    if (odlStus.Count>0) {
+                        if (stuList.students.IsNotEmpty())
                         {
-                            StuList oldStu = odlStus[0];
-                            foreach (var stu in stuList.students)
+
+                            if (  odlStus[0].students.IsNotEmpty())
                             {
-                                bool flag = false;
-                                //判断新增名单成员不在已经存在的名单
-                                foreach (var old in oldStu.students)
+                                StuList oldStu = odlStus[0];
+                                foreach (var stu in stuList.students)
                                 {
-                                    if (old.id == stu.id && old.code == stu.code)
+                                    bool flag = false;
+                                    //判断新增名单成员不在已经存在的名单
+                                    foreach (var old in oldStu.students)
                                     {
-                                        flag = true;
+                                        if (old.id == stu.id && old.code == stu.code)
+                                        {
+                                            flag = true;
+                                        }
+                                    }
+                                    if (flag == false)
+                                    {
+                                        change.stujoin.Add(stu);
                                     }
-                                }
-                                if (flag == false)
-                                {
-                                    change.stujoin.Add(stu);
                                 }
                             }
                         }
-                    }
-                    if (stuList.tmids.IsNotEmpty())
-                    {
-                        if (odlStus.Count > 0 && odlStus[0].tmids.IsNotEmpty())
+                        if (stuList.tmids.IsNotEmpty())
                         {
-                            StuList oldStu = odlStus[0];
-                            foreach (var tmdid in stuList.tmids)
+                            if (  odlStus[0].tmids.IsNotEmpty())
                             {
-                                bool flag = false;
-                                //判断新增名单成员不在已经存在的名单
-                                foreach (var old in oldStu.tmids)
+                                StuList oldStu = odlStus[0];
+                                foreach (var tmdid in stuList.tmids)
                                 {
-                                    if (old == tmdid)
+                                    bool flag = false;
+                                    //判断新增名单成员不在已经存在的名单
+                                    foreach (var old in oldStu.tmids)
                                     {
-                                        flag = true;
+                                        if (old == tmdid)
+                                        {
+                                            flag = true;
+                                        }
+                                    }
+                                    if (flag == false)
+                                    {
+                                        change.tmdjoin.Add(tmdid);
                                     }
-                                }
-                                if (flag == false)
-                                {
-                                    change.tmdjoin.Add(tmdid);
                                 }
                             }
                         }
+                        var messageChange = new ServiceBusMessage(change.ToJsonString());
+                        messageChange.ApplicationProperties.Add("name", "StuList");
+                        await _serviceBus.GetServiceBusClient().SendMessageAsync("active-task", messageChange);
                     }
-                    var messageChange = new ServiceBusMessage(change.ToJsonString());
-                    messageChange.ApplicationProperties.Add("name", "StuList");
-                    await _serviceBus.GetServiceBusClient().SendMessageAsync("active-task", messageChange);
                     stuList.code = "StuList";
                     stuList = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stuList, new PartitionKey($"StuList"));
                 }
@@ -325,7 +338,6 @@ namespace TEAMModelOS.Controllers
                 await _dingDing.SendBotMsg($"OS,{_option.Location},course/upsert-list()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
-
         }
 
         //查询名单

+ 72 - 0
TEAMModelOS/Controllers/School/StudentCommonController.cs

@@ -1,3 +1,4 @@
+using Azure.Cosmos;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
@@ -55,5 +56,76 @@ namespace TEAMModelOS.Controllers
             (List<StuActivity> datas, string continuationToken) = await ActivityStudentService.FindActivity(request, id, school, _azureCosmos, _azureRedis);
             return Ok(new { datas, continuationToken });
         }
+        /// <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-course")]
+        // [AuthToken(Roles = "student")]
+        public async Task<IActionResult> StuCourse(JsonElement request)
+        {
+
+            var (id, name, pic, school) = HttpContext.GetAuthTokenInfo();
+            if (string.IsNullOrWhiteSpace(id))
+            {
+                if (request.TryGetProperty("userid", out JsonElement userid))
+                {
+                    if (!userid.ValueKind.Equals(JsonValueKind.Undefined) && !userid.ValueKind.Equals(JsonValueKind.Null) && userid.ValueKind.Equals(JsonValueKind.String))
+                    {
+                        id = userid.GetString();
+                    }
+                }
+            }
+            if (string.IsNullOrWhiteSpace(school))
+            {
+                if (request.TryGetProperty("school", out JsonElement schooljson)) {
+                    if (!schooljson.ValueKind.Equals(JsonValueKind.Undefined) && !schooljson.ValueKind.Equals(JsonValueKind.Null) && schooljson.ValueKind.Equals(JsonValueKind.String))
+                    {
+                        school = schooljson.GetString();
+                    }
+                }
+               
+            }
+            /// tmdid, schoolid
+            var userType = "tmdid";
+            if (request.TryGetProperty("userType", out JsonElement usertype))
+            {
+                if (!usertype.ValueKind.Equals(JsonValueKind.Undefined) && !usertype.ValueKind.Equals(JsonValueKind.Null) && usertype.ValueKind.Equals(JsonValueKind.String))
+                {
+                    userType = usertype.GetString();
+                }
+            }
+            string containerId = "Teacher";
+            string PartitionKey = $"Course-{id}";
+            if (!string.IsNullOrEmpty(school)) {
+                  containerId = "Student";
+                  PartitionKey = $"Course-{school}-{id}";
+            }
+            /// tmdid, schoolid
+            if (userType.Equals("tmdid"))
+            {
+                containerId = "Teacher";
+                PartitionKey = $"Course-{id}";
+            }
+            List<StuCourse> stus = new List<StuCourse>();
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", containerId).GetItemQueryIterator<StuCourse>(queryText: $"select value(c) from c ",
+              requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey(PartitionKey) }))
+            {
+                stus.Add(item);
+            }
+            return Ok(new { course=stus });
+        }
     }
 }

+ 17 - 7
TEAMModelOS/Services/Common/ActivityStudentService.cs

@@ -225,19 +225,29 @@ namespace TEAMModelOS.Services.Common
 
             if (string.IsNullOrWhiteSpace(id))
             {
-                id = request.GetProperty("userid").GetString();
-            }
-            if (string.IsNullOrWhiteSpace(school))
-            {
-                school = request.GetProperty("school").GetString();
+                if (request.TryGetProperty("userid", out JsonElement userid))
+                {
+                    if (!userid.ValueKind.Equals(JsonValueKind.Undefined) && !userid.ValueKind.Equals(JsonValueKind.Null) && userid.ValueKind.Equals(JsonValueKind.String))
+                    {
+                        id = userid.GetString();
+                    }
+                }
             }
+
+
             if (string.IsNullOrWhiteSpace(school))
             {
-                school = request.GetProperty("school").GetString();
+                if (request.TryGetProperty("school", out JsonElement schooljson))
+                {
+                    if (!schooljson.ValueKind.Equals(JsonValueKind.Undefined) && !schooljson.ValueKind.Equals(JsonValueKind.Null) && schooljson.ValueKind.Equals(JsonValueKind.String))
+                    {
+                        school = schooljson.GetString();
+                    }
+                }
             }
+
             /// tmdid, schoolid
             var userType = "tmdid";
-
             if (request.TryGetProperty("userType", out JsonElement usertype))
             {
                 if (!usertype.ValueKind.Equals(JsonValueKind.Undefined) && !usertype.ValueKind.Equals(JsonValueKind.Null) && usertype.ValueKind.Equals(JsonValueKind.String))