|
@@ -39,7 +39,7 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
|
|
|
|
- public ExamController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
|
|
|
+ public ExamController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
|
|
|
IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
@@ -794,7 +794,8 @@ namespace TEAMModelOS.Controllers
|
|
|
examClassResults.Add(item);
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamClassResult>(
|
|
|
queryText: $"select value(c) from c where c.examId = '{id}' and c.subjectId = '{subjectId}' and array_contains(c.studentIds,'{studentId}')",
|
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{school}") }))
|
|
@@ -802,7 +803,7 @@ namespace TEAMModelOS.Controllers
|
|
|
examClassResults.Add(item);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
ExamClassResult classResult = new ExamClassResult();
|
|
|
//ExamInfo classResult = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
//ExamClassResult classResult = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamClassResult>(id.ToString(), new PartitionKey($"{code}"));
|
|
@@ -1422,17 +1423,29 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
if (!requert.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("tmdId", out JsonElement tId)) return BadRequest();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
var redisClient = _azureRedis.GetRedisClient(8);
|
|
|
ExamInfo info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
|
|
|
List<ExamClassResult> classResults = new();
|
|
|
- List<dynamic> recs = new List<dynamic>();
|
|
|
- var record = await redisClient.HashGetAllAsync($"Exam:Scoring:{id}-{subjectId}");
|
|
|
- foreach (var rcd in record)
|
|
|
- {
|
|
|
- var value = JsonDocument.Parse(rcd.Value.ToString());
|
|
|
- recs.Add(new { stuId = rcd.Name.ToString(), ans = value });
|
|
|
- }
|
|
|
+ List<dynamic> recs = new List<dynamic>();
|
|
|
+ List<dynamic> all = new List<dynamic>();
|
|
|
+ var record = await redisClient.HashGetAllAsync($"Exam:Scoring:{id}-{subjectId}");
|
|
|
+ foreach (var rcd in record)
|
|
|
+ {
|
|
|
+ var value = JsonDocument.Parse(rcd.Value.ToString());
|
|
|
+ value.RootElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
+ if (tId.ToString().Equals(tmdId.ToString()))
|
|
|
+ {
|
|
|
+ recs.Add(new { stuId = rcd.Name.ToString(), ans = value });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ all.Add(new { stuId = rcd.Name.ToString(), ans = value });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
int index = 0;
|
|
|
foreach (ExamSubject subject in info.subjects)
|
|
|
{
|
|
@@ -1445,6 +1458,72 @@ namespace TEAMModelOS.Controllers
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ return Ok(new { recs, all, paper = info.papers[index].blob });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},exam/scoring\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //批阅,给老师随机分配阅卷数据,以及查询改老师已有的阅卷数据
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ //[AuthToken(Roles = "Student")]
|
|
|
+ [HttpPost("review")]
|
|
|
+ public async Task<IActionResult> Review(JsonElement requert)
|
|
|
+ {
|
|
|
+ //ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
+ //var (id, school) = HttpContext.GetAuthTokenInfo();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("tmdId", out JsonElement tId)) return BadRequest();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ var redisClient = _azureRedis.GetRedisClient(8);
|
|
|
+ List<ExamClassResult> classResults = new();
|
|
|
+ List<dynamic> recs = new List<dynamic>();
|
|
|
+ List<dynamic> all = new List<dynamic>();
|
|
|
+ var record = await redisClient.HashGetAllAsync($"Exam:Scoring:{id}-{subjectId}");
|
|
|
+ foreach (var rcd in record)
|
|
|
+ {
|
|
|
+ var value = JsonDocument.Parse(rcd.Value.ToString());
|
|
|
+ value.RootElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
+ if (tId.ToString().Equals(tmdId.ToString()))
|
|
|
+ {
|
|
|
+ recs.Add(new { stuId = rcd.Name.ToString(), ans = value });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ all.Add(new { stuId = rcd.Name.ToString(), ans = value });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (requert.TryGetProperty("stuId", out JsonElement stuId))
|
|
|
+ {
|
|
|
+ var stuAns = await redisClient.HashGetAsync($"Exam:Scoring:{id}-{subjectId}", stuId.ToString());
|
|
|
+ var value = JsonDocument.Parse(stuAns.ToString());
|
|
|
+ return Ok(value);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //随机选取一名学生打分
|
|
|
+ Random random = new Random();
|
|
|
+ int n = random.Next(all.Count);
|
|
|
+ dynamic item = all[n];
|
|
|
+ //序列化单个学生作答记录、得分情况、批注情况
|
|
|
+ var cs = JsonSerializer.Serialize(item);
|
|
|
+ var json = JsonDocument.Parse(cs);
|
|
|
+ json.RootElement.TryGetProperty("stuId", out JsonElement sId);
|
|
|
+ json.RootElement.TryGetProperty("ans", out JsonElement ans);
|
|
|
+ ans.TryGetProperty("score", out JsonElement sc);
|
|
|
+ ans.TryGetProperty("ans", out JsonElement blob);
|
|
|
+ //选取后,缓存池相应的减少,以便于分配给其他的老师
|
|
|
+ await redisClient.HashSetAsync($"Exam:Scoring:{id}-{subjectId}", sId.ToString(), new { ans = blob, score = sc, tmdId = tId }.ToJsonString());
|
|
|
+ return Ok(item);
|
|
|
+ }
|
|
|
+
|
|
|
//var json = JsonDocument.Parse(record);
|
|
|
/*if (info.scope.Equals("school"))
|
|
|
{
|
|
@@ -1476,12 +1555,11 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
}
|
|
|
await Task.WhenAll(tasks);*/
|
|
|
- //info = await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(info, info.id, new PartitionKey($"Exam-{code}"));
|
|
|
- return Ok(new { recs,paper = info.papers[index].blob});
|
|
|
+ //info = await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(info, info.id, new PartitionKey($"Exam-{code}"));
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- await _dingDing.SendBotMsg($"OS,{_option.Location},exam/scoring\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},exam/review\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
return BadRequest();
|
|
|
}
|
|
|
|