浏览代码

修正科目不存在時HiTeach取課程會錯誤的問題

upon 1 年之前
父节点
当前提交
928793c391
共有 1 个文件被更改,包括 30 次插入29 次删除
  1. 30 29
      TEAMModelOS/Controllers/Client/HiTeachController.cs

+ 30 - 29
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -212,10 +212,10 @@ namespace TEAMModelOS.Controllers.Client
                         }
                     }
                 }
-                (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) space = await BlobService.GetSurplusSpace($"{(sp ? request.school : tid)}", request.sp, _option.Location, _azureCosmos, _azureRedis, _azureStorage, _dingDing,_httpTrigger);
+                (long usedSize, long teach, long total, long surplus, Dictionary<string, double?> catalog) space = await BlobService.GetSurplusSpace($"{(sp ? request.school : tid)}", request.sp, _option.Location, _azureCosmos, _azureRedis, _azureStorage, _dingDing, _httpTrigger);
                 //計算學校或個人的使用空間
                 //  RedisValue redisValue = r8.HashGet($"Blob:Record", $"{(sp ? request.school : tid)}");
-                if (space.usedSize>0)
+                if (space.usedSize > 0)
                 {
                     usize = Math.Round(space.usedSize / 1073741824.0 - (sp ? tsize : 0), 2, MidpointRounding.AwayFromZero); //1073741824  1G
                 }
@@ -252,8 +252,8 @@ namespace TEAMModelOS.Controllers.Client
                 sbm.Add(messageChange);
                 //批量發送消息
                 await _serviceBus.GetServiceBusClient().SendBatchMessageAsync(_configuration.GetValue<string>("Azure:ServiceBus:ActiveTask"), sbm);
-               
-                if (sp && usize>size)
+
+                if (sp && usize > size)
                 {
                     ////处理学校开课,空间不足时。检查是否有  当前教师tid,强制保存save<>1,没有标记未删除status<>404,没有被收藏favorite<=0 ,时间最旧的一条记录startTime
                     LessonRecord lessonRecord = null;
@@ -278,10 +278,10 @@ namespace TEAMModelOS.Controllers.Client
                     }
                     else
                     {  //没有找到匹配当前 教师tid,save<>1,status<>404,没有被收藏,时间最旧的一条记录。无法手动再继续 usize -= 1;,则不能继续开课。
-                       
+
                     }
                 }
-                 
+
                 return Ok(new { status = 200, lr.id, students, size, usize });
             }
             catch (Exception ex)
@@ -409,7 +409,7 @@ namespace TEAMModelOS.Controllers.Client
                 jwt.Payload.TryGetValue("name", out object name);
                 jwt.Payload.TryGetValue("picture", out object picture);
 
-                
+
                 List<object> schools = new List<object>();
                 string defaultschool = null;
                 //TODK 取得Teacher 個人相關數據(課程清單、虛擬教室清單、歷史紀錄清單等),學校數據另外API處理,多校切換時不同
