|
@@ -2488,7 +2488,7 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
[HttpPost("data-migration")]
|
|
|
public async Task<IActionResult> DataMigration(JsonElement request) {
|
|
|
try {
|
|
|
- // List<Course> teacherCourses = new List<Course>();
|
|
|
+ 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' ";
|
|
@@ -2497,23 +2497,24 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.school))
|
|
|
{
|
|
|
- if (item.school.Equals("ydzt") ||item.school.Equals("xcfx") ||item.school.Equals("hlgj") ||item.school.Equals("hbcn") ||item.school.Equals("kjyxx") ||item.school.Equals("bjgsex") || item.school.Equals("cdxxps") ||item.school.Equals("pclxxx"))
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
- schoolCourses.Add(item);
|
|
|
- schoolIds.Add(item.school);
|
|
|
- }
|
|
|
+ schoolCourses.Add(item);
|
|
|
+ schoolIds.Add(item.school);
|
|
|
+ //if (item.school.Equals("ydzt") ||item.school.Equals("xcfx") ||item.school.Equals("hlgj") ||item.school.Equals("hbcn") ||item.school.Equals("kjyxx") ||item.school.Equals("bjgsex") || item.school.Equals("cdxxps") ||item.school.Equals("pclxxx"))
|
|
|
+ //{
|
|
|
+
|
|
|
+ //}
|
|
|
+ //else {
|
|
|
+
|
|
|
+ //}
|
|
|
}
|
|
|
}
|
|
|
- //await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<Course>(sql))
|
|
|
- //{
|
|
|
- // teacherCourses.Add(item);
|
|
|
- //}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ 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)
|
|
|
{
|
|
@@ -2769,57 +2770,57 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
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 });
|
|
|
-
|
|
|
- // }
|
|
|
- // }
|
|
|
- // 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 { schoolCourseDtos });
|
|
|
+ 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 });
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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 { schoolCourseDtos, teacherCourseDtos });
|
|
|
} catch (Exception ex ){ return Ok($"{ex.Message},{ex.StackTrace}"); }
|
|
|
|
|
|
}
|
|
@@ -2843,7 +2844,7 @@ namespace TEAMModelOS.Controllers.Both
|
|
|
Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(c.id, new PartitionKey($"Course-{c.code.Replace("CourseBase-","")}"));
|
|
|
if (response.Status==200)
|
|
|
{
|
|
|
- Console.WriteLine("1");
|
|
|
+
|
|
|
}
|
|
|
else {
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).DeleteItemStreamAsync(c.id, new PartitionKey(c.code));
|