|
@@ -28,14 +28,16 @@ namespace TEAMModelOS.Controllers
|
|
public class DataMigrationController : ControllerBase
|
|
public class DataMigrationController : ControllerBase
|
|
{
|
|
{
|
|
///Teacher表
|
|
///Teacher表
|
|
- /// 复制的数据
|
|
|
|
- /// Base ==>>Student
|
|
|
|
- /// 迁移的数据 StuCourse ==>> Student
|
|
|
|
- /// Activity ==>> Student
|
|
|
|
- /// AbilitySub ==>> Student
|
|
|
|
- /// ClassVideo ==>> Student
|
|
|
|
- /// Debate ==>> Student
|
|
|
|
- /// Appraise ==>> Student
|
|
|
|
|
|
+ ///
|
|
|
|
+ /// 复制的数据
|
|
|
|
+ /// Base ==>>Student //IES5&教研中心
|
|
|
|
+ /// 迁移的数据 StuCourse ==>> Student //IES5
|
|
|
|
+ /// Activity ==>> Student //IES5
|
|
|
|
+ ///
|
|
|
|
+ /// AbilitySub ==>> Student //IES5 教研中心
|
|
|
|
+ /// ClassVideo ==>> Student //IES5 教研中心
|
|
|
|
+ /// Debate ==>> Student //IES5 教研中心
|
|
|
|
+ /// Appraise ==>> Student //IES5 教研中心
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
@@ -54,28 +56,25 @@ namespace TEAMModelOS.Controllers
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
//[AuthToken(Roles = "teacher")]
|
|
//[AuthToken(Roles = "teacher")]
|
|
- [HttpPost("teacher-base")]
|
|
|
|
- public async Task<IActionResult> TeacherBase(JsonElement data) {
|
|
|
|
|
|
+ [HttpGet("restore-tmd-course&activity")]
|
|
|
|
+ public async Task<IActionResult> RestoreTmdCourseAndActivity()
|
|
|
|
+ {
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
- List<Teacher> items = new List<Teacher>();
|
|
|
|
- List<Task<Teacher>> update_teachers = new List<Task<Teacher>>();
|
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") })) {
|
|
|
|
- items.Add(item);
|
|
|
|
- if (item.size > 0)
|
|
|
|
- {
|
|
|
|
- if (item.pk == null)
|
|
|
|
- {
|
|
|
|
- item.pk = "Teacher";
|
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(item, item.id, partitionKey: new PartitionKey("Base"));
|
|
|
|
- }
|
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync<Teacher>(item, partitionKey: new PartitionKey("Base"));
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Teacher>(item.id, partitionKey: new PartitionKey("Base"));
|
|
|
|
- }
|
|
|
|
|
|
+ List<StuActivity> activities = new List<StuActivity>();
|
|
|
|
+ List<StuCourse> stuCourses = new List<StuCourse>();
|
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuActivity>(queryText: "select value(c) from c where c.pk='Activity'"))
|
|
|
|
+ {
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync<StuActivity>(item, partitionKey: new PartitionKey(item.code));
|
|
|
|
+ activities.Add(item);
|
|
}
|
|
}
|
|
- return Ok(items);
|
|
|
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuCourse>(queryText: "select value(c) from c where c.pk='StuCourse'"))
|
|
|
|
+ {
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync<StuCourse>(item, partitionKey: new PartitionKey(item.code));
|
|
|
|
+ stuCourses.Add(item);
|
|
|
|
+ }
|
|
|
|
+ return Ok(new { activities, stuCourses });
|
|
}
|
|
}
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 迁移教师基础信息,并处理历史数据。
|
|
/// 迁移教师基础信息,并处理历史数据。
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -83,17 +82,49 @@ namespace TEAMModelOS.Controllers
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
//[AuthToken(Roles = "teacher")]
|
|
//[AuthToken(Roles = "teacher")]
|
|
- [HttpPost("restore-tmduser")]
|
|
|
|
- public async Task<IActionResult> RestoreTmdUser(JsonElement data)
|
|
|
|
|
|
+ [HttpGet("restore-tmduser")]
|
|
|
|
+ public async Task<IActionResult> RestoreTmdUser()
|
|
{
|
|
{
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
- List<Teacher> items = new List<Teacher>();
|
|
|
|
- List<Task<Teacher>> update_teachers = new List<Task<Teacher>>();
|
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TmdUser>(requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
|
|
|
+ List<TmdUser> users = new List<TmdUser>();
|
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
{
|
|
{
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<TmdUser>(item,item.id, partitionKey: new PartitionKey("Base"));
|
|
|
|
|
|
+ ///修复历史数据
|
|
|
|
+ if (item.size > 0)
|
|
|
|
+ {
|
|
|
|
+ if (item.pk == null)
|
|
|
|
+ {
|
|
|
|
+ item.pk = "Teacher";
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(item, item.id, partitionKey: new PartitionKey("Base"));
|
|
|
|
+ }
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ TmdUser user = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<TmdUser>(item.id, partitionKey: new PartitionKey("Base"));
|
|
|
|
+ item.schools.ForEach(x => {
|
|
|
|
+ if (user.schools.Find(y => y.schoolId.Equals(x.schoolId)) == null)
|
|
|
|
+ {
|
|
|
|
+ user.schools.Add(new TmdUser.School { name = x.name, schoolId = x.schoolId, time = x.time, status = x.status });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ users.Add(user);
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<TmdUser>(user, user.id, partitionKey: new PartitionKey("Base"));
|
|
|
|
+ }
|
|
|
|
+ catch (CosmosException ex)
|
|
|
|
+ {
|
|
|
|
+ if (ex.Status == 404)
|
|
|
|
+ {
|
|
|
|
+ TmdUser user = item.ToJsonString().ToObject<TmdUser>();
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync<TmdUser>(user, partitionKey: new PartitionKey("Base"));
|
|
|
|
+ users.Add(user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Teacher>(item.id, partitionKey: new PartitionKey("Base"));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return Ok(items);
|
|
|
|
|
|
+ return Ok(new { users });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|