Browse Source

Merge branch 'develop' of http://52.130.252.100:10000/TEAMMODEL/TEAMModelOS into develop

OnePsycho 1 year ago
parent
commit
b145aa7782

+ 79 - 58
TEAMModelOS/Controllers/Both/CourseBaseController.cs

@@ -29,6 +29,7 @@ using DocumentFormat.OpenXml.Drawing.Spreadsheet;
 using System.Text.RegularExpressions;
 using System.Security.Claims;
 using DocumentFormat.OpenXml.Bibliography;
+using DocumentFormat.OpenXml.Spreadsheet;
 
 namespace TEAMModelOS.Controllers.Both
 {
@@ -41,13 +42,14 @@ namespace TEAMModelOS.Controllers.Both
     {
         private AzureCosmosFactory _azureCosmos;
         private readonly DingDing _dingDing;
+        private readonly CoreAPIHttpService _coreAPIHttpService;
         private readonly Option _option;
         private readonly AzureServiceBusFactory _serviceBus;
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureRedisFactory _azureRedis;
         private static List<string> weekDays = new List<string> { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
         public IConfiguration _configuration { get; set; }
-        public CourseBaseController(AzureRedisFactory azureRedis, AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration)
+        public CourseBaseController(AzureRedisFactory azureRedis, AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, CoreAPIHttpService coreAPIHttpService, AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration)
         {
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
@@ -55,7 +57,7 @@ namespace TEAMModelOS.Controllers.Both
             _serviceBus = serviceBus;
             _configuration = configuration;
             _azureStorage = azureStorage;
-            _azureRedis = azureRedis;
+            _azureRedis = azureRedis; _coreAPIHttpService = coreAPIHttpService;
         }
         /// <summary>
         /// 更新保存课程
@@ -1676,76 +1678,95 @@ namespace TEAMModelOS.Controllers.Both
         public async Task<IActionResult> Student(JsonElement request) {
             try
             {
-                (string student, _, _, string school) = HttpContext.GetAuthTokenInfo();
+                (string userid, _, _, 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)
+                object scope = null;
+                HttpContext?.Items.TryGetValue("Scope", out scope);
+                int memberType = 2;
+                if ($"{scope}".Equals(Constant.ScopeStudent))
                 {
-                    //任教学校课程和个人课程
-                    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>>();
+                    memberType = 2;
+                    // Student student = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<Student>(userid, new PartitionKey($"Base-{school}"));
+                }
+                if ($"{scope}".Equals(Constant.ScopeTmdUser))
+                {
+                    memberType = 1;
+                }
+                if ($"{scope}".Equals(Constant.ScopeTeacher))
+                {
+                    memberType = 1;
+                }
+                List<GroupListGrp> groups = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, userid, memberType, school, new List<string> { "class", "teach" });
+                if (groups.IsNotEmpty()) {
+                    switch (true)
+                    {
+                        //学生应参与的课程
+                        case bool when $"{grant_type}".Equals("attend", StringComparison.OrdinalIgnoreCase):
+                            string sql = $"SELECT distinct value c FROM c  join b in c.schedules where c.pk='CourseTask' and b.groupId 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())
+                            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))
                             {
-                                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())
+                                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))
                                 {
-                                    foreach (var item in result.list)
+                                    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())
                                     {
-                                        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())
+                                        foreach (var item in result.list)
                                         {
-                                            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());
+                                            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 });
                                         }
-                                        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 });
+                            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)

+ 8 - 2
TEAMModelOS/Controllers/Both/GroupListController.cs

@@ -832,7 +832,9 @@ namespace TEAMModelOS.Controllers
         [ProducesDefaultResponseType]
         [AuthToken(Roles = "teacher,admin")]
         [HttpPost("upsert-grouplist")]
-        [Authorize(Roles = "IES")]
+#if !DEBUG
+ [Authorize(Roles = "IES")]
+#endif
         public async Task<IActionResult> UpsertGroupList(JsonElement  json)
         {
 
@@ -880,11 +882,15 @@ namespace TEAMModelOS.Controllers
                                 }
                                 else {
                                     //相同
-                                    if (dblist.review==0  && list.review==1) {
+                                    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 {
+                                        list.qrcodeExpire=dblist.qrcodeExpire;
+                                    }
                                 }
                             }
                             else {