|
@@ -28,6 +28,7 @@ using OpenXmlPowerTools;
|
|
|
using DocumentFormat.OpenXml.Drawing.Spreadsheet;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Security.Claims;
|
|
|
+using DocumentFormat.OpenXml.Bibliography;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.Both
|
|
|
{
|
|
@@ -104,7 +105,7 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
string tbname = $"{scope}".Equals("school", StringComparison.OrdinalIgnoreCase) ? Constant.School : Constant.Teacher;
|
|
|
Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemStreamAsync(_id.ToString(), new PartitionKey($"CourseBase-{_code}"));
|
|
|
//需要联动删除排课
|
|
|
- string taskCode = $"CourseTask-{_code}";
|
|
|
+ string taskCode = $"{scope}".Equals("school", StringComparison.OrdinalIgnoreCase) ? $"CourseTask-{_code}": "CourseTask";
|
|
|
string taskSql = $"select value c from c where c.courseId='{_id}'";
|
|
|
List<CourseTask> courseTasks = new List<CourseTask>();
|
|
|
await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
|
|
@@ -460,7 +461,7 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string taskCode = $"CourseTask-{tmdid}";
|
|
|
+ string taskCode = $"CourseTask";
|
|
|
string taskId = $"{_courseId}";
|
|
|
Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(taskId, new PartitionKey(taskCode));
|
|
|
CourseTask courseTask = default;
|
|
@@ -653,7 +654,7 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string taskCode = $"CourseTask-{tmdid}";
|
|
|
+ string taskCode = $"CourseTask";
|
|
|
string taskId = $"{_courseId}";
|
|
|
CourseTask courseTask = null;
|
|
|
CourseBase courseBase = null;
|
|
@@ -971,7 +972,7 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
var courseTaskInsert = SchoolService.CheckCourseTaskInsertOrChanged($"{grant_type}", scope.ToString(), data, null, null, courseBases, groupListDtos, rooms, null, teachers);
|
|
|
if (courseTaskInsert.invalidCode == 0)
|
|
|
{
|
|
|
- string taskCode = $"CourseTask-{tmdid}";
|
|
|
+ string taskCode = $"CourseTask";
|
|
|
string taskId = courseTaskInsert.courseId;
|
|
|
CourseTask courseTask = courseTasks.Where(z => z.id.Equals(taskId) && z.code.Equals(taskCode)).FirstOrDefault();
|
|
|
if (courseTask == null)
|
|
@@ -1680,23 +1681,143 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
(string tmdid, _, _, string school) = HttpContext.GetAuthTokenInfo();
|
|
|
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)
|
|
|
{
|
|
|
//任教学校课程和个人课程
|
|
|
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 (ARRAY_CONTAINS(b.assistants,'{tmdid}')or b.teacherId ='{tmdid}' )";
|
|
|
+ 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()) {
|
|
|
+ resultSchool.list.ForEach(x => {
|
|
|
+ var schedulesTeacher = x.schedules.Where(z =>!string.IsNullOrWhiteSpace(z.teacherId) && z.teacherId.Equals(tmdid));
|
|
|
+ if (schedulesTeacher.Any())
|
|
|
+ {
|
|
|
+ courseIds.Add(x.courseId);
|
|
|
+ x.schedules=schedulesTeacher.ToList();
|
|
|
+ schoolTeacherTask.Add(new KeyValuePair<string,CourseTask >(x.courseId, x));
|
|
|
+ }
|
|
|
+ var schedulesAssistant = x.schedules.Where(z => z.assistants.Contains(tmdid) &&!string.IsNullOrWhiteSpace(z.teacherId) && !z.teacherId.Equals(tmdid));
|
|
|
+ if (schedulesAssistant.Any())
|
|
|
+ {
|
|
|
+ courseIds.Add(x.courseId);
|
|
|
+ x.schedules=schedulesAssistant.ToList();
|
|
|
+ schoolAssistantTask.Add(new KeyValuePair<string, CourseTask>(x.courseId, x));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ var teacher = schoolTeacherTask.Where(x => x.Key.Equals(item.id)).Select(z => new CourseDto { courseBase=item, courseTask=z.Value, type="teacher" });
|
|
|
+ if (teacher.Any()) {
|
|
|
+ schoolCourses.AddRange(teacher);
|
|
|
+ }
|
|
|
+ var assistant= schoolAssistantTask.Where(x => x.Key.Equals(item.id)).Select(z => new CourseDto { courseBase=item, courseTask=z.Value, type="assistant" });
|
|
|
+ if (assistant.Any()) {
|
|
|
+ schoolCourses.AddRange(assistant);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var resultTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<CourseTask>(sql, $"CourseTask");
|
|
|
+ if (resultTeacher.list.IsNotEmpty()){
|
|
|
+ HashSet<string> courseIds = new HashSet<string>();
|
|
|
+ resultTeacher.list.ForEach(x => {
|
|
|
+ var schedulesTeacher = x.schedules.Where(z => !string.IsNullOrWhiteSpace(z.teacherId) && z.teacherId.Equals(tmdid));
|
|
|
+ if (schedulesTeacher.Any())
|
|
|
+ {
|
|
|
+ courseIds.Add(x.courseId);
|
|
|
+ x.schedules=schedulesTeacher.ToList();
|
|
|
+ privateTeacherTask.Add(new KeyValuePair<string,CourseTask >(x.courseId,x));
|
|
|
+ }
|
|
|
+ var schedulesAssistant = x.schedules.Where(z => z.assistants.Contains(tmdid));
|
|
|
+ if (schedulesAssistant.Any())
|
|
|
+ {
|
|
|
+ courseIds.Add(x.courseId);
|
|
|
+ x.schedules=schedulesAssistant.ToList();
|
|
|
+ privateAssistantTask.Add(new KeyValuePair<string,CourseTask >(x.courseId,x));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ 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");
|
|
|
+ if (result.list.IsNotEmpty())
|
|
|
+ {
|
|
|
+ foreach (var item in result.list)
|
|
|
+
|
|
|
+ {
|
|
|
+ var teacher = privateTeacherTask.Where(x => x.Key.Equals(item.id)).Select(z => new CourseDto { courseBase=item, courseTask=z.Value, type="teacher" });
|
|
|
+ if (teacher.Any())
|
|
|
+ {
|
|
|
+ teahcerCourses.AddRange(teacher);
|
|
|
+ }
|
|
|
+ var assistant = privateAssistantTask.Where(x => x.Key.Equals(item.id)).Select(z => new CourseDto { courseBase=item, courseTask=z.Value, type="assistant" });
|
|
|
+ if (assistant.Any())
|
|
|
+ {
|
|
|
+ teahcerCourses.AddRange(assistant);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//个人,
|
|
|
//学校,
|
|
|
+
|
|
|
//助教,学校。
|
|
|
//助教,个人。
|
|
|
- break;
|
|
|
+ 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();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public class CourseDto {
|
|
|
+ public CourseBase courseBase { get; set; }
|
|
|
+ public CourseTask courseTask { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// teacher主任课教师,assistant,协同教师
|
|
|
+ /// </summary>
|
|
|
+ public string type { get; set; }
|
|
|
}
|
|
|
}
|