1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177 |
- using Azure.Core;
- using Azure.Cosmos;
- using DinkToPdf.Contracts;
- using DocumentFormat.OpenXml.Bibliography;
- using DocumentFormat.OpenXml.Office2010.Excel;
- using DocumentFormat.OpenXml.Office2013.Excel;
- using DocumentFormat.OpenXml.Office2016.Excel;
- using DocumentFormat.OpenXml.Spreadsheet;
- using DocumentFormat.OpenXml.Wordprocessing;
- using HTEXLib.COMM.Helpers;
- using HTEXLib.Helpers.ShapeHelpers;
- using MathNet.Numerics.Distributions;
- using MathNet.Numerics.RootFinding;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Options;
- using NUnit.Framework;
- using OpenXmlPowerTools;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Reflection;
- using System.Security.Policy;
- using System.Text;
- using System.Text.Json;
- using System.Threading.Tasks;
- using System.Web;
- using System.Xml.Linq;
- using TEAMModelOS.Controllers.Analysis;
- using TEAMModelOS.Filter;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos;
- using TEAMModelOS.SDK.Models.Cosmos.Common;
- using Survey = TEAMModelOS.SDK.Models.Survey;
- namespace TEAMModelOS.Controllers.Common
- {
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
- [Route("common/art")]
- [ApiController]
- public class ArtController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly SnowflakeId _snowflakeId;
- private readonly AzureServiceBusFactory _serviceBus;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureStorageFactory _azureStorage;
- private readonly AzureRedisFactory _azureRedis;
- private readonly IConverter _converter;
- public IConfiguration _configuration { get; set; }
- private readonly CoreAPIHttpService _coreAPIHttpService;
- public ArtController(IConverter converter, CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
- IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, IConfiguration configuration)
- {
- _coreAPIHttpService = coreAPIHttpService;
- _azureCosmos = azureCosmos;
- _serviceBus = serviceBus;
- _snowflakeId = snowflakeId;
- _dingDing = dingDing;
- _option = option?.Value;
- _azureStorage = azureStorage;
- _azureRedis = azureRedis;
- _configuration = configuration;
- _converter = converter;
- }
- /// <summary>
- /// 保存艺术评价信息
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "teacher,admin")]
- [HttpPost("save")]
- [Authorize(Roles = "IES")]
- public async Task<IActionResult> Save(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("art", out JsonElement art)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- ArtEvaluation ae = art.ToObject<ArtEvaluation>();
- bool flag = false;
- ArtMusic music = new();
- if (request.TryGetProperty("ArtMusic", out JsonElement am))
- {
- music = am.ToObject<ArtMusic>();
- music.ttl = -1;
- music.code = "ArtMusic";
- flag = true;
- };
- var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
- string code = ae.school;
- ae.ttl = -1;
- ae.progress = "going";
- ae.creatorId = userid;
- if (!ae.owner.Equals("area"))
- {
- ae.owner = "school";
- ae.code = "Art-" + code;
- ae.scope = "school";
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- ae.createTime = now;
- ae.publish = 0;
- }
- if (string.IsNullOrEmpty(ae.id))
- {
- ae.id = Guid.NewGuid().ToString();
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(ae, new PartitionKey($"{ae.code}"));
- if (flag)
- {
- music.id = ae.id;
- await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(music, new PartitionKey("ArtMusic"));
- }
- }
- else
- {
- if (flag)
- {
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(music, music.id, new PartitionKey("ArtMusic"));
- }
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(ae, ae.id, new PartitionKey($"{ae.code}"));
- }
- return Ok(new { ae });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},art/save()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- return Ok(new { code = 500, msg = ex.Message });
- }
- }
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "teacher,admin,student")]
- [HttpPost("update-state")]
- [Authorize(Roles = "IES")]
- public async Task<IActionResult> UpdateState(JsonElement request)
- {
- var client = _azureCosmos.GetCosmosClient();
- try
- {
- if (!request.TryGetProperty("id", out JsonElement stuId)) return BadRequest();
- if (!request.TryGetProperty("artId", out JsonElement artId)) return BadRequest();
- if (!request.TryGetProperty("isAnswer", out JsonElement isAnswer)) return BadRequest();
- var (userid, name, picture, school) = HttpContext.GetAuthTokenInfo();
- HttpContext.Items.TryGetValue("Scope", out object scope);
- int userType = $"{scope}".Equals(Constant.ScopeStudent) ? 2 : 1;
- StudentArtResult artResult = null;
- //long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- var res = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(stuId.ToString(), new PartitionKey($"ArtResult-{artId}"));
- if (res.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(res.ContentStream);
- artResult = json.ToObject<StudentArtResult>();
- //artResult.isAnswer = isAnswer.GetInt32();
- await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(artResult, artResult.id, new PartitionKey($"{artResult.code}"));
- }
- return Ok();
- }
- catch (Exception e)
- {
- return BadRequest(new { msg = e.Message });
- }
- }
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "teacher,admin,student")]
- [HttpPost("upload")]
- [Authorize(Roles = "IES")]
- public async Task<IActionResult> Upload(ArtRecord request)
- {
- try
- {
- var client = _azureCosmos.GetCosmosClient();
- var (userid, name, picture, school) = HttpContext.GetAuthTokenInfo();
- HttpContext.Items.TryGetValue("Scope", out object scope);
- int userType = $"{scope}".Equals(Constant.ScopeStudent) ? 2 : 1;
- request.school = school;
- request.stuId = userid;
- request.code = "ArtRecord";
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- request.createTime = now;
- ArtRecord record;
- StudentArtResult artResult;
- ArtEvaluation art;
- List<string> classIds = new();
- List<GroupListGrp> groups = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, userid, userType, school, new List<string> { "class", "teach" });
- foreach (var grp in groups)
- {
- classIds.Add(grp.id);
- }
- /* if (string.IsNullOrEmpty(request.id))
- {
- request.id = Guid.NewGuid().ToString();
- record = await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(request, new PartitionKey($"{request.code}"));
- }
- else
- {
- 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(request.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-{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);
- artResult.results.ForEach(a =>
- {
- if (a.taskId == request.acId)
- {
- a.files = files;
- }
- });
- 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,
- school = school,
- userType = userType,
- artId = request.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(request.acId))
- {
- quotaResult.files = request.attachments;
- }
- }
- artResult.results.Add(quotaResult);
- }
- }
- await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(artResult, new PartitionKey($"{artResult.code}"));
- }
- }
- return Ok(new { code = 200 });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},art/upload()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- return Ok(new { code = 500, msg = ex.Message });
- }
- }
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "teacher,admin,student")]
- [HttpPost("upload-all")]
- [Authorize(Roles = "IES")]
- public async Task<IActionResult> UploadAll(JsonElement element)
- {
- 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()))
- {
- if (s.code == 1)
- {
- value.Add(s.value);
- }
- }
- if (value.Count > 0)
- {
- return Ok(new { code = 1, msg = "学生ID导入异常", value = value });
- }
- else
- {
- return Ok(new { code = 0 });
- }
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},art/uploadAll()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- return Ok(new { code = 500, msg = ex.Message });
- }
- }
- 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)
- {
- /* 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)
- {
- 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)
- {
- 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}"));
- }
- else
- {
- record = await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(record, record.id, new PartitionKey($"{record.code}"));
- }*/
- string rId = string.Format("{0}{1}{2}", record.school, "-", record.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.files = files;
- }
- });
- await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(artResult, artResult.id, new PartitionKey($"{artResult.code}"));
- }
- else
- {
- 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.files = request.attachments;
- }
- }
- artResult.results.Add(quotaResult);
- }
- }
- await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(artResult, new PartitionKey($"{artResult.code}"));
- }
- }
- }
- catch (Exception e)
- {
- value = request.stuId;
- code = 1;
- }
- yield return (code, value);
- }
- }
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "teacher,admin")]
- [HttpPost("delete")]
- [Authorize(Roles = "IES")]
- public async Task<IActionResult> Delete(JsonElement request)
- {
- try
- {
- //object userScope = null;
- //object _standard = null;
- if (!request.TryGetProperty("id", out JsonElement id)) 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;
- }*/
- var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
- var client = _azureCosmos.GetCosmosClient();
- //TODO 区级活动的联动删除评测活动
- var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Art-{code}"));
- if (sresponse.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
- ArtEvaluation art = json.ToObject<ArtEvaluation>();
- //必须是本人或者这个学校的管理者才能删除
- bool flag = false;
- if (art.creatorId == userid)
- {
- flag = true;
- }
- else
- {
- if (art.scope == "school" && art.school.Equals(school))
- {
- flag = true;
- }
- }
- /*try
- {
- (List<RMember> members, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, null, art.school, null);
- await StatisticsService.DoChange(new TeacherTrainChange
- { standard = standard, tmdids = members.Select(x => x.id)?.ToList(), school = art.school, update = new HashSet<string> { StatisticsService.OfflineRecord }, statistics = 0 }, _azureCosmos);
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},art/delete()ex\n{ex.Message}\n{ex.StackTrace},\n", GroupNames.醍摩豆服務運維群組);
- }*/
- if (flag)
- {
- art.status = 404;
- foreach (var info in art.settings)
- {
- /* if (info.TryGetProperty("examId", out JsonElement eId)) {
- }*/
- foreach (var acs in info.task)
- {
- if (!string.IsNullOrEmpty(acs.acId))
- {
- if (acs.type == 1)
- {
- Azure.Response response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(acs.acId, new PartitionKey($"Exam-{code}"));
- if (response.Status == 200)
- {
- ExamInfo data = JsonDocument.Parse(response.Content).RootElement.Deserialize<ExamInfo>();
- data.status = 404;
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(data, data.id, new PartitionKey($"Exam-{code}"));
- }
- }
- }
- }
- }
- await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(art, art.id, new PartitionKey($"{art.code}"));
- //如果是区级活动删除 先查询该区下面所有的艺术评测ID集合
- if (art.publish == 0)
- {
- List<string> artIds = new();
- string sql = $"select c.id from c where c.pId = '{art.pId}'";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryStreamIterator
- (queryText: sql))
- {
- using var sjson = await JsonDocument.ParseAsync(item.ContentStream);
- if (sjson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in sjson.RootElement.GetProperty("Documents").EnumerateArray())
- {
- if (obj.TryGetProperty("id", out JsonElement subScore))
- {
- string sId = obj.GetProperty("id").GetString();
- artIds.Add(sId);
- }
- }
- }
- }
- foreach (string artId in artIds)
- {
- 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}'"))})";
- 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 sjson = await JsonDocument.ParseAsync(item.ContentStream);
- if (sjson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in sjson.RootElement.GetProperty("Documents").EnumerateArray())
- {
- if (obj.TryGetProperty("id", out JsonElement subScore))
- {
- string sId = obj.GetProperty("id").GetString();
- ids.Add(sId);
- }
- }
- }
- }
- await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemsAsync<ArtRecord>(ids, "ArtRecord");
- }
- else
- {
- 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") }))
- {
- using var sjson = await JsonDocument.ParseAsync(item.ContentStream);
- if (sjson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in sjson.RootElement.GetProperty("Documents").EnumerateArray())
- {
- if (obj.TryGetProperty("id", out JsonElement subScore))
- {
- string sId = obj.GetProperty("id").GetString();
- ids.Add(sId);
- }
- }
- }
- }
- await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemsAsync<ArtRecord>(ids, "ArtRecord");
- await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(art.id, new PartitionKey("ArtMusic"));
- }
- }
- }
- return Ok(new { id });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},art/delete()\n{e.Message}\n{e.StackTrace},\n", GroupNames.醍摩豆服務運維群組);
- return Ok(new { code = 500 });
- }
- }
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin")]
- [HttpPost("find")]
- public async Task<IActionResult> Find(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- request.TryGetProperty("periodId", out JsonElement period);
- request.TryGetProperty("periodType", out JsonElement periodType);
- if (string.IsNullOrWhiteSpace($"{period}") && string.IsNullOrWhiteSpace($"{periodType}"))
- {
- return BadRequest();
- }
- var client = _azureCosmos.GetCosmosClient();
- StringBuilder stringBuilder = new($"select c.id,c.img,c.name,c.classes,c.code,c.type,c.startTime,c.endTime,c.presenter,c.topic,c.address,c.owner,c.progress from c where (c.status<>404 or IS_DEFINED(c.status) = false )");
- string continuationToken = string.Empty;
- string token = default;
- if (!string.IsNullOrWhiteSpace($"{period}") && !string.IsNullOrWhiteSpace($"{periodType}"))
- {
- stringBuilder.Append($" and (c.period.id = '{period}' or c.periodType = '{periodType}')");
- }
- if (string.IsNullOrWhiteSpace($"{period}") && !string.IsNullOrWhiteSpace($"{periodType}"))
- {
- stringBuilder.Append($" and c.periodType = '{periodType}' ");
- }
- if (!string.IsNullOrWhiteSpace($"{period}") && string.IsNullOrWhiteSpace($"{periodType}"))
- {
- stringBuilder.Append($" and c.period.id = '{period}' ");
- }
- stringBuilder.Append("order by c.createTime desc");
- //是否需要进行分页查询,默认不分页
- bool iscontinuation = false;
- if (request.TryGetProperty("token", out JsonElement token_1))
- {
- token = token_1.GetString();
- iscontinuation = true;
- };
- //默认不指定返回大小
- int? topcout = null;
- if (request.TryGetProperty("count", out JsonElement jcount))
- {
- if (!jcount.ValueKind.Equals(JsonValueKind.Undefined) && !jcount.ValueKind.Equals(JsonValueKind.Null) && jcount.TryGetInt32(out int data))
- {
- topcout = data;
- }
- }
- List<ArtEvaluation> arts = new();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), continuationToken: token, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Art-{code}") }))
- {
- 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())
- {
- arts.Add(obj.ToObject<ArtEvaluation>());
- }
- }
- if (iscontinuation)
- {
- continuationToken = item.GetContinuationToken();
- break;
- }
- }
- arts = arts.Where((x, i) => arts.FindIndex(z => z.id == x.id) == i).ToList();
- return Ok(new { arts });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},art/find()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
- return Ok(new { code = 500 });
- }
- }
- [ProducesDefaultResponseType]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,student")]
- [HttpPost("find-summary")]
- public async Task<IActionResult> FindSummary(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- ArtEvaluation art = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ArtEvaluation>(id.GetString(), new PartitionKey($"Art-{code}"));
- if (art.owner.Equals("area") && string.IsNullOrEmpty(art.pId))
- {
- }
- else
- {
- List<(string eId, string sId)> ids = new();
- var examId = art.settings.SelectMany(x => x.task).Where(c => c.type == 1).Select(z => new { z.acId, z.subject }).ToList();
- examId.ForEach(x =>
- {
- ids.Add((x.acId, x.subject));
- });
- List<(string scode, string sub, List<string> stu)> stuInfo = await getLostAsync(ids, client, art.school);
- List<string> stus = new();
- foreach (var (scode, sub, stu) in stuInfo)
- {
- if (stus.Count == 0)
- {
- stus = stus.Union(stu).ToList();
- }
- else
- {
- stus = stus.Intersect(stu).ToList();
- }
- LostStudent lostStudent = new()
- {
- code = scode,
- subject = sub,
- stu = stu.Count
- };
- art.lost.Add(lostStudent);
- }
- art.miss.Add(stus.Count);
- }
- //art.miss = stus.Count;
- //art.pass = 1;
- //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ArtEvaluation>(art, art.id, new PartitionKey(art.code));
- ArtMusic music = new();
- ArtExam ae = new();
- if (art != null)
- {
- string queryArtExam = $" select value(c) from c where c.activityId = '{art.pId}' ";
- //List<ArtExam> aes = new List<ArtExam>();
- /* await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIterator<ArtExam>
- (queryText: queryArtExam, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtExam") }))
- {
- aes.Add(item);
- }*/
- if (!string.IsNullOrWhiteSpace(art.pId))
- {
- var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.pId, new PartitionKey("ArtMusic"));
- var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.pId, new PartitionKey("ArtExam"));
- if (sresponse.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
- ae = json.ToObject<ArtExam>();
- }
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- music = json.ToObject<ArtMusic>();
- }
- }
- else
- {
- var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.id, new PartitionKey("ArtMusic"));
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- music = json.ToObject<ArtMusic>();
- }
- }
- (List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, art.classes, art.school);
- var classes = art.classes.Select(c => new
- {
- id = c,
- groups.Where(g => g.id.Equals(c)).FirstOrDefault()?.name
- });
- rmembers.ForEach(x =>
- {
- groups.ForEach(z =>
- {
- if (z.members.Exists(y => y.id.Equals(x.id) && y.type == x.type))
- {
- x.groupListIds.Add(z.id);
- }
- });
- });
- List<ArtSubjectScore> subjectScores = new List<ArtSubjectScore>();
- art.subjects.ForEach(z => { subjectScores.Add(new ArtSubjectScore { subjectId = z.id, score = 0 }); });
- var students = rmembers.Select(z => new StudentArtResult
- {
- studentId = z.id,
- studentName = z.name,
- userType = z.type,
- classIds = z.groupListIds,
- school = z.schoolId,
- picture = z.picture,
- artId = $"{id}",
- id = $"{z.schoolId}-{z.id}",
- code = $"ArtResult-{id}",
- pk = "ArtResult",
- ttl = -1,
- subjectScores = subjectScores,
- }).ToList();
- //TODO 缺考人数的结算(多科评量检测,作业的提交)
- if (students.Any())
- {
- string query = $" select value c.id from c where c.id in({string.Join(",", students.Select(x => $"'{x.id}'"))}) ";
- List<string> list = new List<string>();
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<string>
- (queryText: query, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtResult-{id}") }))
- {
- list.Add(item);
- }
- students.RemoveAll(x => list.Contains(x.id));
- students.ForEach(x =>
- {
- art.settings.ForEach(a =>
- {
- a.task.ForEach(z =>
- {
- ArtQuotaResult quotaResult = new ArtQuotaResult
- {
- taskId = z.acId,
- subjectId = z.subject,
- quotaId = a.id,
- quotaType = z.type.Value,
- quotaName = a.quotaname
- };
- x.results.Add(quotaResult);
- });
- });
- });
- List<Task<ItemResponse<StudentArtResult>>> responses = new();
- students.ForEach(z =>
- {
- responses.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemAsync(z, new PartitionKey(z.code)));
- });
- if (responses.Count > 0)
- {
- await responses.TaskPage(10);
- }
- }
- if (!string.IsNullOrWhiteSpace(ae.id))
- {
- return Ok(new { art, classes, ae, music, count = rmembers.Count, code = 200 });
- }
- else
- {
- return Ok(new { art, classes, music, count = rmembers.Count, code = 200 });
- }
- }
- else
- {
- return Ok(new { art, code = 404 });
- }
- }
- 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 });
- }
- }
- public static async Task<List<(string code, string subject, List<string> stus)>> getLostAsync(List<(string eId, string sId)> examIds, CosmosClient client, string code)
- {
- List<(string code, string sub, List<string> stu)> stuInfo = new();
- if (examIds.Any())
- {
- string examSql = $"select c.id,c.school,c.lostStu from c where c.id in ({string.Join(",", examIds.Select(o => $"'{o.eId}'"))})";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: examSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Exam-{code}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- List<string> lostStu = account.GetProperty("lostStu").ToObject<List<string>>();
- string id = account.GetProperty("id").GetString();
- string sub = examIds.Where(c => c.eId.Equals(id)).FirstOrDefault().sId;
- stuInfo.Add((account.GetProperty("school").GetString(), sub, lostStu));
- }
- }
- }
- }
- return stuInfo;
- }
- [ProducesDefaultResponseType]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,student")]
- [HttpPost("find-summary-by-student")]
- public async Task<IActionResult> findByStudent(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
- ArtEvaluation art = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ArtEvaluation>(id.GetString(), new PartitionKey($"Art-{code}"));
- ArtMusic music = new();
- if (art != null)
- {
- List<StuActivity> stus = new();
- List<string> wIds = new();
- List<StudentArtResult> works = new();
- if (!string.IsNullOrWhiteSpace(art.pId))
- {
- var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.pId, new PartitionKey("ArtMusic"));
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- music = json.ToObject<ArtMusic>();
- }
- }
- else
- {
- var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.id, new PartitionKey("ArtMusic"));
- if (response.Status == 200)
- {
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
- music = json.ToObject<ArtMusic>();
- }
- }
- var taskType1 = art.settings.SelectMany(z => z.task).Where(t => t.type == 1);
- //wIds = art.settings.SelectMany(z => z.task).Where(t => t.type == 2).Select(a => a.acId).ToList();
- if (taskType1 != null && taskType1.Any())
- {
- string sql = $"select value c from c where c.id in ({string.Join(",", taskType1.Select(z => $"'{z.acId}'"))})";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student)
- .GetItemQueryIterator<StuActivity>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Activity-{school}-{userid}") }))
- {
- stus.Add(item);
- }
- }
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StudentArtResult>(
- queryText: $"select value(c) from c where c.id = '{code}-{userid}'",
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ArtResult-{id}") }))
- {
- works.Add(item);
- }
- return Ok(new { art, stus, works, music, code = 200 });
- }
- else
- {
- return Ok(new { art, code = 404 });
- }
- }
- catch (CosmosException ex) when (ex.Status == 404)
- {
- return Ok(new { code = 404 });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},art/find-summary-by-student()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- return Ok(new { code = 500 });
- }
- }
- [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();
- //艺术评测ID
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("taskId", out JsonElement taskId)) return BadRequest();
- string token = HttpContext.GetXAuth("authtoken");
- var client = _azureCosmos.GetCosmosClient();
- //var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
- List<StudentArtResult> artResults = new();
- string sql = $"select value(c) from c where c.artId = '{id}' and array_contains(c.classIds,'{classId}') ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(
- queryText: sql,
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ArtResult-{id}") }))
- {
- 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())
- {
- artResults.Add(obj.ToObject<StudentArtResult>());
- }
- }
- }
- artResults.ForEach(x => x.results.RemoveAll(z => !string.IsNullOrWhiteSpace(z.subjectId) && !subject.GetString().Equals(z.subjectId)));
- artResults.ForEach(x => x.subjectScores.RemoveAll(z => !string.IsNullOrWhiteSpace(z.subjectId) && !subject.GetString().Equals(z.subjectId)));
- List<(string stuId, string url)> zyUrl = new();
- foreach (StudentArtResult artResult in artResults)
- {
- if (!string.IsNullOrWhiteSpace(artResult.zyanswer.thirdAnswerId))
- {
- var data = new { busType = "aqd", artResult.zyanswer.thirdAnswerId };
- //byte[] inputBytes = Encoding.UTF8.GetBytes(artResult.zyanswer.thirdAnswerId);
- //string base64Str = Convert.ToBase64String(inputBytes);
- var base64Str = HttpUtility.UrlEncode(Convert.ToBase64String(Encoding.UTF8.GetBytes(data.ToJsonString())));
- //var date = Convert.FromBase64String(base64Str);
- StringBuilder url = new("https://amesopen.aimusic.art?appid=8a68f563f3384662acbc268336b98ae2");
- url.Append($"&data={base64Str}");
- url.Append($"&thirdToken={token}");
- zyUrl.Add((artResult.studentId, url.ToString()));
- }
- else
- {
- zyUrl.Add((artResult.studentId, string.Empty));
- }
- }
- //if (string.IsNullOrWhiteSpace(artResult.zyanswer.thirdAnswerId)) { }
- if (subject.GetString().Equals("subject_music"))
- {
- var works = artResults.Select(x => new
- {
- stuId = x.studentId,
- x.studentName,
- x.classIds,
- x.artId,
- isAnswer = string.IsNullOrWhiteSpace(x.zyanswer.thirdAnswerId) ? 0 : 1,
- attachments = x.results.Where(c => c.taskId.Equals(taskId.GetString())).FirstOrDefault().files,
- zyUrl.Where(c => c.stuId.Equals(x.studentId)).FirstOrDefault().url
- });
- return Ok(new { works, code = 200 });
- }
- else {
- var works = artResults.Select(x => new
- {
- stuId = x.studentId,
- x.studentName,
- x.classIds,
- x.artId,
- isAnswer = string.IsNullOrWhiteSpace(x.zyanswer.thirdAnswerId) ? 0 : 1,
- attachments = x.results.Where(c => c.taskId.Equals(taskId.GetString())).FirstOrDefault().files,
- });
- 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/find-summary-by-work()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- return Ok(new { code = 500 });
- }
- }
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin")]
- [HttpPost("find-by-teacher")]
- public async Task<IActionResult> FindByTeacher(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- if (!request.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- var query = $"select c.id,c.img,c.name,c.startTime,c.type,c.endTime,c.presenter,c.topic,c.address,c.owner from c join A0 in c.teachers where A0.id = '{tId}'";
- List<object> arts = new();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Art-{code}") }))
- {
- 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())
- {
- arts.Add(obj.ToObject<object>());
- }
- }
- }
- return Ok(new { arts });
- }
- catch (Exception e)
- {
- 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 });
- }
- }
- [ProducesDefaultResponseType]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin")]
- [HttpPost("find-summary-by-teacher")]
- public async Task<IActionResult> FindSummaryByTeacher(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
- if (!request.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- List<object> arts = new();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c join A0 in c.teachers where A0.id = '{tId}' and c.id = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Art-{code}") }))
- {
- 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())
- {
- arts.Add(obj.ToObject<object>());
- }
- }
- }
- return Ok(new { arts });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},art/find-summary-by-teacher()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
- return Ok(new { code = 500 });
- }
- }
- private class stuFiles
- {
- public string stuId { get; set; }
- public int userType { get; set; }
- public string name { get; set; }
- public List<Attachment> attachments { get; set; } = new List<Attachment>();
- }
- }
- }
|