CrazyIter_Bin 1 tahun lalu
induk
melakukan
c611435166

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/GroupList.cs

@@ -58,7 +58,7 @@ namespace TEAMModelOS.SDK.Models
         /// <summary>
         /// 二维码 天数
         /// </summary>
-        public int qrcodeDays { get; set; }
+        public int qrcodeDays { get; set; } = 1;
         /// <summary>
         /// 二维码过期时间
         /// </summary>

+ 91 - 6
TEAMModelOS/Controllers/Both/CourseBaseController.cs

@@ -1665,6 +1665,97 @@ namespace TEAMModelOS.Controllers.Both
             return Ok();
         }
 
+        /// <summary>
+        /// 教师任教的课程
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "student")]
+        [HttpPost("student")]
+        public async Task<IActionResult> Student(JsonElement request) {
+            try
+            {
+                (string student, _, _, string school) = HttpContext.GetAuthTokenInfo();
+                if (!request.TryGetProperty("grant_type", out JsonElement grant_type)) return BadRequest();
+                string code = $"CourseTask-{school}";
+                var client = _azureCosmos.GetCosmosClient();
+                switch (true)
+                {
+                    //任教学校课程和个人课程
+                    case bool when $"{grant_type}".Equals("teach", StringComparison.OrdinalIgnoreCase):
+                        string sql = $"SELECT distinct value c FROM c  join b in c.schedules where c.pk='CourseTask' and   b.teacherId in() ";
+                        List<KeyValuePair<string, CourseTask>> schoolTeacherTask = new List<KeyValuePair<string, CourseTask>>();
+                        List<KeyValuePair<string, CourseTask>> schoolAssistantTask = new List<KeyValuePair<string, CourseTask>>();
+
+                        List<KeyValuePair<string, CourseTask>> privateTeacherTask = new List<KeyValuePair<string, CourseTask>>();
+                        List<KeyValuePair<string, CourseTask>> privateAssistantTask = new List<KeyValuePair<string, CourseTask>>();
+                        List<CourseDto> schoolCourses = new List<CourseDto>();
+                        List<CourseDto> teahcerCourses = new List<CourseDto>();
+                        if (!string.IsNullOrWhiteSpace(school))
+                        {
+                            School schoolBase = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
+                            JsonElement _year = default, _semesterId = default, _periodId = default;
+                            if (!request.TryGetProperty("periodId", out _periodId)) return BadRequest();
+                            if (!request.TryGetProperty("year", out _year))
+                            {
+                                return BadRequest();
+                            }
+                            if (!request.TryGetProperty("semesterId", out _semesterId))
+                            {
+                                return BadRequest();
+                            }
+                            var period = schoolBase.period.Find(x => x.id.Equals($"{_periodId}"));
+                            //string date = SchoolService.GetOpensByStudyYearAndSemester(period.semesters, int.Parse($"{_year}"), $"{_semesterId}");
+                            sql = $"{sql} and  c.year={_year} and c.semesterId='{_semesterId}'";
+                            HashSet<string> courseIds = new HashSet<string>();
+                            var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseTask>(sql, $"CourseTask-{school}");
+                            if (resultSchool.list.IsNotEmpty())
+                            {
+                                
+                            }
+                            if (courseIds.Any())
+                            {
+                                string sqlCourse = $"select value c from c where c.id in ({string.Join(",", courseIds.Select(b => $"'{b}'"))})";
+                                var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseBase>(sqlCourse, $"CourseBase-{school}");
+                                if (result.list.IsNotEmpty())
+                                {
+                                    foreach (var item in result.list)
+                                    {
+                                        List<CourseTaskDto> courseTaskDtos = new List<CourseTaskDto>();
+                                        var teacher = schoolTeacherTask.Where(x => x.Key.Equals(item.id)).Select(z => new CourseTaskDto { courseTask=z.Value, type="teacher" });
+                                        if (teacher.Any())
+                                        {
+                                            courseTaskDtos.AddRange(teacher.ToList());
+                                        }
+                                        var assistant = schoolAssistantTask.Where(x => x.Key.Equals(item.id)).Select(z => new CourseTaskDto { courseTask=z.Value, type="assistant" });
+                                        if (assistant.Any())
+                                        {
+                                            courseTaskDtos.AddRange(assistant.ToList());
+                                        }
+                                        schoolCourses.Add(new CourseDto { courseBase=item, courseTasks=courseTaskDtos });
+                                    }
+                                }
+                            }
+                        }
+                        var resultTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<CourseTask>(sql, $"CourseTask");
+                        if (resultTeacher.list.IsNotEmpty())
+                        {
+                            HashSet<string> courseIds = new HashSet<string>();
+                            
+                        }
+                        return Ok(new { teahcerCourses, schoolCourses });
+
+                }
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{_option.Location},course-base\teacher{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                return BadRequest(new { ex.Message });
+            }
+            return Ok();
+        }
+
         /// <summary>
         /// 教师任教的课程
         /// </summary>
@@ -1679,9 +1770,7 @@ namespace TEAMModelOS.Controllers.Both
             try
             {
                 (string tmdid, _, _, string school) = HttpContext.GetAuthTokenInfo();
-                tmdid="1528783301";
                 if (!request.TryGetProperty("grant_type", out JsonElement grant_type)) return BadRequest();
-                if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 string code = $"CourseTask-{school}";
                 var client = _azureCosmos.GetCosmosClient();
                 switch (true)
@@ -1800,10 +1889,8 @@ namespace TEAMModelOS.Controllers.Both
                                 }
                             }
                         }
