|
@@ -1823,7 +1823,7 @@ namespace TEAMModelOS.Controllers
|
|
|
//ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
try
|
|
|
{
|
|
|
- //var (userid, _, _, _) = HttpContext.GetAuthTokenInfo(); //取得TMID
|
|
|
+ var (userid, username, _, _) = HttpContext.GetAuthTokenInfo(); //取得TMID
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
if (!request.TryGetProperty("point", out JsonElement point)) return BadRequest();
|
|
@@ -1959,6 +1959,8 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
});
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"Exam-{code}"));
|
|
|
+ //若為統測評量,紀錄修改分數內容
|
|
|
+ if (string.IsNullOrWhiteSpace(exam.jointExamId)) await upsertExamClassResultMark(result, userid, username, sIds, ans);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -1966,6 +1968,8 @@ namespace TEAMModelOS.Controllers
|
|
|
ExamInfo exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
|
|
|
exam.updateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"Exam-{code}"));
|
|
|
+ //若為統測評量,紀錄修改分數內容
|
|
|
+ if (string.IsNullOrWhiteSpace(exam.jointExamId)) await upsertExamClassResultMark(result, userid, username, sIds, ans);
|
|
|
}
|
|
|
classResult = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
|
|
|
// await Task.WhenAll(tasks);
|
|
@@ -4774,9 +4778,52 @@ namespace TEAMModelOS.Controllers
|
|
|
return Ok(new { error });
|
|
|
}
|
|
|
|
|
|
+ //記入班級評量結果批改結果 ※目前只套用統測結果批改ReadItemAsync
|
|
|
+ private async Task upsertExamClassResultMark(ExamClassResult examClassResult, string userId, string userName, List<stus> students, List<List<double>> points)
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ ExamClassResultMark exMark = new ExamClassResultMark();
|
|
|
+ String code = examClassResult.code.Replace("ExamClassResult", "ExamClassResultMark");
|
|
|
+ string id = examClassResult.id;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ exMark = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamClassResultMark>(id, new PartitionKey($"{code}"));
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ exMark.id = id;
|
|
|
+ exMark.code = code;
|
|
|
+ }
|
|
|
+ exMark.markerId = userId;
|
|
|
+ exMark.markerName = userName;
|
|
|
+ exMark.studentIds = examClassResult.studentIds;
|
|
|
+ //學生ID對應index字典
|
|
|
+ Dictionary<string, int> stuIndexDic = new Dictionary<string, int>();
|
|
|
+ foreach (var item in exMark.studentIds.Select((value, i) => new { i, value }))
|
|
|
+ {
|
|
|
+ string studentId = item.value;
|
|
|
+ int index = item.i;
|
|
|
+ stuIndexDic.Add(studentId, index);
|
|
|
+ }
|
|
|
+ //points內容數不足對應
|
|
|
+ while (exMark.studentIds.Count - exMark.points.Count > 0)
|
|
|
+ {
|
|
|
+ exMark.points.Add(new List<double>());
|
|
|
+ }
|
|
|
+ //points分數記入
|
|
|
+ foreach (var stu in students.Select((value, i) => new { i, value }))
|
|
|
+ {
|
|
|
+ List<double> point = points[stu.i];
|
|
|
+ if (stuIndexDic.ContainsKey(stu.value.id))
|
|
|
+ {
|
|
|
+ int index = stuIndexDic[stu.value.id];
|
|
|
+ exMark.points[index] = point;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, Constant.Common).UpsertItemAsync<ExamClassResultMark>(exMark, new PartitionKey(code));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public class stus
|
|
|
{
|
|
|
public string id { get; set; }
|