CrazyIter_Bin 1 ano atrás
pai
commit
a03313f025
1 arquivos alterados com 89 adições e 0 exclusões
  1. 89 0
      TEAMModelOS/Controllers/Both/CourseBaseController.cs

+ 89 - 0
TEAMModelOS/Controllers/Both/CourseBaseController.cs

@@ -123,6 +123,8 @@ namespace TEAMModelOS.Controllers.Both
                             }
                             if (!request.TryGetProperty("periodId", out JsonElement _periodId)) return BadRequest();
                             List<CourseBase> courseBases = _courses.ToObject<List<CourseBase>>();
+
+                            courseBases.Where(x => string.IsNullOrWhiteSpace(x.no));
                             //1.检查导入的课程名称是否有效
                             StringBuilder sqlName = new StringBuilder(" select  value c from c ");
                             sqlName.Append($" where c.name in( {string.Join(",", courseBases.Select(z => $"'{z.name}'"))} )   and  c.period.id='{_periodId}' ");
@@ -1342,6 +1344,93 @@ namespace TEAMModelOS.Controllers.Both
                             }
                             return BadRequest();
                         }
+                    case bool when $"{grant_type}".Equals("export-task", StringComparison.OrdinalIgnoreCase) && $"{scope}".Equals("school", StringComparison.OrdinalIgnoreCase): 
+                        {
+
+                            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();
+                            }
+                            string sql = $"select value c from c where c.year={_year} and c.semesterId='{_semesterId}'";
+                            string code = $"CourseTask-{school}";
+                            var  result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseTask>(sql, code);
+                            if (result.list.IsNotEmpty()) {
+                                string courseIdSQL = $"select value c from c where c.id in({string.Join(",",result.list.Select(z=>$"'{z.courseId}'"))})";
+                                List<CourseBase> courseBases = new List<CourseBase>();
+                                var resultCourse = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseBase>(courseIdSQL, $"CourseBase-{school}");
+                                if (resultCourse.list.IsNotEmpty())
+                                {
+                                    courseBases.AddRange(resultCourse.list);
+                                }
+                                var classIds=  result.list.SelectMany(z => z.schedules).Where(y => y.type.Equals("class") && !string.IsNullOrWhiteSpace(y.groupId)).Select(x => x.groupId);
+                                var teachIds = result.list.SelectMany(z => z.schedules).Where(y => y.type.Equals("teach")&& !string.IsNullOrWhiteSpace(y.groupId)).Select(x => x.groupId);
+                                var teacherIds = result.list.SelectMany(z => z.schedules).Where(y =>!string.IsNullOrWhiteSpace(y.teacherId) ).Select(x => x.teacherId);
+                                var assistantIds = result.list.SelectMany(z => z.schedules).Where(y => y.assistants!=null && y.assistants.Any()).SelectMany(x => x.assistants);
+                                List<Class> classes = new List<Class>();
+                                if (classIds!=null  && classIds.Count()>0)
+                                {
+                                    string classIdSQL = $"select value c from c where c.id in({string.Join(",", classIds.Select(x => $"'{x}'"))})";
+                                    var resultClass = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<Class>(classIdSQL, $"Class-{school}");
+                                    if (resultClass.list.IsNotEmpty())
+                                    {
+                                        classes.AddRange(resultClass.list);
+                                    }
+                                }
+                                List<GroupList> groupLists = new List<GroupList>();
+                                if (teachIds!=null  && teachIds.Count()>0) {
+                                    string teachIdSQL = $"select value c from c where c.id in({string.Join(",", teachIds.Select(x => $"'{x}'"))})";
+                                    var resultGroupList = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<GroupList>(teachIdSQL, $"GroupList-{school}");
+                                    if (resultGroupList.list.IsNotEmpty())
+                                    {
+                                        groupLists.AddRange(resultGroupList.list);
+                                    }
+                                }
+                              
+                                List<string> tmdids = new List<string>();
+                                if (teacherIds!=null  && teacherIds.Count()>0) {
+                                    tmdids.AddRange(teacherIds);
+                                }
+                                if (assistantIds!=null  && assistantIds.Count()>0)
+                                {
+                                    tmdids.AddRange(assistantIds);
+                                }
+                                List<Teacher> teachers = new List<Teacher>();
+                                if (tmdids.Count>0) {
+                                    string tmdidSQL = $"select value c from c where c.id in({string.Join(",", tmdids.Select(x => $"'{x}'"))})";
+                                    var resultTmdid= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<Teacher>(tmdidSQL, "Base");
+                                    if (resultTmdid.list.IsNotEmpty())
+                                    {
+                                        teachers.AddRange(resultTmdid.list);
+                                    }
+                                }
+                                List<CourseCheckImport> imports= new List<CourseCheckImport>();
+                                foreach (var item in result.list) {
+                                    var courseBase=  courseBases.Find(z => z.id.Equals(item.courseId));
+                                    item.schedules.ForEach(z => {
+                                        
+                                        CourseCheckImport courseCheckImport = new CourseCheckImport {name=courseBase?.name };
+                                        if (z.type.Equals("class")) {
+                                          var clazz=   classes.Find(x => x.id.Equals(z.groupId));
+                                            courseCheckImport.type=z.type;
+                                            courseCheckImport.list=$"{clazz.year}-{clazz.no}";
+                                        }
+                                        if (z.type.Equals("teach"))
+                                        {
+                                            var groupList = groupLists.Find(x => x.id.Equals(z.groupId));
+                                            courseCheckImport.type=z.type;
+                                            courseCheckImport.list=$"{groupList.name}";
+                                        }
+                                    });
+                                }
+                            }
+                            break;
+                        }
                 }
             } catch (Exception ex) {
                await _dingDing.SendBotMsg($"{_option.Location},课程处理异常,{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);