-
                         //个人,
                         //学校,
-
                         //助教,学校。
                         //助教,个人。
                         return Ok(new { teahcerCourses , schoolCourses});
@@ -1817,8 +1904,6 @@ namespace TEAMModelOS.Controllers.Both
             }
             return Ok();
         }
-    
-        
     }
 
     public class CourseDto { 

+ 11 - 4
TEAMModelOS/Controllers/Both/GroupListController.cs

@@ -857,8 +857,6 @@ namespace TEAMModelOS.Controllers
                     //只有开启审核,且设置天数大于零,且之前没有设置过期时间的时候才会重新设置过期时间。
                     if (list.review==1)
                     {
-
-                        
                         if (list.qrcodeDays>0)
                         {
                             GroupList dblist = null;
@@ -874,11 +872,20 @@ namespace TEAMModelOS.Controllers
                             if (dblist!=null)
                             {
                                 //更新过期时间
-                                if (dblist.qrcodeDays!=list.qrcodeDays) {
+                                if (dblist.qrcodeDays!=list.qrcodeDays)
+                                {
                                     list.qrcodeExpire= DateTimeOffset.UtcNow.AddDays(list.qrcodeDays).ToUnixTimeMilliseconds();
                                     string key = $"GroupList:Waitinglist:{list.scope}:{list.id}";
                                     await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, expiry: DateTimeOffset.FromUnixTimeMilliseconds(list.qrcodeExpire).UtcDateTime);
                                 }
+                                else {
+                                    //相同
+                                    if (dblist.review==0  && list.review==1) {
+                                        list.qrcodeExpire= DateTimeOffset.UtcNow.AddDays(list.qrcodeDays).ToUnixTimeMilliseconds();
+                                        string key = $"GroupList:Waitinglist:{list.scope}:{list.id}";
+                                        await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, expiry: DateTimeOffset.FromUnixTimeMilliseconds(list.qrcodeExpire).UtcDateTime);
+                                    }
+                                }
                             }
                             else {
                                 if (list.qrcodeExpire<=0)
@@ -894,7 +901,7 @@ namespace TEAMModelOS.Controllers
                     }
                     else
                     {
-                        list.qrcodeDays = 0;
+                        list.qrcodeDays = 1;
                         list.qrcodeExpire = 0;
                     }
                     list.school = null;