|
@@ -2082,20 +2082,187 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
|
|
|
[HttpPost("data-migration")]
|
|
[HttpPost("data-migration")]
|
|
public async Task<IActionResult> DataMigration(JsonElement request) {
|
|
public async Task<IActionResult> DataMigration(JsonElement request) {
|
|
|
|
+ try {
|
|
|
|
+ List<Course> teacherCourses = new List<Course>();
|
|
|
|
+ List<Course> schoolCourses = new List<Course>();
|
|
|
|
+ HashSet<string> schoolIds = new HashSet<string>();
|
|
|
|
+ string sql = "select value c from c where c.pk='Course' ";
|
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<Course>(sql))
|
|
|
|
+ {
|
|
|
|
+ schoolCourses.Add(item);
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(item.school))
|
|
|
|
+ {
|
|
|
|
+ schoolIds.Add(item.school);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<Course>(sql))
|
|
|
|
+ {
|
|
|
|
+ teacherCourses.Add(item);
|
|
|
|
+ }
|
|
|
|
+ List<School> schools = new List<School>();
|
|
|
|
+ if (schoolIds.Count>0)
|
|
|
|
+ {
|
|
|
|
+ var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<School>($"select value c from c where c.id in ({string.Join(",", schoolIds.Select(z => $"'{z}'"))})", "Base");
|
|
|
|
+ if (result.list.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ schools.AddRange(result.list);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<CourseDto> schoolCourseDtos = new List<CourseDto>();
|
|
|
|
+ foreach (var course in schoolCourses)
|
|
|
|
+ {
|
|
|
|
+ var school = schools.Find(z => z.id.Equals(course.school));
|
|
|
|
+ var period = school.period.Find(z => z.id.Equals(course.period?.id));
|
|
|
|
+ var semester = SchoolService.GetSemester(period, course._ts.Value);
|
|
|
|
+ CourseBase courseBase = new CourseBase()
|
|
|
|
+ {
|
|
|
|
+ id= course.id,
|
|
|
|
+ code=$"CourseBase-{school.id}",
|
|
|
|
+ pk="CourseBase",
|
|
|
|
+ ttl=-1,
|
|
|
|
+ name=course.name,
|
|
|
|
+ subject= new IdName { id=course.subject?.id, name=course.subject?.name },
|
|
|
|
+ period= new IdName { id= course.period?.id, name =course.period?.name },
|
|
|
|
+ school=school.id,
|
|
|
|
+ scope="school",
|
|
|
|
+ no=course.no,
|
|
|
|
+ creatorId=course.creatorId,
|
|
|
|
+ desc=course.desc,
|
|
|
|
+ status=1,
|
|
|
|
+ grade=0,
|
|
|
|
+ };
|
|
|
|
+ List<ScheduleTask> schedules = new List<ScheduleTask>();
|
|
|
|
+ int grade = -1;
|
|
|
|
+ foreach (var schedule in course.schedule)
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(schedule.teacherId) && !string.IsNullOrWhiteSpace(schedule.classId))
|
|
|
|
+ {
|
|
|
|
+ schedules.Add(new ScheduleTask() { type="class", groupId=schedule.classId, teacherId=schedule.teacherId, roomId= schedule.room, school=school.id });
|
|
|
|
+ try {
|
|
|
|
+ Class clazz = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<Class>(schedule.classId, new PartitionKey($"Class-{school.id}"));
|
|
|
|
+ var gradeData = SchoolService.GetGrades(school, period.id, new List<int>() { clazz.year }, course._ts.Value);
|
|
|
|
+ if (gradeData.grades.Any() && gradeData.grades.Count>0)
|
|
|
|
+ {
|
|
|
|
+ int.TryParse(gradeData.grades.First(), out grade);
|
|
|
|
+ }
|
|
|
|
+ } catch { }
|
|
|
|
+ }
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(schedule.teacherId) && !string.IsNullOrWhiteSpace(schedule.stulist))
|
|
|
|
+ {
|
|
|
|
+ schedules.Add(new ScheduleTask() { type="teach", groupId=schedule.stulist, teacherId=schedule.teacherId, roomId= schedule.room, school=school.id });
|
|
|
|
+ if (grade==-1)
|
|
|
|
+ {
|
|
|
|
+ var groups = await GroupListService.GetMemberByListids(_coreAPIHttpService, _azureCosmos.GetCosmosClient(), _dingDing, new List<string> { schedule.stulist }, school.id);
|
|
|
|
+ if (groups.rmembers.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ var a = groups.rmembers.Where(z => z.type==2 && z.year>0).GroupBy(z => z.year).Select(z => new { key = z.Key, list = z.ToList() }).OrderByDescending(y => y.list.Count).FirstOrDefault();
|
|
|
|
+ if (a!=null)
|
|
|
|
+ {
|
|
|
|
+ var gradeData = SchoolService.GetGrades(school, period.id, new List<int>() { a.key }, course._ts.Value);
|
|
|
|
+ if (gradeData.grades.Any() && gradeData.grades.Count>0)
|
|
|
|
+ {
|
|
|
|
+ int.TryParse(gradeData.grades.First(), out grade);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (grade>-1)
|
|
|
|
+ {
|
|
|
|
+ courseBase.grade=grade;
|
|
|
|
+ }
|
|
|
|
+ CourseDto courseDto = new CourseDto();
|
|
|
|
+ courseDto.courseBase=courseBase;
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).UpsertItemAsync(courseBase, new PartitionKey(courseBase.code));
|
|
|
|
+ if (schedules.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ if (semester.currSemester!=null)
|
|
|
|
+ {
|
|
|
|
+ string id = $"{semester.studyYear}-{semester.currSemester.id}-{courseBase.id}";
|
|
|
|
+ string code = $"CourseTask-{school.id}";
|
|
|
|
+ CourseTask courseTask = new CourseTask
|
|
|
|
+ {
|
|
|
|
+ id = id,
|
|
|
|
+ code = code,
|
|
|
|
+ pk="CourseTask",
|
|
|
|
+ ttl=-1,
|
|
|
|
+ courseId=courseBase.id,
|
|
|
|
+ year= semester.studyYear,
|
|
|
|
+ expire= semester.nextSemester.AddDays(-1).ToUnixTimeMilliseconds(),
|
|
|
|
+ semesterId=semester.currSemester.id,
|
|
|
|
+ schedules=schedules
|
|
|
|
+ };
|
|
|
|
+ courseDto.courseTasks.Add(new CourseTaskDto { courseTask=courseTask, type="school" });
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).UpsertItemAsync(courseTask, new PartitionKey(code));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ schoolCourseDtos.Add(courseDto);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ List<CourseDto> teacherCourseDtos = new List<CourseDto>();
|
|
|
|
+ foreach (var course in teacherCourses)
|
|
|
|
+ {
|
|
|
|
+ CourseBase courseBase = new CourseBase()
|
|
|
|
+ {
|
|
|
|
+ id= course.id,
|
|
|
|
+ code=$"CourseBase",
|
|
|
|
+ pk="CourseBase",
|
|
|
|
+ ttl=-1,
|
|
|
|
+ name=course.name,
|
|
|
|
+ scope="private",
|
|
|
|
+ no=course.no,
|
|
|
|
+ creatorId=course.creatorId,
|
|
|
|
+ desc=course.desc,
|
|
|
|
+ status=1,
|
|
|
|
+ };
|
|
|
|
+ List<ScheduleTask> schedules = new List<ScheduleTask>();
|
|
|
|
+ foreach (var schedule in course.schedule)
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(schedule.teacherId) && !string.IsNullOrWhiteSpace(schedule.classId))
|
|
|
|
+ {
|
|
|
|
+ schedules.Add(new ScheduleTask() { type="class", groupId=schedule.classId, teacherId=schedule.teacherId, roomId= schedule.room });
|
|
|
|
+ }
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(schedule.teacherId) && !string.IsNullOrWhiteSpace(schedule.stulist))
|
|
|
|
+ {
|
|
|
|
+ schedules.Add(new ScheduleTask() { type="teach", groupId=schedule.stulist, teacherId=schedule.teacherId, roomId= schedule.room });
|
|
|
|
|
|
- return Ok();
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ CourseDto courseDto = new CourseDto();
|
|
|
|
+ courseDto.courseBase=courseBase;
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(courseBase, new PartitionKey(courseBase.code));
|
|
|
|
+ if (schedules.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ string id = $"{courseBase.id}";
|
|
|
|
+ string code = $"CourseTask";
|
|
|
|
+ CourseTask courseTask = new CourseTask
|
|
|
|
+ {
|
|
|
|
+ id = id,
|
|
|
|
+ code = code,
|
|
|
|
+ pk="CourseTask",
|
|
|
|
+ ttl=-1,
|
|
|
|
+ courseId=courseBase.id,
|
|
|
|
+ schedules=schedules
|
|
|
|
+ };
|
|
|
|
+ courseDto.courseTasks.Add(new CourseTaskDto { courseTask=courseTask, type="private" });
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(courseTask, new PartitionKey(code));
|
|
|
|
+ }
|
|
|
|
+ teacherCourseDtos.Add(courseDto);
|
|
|
|
+ }
|
|
|
|
+ return Ok(new { teacherCourseDtos, schoolCourseDtos });
|
|
|
|
+ } catch (Exception ex ){ return Ok($"{ex.Message},{ex.StackTrace}"); }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public class CourseStudentDto
|
|
public class CourseStudentDto
|
|
{
|
|
{
|
|
public CourseBase courseBase { get; set; }
|
|
public CourseBase courseBase { get; set; }
|
|
- public List<CourseTask> courseTasks { get; set; }
|
|
|
|
|
|
+ public List<CourseTask> courseTasks { get; set; } = new List<CourseTask>();
|
|
|
|
|
|
}
|
|
}
|
|
public class CourseDto {
|
|
public class CourseDto {
|
|
public CourseBase courseBase { get; set; }
|
|
public CourseBase courseBase { get; set; }
|
|
- public List<CourseTaskDto> courseTasks { get; set; }
|
|
|
|
|
|
+ public List<CourseTaskDto> courseTasks { get; set; } = new List<CourseTaskDto>();
|
|
|
|
|
|
}
|
|
}
|
|
public class CourseTaskDto {
|
|
public class CourseTaskDto {
|