@@ -428,7 +428,7 @@ namespace TEAMModelOS.Controllers.Client
                             if (statusNow.Equals("join")) //成為老師的才放入
                             {
                                 var schoolJson = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{obj.GetProperty("schoolId")}", new PartitionKey("Base"));
-                                if(schoolJson.Status.Equals(StatusCodes.Status200OK))
+                                if (schoolJson.Status.Equals(StatusCodes.Status200OK))
                                 {
                                     var school = await JsonDocument.ParseAsync(schoolJson.ContentStream);
                                     schoolExtobj = new GetTeacherInfoApiSchool();
@@ -485,7 +485,8 @@ namespace TEAMModelOS.Controllers.Client
                 var resultTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<CourseTask>(sqlprivate, $"CourseTask");
                 if (resultTeacher.list.IsNotEmpty())
                 {
-                    resultTeacher.list.ForEach(x => {
+                    resultTeacher.list.ForEach(x =>
+                    {
                         var schedulesTeacher = x.schedules.Where(z => !string.IsNullOrWhiteSpace(z.teacherId) && z.teacherId.Equals(id));
                         if (schedulesTeacher.Any())
                         {
@@ -505,7 +506,7 @@ namespace TEAMModelOS.Controllers.Client
                     var resultGroup = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<GroupListMemberCnt>(sqlGroup, $"GroupList");
                     if (resultGroup.list.IsNotEmpty())
                     {
-                        foreach(GroupListMemberCnt groupData in resultGroup.list)
+                        foreach (GroupListMemberCnt groupData in resultGroup.list)
                         {
                             groupCntDic.Add(groupData.id, groupData);
                         }
@@ -532,7 +533,7 @@ namespace TEAMModelOS.Controllers.Client
                             if (teacher.Any())
                             {
                                 List<CourseTaskDto> teacherList = teacher.ToList();
-                                foreach(CourseTaskDto teacherTaskDto in teacherList)
+                                foreach (CourseTaskDto teacherTaskDto in teacherList)
                                 {
                                     List<ScheduleTask> schedules = teacherTaskDto.courseTask.schedules;
                                     foreach (ScheduleTask schedule in schedules)
@@ -747,7 +748,7 @@ namespace TEAMModelOS.Controllers.Client
                 List<object> subjects = new List<object>();
                 List<object> examTypes = new List<object>();
                 List<string> periodIds = new List<string>(); //學段ID 取得課程時限制用
-                
+
                 string lang = "en-us";
                 School school_base = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{school_code}", new PartitionKey("Base"));
                 if (!string.IsNullOrWhiteSpace(school_base.id))
@@ -765,11 +766,11 @@ namespace TEAMModelOS.Controllers.Client
                     //年級、科目、評測類型取得
                     foreach (Period periodinfo in school_base.period)
                     {
-                        if(!string.IsNullOrWhiteSpace(inputPeriodId))
+                        if (!string.IsNullOrWhiteSpace(inputPeriodId))
                         {
                             if (!periodinfo.id.Equals(inputPeriodId)) continue; //若有給periodId,則過濾學段;未給則全取
                         }
-                        periods.Add(new { id= periodinfo.id, name= periodinfo.name, subjects = periodinfo.subjects });
+                        periods.Add(new { id = periodinfo.id, name = periodinfo.name, subjects = periodinfo.subjects });
                         periodIds.Add(periodinfo.id);
                         int gradeIndex = 0;
                         foreach (string gradeName in periodinfo.grades)
@@ -782,7 +783,7 @@ namespace TEAMModelOS.Controllers.Client
                             subjects.Add(new { id = subjectinfo.id, name = subjectinfo.name, periodId = periodinfo.id });
                         }
                         foreach (var examType in periodinfo.analysis.type)
-{
+                        {
                             examTypes.Add(examType);
                         }
                     }
@@ -846,7 +847,7 @@ namespace TEAMModelOS.Controllers.Client
                                 {
                                     groupCntDic.Add(groupData.id, groupData);
                                 }
-                                
+
                             }
                         }
                         string sqlClass = $"SELECT c.code, c.id, c.name, c.scope, c.year, 'class' as type, 0 as memberCount FROM c WHERE  c.id in ({string.Join(",", groupIds.Select(b => $"'{b}'"))})";
@@ -858,7 +859,7 @@ namespace TEAMModelOS.Controllers.Client
                                 if (!groupCntDic.ContainsKey(groupData.id))
                                 {
                                     groupCntDic.Add(groupData.id, groupData);
-                                }   
+                                }
                             }
                         }
                         //取得學生數
@@ -897,7 +898,7 @@ namespace TEAMModelOS.Controllers.Client
                             classes = new List<GetTeacherInfoApiCourseClass>();
                             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())
+                            if (teacher.Any() && period != null)
                             {
                                 List<CourseTaskDto> teacherList = teacher.ToList();
                                 foreach (CourseTaskDto teacherTaskDto in teacherList)
@@ -1140,7 +1141,7 @@ namespace TEAMModelOS.Controllers.Client
                             string classId = obj.GetProperty("classId").ToString();
                             string subjectId = obj.GetProperty("subjectId").ToString();
                             ExamFinishClassesSubList existExamFinishClassesSubRow = examFinClassSubList.Where(e => e.examId == examId && e.classId == classId && e.subjectId == subjectId).FirstOrDefault();
-                            if(existExamFinishClassesSubRow == null)
+                            if (existExamFinishClassesSubRow == null)
                             {
                                 ExamFinishClassesSubList ExamFinishClassesSubRow = new ExamFinishClassesSubList();
                                 ExamFinishClassesSubRow.examId = examId;
@@ -1188,7 +1189,7 @@ namespace TEAMModelOS.Controllers.Client
                             foreach (string classIdNow in examExtobj.classes)
                             {
                                 GetSchInfoExamFinishClassesSub examClassSubjectRow = examClassSubjectList.Where(x => x.classId == classIdNow).FirstOrDefault();
-                                if(examClassSubjectRow == null)
+                                if (examClassSubjectRow == null)
                                 {
                                     examClassSubjectRow = new GetSchInfoExamFinishClassesSub();
                                     examClassSubjectRow.classId = classIdNow;
@@ -1198,12 +1199,12 @@ namespace TEAMModelOS.Controllers.Client
                                 foreach (GetSchInfoExamSubject subjectNow in examExtobj.subjects)
                                 {
                                     string subjectIdNow = subjectNow.id;
-                                    if(!examClassSubjectRow.subjectIds.Contains(subjectIdNow))
+                                    if (!examClassSubjectRow.subjectIds.Contains(subjectIdNow))
                                     {
                                         examClassSubjectRow.subjectIds.Add(subjectIdNow);
                                     }
                                     ExamFinishClassesSubList existFinClassesSub = examFinClassSubList.Where(e => e.examId == examId && e.classId == classIdNow && e.subjectId == subjectIdNow).FirstOrDefault();
-                                    if(existFinClassesSub != null)
+                                    if (existFinClassesSub != null)
                                     {
                                         examClassSubjectRow.finishSubjectIds.Add(subjectIdNow);
                                     }
@@ -1211,7 +1212,7 @@ namespace TEAMModelOS.Controllers.Client
                                 examExtobj.finishClassesSub.Add(examClassSubjectRow);
                                 if (examClassSubjectRow.subjectIds.Count.Equals(examClassSubjectRow.finishSubjectIds.Count))
                                 {
-                                    if(!examExtobj.finishClasses.Contains(classIdNow))
+                                    if (!examExtobj.finishClasses.Contains(classIdNow))
                                     {
                                         examExtobj.finishClasses.Add(classIdNow);
                                     }
@@ -1679,13 +1680,13 @@ namespace TEAMModelOS.Controllers.Client
             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Share>(queryText: queryText.ToString(),
             requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Share-share-{id}") }))
             {
-                
-                if(!string.IsNullOrWhiteSpace(syllabusId))
+
+                if (!string.IsNullOrWhiteSpace(syllabusId))
                 {
-                    if(item.id.Equals(syllabusId))
+                    if (item.id.Equals(syllabusId))
                     {
                         Volume volumeExist = volumeList.Where((Volume v) => v.id == item.volumeId).FirstOrDefault();
-                        if(volumeExist == null)
+                        if (volumeExist == null)
                         {
                             Volume volume = new Volume();
                             volume.id = item.volumeId;
@@ -1716,7 +1717,7 @@ namespace TEAMModelOS.Controllers.Client
                         volume.syllabusIds.Add(item.id);
                         volumeList.Add(volume);
                         var (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS(item.issuer, BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
-                        if(!tmidDic.ContainsKey(item.issuer)) tmidDic.Add(item.issuer, blob_sas);
+                        if (!tmidDic.ContainsKey(item.issuer)) tmidDic.Add(item.issuer, blob_sas);
                     }
                     else
                     {
@@ -1727,7 +1728,7 @@ namespace TEAMModelOS.Controllers.Client
 
             //取得課綱並輸出回傳值
             List<object> result = new List<object>();
-            foreach(Volume volTmp in volumeList)
+            foreach (Volume volTmp in volumeList)
             {
                 List<SyllabusTreeNode> treeNodes = new();
                 if (!display.Equals(1))