|
@@ -1,5 +1,6 @@
|
|
using Azure.Cosmos;
|
|
using Azure.Cosmos;
|
|
using DinkToPdf.Contracts;
|
|
using DinkToPdf.Contracts;
|
|
|
|
+using DocumentFormat.OpenXml.Office2010.Excel;
|
|
using DocumentFormat.OpenXml.Office2013.Excel;
|
|
using DocumentFormat.OpenXml.Office2013.Excel;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
@@ -91,7 +92,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(ae, new PartitionKey($"{ae.code}"));
|
|
await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(ae, new PartitionKey($"{ae.code}"));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {
|
|
|
|
|
|
+ {
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(ae, ae.id, new PartitionKey($"{ae.code}"));
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(ae, ae.id, new PartitionKey($"{ae.code}"));
|
|
}
|
|
}
|
|
return Ok(new { ae });
|
|
return Ok(new { ae });
|
|
@@ -113,22 +114,84 @@ namespace TEAMModelOS.Controllers.Common
|
|
try
|
|
try
|
|
{
|
|
{
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
- var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
|
|
|
+ var (userid, name, picture, school) = HttpContext.GetAuthTokenInfo();
|
|
request.school = school;
|
|
request.school = school;
|
|
request.stuId = userid;
|
|
request.stuId = userid;
|
|
request.code = "ArtRecord";
|
|
request.code = "ArtRecord";
|
|
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
request.createTime = now;
|
|
request.createTime = now;
|
|
ArtRecord record;
|
|
ArtRecord record;
|
|
|
|
+ StudentArtResult artResult;
|
|
|
|
+ ArtEvaluation art;
|
|
if (string.IsNullOrEmpty(request.id))
|
|
if (string.IsNullOrEmpty(request.id))
|
|
{
|
|
{
|
|
request.id = Guid.NewGuid().ToString();
|
|
request.id = Guid.NewGuid().ToString();
|
|
- record = await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
|
|
|
+ record = await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
record = await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
|
|
record = await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
|
|
}
|
|
}
|
|
|
|
+ string rId = string.Format("{0}{1}{2}", request.school, "-", userid);
|
|
|
|
+ //首先根据大ID获取整个活动得内容
|
|
|
|
+ var aresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(rId, new PartitionKey($"Art-{school}"));
|
|
|
|
+ if (aresponse.Status == 200)
|
|
|
|
+ {
|
|
|
|
+ using var json = await JsonDocument.ParseAsync(aresponse.ContentStream);
|
|
|
|
+ art = json.ToObject<ArtEvaluation>();
|
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "Student").ReadItemStreamAsync(rId, new PartitionKey($"ArtResult-{request.artId}"));
|
|
|
|
+ if (response.Status == 200)
|
|
|
|
+ {
|
|
|
|
+ using var json_1 = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
|
+ artResult = json_1.ToObject<StudentArtResult>();
|
|
|
|
+ List<Attachment> files = new();
|
|
|
|
+ files = request.attachments;
|
|
|
|
+ bool flage = artResult.results.Exists(a => a.taskId == request.acId);
|
|
|
|
+ if (flage)
|
|
|
|
+ {
|
|
|
|
+ artResult.results.ForEach(r =>
|
|
|
|
+ {
|
|
|
|
+ r.files = files;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ArtQuotaResult quotaResult = new()
|
|
|
|
+ {
|
|
|
|
+ taskId = request.acId,
|
|
|
|
+ subjectId = request.subject,
|
|
|
|
+ quotaId = request.quotaId,
|
|
|
|
+ files = request.attachments
|
|
|
|
+ };
|
|
|
|
+ artResult.results.Add(quotaResult);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(artResult, artResult.id, new PartitionKey($"{artResult.code}"));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ artResult = new StudentArtResult
|
|
|
|
+ {
|
|
|
|
+ id = rId,
|
|
|
|
+ pk = "ArtResult",
|
|
|
|
+ code = $"ArtResult-{request.artId}",
|
|
|
|
+ studentId = userid,
|
|
|
|
+ picture = picture,
|
|
|
|
+ studentName = name,
|
|
|
|
+ artId = request.artId,
|
|
|
|
+ classIds = art.classes,
|
|
|
|
+ };
|
|
|
|
+ ArtQuotaResult quotaResult = new()
|
|
|
|
+ {
|
|
|
|
+ taskId = request.acId,
|
|
|
|
+ subjectId = request.subject,
|
|
|
|
+ quotaId = request.quotaId,
|
|
|
|
+ files = request.attachments
|
|
|
|
+ };
|
|
|
|
+ artResult.results.Add(quotaResult);
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(artResult, new PartitionKey($"{artResult.code}"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return Ok(new { record, code = 200 });
|
|
return Ok(new { record, code = 200 });
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
@@ -151,13 +214,13 @@ namespace TEAMModelOS.Controllers.Common
|
|
//object _standard = null;
|
|
//object _standard = null;
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
- /* string standard = null;
|
|
|
|
- HttpContext?.Items?.TryGetValue("Scope", out userScope);
|
|
|
|
- if (userScope != null && $"{userScope}".Equals(Constant.ScopeTeacher))
|
|
|
|
- {
|
|
|
|
- HttpContext?.Items?.TryGetValue("Standard", out _standard);
|
|
|
|
- standard = _standard != null && string.IsNullOrEmpty($"{userScope}") ? _standard.ToString() : null;
|
|
|
|
- }*/
|
|
|
|
|
|
+ /* string standard = null;
|
|
|
|
+ HttpContext?.Items?.TryGetValue("Scope", out userScope);
|
|
|
|
+ if (userScope != null && $"{userScope}".Equals(Constant.ScopeTeacher))
|
|
|
|
+ {
|
|
|
|
+ HttpContext?.Items?.TryGetValue("Standard", out _standard);
|
|
|
|
+ standard = _standard != null && string.IsNullOrEmpty($"{userScope}") ? _standard.ToString() : null;
|
|
|
|
+ }*/
|
|
var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Art-{code}"));
|
|
var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Art-{code}"));
|
|
@@ -192,12 +255,15 @@ namespace TEAMModelOS.Controllers.Common
|
|
{
|
|
{
|
|
|
|
|
|
art.status = 404;
|
|
art.status = 404;
|
|
- foreach (var info in art.settings) {
|
|
|
|
|
|
+ foreach (var info in art.settings)
|
|
|
|
+ {
|
|
/* if (info.TryGetProperty("examId", out JsonElement eId)) {
|
|
/* if (info.TryGetProperty("examId", out JsonElement eId)) {
|
|
|
|
|
|
}*/
|
|
}*/
|
|
- foreach (var acs in info.task) {
|
|
|
|
- if (!string.IsNullOrEmpty(acs.acId)) {
|
|
|
|
|
|
+ foreach (var acs in info.task)
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrEmpty(acs.acId))
|
|
|
|
+ {
|
|
if (acs.type == 1)
|
|
if (acs.type == 1)
|
|
{
|
|
{
|
|
Azure.Response response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(acs.acId, new PartitionKey($"Exam-{code}"));
|
|
Azure.Response response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(acs.acId, new PartitionKey($"Exam-{code}"));
|
|
@@ -207,7 +273,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
data.status = 404;
|
|
data.status = 404;
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(data, data.id, new PartitionKey($"Exam-{code}"));
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(data, data.id, new PartitionKey($"Exam-{code}"));
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
if (acs.type == 2)
|
|
if (acs.type == 2)
|
|
{
|
|
{
|
|
Azure.Response response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(acs.acId, new PartitionKey($"Homework-{code}"));
|
|
Azure.Response response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(acs.acId, new PartitionKey($"Homework-{code}"));
|
|
@@ -219,7 +285,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/*if (!string.IsNullOrEmpty(art.examId))
|
|
/*if (!string.IsNullOrEmpty(art.examId))
|
|
@@ -322,7 +388,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
{
|
|
{
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},art/find()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},art/find()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
- return Ok(new { code = 500});
|
|
|
|
|
|
+ return Ok(new { code = 500 });
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -346,7 +412,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
{
|
|
{
|
|
id = c,
|
|
id = c,
|
|
groups.Where(g => g.id.Equals(c)).FirstOrDefault().name
|
|
groups.Where(g => g.id.Equals(c)).FirstOrDefault().name
|
|
- }) ;
|
|
|
|
|
|
+ });
|
|
return Ok(new { art, classes, code = 200 });
|
|
return Ok(new { art, classes, code = 200 });
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -398,19 +464,21 @@ namespace TEAMModelOS.Controllers.Common
|
|
stus.Add(info);
|
|
stus.Add(info);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (acs.type == 2) {
|
|
|
|
|
|
+ if (acs.type == 2)
|
|
|
|
+ {
|
|
wIds.Add(acs.acId);
|
|
wIds.Add(acs.acId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (wIds.Count > 0) {
|
|
|
|
|
|
+ if (wIds.Count > 0)
|
|
|
|
+ {
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<ArtRecord>(
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<ArtRecord>(
|
|
queryText: $"select value(c) from c where c.stuId = '{userid}' and c.acId in ({string.Join(",", wIds.Select(o => $"'{o}'"))})",
|
|
queryText: $"select value(c) from c where c.stuId = '{userid}' and c.acId in ({string.Join(",", wIds.Select(o => $"'{o}'"))})",
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ArtRecord") }))
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ArtRecord") }))
|
|
{
|
|
{
|
|
works.Add(item);
|
|
works.Add(item);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
return Ok(new { art, stus, works, code = 200 });
|
|
return Ok(new { art, stus, works, code = 200 });
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -430,6 +498,41 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
|
+ [AuthToken(Roles = "teacher,admin")]
|
|
|
|
+ [HttpPost("find-summary-by-work")]
|
|
|
|
+ public async Task<IActionResult> findBywork(JsonElement request)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ if (!request.TryGetProperty("classId", out JsonElement classId)) return BadRequest();
|
|
|
|
+ if (!request.TryGetProperty("subject", out JsonElement subject)) return BadRequest();
|
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+ var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
|
+ List<ArtRecord> works = new();
|
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<ArtRecord>(
|
|
|
|
+ queryText: $"select value(c) from c where c.classId = '{classId}' and c.artId = '{id}' and c.subject = '{subject}'",
|
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ArtRecord") }))
|
|
|
|
+ {
|
|
|
|
+ works.Add(item);
|
|
|
|
+ }
|
|
|
|
+ return Ok(new { works, code = 200 });
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ catch (CosmosException ex) when (ex.Status == 404)
|
|
|
|
+ {
|
|
|
|
+ return Ok(new { code = 404 });
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},art/FindSummary()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
|
|
|
|
+ return Ok(new { code = 500 });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/// <param name="request"></param>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
@@ -463,7 +566,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
{
|
|
{
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},art/find-by-teacher()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},art/find-by-teacher()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
- return Ok(new { code = 500});
|
|
|
|
|
|
+ return Ok(new { code = 500 });
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|