|
@@ -606,7 +606,7 @@ namespace TEAMModelOS.Controllers
|
|
/// <param name="request"></param>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
- //[AuthToken(Roles = "Teacher")]
|
|
|
|
|
|
+ [AuthToken(Roles = "student,teacher")]
|
|
[HttpPost("upsert-record")]
|
|
[HttpPost("upsert-record")]
|
|
public async Task<IActionResult> upsertRecord(JsonElement request)
|
|
public async Task<IActionResult> upsertRecord(JsonElement request)
|
|
{
|
|
{
|
|
@@ -615,7 +615,7 @@ namespace TEAMModelOS.Controllers
|
|
//学校编码
|
|
//学校编码
|
|
//if (!request.TryGetProperty("school", out JsonElement school)) return BadRequest();
|
|
//if (!request.TryGetProperty("school", out JsonElement school)) return BadRequest();
|
|
if (!request.TryGetProperty("answer", out JsonElement answer)) return BadRequest();
|
|
if (!request.TryGetProperty("answer", out JsonElement answer)) return BadRequest();
|
|
- if (!request.TryGetProperty("studentId", out JsonElement studentId)) return BadRequest();
|
|
|
|
|
|
+ //if (!request.TryGetProperty("studentId", out JsonElement studentId)) return BadRequest();
|
|
if (!request.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
|
|
if (!request.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
|
|
if (!request.TryGetProperty("classIds", out JsonElement classId)) return BadRequest();
|
|
if (!request.TryGetProperty("classIds", out JsonElement classId)) return BadRequest();
|
|
if (!request.TryGetProperty("multipleRule", out JsonElement multipleRule)) return BadRequest();
|
|
if (!request.TryGetProperty("multipleRule", out JsonElement multipleRule)) return BadRequest();
|
|
@@ -624,6 +624,7 @@ namespace TEAMModelOS.Controllers
|
|
//根据不同评测的类型返回对应的编码
|
|
//根据不同评测的类型返回对应的编码
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
if (!request.TryGetProperty("scode", out JsonElement scode)) return BadRequest();
|
|
if (!request.TryGetProperty("scode", out JsonElement scode)) return BadRequest();
|
|
|
|
+ var (userId, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
try
|
|
try
|
|
{
|
|
{
|
|
List<string> ids = new List<string>();
|
|
List<string> ids = new List<string>();
|
|
@@ -636,14 +637,14 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
//List<string> stus = new List<string>();
|
|
//List<string> stus = new List<string>();
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(
|
|
- queryText: $"select c.classId as id from c where c.classId = '{cId}' and c.id = '{studentId}'",
|
|
|
|
|
|
+ queryText: $"select c.classId as id from c where c.classId = '{cId}' and c.id = '{userId}'",
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{info.school}") }))
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{info.school}") }))
|
|
{
|
|
{
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
{
|
|
{
|
|
var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
- while (accounts.MoveNext())
|
|
|
|
|
|
+ while (accounts.MoveNext())
|
|
{
|
|
{
|
|
JsonElement account = accounts.Current;
|
|
JsonElement account = accounts.Current;
|
|
cIds.Add(account.GetProperty("id").GetString());
|
|
cIds.Add(account.GetProperty("id").GetString());
|
|
@@ -654,7 +655,7 @@ namespace TEAMModelOS.Controllers
|
|
if (info.scope.Equals("private"))
|
|
if (info.scope.Equals("private"))
|
|
{
|
|
{
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(
|
|
- queryText: $"select c.id from c join A0 in c.students where c.id = '{cId}' and (A0.id = '{studentId}' or array_contains(c.tmids,'{studentId}')) and A0.schoolId = '{info.school}'",
|
|
|
|
|
|
+ queryText: $"select c.id from c join A0 in c.students where c.id = '{cId}' and (A0.id = '{userId}' or array_contains(c.tmids,'{userId}')) and A0.schoolId = '{info.school}'",
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList") }))
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList") }))
|
|
{
|
|
{
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
@@ -673,7 +674,7 @@ namespace TEAMModelOS.Controllers
|
|
else
|
|
else
|
|
{
|
|
{
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(
|
|
- queryText: $"select c.id from c join A0 in c.students where c.id = '{cId}' and A0.id = '{studentId}'",
|
|
|
|
|
|
+ queryText: $"select c.id from c join A0 in c.students where c.id = '{cId}' and A0.id = '{userId}'",
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList-{info.school}") }))
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList-{info.school}") }))
|
|
{
|
|
{
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
@@ -689,11 +690,7 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- /* if(stus.Count > 0)
|
|
|
|
- {
|
|
|
|
- cIds.Add(cId);
|
|
|
|
- }*/
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
List<ExamClassResult> examClassResults = new List<ExamClassResult>();
|
|
List<ExamClassResult> examClassResults = new List<ExamClassResult>();
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(
|
|
queryText: $"select value(c) from c where c.examId = '{id}' and c.subjectId = '{subjectId}' and c.info.id in ({string.Join(",", cIds.Select(o => $"'{o}'"))})",
|
|
queryText: $"select value(c) from c where c.examId = '{id}' and c.subjectId = '{subjectId}' and c.info.id in ({string.Join(",", cIds.Select(o => $"'{o}'"))})",
|
|
@@ -736,7 +733,7 @@ namespace TEAMModelOS.Controllers
|
|
List<Task<string>> tasks = new List<Task<string>>();
|
|
List<Task<string>> tasks = new List<Task<string>>();
|
|
foreach (ExamClassResult result in examClassResults)
|
|
foreach (ExamClassResult result in examClassResults)
|
|
{
|
|
{
|
|
- int index = result.studentIds.IndexOf(studentId.ToString());
|
|
|
|
|
|
+ int index = result.studentIds.IndexOf(userId.ToString());
|
|
//存放客观题作答详情
|
|
//存放客观题作答详情
|
|
if (result.ans.Count == 0)
|
|
if (result.ans.Count == 0)
|
|
{
|
|
{
|
|
@@ -756,12 +753,20 @@ namespace TEAMModelOS.Controllers
|
|
if (index == -1)
|
|
if (index == -1)
|
|
{
|
|
{
|
|
List<double> ansPoint = new List<double>();
|
|
List<double> ansPoint = new List<double>();
|
|
|
|
+ List<List<string>> anc = new List<List<string>>();
|
|
|
|
+ List<List<Details>> mark = new List<List<Details>>();
|
|
foreach (List<string> num in standard)
|
|
foreach (List<string> num in standard)
|
|
{
|
|
{
|
|
- //ans.Add(new List<string>());
|
|
|
|
|
|
+ List<string> newAns = new List<string>();
|
|
|
|
+ foreach (string san in num) {
|
|
|
|
+ newAns.Add(san);
|
|
|
|
+ }
|
|
|
|
+ anc.Add(newAns);
|
|
ansPoint.Add(-1);
|
|
ansPoint.Add(-1);
|
|
|
|
+ mark.Add(new List<Details>());
|
|
}
|
|
}
|
|
- result.studentIds.Add(studentId.ToString());
|
|
|
|
|
|
+ result.ans.Add(anc);
|
|
|
|
+ result.studentIds.Add(userId.ToString());
|
|
result.studentScores.Add(ansPoint);
|
|
result.studentScores.Add(ansPoint);
|
|
result.studentAnswers.Add(new List<string>());
|
|
result.studentAnswers.Add(new List<string>());
|
|
result.sum.Add(0);
|
|
result.sum.Add(0);
|
|
@@ -773,13 +778,13 @@ namespace TEAMModelOS.Controllers
|
|
flagCount++;
|
|
flagCount++;
|
|
}
|
|
}
|
|
} */
|
|
} */
|
|
- int newIndex = result.studentIds.IndexOf(studentId.ToString());
|
|
|
|
|
|
+ int newIndex = result.studentIds.IndexOf(userId.ToString());
|
|
/* if (flagCount != standard.Count)
|
|
/* if (flagCount != standard.Count)
|
|
{*/
|
|
{*/
|
|
StringBuilder builder = new StringBuilder();
|
|
StringBuilder builder = new StringBuilder();
|
|
builder.Append(result.examId).Append("/");
|
|
builder.Append(result.examId).Append("/");
|
|
builder.Append(result.subjectId).Append("/");
|
|
builder.Append(result.subjectId).Append("/");
|
|
- builder.Append(studentId).Append("/");
|
|
|
|
|
|
+ builder.Append(userId).Append("/");
|
|
builder.Append("ans.json");
|
|
builder.Append("ans.json");
|
|
/*string FileName = result.examId + "/" + result.subjectId + "/" + studentId;
|
|
/*string FileName = result.examId + "/" + result.subjectId + "/" + studentId;
|
|
string blob = FileName + "/" + "ans.json";*/
|
|
string blob = FileName + "/" + "ans.json";*/
|
|
@@ -798,7 +803,7 @@ namespace TEAMModelOS.Controllers
|
|
//算分处理
|
|
//算分处理
|
|
if (sc > 0)
|
|
if (sc > 0)
|
|
{
|
|
{
|
|
- result.ans[index][i] = ans[i];
|
|
|
|
|
|
+ result.ans[newIndex][i] = ans[i];
|
|
if (ac == sc && sc == 1)
|
|
if (ac == sc && sc == 1)
|
|
{
|
|
{
|
|
foreach (string right in ans[i])
|
|
foreach (string right in ans[i])
|
|
@@ -929,7 +934,7 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
if (flag)
|
|
if (flag)
|
|
{
|
|
{
|
|
- ExamInfo exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{scode}"));
|
|
|
|
|
|
+ //ExamInfo exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{scode}"));
|
|
result.progress = true;
|
|
result.progress = true;
|
|
/*//标记单科单班总得分
|
|
/*//标记单科单班总得分
|
|
double score = 0;
|
|
double score = 0;
|
|
@@ -946,20 +951,69 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
result.standard = Math.Round(scount > 0 ? Math.Pow(powSum / scount, 0.5) : 0, 2);
|
|
result.standard = Math.Round(scount > 0 ? Math.Pow(powSum / scount, 0.5) : 0, 2);
|
|
result.average = scount > 0 ? Math.Round(score / scount, 2) : 0;*/
|
|
result.average = scount > 0 ? Math.Round(score / scount, 2) : 0;*/
|
|
- exam.subjects.ForEach(s =>
|
|
|
|
|
|
+ info.subjects.ForEach(s =>
|
|
{
|
|
{
|
|
if (s.id.Equals(subjectId.ToString()))
|
|
if (s.id.Equals(subjectId.ToString()))
|
|
{
|
|
{
|
|
s.classCount += 1;
|
|
s.classCount += 1;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{scode}"));
|
|
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(info, id.ToString(), new PartitionKey($"{scode}"));
|
|
|
|
+ try {
|
|
|
|
+ if (string.IsNullOrEmpty(school))
|
|
|
|
+ {
|
|
|
|
+ StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{userId}"));
|
|
|
|
+ activity.taskStatus = 1;
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{info.school}-{userId}"));
|
|
|
|
+ activity.taskStatus = 1;
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
|
|
|
|
+ }
|
|
|
|
+ } catch (CosmosException e) {
|
|
|
|
+ if (e.Status == 404) {
|
|
|
|
+ StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{userId}"));
|
|
|
|
+ activity.taskStatus = 1;
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ if (string.IsNullOrEmpty(school))
|
|
|
|
+ {
|
|
|
|
+ StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{userId}"));
|
|
|
|
+ activity.taskStatus = 0;
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{info.school}-{userId}"));
|
|
|
|
+ activity.taskStatus = 1;
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (CosmosException e)
|
|
|
|
+ {
|
|
|
|
+ if (e.Status == 404)
|
|
|
|
+ {
|
|
|
|
+ StuActivity activity = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(id.ToString(), new PartitionKey($"Activity-{userId}"));
|
|
|
|
+ activity.taskStatus = 0;
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(activity, activity.id, new PartitionKey($"{activity.code}"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
result.sum[newIndex] = result.studentScores[newIndex].Sum();
|
|
result.sum[newIndex] = result.studentScores[newIndex].Sum();
|
|
classResult = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
|
|
classResult = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(result, result.id, new PartitionKey($"{result.code}"));
|
|
}
|
|
}
|
|
await Task.WhenAll(tasks);
|
|
await Task.WhenAll(tasks);
|
|
|
|
|
|
|
|
+
|
|
return Ok(new { classResult });
|
|
return Ok(new { classResult });
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
catch (Exception e)
|