|
@@ -31,6 +31,13 @@ using TEAMModelOS.Models;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using TEAMModelOS.SDK.Services;
|
|
|
using Azure.Messaging.ServiceBus;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
+using static ICSharpCode.SharpZipLib.Zip.ZipEntryFactory;
|
|
|
+using Azure.Storage.Sas;
|
|
|
+using DocumentFormat.OpenXml.Drawing.Diagrams;
|
|
|
+using TEAMModelOS.SDK.Models.Dtos;
|
|
|
+using DocumentFormat.OpenXml.Bibliography;
|
|
|
+using System.Formats.Asn1;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -2966,5 +2973,479 @@ namespace TEAMModelOS.Controllers
|
|
|
return BadRequest(ex.StackTrace);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 修复研修平台账号重复的问题
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("fix-training")]
|
|
|
+ public async Task<IActionResult> RepairTraining(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("trainingIds", out JsonElement ids)) return BadRequest();
|
|
|
+ List<TrainingId> trainingIds = ids.ToObject<List<TrainingId>>();
|
|
|
+ List<string> noCopyFiles = new();
|
|
|
+
|
|
|
+ var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+
|
|
|
+ foreach (var item in trainingIds)
|
|
|
+ {
|
|
|
+ List<ScTeacher> scTeachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "tmdid", $"{item.oldId}" } });
|
|
|
+ if (scTeachers.Count > 0)
|
|
|
+ {
|
|
|
+ scTeachers.ForEach(sct => sct.tmdid = item.newId);
|
|
|
+ //保存和更新研修信息
|
|
|
+ await table.SaveOrUpdateAll(scTeachers);
|
|
|
+ }
|
|
|
+ string defaultSc = null;
|
|
|
+
|
|
|
+ //教师基础信息
|
|
|
+ Teacher teacher = new();
|
|
|
+ var resTchBase = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{item.oldId}", new PartitionKey("Base"));
|
|
|
+ if (resTchBase.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(resTchBase.ContentStream);
|
|
|
+ teacher = json.ToObject<Teacher>();
|
|
|
+ defaultSc = teacher.defaultSchool;
|
|
|
+ if (string.IsNullOrEmpty(teacher.defaultSchool))
|
|
|
+ defaultSc = teacher.schools[0].schoolId;
|
|
|
+
|
|
|
+ teacher.id = $"{item.newId}";
|
|
|
+ //教师基础信息
|
|
|
+ teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+
|
|
|
+ //教师研修文件
|
|
|
+ TeacherFile teacherFile = new();
|
|
|
+ var resTchFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{item.oldId}", new PartitionKey($"TeacherFile-{defaultSc}"));
|
|
|
+ if (resTchFile.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(resTchFile.ContentStream);
|
|
|
+ teacherFile = json.ToObject<TeacherFile>();
|
|
|
+ teacherFile.id = $"{item.newId}";
|
|
|
+ //创建新的教师研修文件
|
|
|
+ teacherFile = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<TeacherFile>(teacherFile, new PartitionKey(teacherFile.code));
|
|
|
+ }
|
|
|
+
|
|
|
+ //研修统计
|
|
|
+ TeacherTrain teacherTrain = new();
|
|
|
+ var resTchTrain = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{item.oldId}", new PartitionKey($"TeacherTrain-{defaultSc}"));
|
|
|
+ if (resTchTrain.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(resTchTrain.ContentStream);
|
|
|
+ teacherTrain = json.ToObject<TeacherTrain>();
|
|
|
+ teacherTrain.tmdid = $"{item.newId}";
|
|
|
+ teacherTrain.id = $"{item.newId}";
|
|
|
+ //研修报告外层文件路径
|
|
|
+ if (!string.IsNullOrEmpty($"{teacherTrain.offlineUrl}"))
|
|
|
+ {
|
|
|
+ string oldOffUrl = teacherTrain.offlineUrl;
|
|
|
+ teacherTrain.offlineUrl = teacherTrain.offlineUrl.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ if (!oldOffUrl.Equals(teacherTrain.offlineUrl))
|
|
|
+ {
|
|
|
+ //复制研修报告
|
|
|
+ var tempFileCopy = await BatchCopyFileService.SingleCopyFile(_azureStorage, "teammodelos", teacherTrain.offlineUrl, item.oldId, item.newId);
|
|
|
+ if (tempFileCopy != 200)
|
|
|
+ noCopyFiles.Add(oldOffUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (teacherTrain.offlineRecords.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var off in teacherTrain.offlineRecords)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(off.url))
|
|
|
+ {
|
|
|
+ string oldOffRe = off.url;
|
|
|
+ off.url = off.url.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ if (!oldOffRe.Equals(off.url))
|
|
|
+ {
|
|
|
+ //线下研修文件
|
|
|
+ var tempFileRe = await BatchCopyFileService.SingleCopyFile(_azureStorage, defaultSc, oldOffRe, item.oldId, item.newId);
|
|
|
+ if (tempFileRe != 200)
|
|
|
+ noCopyFiles.Add(oldOffRe);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (off.other != null)
|
|
|
+ {
|
|
|
+ //作业附件
|
|
|
+ foreach (var offOther in off.other)
|
|
|
+ {
|
|
|
+ //替换文件路径
|
|
|
+ string oldOffOther = offOther.url;
|
|
|
+ offOther.url = offOther.url.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ offOther.blob = offOther.blob.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ if (!oldOffOther.Equals(offOther.url))
|
|
|
+ {
|
|
|
+ //复制作业附件
|
|
|
+ var tempFileCopy = await BatchCopyFileService.SingleCopyFile(_azureStorage, defaultSc, oldOffOther, item.oldId, item.newId);
|
|
|
+ if (tempFileCopy != 200)
|
|
|
+ noCopyFiles.Add(oldOffOther);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (teacherTrain.teacherClasses.Count > 0)
|
|
|
+ {
|
|
|
+ //课堂实录
|
|
|
+ foreach (var tchClass in teacherTrain.teacherClasses)
|
|
|
+ {
|
|
|
+ string tchCla = tchClass.url;
|
|
|
+ //替换课堂实录路径地址
|
|
|
+ tchClass.url = tchClass.url.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ if (!tchCla.Equals(tchClass.url))
|
|
|
+ {
|
|
|
+ //复制课堂实录文件
|
|
|
+ var tempFileCopy = await BatchCopyFileService.SingleCopyFile(_azureStorage, defaultSc, tchCla, item.oldId, item.newId);
|
|
|
+ if (tempFileCopy != 200)
|
|
|
+ noCopyFiles.Add(tchCla);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //研修报告信息
|
|
|
+ if (teacherTrain.offlineReport != null)
|
|
|
+ {
|
|
|
+ //替换研修报告信息文件路径地址
|
|
|
+ string tchTrain = teacherTrain.offlineReport.url;
|
|
|
+ teacherTrain.offlineReport.url = teacherTrain.offlineReport.url.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ teacherTrain.offlineReport.blob = teacherTrain.offlineReport.blob.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ if (!tchTrain.Equals(teacherTrain.offlineReport.url))
|
|
|
+ {
|
|
|
+ //研修报告信息文件路径
|
|
|
+ var tempFileCopy = await BatchCopyFileService.SingleCopyFile(_azureStorage, "teammodelos", tchTrain, item.oldId, item.newId);
|
|
|
+ if (tempFileCopy != 200)
|
|
|
+ noCopyFiles.Add(tchTrain);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ teacherTrain.id = item.newId;
|
|
|
+ //创建新的教师研修统计
|
|
|
+ teacherTrain = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<TeacherTrain>(teacherTrain, new PartitionKey(teacherTrain.code));
|
|
|
+ }
|
|
|
+
|
|
|
+ //课堂实录
|
|
|
+ ClassVideo classVideo = new();
|
|
|
+ var respCalsVideo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{item.oldId}", new PartitionKey($"ClassVideo-{defaultSc}"));
|
|
|
+ if (respCalsVideo.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(respCalsVideo.ContentStream);
|
|
|
+ classVideo = json.ToObject<ClassVideo>();
|
|
|
+ classVideo.creatorId = $"{item.newId}";
|
|
|
+ if (classVideo.files.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var cv in classVideo.files)
|
|
|
+ {
|
|
|
+ string tchCla = cv.url;
|
|
|
+ cv.url = cv.url.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ if (!tchCla.Equals(cv.url))
|
|
|
+ {
|
|
|
+ //复制课堂实录文件
|
|
|
+ var tempFileCopy = await BatchCopyFileService.SingleCopyFile(_azureStorage, defaultSc, tchCla, item.oldId, item.newId);
|
|
|
+ if (tempFileCopy != 200)
|
|
|
+ noCopyFiles.Add(tchCla);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ classVideo.id = $"{item.newId}";
|
|
|
+ //创建新的教师课堂实录
|
|
|
+ classVideo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<ClassVideo>(classVideo, new PartitionKey(classVideo.code));
|
|
|
+ }
|
|
|
+
|
|
|
+ //订阅记录和学习记录
|
|
|
+ List<Task<ItemResponse<AbilitySub>>> abilitySubs = new();
|
|
|
+ await foreach (var abilitySub in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<AbilitySub>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{defaultSc}-{item.oldId}") }))
|
|
|
+ {
|
|
|
+ abilitySub.creatorId = item.newId;
|
|
|
+ if (abilitySub.uploads.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var asup in abilitySub.uploads)
|
|
|
+ {
|
|
|
+ if (asup.urls.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var asupurl in asup.urls)
|
|
|
+ {
|
|
|
+ string asupUr = asupurl.url;
|
|
|
+ asupurl.url = asupurl.url.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ if (!asupUr.Equals(asupurl.url))
|
|
|
+ {
|
|
|
+ //订阅记录和学习记录文件地址
|
|
|
+ var tempFileCopy = await BatchCopyFileService.SingleCopyFile(_azureStorage, defaultSc, asupUr, item.oldId, item.newId);
|
|
|
+ if (tempFileCopy != 200)
|
|
|
+ noCopyFiles.Add(asupUr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (abilitySub.otherScore.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var abother in abilitySub.otherScore)
|
|
|
+ {
|
|
|
+ if (abother.tmdid.Equals(item.oldId))
|
|
|
+ abother.tmdid = item.oldId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ abilitySub.code = abilitySub.code.Replace($"-{item.oldId}", $"-{item.newId}");
|
|
|
+ abilitySubs.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<AbilitySub>(abilitySub, new PartitionKey($"AbilitySub-{defaultSc}-{item.newId}")));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (abilitySubs.Count < 256)
|
|
|
+ await Task.WhenAll(abilitySubs);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int pages = (abilitySubs.Count + 255) / 256;
|
|
|
+ for (int i = 0; i < pages; i++)
|
|
|
+ {
|
|
|
+ List<Task<ItemResponse<AbilitySub>>> tempAbilSub = abilitySubs.Skip((i) * 256).Take(256).ToList();
|
|
|
+ await Task.WhenAll(tempAbilSub);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //教师所在学校的基础信息
|
|
|
+ SchoolTeacher schoolTeacher = new();
|
|
|
+ var resScTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{item.oldId}", new PartitionKey($"Teacher-{defaultSc}"));
|
|
|
+ if (resScTeacher.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(resScTeacher.ContentStream);
|
|
|
+ schoolTeacher = json.ToObject<SchoolTeacher>();
|
|
|
+ schoolTeacher.id = item.newId;
|
|
|
+
|
|
|
+ //创建新的教师在学校的基础信息
|
|
|
+ schoolTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
+ }
|
|
|
+
|
|
|
+ //名单信息
|
|
|
+ List<Task<ItemResponse<GroupList>>> groupLists = new();
|
|
|
+ await foreach (var grups in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{defaultSc}") }))
|
|
|
+ {
|
|
|
+ bool isReplace = false;
|
|
|
+ if (grups.members.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var griupm in grups.members)
|
|
|
+ {
|
|
|
+ if (griupm.id.Equals(item.oldId))
|
|
|
+ {
|
|
|
+ griupm.id = item.newId;
|
|
|
+ isReplace = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (grups.creatorId.Equals(item.oldId))
|
|
|
+ {
|
|
|
+ grups.creatorId = item.newId;
|
|
|
+ isReplace = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isReplace == true)
|
|
|
+ groupLists.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<GroupList>(grups, grups.id, new PartitionKey(grups.code)));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (groupLists.Count < 256)
|
|
|
+ await Task.WhenAll(groupLists);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int pages = (groupLists.Count + 255) / 256;
|
|
|
+ for (int i = 0; i < pages; i++)
|
|
|
+ {
|
|
|
+ List<Task<ItemResponse<GroupList>>> tempGroups = groupLists.Skip((i) * 256).Take(256).ToList();
|
|
|
+ await Task.WhenAll(tempGroups);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //教研活动
|
|
|
+ List<Task<ItemResponse<Study>>> studys = new();
|
|
|
+ await foreach (var study in cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<Study>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{defaultSc}") }))
|
|
|
+ {
|
|
|
+ bool isReplace = false;
|
|
|
+ if (study.creatorId.Equals(item.oldId))
|
|
|
+ {
|
|
|
+ study.creatorId = item.newId;
|
|
|
+ isReplace = true;
|
|
|
+ }
|
|
|
+ if (study.teacIds.Contains(item.oldId) == true)
|
|
|
+ {
|
|
|
+ study.teacIds = study.teacIds.Select(x => x.Replace($"{item.oldId}", $"{item.newId}")).ToList();
|
|
|
+ isReplace = true;
|
|
|
+ }
|
|
|
+ //if (isReplace == true)
|
|
|
+ studys.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<Study>(study, study.id, new PartitionKey($"Study-{defaultSc}")));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (studys.Count < 256)
|
|
|
+ await Task.WhenAll(studys);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int pages = (studys.Count + 255) / 256;
|
|
|
+ for (int i = 0; i < pages; i++)
|
|
|
+ {
|
|
|
+ List<Task<ItemResponse<Study>>> tempStudys = studys.Skip((i) * 256).Take(256).ToList();
|
|
|
+ await Task.WhenAll(tempStudys);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //教研测验活动记录
|
|
|
+ List<Task<ItemResponse<ExamLite>>> examLites = new();
|
|
|
+ await foreach (var examl in cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamLite>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamLite-{defaultSc}") }))
|
|
|
+ {
|
|
|
+ bool isReplace = false;
|
|
|
+ if (examl.teachers.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var examTch in examl.teachers)
|
|
|
+ {
|
|
|
+ if (examTch.id.Equals(item.oldId))
|
|
|
+ {
|
|
|
+ examTch.id = item.newId;
|
|
|
+ isReplace = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //if (isReplace == true)
|
|
|
+ examLites.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamLite>(examl, examl.id, new PartitionKey($"ExamLite-{defaultSc}")));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (examLites.Count < 256)
|
|
|
+ await Task.WhenAll(examLites);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int pages = (examLites.Count + 255) / 256;
|
|
|
+ for (int i = 0; i < pages; i++)
|
|
|
+ {
|
|
|
+ List<Task<ItemResponse<ExamLite>>> tempExam = examLites.Skip((i) * 256).Take(256).ToList();
|
|
|
+ await Task.WhenAll(tempExam);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //作业记录
|
|
|
+ List<Task<ItemResponse<HomeworkRecord>>> homeworkRecord = new();
|
|
|
+ await foreach (var homerec in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<HomeworkRecord>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"HomeworkRecord-{item.oldId}") }))
|
|
|
+ {
|
|
|
+ bool isReplace = false;
|
|
|
+ if (homerec.content.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var hrCon in homerec.content)
|
|
|
+ {
|
|
|
+ if (hrCon.url.Contains($"/{item.oldId}/"))
|
|
|
+ {
|
|
|
+ string hrUrl = hrCon.url;
|
|
|
+ hrCon.url = hrCon.url.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ hrCon.blob = hrCon.blob.Replace($"/{item.oldId}/", $"/{item.newId}/");
|
|
|
+ //作业附件地址
|
|
|
+ var tempFileCopy = await BatchCopyFileService.SingleCopyFile(_azureStorage, defaultSc, hrUrl, item.oldId, item.newId);
|
|
|
+ if (tempFileCopy != 200)
|
|
|
+ noCopyFiles.Add(hrUrl);
|
|
|
+ isReplace = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isReplace == true)
|
|
|
+ {
|
|
|
+ homerec.code = homerec.code.Replace($"-{item.oldId}", $"-{item.newId}");
|
|
|
+ homeworkRecord.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<HomeworkRecord>(homerec, new PartitionKey(homerec.code)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (homeworkRecord.Count < 256)
|
|
|
+ await Task.WhenAll(homeworkRecord);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int pages = (homeworkRecord.Count + 255) / 256;
|
|
|
+ for (int i = 0; i < pages; i++)
|
|
|
+ {
|
|
|
+ List<Task<ItemResponse<HomeworkRecord>>> tempHomeR = homeworkRecord.Skip((i) * 256).Take(256).ToList();
|
|
|
+ await Task.WhenAll(tempHomeR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //视频点评
|
|
|
+ List<Task<ItemResponse<Appraise>>> appraises = new();
|
|
|
+ await foreach (var appra in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Appraise>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Appraise-{item.oldId}") }))
|
|
|
+ {
|
|
|
+ bool isRepCode = false;
|
|
|
+ bool isReplace = false;
|
|
|
+ if (appra.code.Contains(item.oldId))
|
|
|
+ {
|
|
|
+ appra.code = appra.code.Replace($"-{item.oldId}", $"-{item.newId}");
|
|
|
+ isRepCode = true;
|
|
|
+ }
|
|
|
+ if (appra.roles.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var appRoles in appra.roles)
|
|
|
+ {
|
|
|
+ if (appRoles.commentTmdid.Equals(item.oldId))
|
|
|
+ {
|
|
|
+ appRoles.commentTmdid = item.newId;
|
|
|
+ isReplace = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((isRepCode == true && isReplace == true) || (isRepCode == true && isReplace == false))
|
|
|
+ appraises.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Appraise>(appra, new PartitionKey(appra.code)));
|
|
|
+ if (isReplace == true && isRepCode == false)
|
|
|
+ appraises.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Appraise>(appra, appra.id, new PartitionKey(appra.code)));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (appraises.Count < 256)
|
|
|
+ await Task.WhenAll(appraises);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int pages = (appraises.Count + 255) / 256;
|
|
|
+ for (int i = 0; i < pages; i++)
|
|
|
+ {
|
|
|
+ List<Task<ItemResponse<Appraise>>> tempAppra = appraises.Skip((i) * 256).Take(256).ToList();
|
|
|
+ await Task.WhenAll(tempAppra);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //话题记录
|
|
|
+ List<Task<ItemResponse<Debate>>> debates = new();
|
|
|
+ await foreach (var debate in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Debate>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Debate-{defaultSc}") }))
|
|
|
+ {
|
|
|
+ bool isReplace = false;
|
|
|
+ if (debate.tmdid.Equals(item.oldId))
|
|
|
+ {
|
|
|
+ debate.tmdid = item.newId;
|
|
|
+ isReplace = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (debate.replies.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var deRep in debate.replies)
|
|
|
+ {
|
|
|
+ if (deRep.tmdid.Equals(item.oldId))
|
|
|
+ {
|
|
|
+ deRep.tmdid = item.newId;
|
|
|
+ isReplace = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isReplace == true)
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<Debate>(debate, debate.id, new PartitionKey(debate.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { state = 200, noCopyFiles });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return Ok(new { state = 500 });
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public record TrainingId
|
|
|
+ {
|
|
|
+ public string oldId { get; set; }
|
|
|
+
|
|
|
+ public string newId { get; set; }
|
|
|
+ }
|
|
|
}
|
|
|
}
|