CrazyIter_Bin 3 years ago
parent
commit
4c41d51616

+ 55 - 9
TEAMModelAPI/Controllers/School/CourseController.cs

@@ -75,11 +75,11 @@ namespace TEAMModelAPI.Controllers
                 return Ok(new { error = 1, msg = "学段不存在!" });
             }
         }
-       
+
 
         [ProducesDefaultResponseType]
         [HttpPost("upsert-course-info")]
-        [ApiToken(Auth = "1302", Name = "课程详细信息", RW = "R", Limit = false)]
+        [ApiToken(Auth = "1302", Name = "课程详细信息", RW = "W", Limit = false)]
         public async Task<IActionResult> UpsertCourseInfo(JsonElement json)
         {
             var (id, school) = HttpContext.GetApiTokenInfo();
@@ -102,19 +102,53 @@ namespace TEAMModelAPI.Controllers
                                 id = Guid.NewGuid().ToString(),
                                 code = $"Course-{school}",
                                 name = courseDto.name,
-                                subject = new SubjectSimple { id = subject.id, name = subject.name  },
-                                period= new PeriodSimple { id = period.id, name = period.name },
-
+                                subject = new SubjectSimple { id = subject.id, name = subject.name },
+                                period = new PeriodSimple { id = period.id, name = period.name },
+                                school = school,
+                                desc = courseDto.desc,
+                                scope = "school",
+                                no = courseDto.no,
                             };
+                            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(course, new PartitionKey(course.code));
                         }
                         else
                         {
-
+                            Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{course.id}", new PartitionKey($"Course-{school}"));
+                            if (response.Status == 200)
+                            {
+                                JsonDocument jsonDocument = JsonDocument.Parse(response.Content);
+                                course = jsonDocument.RootElement.ToObject<Course>();
+                                course.pk = "Course";
+                                course.name = string.IsNullOrWhiteSpace(courseDto.name) ? course.name : courseDto.name;
+                                course.subject = new SubjectSimple { id = subject.id, name = subject.name };
+                                course.period = new PeriodSimple { id = period.id, name = period.name };
+                                course.school = school;
+                                course.desc = string.IsNullOrWhiteSpace(courseDto.desc) ? course.desc : courseDto.desc;
+                                course.scope = "school";
+                                course.no = string.IsNullOrWhiteSpace(courseDto.no) ? course.no : courseDto.no;
+                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(course, new PartitionKey(course.code));
+                            }
+                            else {
+                                course = new Course
+                                {
+                                    pk = "Course",
+                                    id = Guid.NewGuid().ToString(),
+                                    code = $"Course-{school}",
+                                    name = courseDto.name,
+                                    subject = new SubjectSimple { id = subject.id, name = subject.name },
+                                    period = new PeriodSimple { id = period.id, name = period.name },
+                                    school = school,
+                                    desc = courseDto.desc,
+                                    scope = "school",
+                                    no = courseDto.no,
+                                };
+                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(course, new PartitionKey(course.code));
+                            }
                         }
-                        return Ok(new { period.subjects, period.timetable, period.grades, period.majors });
+                        return Ok(new { period.subjects, period.timetable, course = course });
                     }
                     else {
-                        return Ok(new { error = 2, msg = "科目不存在!" });
+                        return Ok(new { error =4, msg = "科目不存在!" });
                     }
                 }
                 else
@@ -126,8 +160,20 @@ namespace TEAMModelAPI.Controllers
             {
                 return Ok(new { error = 3, msg = courseDto.Valid() });
             }
-            
         }
+
+        [ProducesDefaultResponseType]
+        [HttpPost("upsert-course-schedule")]
+        [ApiToken(Auth = "1302", Name = "更新课程的排课信息", RW = "W", Limit = false)]
+        public async Task<IActionResult> UpsertCourseSchedule(JsonElement json)
+        {
+            var (id, school) = HttpContext.GetApiTokenInfo();
+            if (!json.TryGetProperty("courseId", out JsonElement _courseId)) { return Ok(new { error = 1, msg = "课程参数错误" }); }
+            School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
+            Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{_courseId}", new PartitionKey($"Course-{school}"));
+            return Ok();
+        }
+
         [ProducesDefaultResponseType]
         [HttpPost("get-course-list")]
         [ApiToken(Auth = "1303", Name = "获取课程列表信息", RW = "R", Limit = false)]

+ 1 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerCorrect.cs

@@ -424,7 +424,7 @@ namespace TEAMModelOS.FunctionV4
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception e)
             {

+ 1 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerExam.cs

@@ -425,7 +425,7 @@ namespace TEAMModelOS.FunctionV4
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception e)
             {

+ 1 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerExamLite.cs

@@ -163,7 +163,7 @@ namespace TEAMModelOS.FunctionV4
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {

+ 1 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerHomework.cs

@@ -250,7 +250,7 @@ namespace TEAMModelOS.FunctionV4
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {

+ 1 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerStudy.cs

@@ -175,7 +175,7 @@ namespace TEAMModelOS.FunctionV4
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {

+ 1 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerSurvey.cs

@@ -398,7 +398,7 @@ namespace TEAMModelOS.FunctionV4
 
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {

+ 1 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerVote.cs

@@ -336,7 +336,7 @@ namespace TEAMModelOS.FunctionV4
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {

+ 7 - 7
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -68,7 +68,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamBus()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamBus()-CosmosDB异常{e.Message}\n{e.Status}{e.StackTrace}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {
@@ -92,7 +92,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,VoteBus()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,VoteBus()-CosmosDB异常{e.Message}\n{e.Status}{e.StackTrace}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {
@@ -116,7 +116,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Correct()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Correct()-CosmosDB异常{e.Message}\n{e.Status}{e.StackTrace}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {
@@ -141,7 +141,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,SurveyBus()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,SurveyBus()-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {
@@ -164,7 +164,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Homework()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Homework()-CosmosDB异常{e.StackTrace}{e.Message}{e.StackTrace}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {
@@ -188,7 +188,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Study()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Study()-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {
@@ -212,7 +212,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
             }
             catch (CosmosException e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamLite()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamLite()-CosmosDB异常{e.StackTrace}{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
             }
             catch (Exception ex)
             {

+ 1 - 1
TEAMModelOS/Controllers/Teacher/TeacherCommonController.cs

@@ -147,7 +147,7 @@ namespace TEAMModelOS.Controllers
             }
             List<CourseCount> schoolCourse = new List<CourseCount>();
             if (!string.IsNullOrEmpty(school)) {
-                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<CourseCount>(courseSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school}") }))
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<CourseCount>(courseSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school}") }))
                 {   
                     schoolCourse.Add(item);
                 }