|
@@ -1083,6 +1083,7 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
|
|
|
if (!request.TryGetProperty("exam", out JsonElement exam)) return BadRequest();
|
|
|
if (!request.TryGetProperty("examClassResult", out JsonElement examClassResult)) return BadRequest();
|
|
|
+ bool blobUploaded = (request.TryGetProperty("blobUploaded", out JsonElement blobUploadedJson)) ? blobUploadedJson.GetBoolean() : false;
|
|
|
|
|
|
ExamInfo ExamInfoFromReq = exam.ToObject<ExamInfo>();
|
|
|
string examId = ExamInfoFromReq.id;
|
|
@@ -1105,7 +1106,7 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
dbExamInfo = ExamInfoFromReq;
|
|
|
}
|
|
|
|
|
|
- Boolean isTestFlg = (_option.Location.Contains("Test") || _option.Location.Contains("Dep")) ? true : false;
|
|
|
+ //Boolean isTestFlg = (_option.Location.Contains("Test") || _option.Location.Contains("Dep")) ? true : false;
|
|
|
//ExamInfo內容取得、調整 [2021-7-13 廢除,給予HiTeach學校Blob寫入權限,API不再對Blob做搬運]
|
|
|
//※規則 owner:"school" => 校園評測 "teacher" => 個人評測
|
|
|
//※規則 scope:"school" => 校本班級 "private" => 個人班級
|
|
@@ -1113,18 +1114,23 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
string blobContainer = (!string.IsNullOrWhiteSpace(dbExamInfo.school) && dbExamInfo.scope .Equals("school")) ? dbExamInfo.school : id; //blob容器
|
|
|
//dbExamInfo.source = "1"; //評測來源固定為 1:課中評量(不應由API擅自變更)
|
|
|
|
|
|
+ //試卷List
|
|
|
+ List<Dictionary<string, string>> recordPaperInfo = new List<Dictionary<string, string>>();
|
|
|
+ int paperIndex = 0;
|
|
|
+ foreach (PaperSimple paperInfo in ExamInfoFromReq.papers)
|
|
|
+ {
|
|
|
+ string paperBlobPath = (!paperInfo.blob.EndsWith("/")) ? paperInfo.blob + "/" : paperInfo.blob;
|
|
|
+ paperBlobPath = (paperInfo.blob.StartsWith("/")) ? paperBlobPath.Remove(0, 1) : paperBlobPath;
|
|
|
+ string subjectId = dbExamInfo.subjects[paperIndex].id;
|
|
|
+ recordPaperInfo.Add(new Dictionary<string, string>() { { "id", paperInfo.id }, { "blob", paperBlobPath }, { "subjectId", subjectId }, { "itemcount", paperInfo.point.Count.ToString() } });
|
|
|
+ paperIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
//取得課堂紀錄下的試卷資料(blob)、複製到評測紀錄下
|
|
|
bool paperDataCopyErrFlg = false; //試卷資料拷貝錯誤Flag true:拷貝錯誤 [2021-7-13 (測試站)不再對Blob做搬運 永為false]
|
|
|
- //非測試站執行以下程序 (待HiTeach完善後刪除)
|
|
|
- if (!isTestFlg)
|
|
|
+ //Blob搬運 (待HiTeach完善後刪除)
|
|
|
+ if (!blobUploaded)
|
|
|
{
|
|
|
- List<Dictionary<string, string>> recordPaperInfo = new List<Dictionary<string, string>>();
|
|
|
- foreach (PaperSimple paperInfo in ExamInfoFromReq.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:私人課程
|
|
@@ -1186,8 +1192,8 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
|
|
|
//ExamClassResult內容調整
|
|
|
bool studentAnswerCopyErrFlg = false; //學生作答資料拷貝錯誤Flag true:拷貝錯誤 [2021-7-13 不再對Blob做搬運 永為false]
|
|
|
- //非測試站執行以下程序 (待HiTeach完善後刪除)
|
|
|
- if (!isTestFlg)
|
|
|
+ //Blob搬運 (待HiTeach完善後刪除)
|
|
|
+ if (!blobUploaded)
|
|
|
{
|
|
|
List<ExamClassResultStudentAnswerArrayOld> dbExamClassResultList = examClassResult.ToObject<List<ExamClassResultStudentAnswerArrayOld>>();
|
|
|
foreach (ExamClassResultStudentAnswerArrayOld examClassResultRow in dbExamClassResultList)
|
|
@@ -1233,7 +1239,6 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
examClassResultUpd.scope = examClassResultRow.scope;
|
|
|
examClassResultUpd.sum = examClassResultRow.sum;
|
|
|
}
|
|
|
-
|
|
|
//examClassResult.studentAnswers 將學生答案上傳blob後轉換內容為blob路徑 //[2021-7-13 不再對Blob做搬運]
|
|
|
if (examClassResultRow.studentIds != null && examClassResultRow.studentIds.Count > 0 && examClassResultRow.studentAnswersArray != null && examClassResultRow.studentAnswersArray.Count > 0)
|
|
|
{
|
|
@@ -1252,6 +1257,13 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
examClassResultUpd.studentAnswers.Add(studenrAnswerRow);
|
|
|
}
|
|
|
}
|
|
|
+ //批註欄位處理
|
|
|
+ Dictionary<string, string> paperStatusNow = recordPaperInfo.Where((Dictionary<string, string> p) => p.TryGetValue("subjectId", out string paperStatusSubjectId) && paperStatusSubjectId.Equals(subjectId)).FirstOrDefault();
|
|
|
+ int itemCount = Convert.ToInt32(paperStatusNow["itemcount"]);
|
|
|
+ if (examClassResultUpd.mark.Count != examClassResultUpd.studentIds.Count || (examClassResultUpd.mark.ElementAtOrDefault(0) != null && examClassResultUpd.mark[0].Count != itemCount)) //第一層:學生數不符 OR 第二層:第一位學生批註數!=試卷題數 => 批註格式不符
|
|
|
+ {
|
|
|
+ examClassResultUpd.mark = this.createEmptyMark(examClassResultUpd.studentIds.Count, itemCount);
|
|
|
+ }
|
|
|
|
|
|
//UPDATE ExamClassResult
|
|
|
var examClassResultResponse = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(examClassResultUpd, new PartitionKey(examClassResultUpd.code));
|
|
@@ -1304,6 +1316,13 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
examClassResultUpd.sum = examClassResultRow.sum;
|
|
|
}
|
|
|
examClassResultUpd.studentAnswers = examClassResultRow.studentAnswersArray; //[2021-7-13 不再對Blob做搬運 學生答案直接寫入DB]
|
|
|
+ //批註欄位處理
|
|
|
+ Dictionary<string, string> paperStatusNow = recordPaperInfo.Where((Dictionary<string, string> p) => p.TryGetValue("subjectId", out string subjectId) && subjectId.Equals(examClassResultUpd.subjectId)).FirstOrDefault();
|
|
|
+ int itemCount = Convert.ToInt32(paperStatusNow["itemcount"]);
|
|
|
+ if (examClassResultUpd.mark.Count != examClassResultUpd.studentIds.Count || (examClassResultUpd.mark.ElementAtOrDefault(0) != null && examClassResultUpd.mark[0].Count != itemCount)) //第一層:學生數不符 OR 第二層:第一位學生批註數!=試卷題數 => 批註格式不符
|
|
|
+ {
|
|
|
+ examClassResultUpd.mark = this.createEmptyMark(examClassResultUpd.studentIds.Count, itemCount);
|
|
|
+ }
|
|
|
|
|
|
//UPDATE ExamClassResult
|
|
|
var examClassResultResponse = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(examClassResultUpd, new PartitionKey(examClassResultUpd.code));
|
|
@@ -1339,6 +1358,21 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private List<List<List<Details>>> createEmptyMark(int studentNum, int itemNum)
|
|
|
+ {
|
|
|
+ List<List<List<Details>>> mark = new List<List<List<Details>>>();
|
|
|
+ for (int i = 0; i < studentNum; i++)
|
|
|
+ {
|
|
|
+ List<List<Details>> markRow = new List<List<Details>>();
|
|
|
+ for (int j = 0; j < itemNum; j++)
|
|
|
+ {
|
|
|
+ markRow.Add(new List<Details>());
|
|
|
+ }
|
|
|
+ mark.Add(markRow);
|
|
|
+ }
|
|
|
+ return mark;
|
|
|
+ }
|
|
|
+
|
|
|
//課綱的model先記在下面,待式樣確定後再轉換
|
|
|
private List<SyllabusNode> CreateSyllabusTree(List<Syllabus> syllabuses)
|
|
|
{
|