|
@@ -301,18 +301,10 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
try
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- var (_, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
- if (!element.TryGetProperty("artId", out JsonElement artId)) return BadRequest();
|
|
|
- if (!element.TryGetProperty("classId", out JsonElement classId)) return BadRequest();
|
|
|
- if (!element.TryGetProperty("quotaId", out JsonElement quotaId)) return BadRequest();
|
|
|
- if (!element.TryGetProperty("acId", out JsonElement acId)) return BadRequest();
|
|
|
- if (!element.TryGetProperty("subject", out JsonElement subject)) return BadRequest();
|
|
|
if (!element.TryGetProperty("stus", out JsonElement stus)) return BadRequest();
|
|
|
- //HttpContext.Items.TryGetValue("Scope", out object scope);
|
|
|
- //int userType = $"{scope}".Equals(Constant.ScopeStudent) ? 2 : 1;
|
|
|
List<stuFiles> stuFiles = stus.ToObject<List<stuFiles>>();
|
|
|
List<string> value = new List<string>();
|
|
|
- await foreach (var s in stuTask(stuFiles, client, school, artId.GetString(), classId.GetString(), quotaId.GetString(), acId.GetString(), subject.GetString()))
|
|
|
+ await foreach (var s in stuTask(stuFiles, client))
|
|
|
{
|
|
|
if (s.code == 1)
|
|
|
{
|
|
@@ -336,136 +328,70 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
|
|
|
}
|
|
|
|
|
|
- private async IAsyncEnumerable<(int code, string value)> stuTask(List<stuFiles> stuFiles, CosmosClient client, string school, string artId, string classId, string quotaId, string acId, string subject)
|
|
|
+ private async IAsyncEnumerable<(int code, string value)> stuTask(List<stuFiles> stuFiles, CosmosClient client)
|
|
|
{
|
|
|
- /* string queryScore = $" select c.id from c where c.artId ='{artId}' and c.quotaId = '{quotaId}' and c.acId = '{acId}' and c.subject = '{subject}' and c.classId = '{classId}'";
|
|
|
- List<string> ids = new();
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryStreamIterator
|
|
|
- (queryText: queryScore, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("ArtRecord") }))
|
|
|
- {
|
|
|
- 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())
|
|
|
- {
|
|
|
- if (obj.TryGetProperty("id", out JsonElement subScore))
|
|
|
- {
|
|
|
- //string sId = obj.GetProperty("id").GetString();
|
|
|
- ids.Add(subScore.GetString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemsAsync<ArtRecord>(ids, "ArtRecord");*/
|
|
|
- // await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, school, new List<string> { $"art/{artId}" });
|
|
|
- foreach (var request in stuFiles)
|
|
|
+ foreach (var files in stuFiles)
|
|
|
{
|
|
|
string value = "";
|
|
|
int code = 0;
|
|
|
try
|
|
|
{
|
|
|
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- /*ArtRecord record = new()
|
|
|
- {
|
|
|
- school = school,
|
|
|
- stuId = request.stuId,
|
|
|
- artId = artId,
|
|
|
- classId = classId,
|
|
|
- quotaId = quotaId,
|
|
|
- acId = acId,
|
|
|
- subject = subject,
|
|
|
- createTime = now,
|
|
|
- code = "ArtRecord",
|
|
|
- attachments = request.attachments
|
|
|
- };*/
|
|
|
- StudentArtResult artResult;
|
|
|
- ArtEvaluation art;
|
|
|
- List<string> classIds = new();
|
|
|
- List<GroupListGrp> groups = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, request.stuId, request.userType, school, new List<string> { "class", "teach" });
|
|
|
- foreach (var grp in groups)
|
|
|
+ if (string.IsNullOrEmpty(files.id))
|
|
|
{
|
|
|
- classIds.Add(grp.id);
|
|
|
- }
|
|
|
- /*if (string.IsNullOrEmpty(record.id))
|
|
|
- {
|
|
|
- record.id = Guid.NewGuid().ToString();
|
|
|
- record = await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(record, new PartitionKey($"{record.code}"));
|
|
|
+ ArtAttachment attachment = new()
|
|
|
+ {
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ artId = files.artId,
|
|
|
+ achievement = files.achievement,
|
|
|
+ address = files.address,
|
|
|
+ studentId = files.studentId,
|
|
|
+ taskId = files.taskId,
|
|
|
+ subjectId = files.subjectId,
|
|
|
+ quotaId = files.quotaId,
|
|
|
+ quotaName = files.quotaName,
|
|
|
+ uploadName = files.uploadName,
|
|
|
+ uploadTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ duration = files.duration,
|
|
|
+ name = files.name,
|
|
|
+ des = files.des,
|
|
|
+ artType = files.artType,
|
|
|
+ level = files.level,
|
|
|
+ files = files.files,
|
|
|
+ ttl = -1,
|
|
|
+ code = "ArtAttachment-" + files.school
|
|
|
+
|
|
|
+ };
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(attachment, new PartitionKey($"{attachment.code}"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- record = await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(record, record.id, new PartitionKey($"{record.code}"));
|
|
|
- }*/
|
|
|
- string rId = string.Format("{0}{1}{2}", school, "-", request.stuId);
|
|
|
- //首先根据大ID获取整个活动得内容
|
|
|
- var aresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(artId, 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-{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);
|
|
|
- artResult.results.ForEach(a =>
|
|
|
- {
|
|
|
- if (a.taskId == acId)
|
|
|
- {
|
|
|
- a.name = request.name;
|
|
|
- a.files = files;
|
|
|
- }
|
|
|
- });
|
|
|
- await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(artResult, artResult.id, new PartitionKey($"{artResult.code}"));
|
|
|
- }
|
|
|
- else
|
|
|
+ ArtAttachment attachment = new()
|
|
|
{
|
|
|
- artResult = new StudentArtResult
|
|
|
- {
|
|
|
- id = rId,
|
|
|
- pk = "ArtResult",
|
|
|
- code = $"ArtResult-{artId}",
|
|
|
- studentId = request.stuId,
|
|
|
- //picture = picture,
|
|
|
- studentName = request.name,
|
|
|
- school = school,
|
|
|
- userType = request.userType,
|
|
|
- artId = artId,
|
|
|
- classIds = classIds,
|
|
|
- };
|
|
|
- foreach (var qIds in art.settings)
|
|
|
- {
|
|
|
- foreach (var task in qIds.task)
|
|
|
- {
|
|
|
- ArtQuotaResult quotaResult = new()
|
|
|
- {
|
|
|
- quotaId = qIds.id,
|
|
|
- quotaName = qIds.quotaname,
|
|
|
- quotaType = (int)task.type,
|
|
|
- subjectId = task.subject,
|
|
|
- taskId = task.acId
|
|
|
- };
|
|
|
- if (!string.IsNullOrEmpty(quotaResult.taskId))
|
|
|
- {
|
|
|
- if (quotaResult.taskId.Equals(acId))
|
|
|
- {
|
|
|
- quotaResult.name = request.name;
|
|
|
- quotaResult.files = request.attachments;
|
|
|
- }
|
|
|
- }
|
|
|
- artResult.results.Add(quotaResult);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(artResult, new PartitionKey($"{artResult.code}"));
|
|
|
- }
|
|
|
+ artId = files.artId,
|
|
|
+ achievement = files.achievement,
|
|
|
+ address = files.address,
|
|
|
+ studentId = files.studentId,
|
|
|
+ taskId = files.taskId,
|
|
|
+ subjectId = files.subjectId,
|
|
|
+ quotaId = files.quotaId,
|
|
|
+ quotaName = files.quotaName,
|
|
|
+ updateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ uploadName = files.uploadName,
|
|
|
+ duration = files.duration,
|
|
|
+ name = files.name,
|
|
|
+ des = files.des,
|
|
|
+ artType = files.artType,
|
|
|
+ level = files.level,
|
|
|
+ files = files.files,
|
|
|
+ ttl = -1,
|
|
|
+ code = "ArtAttachment-" + files.school
|
|
|
+ };
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(attachment, attachment.id, new PartitionKey($"{attachment.code}"));
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
- value = request.stuId;
|
|
|
+ value = files.studentId;
|
|
|
code = 1;
|
|
|
}
|
|
|
yield return (code, value);
|
|
@@ -577,7 +503,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(artId, new PartitionKey("ArtMusic"));
|
|
|
await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(artId, new PartitionKey("ArtExam"));
|
|
|
}
|
|
|
- string queryScore = $" select c.id from c where c.artId in ({string.Join(",", artIds.Select(o => $"'{o}'"))})";
|
|
|
+ /*string queryScore = $" select c.id from c where c.artId in ({string.Join(",", artIds.Select(o => $"'{o}'"))})";
|
|
|
List<string> ids = new();
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryStreamIterator
|
|
|
(queryText: queryScore, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("ArtRecord") }))
|
|
@@ -595,11 +521,11 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemsAsync<ArtRecord>(ids, "ArtRecord");
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemsAsync<ArtRecord>(ids, "ArtRecord");*/
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string queryScore = $" select c.id from c where c.artId = '{art.id})'";
|
|
|
+ /* string queryScore = $" select c.id from c where c.artId = '{art.id})'";
|
|
|
List<string> ids = new();
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryStreamIterator
|
|
|
(queryText: queryScore, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("ArtRecord") }))
|
|
@@ -617,7 +543,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemsAsync<ArtRecord>(ids, "ArtRecord");
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemsAsync<ArtRecord>(ids, "ArtRecord");*/
|
|
|
await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(art.id, new PartitionKey("ArtMusic"));
|
|
|
}
|
|
|
}
|
|
@@ -1039,7 +965,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
{
|
|
|
artAttachments.Add(item);
|
|
|
}
|
|
|
- List<(string stuId, string url)> zyUrl = new();
|
|
|
+ List<(string stuId, string url, long time)> zyUrl = new();
|
|
|
foreach (StudentArtResult artResult in artResults)
|
|
|
{
|
|
|
if (!string.IsNullOrWhiteSpace(artResult.zyanswer.thirdAnswerId))
|
|
@@ -1052,11 +978,11 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
StringBuilder url = new("https://amesopen.aimusic.art?appid=8a68f563f3384662acbc268336b98ae2");
|
|
|
url.Append($"&data={base64Str}");
|
|
|
url.Append($"&thirdToken={token}");
|
|
|
- zyUrl.Add((artResult.studentId, url.ToString()));
|
|
|
+ zyUrl.Add((artResult.studentId, url.ToString(), artResult.zyanswer.time));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- zyUrl.Add((artResult.studentId, string.Empty));
|
|
|
+ zyUrl.Add((artResult.studentId, string.Empty, 0));
|
|
|
}
|
|
|
}
|
|
|
//if (string.IsNullOrWhiteSpace(artResult.zyanswer.thirdAnswerId)) { }
|
|
@@ -1069,12 +995,14 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
x.classIds,
|
|
|
x.artId,
|
|
|
isAnswer = string.IsNullOrWhiteSpace(x.zyanswer.thirdAnswerId) ? 0 : 1,
|
|
|
- attachments = artAttachments.Where(c => c.taskId.Equals(taskId.GetString()) && c.studentId.Equals(x.studentId)).ToList(),
|
|
|
- url = x.results.Where(c => c.taskId.Equals(taskId.GetString())).FirstOrDefault().quotaId.Equals("quota_22") ? zyUrl.Where(c => c.stuId.Equals(x.studentId)).FirstOrDefault().url : ""
|
|
|
+ attachments = artAttachments.Count > 0 ?artAttachments.Where(c => c.taskId.Equals(taskId.GetString()) && c.studentId.Equals(x.studentId)).ToList() : null,
|
|
|
+ url = x.results.Where(c => c.taskId.Equals(taskId.GetString())).FirstOrDefault().quotaId.Equals("quota_22") ? zyUrl.Where(c => c.stuId.Equals(x.studentId)).FirstOrDefault().url : "",
|
|
|
+ time = x.results.Where(c => c.taskId.Equals(taskId.GetString())).FirstOrDefault().quotaId.Equals("quota_22") ? zyUrl.Where(c => c.stuId.Equals(x.studentId)).FirstOrDefault().time : 0
|
|
|
});
|
|
|
return Ok(new { works, code = 200 });
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
var works = artResults.Select(x => new
|
|
|
{
|
|
|
stuId = x.studentId,
|
|
@@ -1082,12 +1010,13 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
x.classIds,
|
|
|
x.artId,
|
|
|
isAnswer = string.IsNullOrWhiteSpace(x.zyanswer.thirdAnswerId) ? 0 : 1,
|
|
|
- attachments = artAttachments.Where(c => c.taskId.Equals(taskId.GetString()) && c.studentId.Equals(x.studentId)).ToList(),
|
|
|
+ attachments = artAttachments.Count > 0 ? artAttachments.Where(c => c.taskId.Equals(taskId.GetString()) && c.studentId.Equals(x.studentId)).ToList(): null,
|
|
|
+ time = artAttachments.Count > 0 ? artAttachments.Where(c => c.taskId.Equals(taskId.GetString()) && c.studentId.Equals(x.studentId)).LastOrDefault().updateTime : 0,
|
|
|
});
|
|
|
return Ok(new { works, code = 200 });
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
catch (CosmosException ex) when (ex.Status == 404)
|
|
@@ -1175,10 +1104,33 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
}
|
|
|
private class stuFiles
|
|
|
{
|
|
|
- public string stuId { get; set; }
|
|
|
- public int userType { get; set; }
|
|
|
+ public string id { get; set; }
|
|
|
+ public string school { get; set; }
|
|
|
+ public string artId { get; set; }
|
|
|
+ public string taskId { get; set; }
|
|
|
+ public string studentId { get; set; }
|
|
|
+ public string quotaId { get; set; }
|
|
|
+ public string quotaName { get; set; }
|
|
|
+ public string subjectId { get; set; }
|
|
|
+ public string address { get; set; }
|
|
|
+ public string time { get; set; }
|
|
|
+ public string duration { get; set; }
|
|
|
+ public string achievement { get; set; }
|
|
|
public string name { get; set; }
|
|
|
- public List<Attachment> attachments { get; set; } = new List<Attachment>();
|
|
|
+ public string des { get; set; }
|
|
|
+ //0 艺术特长 1 艺术体验
|
|
|
+ public int artType { get; set; } = -1;
|
|
|
+ // 0 校级 1 区级 2 市级 3 省级 4 国家级
|
|
|
+ public int level { get; set; } = -1;
|
|
|
+ public long uploadTime { get; set; }
|
|
|
+ public string uploadName { get; set; }
|
|
|
+ public List<Attachment> files { get; set; } = new List<Attachment>();
|
|
|
+ }
|
|
|
+ private class studentInfos
|
|
|
+ {
|
|
|
+ public string id { get; set; }
|
|
|
+ public string paper { get; set; }
|
|
|
+ public string subject { get; set; }
|
|
|
}
|
|
|
}
|
|
|
}
|