|
@@ -892,31 +892,65 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
List<ExamClassResultStudentAnswerArray> dbExamClassResultList = examClassResult.ToObject<List<ExamClassResultStudentAnswerArray>>();
|
|
|
|
|
|
//ExamInfo內容取得、調整
|
|
|
- string blobContainer = (dbExamInfo.range == "school" && dbExamInfo.scope == "school" && dbExamInfo.school != null) ? dbExamInfo.school : id; //blob容器
|
|
|
- dbExamInfo.source = "1"; //評測來源固定為 1:課中評量
|
|
|
+ string blobContainer = (!string.IsNullOrWhiteSpace(dbExamInfo.school) && dbExamInfo.code.Contains(dbExamInfo.school)) ? dbExamInfo.school : id; //blob容器
|
|
|
+ //dbExamInfo.source = "1"; //評測來源固定為 1:課中評量(不應由API擅自變更)
|
|
|
//取得課堂紀錄下的試卷資料(blob)、複製到評測紀錄下
|
|
|
- //List<Dictionary<string, string>> recordPaperInfo = new List<Dictionary<string, string>>();
|
|
|
- //foreach (PaperSimple paperInfo in dbExamInfo.papers)
|
|
|
- //{
|
|
|
- // recordPaperInfo.Add(new Dictionary<string, string>() { { "id", paperInfo.id }, { "blob", paperInfo.blob } });
|
|
|
- //}
|
|
|
- //foreach (Dictionary<string, string> recordPaperInfoDic in recordPaperInfo)
|
|
|
- //{
|
|
|
- // string targetScope = dbExamInfo.scope; //評測對象 school:校本班級 private:私人課程
|
|
|
- // var blobPrivateContainer = _azureStorage.GetBlobContainerClient(id);
|
|
|
- // var sourceBlob = blobPrivateContainer.GetBlobClient(recordPaperInfoDic["blob"]);
|
|
|
- // string destBlobPath = $"exam/{dbExamInfo.id}/paper/{recordPaperInfoDic["id"]}"; //path:exam/{評測ID}/paper/{試卷ID}
|
|
|
- // if (targetScope == "school") //校本
|
|
|
- // {
|
|
|
- // string schoolId = dbExamInfo.school;
|
|
|
- // var blobSchoolContainer = _azureStorage.GetBlobContainerClient(schoolId);
|
|
|
- // blobSchoolContainer.GetBlobClient(destBlobPath).StartCopyFromUri(sourceBlob.Uri);
|
|
|
- // }
|
|
|
- // else //私人
|
|
|
- // {
|
|
|
- // blobPrivateContainer.GetBlobClient(destBlobPath).StartCopyFromUri(sourceBlob.Uri);
|
|
|
- // }
|
|
|
- //}
|
|
|
+ List<Dictionary<string, string>> recordPaperInfo = new List<Dictionary<string, string>>();
|
|
|
+ foreach (PaperSimple paperInfo in dbExamInfo.papers)
|
|
|
+ {
|
|
|
+ string paperBlobPath = (!paperInfo.blob.EndsWith("/")) ? paperInfo.blob + "/" : paperInfo.blob;
|
|
|
+ paperBlobPath = (paperInfo.blob.StartsWith("/")) ? paperBlobPath.Remove(0, 1) : paperBlobPath;
|
|
|
+ recordPaperInfo.Add(new Dictionary<string, string>() { { "id", paperInfo.id }, { "blob", paperBlobPath } });
|
|
|
+ }
|
|
|
+ foreach (Dictionary<string, string> recordPaperInfoDic in recordPaperInfo)
|
|
|
+ {
|
|
|
+ string targetScope = dbExamInfo.scope; //評測對象 school:校本班級 private:私人課程
|
|
|
+ var blobPrivateContainer = _azureStorage.GetBlobContainerClient(id);
|
|
|
+ string sourceBlobPath = recordPaperInfoDic["blob"];
|
|
|
+ Azure.Pageable<BlobItem> sourceBlobs = blobPrivateContainer.GetBlobs(prefix: sourceBlobPath);
|
|
|
+ string destBlobPath = $"exam/{dbExamInfo.id}/paper/{recordPaperInfoDic["id"]}/"; //path:exam/{評測ID}/paper/{試卷ID}/
|
|
|
+ if (targetScope == "school") //校本
|
|
|
+ {
|
|
|
+ string schoolId = dbExamInfo.school;
|
|
|
+ var blobSchoolContainer = _azureStorage.GetBlobContainerClient(schoolId);
|
|
|
+ if (sourceBlobs.Count() > 0)
|
|
|
+ {
|
|
|
+ foreach (var blob in sourceBlobs)
|
|
|
+ {
|
|
|
+ var sourceFileBlob = blobPrivateContainer.GetBlobClient(blob.Name);
|
|
|
+ if(sourceFileBlob.Exists())
|
|
|
+ {
|
|
|
+ var sourceFileUri = blobPrivateContainer.GetBlobClient(blob.Name).Uri;
|
|
|
+ string fileName = blob.Name.Replace(sourceBlobPath, "");
|
|
|
+ string destBlobFilePath = $"{destBlobPath}{fileName}";
|
|
|
+ blobSchoolContainer.GetBlobClient(destBlobFilePath).StartCopyFromUri(sourceFileUri);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else //私人
|
|
|
+ {
|
|
|
+ if (sourceBlobs.Count() > 0)
|
|
|
+ {
|
|
|
+ foreach (var blob in sourceBlobs)
|
|
|
+ {
|
|
|
+ var sourceFileBlob = blobPrivateContainer.GetBlobClient(blob.Name);
|
|
|
+ if (sourceFileBlob.Exists())
|
|
|
+ {
|
|
|
+ var sourceFileUri = blobPrivateContainer.GetBlobClient(blob.Name).Uri;
|
|
|
+ string fileName = blob.Name.Replace(sourceBlobPath, "");
|
|
|
+ string destBlobFilePath = $"{destBlobPath}{fileName}";
|
|
|
+ blobPrivateContainer.GetBlobClient(destBlobFilePath).StartCopyFromUri(sourceFileUri);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //替換 Exam.papers.blob
|
|
|
+ PaperSimple paperInfoNow = dbExamInfo.papers.Where((PaperSimple p) => p.id == recordPaperInfoDic["id"]).FirstOrDefault();
|
|
|
+ string destBlobPathForDocument = (destBlobPath.EndsWith("/")) ? destBlobPath.Remove(destBlobPath.Length - 1, 1) : destBlobPath;
|
|
|
+ destBlobPathForDocument = (!destBlobPathForDocument.StartsWith("/")) ? "/" + destBlobPathForDocument : destBlobPathForDocument;
|
|
|
+ paperInfoNow.blob = destBlobPathForDocument;
|
|
|
+ }
|
|
|
//UPDATE
|
|
|
var examResponse = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").UpsertItemAsync(dbExamInfo, new PartitionKey(dbExamInfo.code)).GetAwaiter().GetResult();
|
|
|
|