|
@@ -870,6 +870,9 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
return Ok(new { lesson_code });
|
|
|
}
|
|
|
|
|
|
+ //上傳評測結果
|
|
|
+ //錯誤代碼:error = 1001 message = "Paper blob copy failure."
|
|
|
+ // error = 1002 message = "Student answers blob upload failure."
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("upd-exam-result")]
|
|
|
public async Task<IActionResult> UploadExamResult(JsonElement request)
|
|
@@ -898,6 +901,7 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
string blobContainer = (!string.IsNullOrWhiteSpace(dbExamInfo.school) && dbExamInfo.scope == "school") ? dbExamInfo.school : id; //blob容器
|
|
|
//dbExamInfo.source = "1"; //評測來源固定為 1:課中評量(不應由API擅自變更)
|
|
|
//取得課堂紀錄下的試卷資料(blob)、複製到評測紀錄下
|
|
|
+ bool paperDataCopyErrFlg = false; //試卷資料拷貝錯誤Flag true:拷貝錯誤
|
|
|
List<Dictionary<string, string>> recordPaperInfo = new List<Dictionary<string, string>>();
|
|
|
foreach (PaperSimple paperInfo in dbExamInfo.papers)
|
|
|
{
|
|
@@ -911,7 +915,7 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
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}/
|
|
|
+ string destBlobPath = $"exam/{dbExamInfo.id}/paper/{recordPaperInfoDic["id"]}/"; //拷貝對象路徑 path:exam/{評測ID}/paper/{試卷ID}/
|
|
|
if (targetScope == "school") //校本
|
|
|
{
|
|
|
string schoolId = dbExamInfo.school;
|
|
@@ -926,7 +930,11 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
var sourceFileUri = blobPrivateContainer.GetBlobClient(blob.Name).Uri;
|
|
|
string fileName = blob.Name.Replace(sourceBlobPath, "");
|
|
|
string destBlobFilePath = $"{destBlobPath}{fileName}";
|
|
|
- blobSchoolContainer.GetBlobClient(destBlobFilePath).StartCopyFromUri(sourceFileUri);
|
|
|
+ await blobSchoolContainer.GetBlobClient(destBlobFilePath).StartCopyFromUriAsync(sourceFileUri);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ paperDataCopyErrFlg = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -943,7 +951,11 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
var sourceFileUri = blobPrivateContainer.GetBlobClient(blob.Name).Uri;
|
|
|
string fileName = blob.Name.Replace(sourceBlobPath, "");
|
|
|
string destBlobFilePath = $"{destBlobPath}{fileName}";
|
|
|
- blobPrivateContainer.GetBlobClient(destBlobFilePath).StartCopyFromUri(sourceFileUri);
|
|
|
+ await blobPrivateContainer.GetBlobClient(destBlobFilePath).StartCopyFromUriAsync(sourceFileUri);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ paperDataCopyErrFlg = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -954,10 +966,9 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
destBlobPathForDocument = (!destBlobPathForDocument.StartsWith("/")) ? "/" + destBlobPathForDocument : destBlobPathForDocument;
|
|
|
paperInfoNow.blob = destBlobPathForDocument;
|
|
|
}
|
|
|
- //UPDATE
|
|
|
- var examResponse = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").UpsertItemAsync(dbExamInfo, new PartitionKey(dbExamInfo.code)).GetAwaiter().GetResult();
|
|
|
-
|
|
|
+
|
|
|
//ExamClassResult內容調整
|
|
|
+ bool studentAnswerCopyErrFlg = false; //學生作答資料拷貝錯誤Flag true:拷貝錯誤
|
|
|
foreach (ExamClassResultStudentAnswerArray examClassResultRow in dbExamClassResultList)
|
|
|
{
|
|
|
ExamClassResult examClassResultUpd = new ExamClassResult();
|
|
@@ -987,26 +998,49 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
string studentId = examClassResultRow.studentIds[i];
|
|
|
string fileName = examId + "/" + subjectId + "/" + studentId;
|
|
|
string blob = fileName + "/" + "ans.json";
|
|
|
- await _azureStorage.UploadFileByContainer(blobContainer, examClassResultRow.studentAnswersArray[i].ToJsonString(), "exam", blob, false);
|
|
|
+ var uploadFileResult = await _azureStorage.UploadFileByContainer(blobContainer, examClassResultRow.studentAnswersArray[i].ToJsonString(), "exam", blob, false);
|
|
|
+ if(string.IsNullOrWhiteSpace(uploadFileResult))
|
|
|
+ {
|
|
|
+ studentAnswerCopyErrFlg = true;
|
|
|
+ }
|
|
|
List<string> studenrAnswerRow = new List<string>();
|
|
|
studenrAnswerRow.Add(blob);
|
|
|
examClassResultUpd.studentAnswers.Add(studenrAnswerRow);
|
|
|
}
|
|
|
}
|
|
|
- //UPDATE
|
|
|
+ //UPDATE ExamClassResult
|
|
|
var examClassResultResponse = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").UpsertItemAsync(examClassResultUpd, new PartitionKey(examClassResultUpd.code));
|
|
|
}
|
|
|
|
|
|
+ //UPDATE Exam
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Common").UpsertItemAsync(dbExamInfo, new PartitionKey(dbExamInfo.code));
|
|
|
+
|
|
|
+ //錯誤處理
|
|
|
+ if(paperDataCopyErrFlg) //試卷Blob拷貝失敗
|
|
|
+ {
|
|
|
+ error = 1001;
|
|
|
+ message = "Paper blob copy failure.";
|
|
|
+ } else if(studentAnswerCopyErrFlg) //學生作答資料上傳blob失敗
|
|
|
+ {
|
|
|
+ error = 1002;
|
|
|
+ message = "Student answers blob upload failure.";
|
|
|
+ }
|
|
|
return Ok(new { error, message });
|
|
|
}
|
|
|
+ catch (CosmosException cex)
|
|
|
+ {
|
|
|
+ return BadRequest(cex.Message);
|
|
|
+ }
|
|
|
+ catch (StorageException bex)
|
|
|
+ {
|
|
|
+ return BadRequest(bex.Message);
|
|
|
+ }
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- return BadRequest();
|
|
|
+ return BadRequest(ex.Message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//課綱的model先記在下面,待式樣確定後再轉換
|
|
|
private List<SyllabusNode> CreateSyllabusTree(List<Syllabus> syllabuses)
|
|
|
{
|