|
@@ -41,6 +41,8 @@ namespace TEAMModelAPI.Controllers
|
|
|
private readonly IConfiguration _configuration;
|
|
|
private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ //1 2 3 4 5 6 7
|
|
|
+ private List<string> weekDays = new List<string> { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
|
|
|
public CourseController(CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, AzureServiceBusFactory serviceBus)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
@@ -68,9 +70,8 @@ namespace TEAMModelAPI.Controllers
|
|
|
var period = data.period.Find(x => x.id.Equals($"{_periodId}"));
|
|
|
if (period != null)
|
|
|
{
|
|
|
- //1 2 3 4 5 6 7
|
|
|
- List<string> weekDays = new List<string> { "MON","TUE","WED","THU","FRI","SAT","SUN" };
|
|
|
- return Ok(new { period.subjects, period.timetable, period.grades, period.majors });
|
|
|
+
|
|
|
+ return Ok(new { period.subjects, period.timetable, period.grades, period.majors , weekDays });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -128,7 +129,7 @@ namespace TEAMModelAPI.Controllers
|
|
|
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));
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(course,course.id, new PartitionKey(course.code));
|
|
|
}
|
|
|
else {
|
|
|
course = new Course
|
|
@@ -164,50 +165,234 @@ namespace TEAMModelAPI.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public class IptCourse {
|
|
|
+ public string courseId { get; set; }
|
|
|
+ public List<Schedule> schedules { get; set; }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public class ScheduleDto : Schedule {
|
|
|
+ public ScheduleDto(Schedule schedule,string courseId) {
|
|
|
+ this.room= schedule.room;
|
|
|
+ this.courseId = courseId;
|
|
|
+ this.time = schedule.time;
|
|
|
+ this.stulist = schedule.stulist;
|
|
|
+ this.classId =schedule.classId;
|
|
|
+ this.teacherId = schedule.teacherId;
|
|
|
+ }
|
|
|
+ public string courseId { get; set; }
|
|
|
+ }
|
|
|
[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 = "课程参数错误" }); }
|
|
|
- if (!json.TryGetProperty("schedules", out JsonElement _schedules) || !_schedules.ValueKind.Equals(JsonValueKind.Array)) { return Ok(new { error = 1, msg = "排课参数错误" }); }
|
|
|
+ if (!json.TryGetProperty("courses", out JsonElement _courses)) { return Ok(new { error = 1, msg = "课程参数错误!" }); }
|
|
|
+ IEnumerable<IptCourse> iptcourses= _courses.ToObject<List<IptCourse>>();
|
|
|
+ var result = iptcourses.Valid();
|
|
|
+ if (!result.isVaild) {
|
|
|
+ return Ok(new { error = 2, msg =result});
|
|
|
+ }
|
|
|
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}"));
|
|
|
- List<Schedule> schedules= _schedules.ToObject<List<Schedule>>();
|
|
|
- if (schedules.IsNotEmpty() && schedules.Valid().isVaild)
|
|
|
+ HashSet<string> courseIds= iptcourses.Select(x => x.courseId).ToHashSet();
|
|
|
+ if (courseIds.Count < 1) { return Ok(new { error = 1, msg = "课程参数错误!" }); }
|
|
|
+
|
|
|
+ //string sql = $"select value(c) from c where c.id in({string.Join(",",courseIds.Select(x=>$"'{x}'"))})";
|
|
|
+ string sql = $"select value(c) from c ";//直接获取全校的课程
|
|
|
+ List<Course> courses = new List<Course>();
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
|
|
|
+ .GetItemQueryIterator<Course>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Course-{school}") })) {
|
|
|
+ courses.Add(item);
|
|
|
+ }
|
|
|
+ //不存在的课程
|
|
|
+ var notinCourseIds= courseIds.Except(courses.Select(x => x.id));
|
|
|
+ iptcourses=iptcourses.Where(x => !notinCourseIds.Contains(x.courseId));
|
|
|
+
|
|
|
+ //排查 课程学段,课程排课作息,课程排课的星期几是否准确
|
|
|
+ List<ScheduleDto> schedules = new List<ScheduleDto>() ;
|
|
|
+ iptcourses.ToList().ForEach(x => {
|
|
|
+ x.schedules.ForEach(z => {
|
|
|
+ schedules.Add(new ScheduleDto(z, x.courseId));
|
|
|
+ });
|
|
|
+ });
|
|
|
+ if (schedules.IsNotEmpty())
|
|
|
{
|
|
|
- //检查排课时段相同的情况
|
|
|
- Dictionary<string, List<Schedule>> dict = new Dictionary<string, List<Schedule>>();
|
|
|
+ //排查没用选用名单的排课
|
|
|
+ var noListSchedules = schedules.Where(x => string.IsNullOrWhiteSpace(x.stulist) && string.IsNullOrWhiteSpace(x.stulist));
|
|
|
+ //排查没有任课教师的排课,使用Valid 时已经验证
|
|
|
+ //var noTeacherSchedules = schedules.Where(x => string.IsNullOrWhiteSpace(x.teacherId));
|
|
|
+ //检查教师是否在同一天且上课时间段冲突的排课
|
|
|
+ Dictionary<string, List<Schedule>> teacher_check = new Dictionary<string, List<Schedule>>();
|
|
|
schedules.ForEach(item => {
|
|
|
item.time.ForEach(x => {
|
|
|
- string key = $"{item.teacherId}-{x.id}-{x.week}";
|
|
|
- if (dict.ContainsKey(key))
|
|
|
+
|
|
|
+ string key = $"{item.teacherId}-{x.id}-{x.week}";//教师id-时间段id-星期几
|
|
|
+ if (teacher_check.ContainsKey(key))
|
|
|
{
|
|
|
- dict[key].Add(item);
|
|
|
+ teacher_check[key].Add(item);
|
|
|
}
|
|
|
else {
|
|
|
- dict[key] = new List<Schedule> { item };
|
|
|
+ teacher_check[key] = new List<Schedule> { item };
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
+ //最终能进入下一个条件匹配的排课
|
|
|
+ HashSet<Schedule> saveSchedules = new HashSet<Schedule>();
|
|
|
+ //检查排课冲突的大集合,包含教师,行政班,教学班,冲突的
|
|
|
+
|
|
|
+ HashSet<Schedule> repeatSchedules = new HashSet<Schedule>();
|
|
|
+ //检查教师有安排冲突的
|
|
|
+ HashSet<Schedule> repeatTeahcerSchedules = new HashSet<Schedule>();
|
|
|
+ teacher_check.Values.ToList().ForEach(x => {
|
|
|
+ if (x.Count > 1)
|
|
|
+ {
|
|
|
+ x.ForEach(y => {
|
|
|
+ repeatTeahcerSchedules.Add(y);
|
|
|
+ repeatSchedules.Add(y);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ saveSchedules.Add(x.First());
|
|
|
+ }
|
|
|
+ });
|
|
|
//教学班
|
|
|
var stulist_schedules = schedules.Where(x => !string.IsNullOrWhiteSpace(x.stulist));
|
|
|
+ Dictionary<string, List<Schedule>> stulist_check = new Dictionary<string, List<Schedule>>();
|
|
|
+ stulist_schedules.ToList().ForEach(item => {
|
|
|
+ item.time.ForEach(x => {
|
|
|
+ string key = $"{item.stulist}-{x.id}-{x.week}";//教师id-时间段id-星期几
|
|
|
+ if (stulist_check.ContainsKey(key))
|
|
|
+ {
|
|
|
+ stulist_check[key].Add(item);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ stulist_check[key] = new List<Schedule> { item };
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ //检查教学班和行政班有冲突的
|
|
|
+ HashSet<Schedule> repeatListSchedules = new HashSet<Schedule>();
|
|
|
+ stulist_check.Values.ToList().ForEach(x => {
|
|
|
+ if (x.Count > 1)
|
|
|
+ {
|
|
|
+ x.ForEach(y => {
|
|
|
+ repeatSchedules.Add(y);
|
|
|
+ repeatListSchedules.Add(y);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var schedule = x.First();
|
|
|
+ if (!repeatSchedules.Contains(schedule))
|
|
|
+ {
|
|
|
+ saveSchedules.Add(schedule);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ repeatSchedules.Add(schedule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
//行政班
|
|
|
var classId_schedules = schedules.Where(x => !string.IsNullOrWhiteSpace(x.classId));
|
|
|
- //处理教室和教学班名单,教师,同时存在且相同,重复的课堂
|
|
|
- var stulist_schedules_hasRoom = stulist_schedules.Where(x => !string.IsNullOrWhiteSpace(x.room));
|
|
|
- //处理教学班名单,教师,同时存在且相同,重复的课堂
|
|
|
- var stulist_schedules_noRoom = stulist_schedules.Where(x => !string.IsNullOrWhiteSpace(x.room));
|
|
|
+ Dictionary<string, List<Schedule>> classId_check = new Dictionary<string, List<Schedule>>();
|
|
|
+ classId_schedules.ToList().ForEach(item => {
|
|
|
+ item.time.ForEach(x => {
|
|
|
+ string key = $"{item.classId}-{x.id}-{x.week}";//教师id-时间段id-星期几
|
|
|
+ if (classId_check.ContainsKey(key))
|
|
|
+ {
|
|
|
+ classId_check[key].Add(item);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ classId_check[key] = new List<Schedule> { item };
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ classId_check.Values.ToList().ForEach(x => {
|
|
|
+ if (x.Count > 1)
|
|
|
+ {
|
|
|
+ x.ForEach(y => {
|
|
|
+ repeatSchedules.Add(y);
|
|
|
+ repeatListSchedules.Add(y);
|
|
|
+ });
|
|
|
|
|
|
- //处理教室和行政班名单,教师,同时存在且相同,重复的课堂
|
|
|
- var classId_schedules_hasRoom = stulist_schedules_hasRoom.Where(x => !string.IsNullOrWhiteSpace(x.room));
|
|
|
- //处理行政班名单,教师,同时存在且相同,重复的课堂
|
|
|
- var classId_schedules_noRoom = stulist_schedules_hasRoom.Where(x => !string.IsNullOrWhiteSpace(x.room));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var schedule = x.First();
|
|
|
+ if (!repeatSchedules.Contains(schedule))
|
|
|
+ {
|
|
|
+ saveSchedules.Add(schedule);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ repeatSchedules.Add(schedule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //教室资源占用情况冲突。
|
|
|
|
|
|
-
|
|
|
- return Ok();
|
|
|
+ var room_schedules = schedules.Where(x => !string.IsNullOrWhiteSpace(x.classId));
|
|
|
+ Dictionary<string, List<Schedule>> room_check = new Dictionary<string, List<Schedule>>();
|
|
|
+ room_schedules.ToList().ForEach(item => {
|
|
|
+ item.time.ForEach(x => {
|
|
|
+ string key = $"{item.classId}-{x.id}-{x.week}";//教师id-时间段id-星期几
|
|
|
+ if (room_check.ContainsKey(key))
|
|
|
+ {
|
|
|
+ room_check[key].Add(item);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ room_check[key] = new List<Schedule> { item };
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ //检查教室有冲突的
|
|
|
+ HashSet<Schedule> repeatRoomSchedules = new HashSet<Schedule>();
|
|
|
+ room_check.Values.ToList().ForEach(x => {
|
|
|
+ if (x.Count > 1)
|
|
|
+ {
|
|
|
+ x.ForEach(y => {
|
|
|
+ repeatSchedules.Add(y);
|
|
|
+ repeatRoomSchedules.Add(y);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var schedule = x.First();
|
|
|
+ if (!repeatSchedules.Contains(schedule))
|
|
|
+ {
|
|
|
+ saveSchedules.Add(schedule);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ repeatSchedules.Add(schedule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ schedules.RemoveAll(x => repeatListSchedules.Contains(x));
|
|
|
+ schedules.RemoveAll(x => repeatRoomSchedules.Contains(x));
|
|
|
+ schedules.RemoveAll(x => repeatTeahcerSchedules.Contains(x));
|
|
|
+ ////处理教室和教学班名单,教师,同时存在且相同,重复的课堂
|
|
|
+ //var stulist_schedules_hasRoom = saveSchedules.Where(x => !string.IsNullOrWhiteSpace(x.stulist) && !string.IsNullOrWhiteSpace(x.room));
|
|
|
+ ////处理教学班名单,教师,同时存在且相同,重复的课堂
|
|
|
+ //var stulist_schedules_noRoom = stulist_schedules.Where(x => !string.IsNullOrWhiteSpace(x.stulist) && string.IsNullOrWhiteSpace(x.room));
|
|
|
+
|
|
|
+ ////处理教室和行政班名单,教师,同时存在且相同,重复的课堂
|
|
|
+ //var classId_schedules_hasRoom = classId_schedules.Where(x => !string.IsNullOrWhiteSpace(x.classId) && !string.IsNullOrWhiteSpace(x.room));
|
|
|
+ ////处理行政班名单,教师,同时存在且相同,重复的课堂
|
|
|
+ //var classId_schedules_noRoom = classId_schedules.Where(x => !string.IsNullOrWhiteSpace(x.classId) && string.IsNullOrWhiteSpace(x.room));
|
|
|
+ return Ok(new {
|
|
|
+ notinCourseIds ,//课程不存在的排课
|
|
|
+ noListSchedules,//没有教学名单的排课,包含行政班,教学班
|
|
|
+ repeatTeahcerSchedules,//教师在同一课时有冲突的排课
|
|
|
+ repeatListSchedules,//行政班或教学班在同一课时段有冲突的排课
|
|
|
+
|
|
|
+ });
|
|
|
}
|
|
|
else {
|
|
|
return Ok(new { error = 1, msg = "排课参数错误" });
|