|
@@ -13,6 +13,8 @@ using TEAMModelOS.SDK.DI;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
using TEAMModelOS.SDK.Helper.Common.StringHelper;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -24,9 +26,15 @@ namespace TEAMModelOS.Controllers
|
|
|
public class CommentController :ControllerBase
|
|
|
{
|
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
|
- public CommentController(AzureCosmosFactory azureCosmos)
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ public CommentController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _option = option?.Value;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -123,6 +131,64 @@ namespace TEAMModelOS.Controllers
|
|
|
return Ok();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //批注
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ //[AuthToken(Roles = "Teacher")]
|
|
|
+ [HttpPost("upsert-answer")]
|
|
|
+ public async Task<IActionResult> upsertAnswer(JsonElement request)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ //if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("answer", out JsonElement answer)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("studentId", out JsonElement studentId)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("classId", out JsonElement classId)) return BadRequest();
|
|
|
+ //if (!request.TryGetProperty("multipleRule", out JsonElement multipleRule)) return BadRequest();
|
|
|
+ //if (!request.TryGetProperty("answers ", out JsonElement tandardAnswer)) return BadRequest();
|
|
|
+ //if (!request.TryGetProperty("paperId", out JsonElement paperId)) return BadRequest();
|
|
|
+ //根据不同评测的类型返回对应的编码
|
|
|
+ if (!request.TryGetProperty("code", out JsonElement school)) return BadRequest();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ List<ExamClassResult> examClassResults = new List<ExamClassResult>();
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(
|
|
|
+ queryText: $"select value(c) from c where c.examId = '{id}' and c.subjectId = '{subjectId}' and c.info.id = '{classId}'",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{school}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ examClassResults.Add(obj.ToObject<ExamClassResult>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ExamClassResult classResult = new ExamClassResult();
|
|
|
+ List<List<string>> ans = answer.ToObject<List<List<string>>>();
|
|
|
+ List<List<string>> standard = new List<List<string>>();
|
|
|
+ List<double> points = new List<double>();
|
|
|
+ foreach (ExamClassResult result in examClassResults)
|
|
|
+ {
|
|
|
+ int index = result.studentIds.IndexOf(studentId.ToString());
|
|
|
+ string FileName = result.examId + "/" + result.subjectId + "/" + studentId;
|
|
|
+ string blob = await _azureStorage.UploadFileByContainer(school.ToString(), ans.ToJsonString(), "exam", FileName + "/" + "ans.json");
|
|
|
+ result.studentAnswers[index].Add(blob);
|
|
|
+ classResult = await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { classResult });
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/comment/upsertAnswer()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|