|
@@ -25,6 +25,7 @@ using Microsoft.Azure.Amqp.Sasl;
|
|
|
using DocumentFormat.OpenXml.Drawing.Charts;
|
|
|
using FastJSON;
|
|
|
using OpenXmlPowerTools;
|
|
|
+using DocumentFormat.OpenXml.Drawing.Spreadsheet;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.Both
|
|
|
{
|
|
@@ -99,8 +100,8 @@ 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}-{_id}";
|
|
|
- string taskSql = $"select value c from c ";
|
|
|
+ string taskCode = $"CourseTask-{_code}";
|
|
|
+ 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)
|
|
|
.GetItemQueryIterator<CourseTask>(queryText: taskSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey(taskCode) }))
|
|
@@ -146,12 +147,14 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
{
|
|
|
return BadRequest();
|
|
|
}
|
|
|
+ if (!request.TryGetProperty("courseId", out JsonElement _courseId)) return BadRequest();
|
|
|
+
|
|
|
string tbname = $"{_scope}".Equals("school", StringComparison.OrdinalIgnoreCase) ? Constant.School : Constant.Teacher;
|
|
|
if (_scope.ToString().Equals("school", StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
|
|
|
if (!request.TryGetProperty("periodId", out JsonElement _periodId)) return BadRequest();
|
|
|
- if (!request.TryGetProperty("courseId", out JsonElement _courseId)) return BadRequest();
|
|
|
+
|
|
|
int studyYear = -1;
|
|
|
string semesterId = string.Empty;
|
|
|
School schoolBase = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
@@ -159,8 +162,6 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
if (!request.TryGetProperty("year", out JsonElement _year) || !request.TryGetProperty("semesterId", out JsonElement _semesterId))
|
|
|
{
|
|
|
//如果没传,则以当前时间获取学年和学期信息
|
|
|
-
|
|
|
-
|
|
|
(Semester currSemester, int studyYear, DateTimeOffset date, DateTimeOffset nextSemester) info = SchoolService.GetSemester(period);
|
|
|
semesterId = info.currSemester.id;
|
|
|
studyYear = info.studyYear;
|
|
@@ -169,8 +170,8 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
studyYear = _year.GetInt32();
|
|
|
semesterId=_semesterId.GetString();
|
|
|
}
|
|
|
- string taskCode = $"CourseTask-{school}-{_courseId}";
|
|
|
- string taskId = $"{studyYear}-{semesterId}";
|
|
|
+ string taskCode = $"CourseTask-{school}";
|
|
|
+ string taskId = $"{studyYear}-{semesterId}-{_courseId}";
|
|
|
Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(taskId, new PartitionKey(taskCode));
|
|
|
bool has_schedule = false;
|
|
|
CourseTask courseTask = default;
|
|
@@ -206,21 +207,138 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
}
|
|
|
//当courseTask 为空,则matchedClasses可能会有年级匹配建议升学年的班级清单,
|
|
|
//注:比如高二可能会将高三的课程学完,则该高三的课程的学年级应该是手动处理为高中二年级。不区分学期的目的,也是可能存在提前一学期学完第二学期的课程。
|
|
|
- return Ok(new { studyYear, semesterId, courseTask, matchedClasses = classes, matchedTeachers = teachers });
|
|
|
+ return Ok(new { studyYear, semesterId, courseTask, matchedClasses = classes, matchedTeachers = teachers.Select(z=>new { z.id,z.name,z.subjectIds,z.job,z.periodId,z.picture })});
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
+ string taskCode = $"CourseTask-{id}";
|
|
|
+ string taskId = $"{_courseId}";
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(taskId, new PartitionKey(taskCode));
|
|
|
+ CourseTask courseTask = default;
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ courseTask = JsonDocument.Parse(response.Content).RootElement.ToObject<CourseTask>();
|
|
|
+ }
|
|
|
+ return Ok(new { courseTask });
|
|
|
}
|
|
|
- break;
|
|
|
}
|
|
|
case bool when $"{grant_type}".Equals("insert-task", StringComparison.OrdinalIgnoreCase) :
|
|
|
{
|
|
|
- if ( !request.TryGetProperty("scope", out JsonElement _scope))
|
|
|
+ if ( !request.TryGetProperty("scope", out JsonElement _scope)|| !request.TryGetProperty("datas", out JsonElement _datas))
|
|
|
{
|
|
|
return BadRequest();
|
|
|
}
|
|
|
+
|
|
|
string tbname = $"{_scope}".Equals("school", StringComparison.OrdinalIgnoreCase) ? Constant.School : Constant.Teacher;
|
|
|
+ List<CourseTaskInsert> datas = _datas.ToObject<List<CourseTaskInsert>>();
|
|
|
+ if (_scope.ToString().Equals("school", StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ if (!request.TryGetProperty("periodId", out JsonElement _periodId)) return BadRequest();
|
|
|
+ //获取相关的名单
|
|
|
+ List<GroupListDto> groupListDtos= await GroupListService.GetGroupListByListids(client, _dingDing, datas.Select(z => z.groupId).ToHashSet().ToList(), school);
|
|
|
+ //获取相关的教室
|
|
|
+ var roomIds = datas.Where(x => !string.IsNullOrWhiteSpace(x.roomId)).Select(c=>$"'{c.roomId}'");
|
|
|
+ List<Room> rooms = new List<Room>();
|
|
|
+ if (roomIds.Any()) {
|
|
|
+ string sqlRoom = $"select value c from c where c.id in ({string.Join(",", roomIds)})";
|
|
|
+ var result= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<Room>(sqlRoom,$"Room-{school}");
|
|
|
+ if (result.list.IsNotEmpty()) {
|
|
|
+ rooms.AddRange(result.list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取教师
|
|
|
+ List<SchoolTeacher> schoolTeachers = new List<SchoolTeacher>();
|
|
|
+ var teacherIds = datas.Where(x => !string.IsNullOrWhiteSpace(x.teacherId)).Select(c => $"'{c.teacherId}'");
|
|
|
+ if (teacherIds.Any()) {
|
|
|
+ string sqlTeacher = $"select value c from c where c.id in ({string.Join(",", teacherIds)}) ";
|
|
|
+ var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<SchoolTeacher>(sqlTeacher, $"Teacher-{school}");
|
|
|
+ if (result.list.IsNotEmpty())
|
|
|
+ {
|
|
|
+ schoolTeachers.AddRange(result.list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取课程
|
|
|
+ List<CourseBase> courseBases = new List<CourseBase>();
|
|
|
+ var courseIds = datas.Where(x => !string.IsNullOrWhiteSpace(x.courseId)).Select(c => $"'{c.courseId}'");
|
|
|
+ if (courseIds.Any())
|
|
|
+ {
|
|
|
+ string sqlCourse = $"select value c from c where c.id in ({string.Join(",", courseIds)}) ";
|
|
|
+ var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseBase>(sqlCourse, $"CourseBase-{school}");
|
|
|
+ if (result.list.IsNotEmpty())
|
|
|
+ {
|
|
|
+ courseBases.AddRange(result.list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ School schoolBase = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
+ var period = schoolBase.period.Find(x => x.id.Equals($"{_periodId}"));
|
|
|
+ HashSet<CourseTask> courseTasks = new HashSet<CourseTask>();
|
|
|
+ List<CourseTaskInsert> invalidCourseTaskInsert= new List<CourseTaskInsert>();
|
|
|
+ foreach (var data in datas)
|
|
|
+ {
|
|
|
+ var courseTaskInsert = SchoolService.CheckCourseTaskInsert(data, schoolBase, period, courseBases, groupListDtos, rooms, schoolTeachers);
|
|
|
+ if (courseTaskInsert.invalidCode == 0)
|
|
|
+ {
|
|
|
+ string taskCode = $"CourseTask-{school}";
|
|
|
+ string taskId = $"{courseTaskInsert.year}-{courseTaskInsert.semesterId}-{courseTaskInsert.courseId}";
|
|
|
+ CourseTask courseTask = courseTasks.Where(z => z.id.Equals(taskId) && z.code.Equals(taskCode)).FirstOrDefault();
|
|
|
+ if (courseTask == null)
|
|
|
+ {
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(taskId, new PartitionKey(taskCode));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ courseTask = JsonDocument.Parse(response.Content).RootElement.ToObject<CourseTask>();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ courseTask = new CourseTask
|
|
|
+ {
|
|
|
+ id = taskId,
|
|
|
+ code = taskCode,
|
|
|
+ pk = "CourseTask",
|
|
|
+ ttl = -1,
|
|
|
+ courseId = courseTaskInsert.courseId,
|
|
|
+ year = courseTaskInsert.year,
|
|
|
+ semesterId = courseTaskInsert.semesterId,
|
|
|
+ schedules = new List<ScheduleTask> { new ScheduleTask {
|
|
|
+ roomId = courseTaskInsert.roomId,
|
|
|
+ groupId = courseTaskInsert.groupId,
|
|
|
+ type = courseTaskInsert.type,
|
|
|
+ teacherId = courseTaskInsert.teacherId,
|
|
|
+ notice=courseTaskInsert.notice,
|
|
|
+ startTime = courseTaskInsert.startTime,
|
|
|
+ times= new List<ScheduleTime>()
|
|
|
+ } }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var scheduleTask = courseTask.schedules.Find(z => z.type.Equals(courseTaskInsert.type) && z.groupId.Equals(courseTaskInsert.groupId) && z.teacherId.Equals(courseTaskInsert.teacherId));
|
|
|
+ if (scheduleTask == null)
|
|
|
+ {
|
|
|
+ courseTask.schedules.Add(new ScheduleTask()
|
|
|
+ {
|
|
|
+ roomId = courseTaskInsert.roomId,
|
|
|
+ groupId = courseTaskInsert.groupId,
|
|
|
+ type = courseTaskInsert.type,
|
|
|
+ teacherId = courseTaskInsert.teacherId,
|
|
|
+ times = new List<ScheduleTime>()
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ scheduleTask.roomId = courseTaskInsert.roomId;
|
|
|
+ }
|
|
|
+ courseTasks.Add(courseTask);
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).UpsertItemAsync(courseTask, new PartitionKey(taskCode));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ invalidCourseTaskInsert.Add(courseTaskInsert);
|
|
|
+ }
|
|
|
+ return Ok(new { invalidCourseTaskInsert, courseTasks });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
//按照模板导入进行数据转换并且进行检查
|
|
@@ -539,8 +657,8 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
string roomId= room?.id;
|
|
|
string teacherId = teachers.Find(z => z.id.Equals(item.tmdid))?.id;
|
|
|
CourseBase courseBase = courseBases.Find(z => z.name.Equals(item.name));
|
|
|
- string taskId = $"{info.studyYear}-{info.currSemester.id}";
|
|
|
- string taskCode = $"CourseTask-{school}-{courseBase.id}";
|
|
|
+ string taskId = $"{info.studyYear}-{info.currSemester.id}-{courseBase.id}";
|
|
|
+ string taskCode = $"CourseTask-{school}";
|
|
|
CourseTask courseTask = courseTasks.FirstOrDefault(z => z.id.Equals(taskId) && z.code.Equals(taskCode));
|
|
|
if (courseTask == null) {
|
|
|
Azure.Response courseTaskResponse = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(taskId, new PartitionKey(taskCode));
|