ArtController.cs 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. using Azure.Core;
  2. using Azure.Cosmos;
  3. using DinkToPdf.Contracts;
  4. using DocumentFormat.OpenXml.Bibliography;
  5. using DocumentFormat.OpenXml.Office2010.Excel;
  6. using DocumentFormat.OpenXml.Office2013.Excel;
  7. using DocumentFormat.OpenXml.Office2016.Excel;
  8. using DocumentFormat.OpenXml.Presentation;
  9. using DocumentFormat.OpenXml.Spreadsheet;
  10. using DocumentFormat.OpenXml.Wordprocessing;
  11. using HTEXLib.COMM.Helpers;
  12. using HTEXLib.Helpers.ShapeHelpers;
  13. using MathNet.Numerics.Distributions;
  14. using MathNet.Numerics.RootFinding;
  15. using Microsoft.AspNetCore.Authorization;
  16. using Microsoft.AspNetCore.Http;
  17. using Microsoft.AspNetCore.Mvc;
  18. using Microsoft.Extensions.Configuration;
  19. using Microsoft.Extensions.Options;
  20. using NUnit.Framework;
  21. using OpenXmlPowerTools;
  22. using System;
  23. using System.Collections.Generic;
  24. using System.Linq;
  25. using System.Net;
  26. using System.Reflection;
  27. using System.Security.Policy;
  28. using System.Text;
  29. using System.Text.Json;
  30. using System.Threading.Tasks;
  31. using System.Web;
  32. using System.Xml.Linq;
  33. using TEAMModelOS.Controllers.Analysis;
  34. using TEAMModelOS.Filter;
  35. using TEAMModelOS.Models;
  36. using TEAMModelOS.SDK;
  37. using TEAMModelOS.SDK.DI;
  38. using TEAMModelOS.SDK.Extension;
  39. using TEAMModelOS.SDK.Models;
  40. using TEAMModelOS.SDK.Models.Cosmos;
  41. using TEAMModelOS.SDK.Models.Cosmos.Common;
  42. using TEAMModelOS.SDK.Models.Cosmos.Student;
  43. using Survey = TEAMModelOS.SDK.Models.Survey;
  44. namespace TEAMModelOS.Controllers.Common
  45. {
  46. [ProducesResponseType(StatusCodes.Status200OK)]
  47. [ProducesResponseType(StatusCodes.Status400BadRequest)]
  48. [Route("common/art")]
  49. [ApiController]
  50. public class ArtController : ControllerBase
  51. {
  52. private readonly AzureCosmosFactory _azureCosmos;
  53. private readonly SnowflakeId _snowflakeId;
  54. private readonly AzureServiceBusFactory _serviceBus;
  55. private readonly DingDing _dingDing;
  56. private readonly Option _option;
  57. private readonly AzureStorageFactory _azureStorage;
  58. private readonly AzureRedisFactory _azureRedis;
  59. private readonly IConverter _converter;
  60. public IConfiguration _configuration { get; set; }
  61. private readonly CoreAPIHttpService _coreAPIHttpService;
  62. public ArtController(IConverter converter, CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
  63. IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, IConfiguration configuration)
  64. {
  65. _coreAPIHttpService = coreAPIHttpService;
  66. _azureCosmos = azureCosmos;
  67. _serviceBus = serviceBus;
  68. _snowflakeId = snowflakeId;
  69. _dingDing = dingDing;
  70. _option = option?.Value;
  71. _azureStorage = azureStorage;
  72. _azureRedis = azureRedis;
  73. _configuration = configuration;
  74. _converter = converter;
  75. }
  76. /// <summary>
  77. /// 保存艺术评价信息
  78. /// </summary>
  79. /// <param name="request"></param>
  80. /// <returns></returns>
  81. [ProducesDefaultResponseType]
  82. [AuthToken(Roles = "teacher,admin")]
  83. [HttpPost("save")]
  84. [Authorize(Roles = "IES")]
  85. public async Task<IActionResult> Save(JsonElement request)
  86. {
  87. try
  88. {
  89. if (!request.TryGetProperty("art", out JsonElement art)) return BadRequest();
  90. var client = _azureCosmos.GetCosmosClient();
  91. ArtEvaluation ae = art.ToObject<ArtEvaluation>();
  92. bool flag = false;
  93. ArtMusic music = new();
  94. if (request.TryGetProperty("ArtMusic", out JsonElement am))
  95. {
  96. music = am.ToObject<ArtMusic>();
  97. music.ttl = -1;
  98. music.code = "ArtMusic";
  99. flag = true;
  100. };
  101. var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
  102. string code = ae.school;
  103. ae.ttl = -1;
  104. ae.progress = "going";
  105. ae.creatorId = userid;
  106. if (!ae.owner.Equals("area"))
  107. {
  108. ae.owner = "school";
  109. ae.code = "Art-" + code;
  110. ae.scope = "school";
  111. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  112. ae.createTime = now;
  113. ae.publish = 0;
  114. }
  115. if (string.IsNullOrEmpty(ae.id))
  116. {
  117. ae.id = Guid.NewGuid().ToString();
  118. await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(ae, new PartitionKey($"{ae.code}"));
  119. if (flag)
  120. {
  121. music.id = ae.id;
  122. await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(music, new PartitionKey("ArtMusic"));
  123. }
  124. }
  125. else
  126. {
  127. if (flag)
  128. {
  129. await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(music, music.id, new PartitionKey("ArtMusic"));
  130. }
  131. await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(ae, ae.id, new PartitionKey($"{ae.code}"));
  132. }
  133. return Ok(new { ae });
  134. }
  135. catch (Exception ex)
  136. {
  137. await _dingDing.SendBotMsg($"OS,{_option.Location},art/save()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  138. return Ok(new { code = 500, msg = ex.Message });
  139. }
  140. }
  141. [ProducesDefaultResponseType]
  142. [AuthToken(Roles = "teacher,admin,student")]
  143. [HttpPost("update-state")]
  144. [Authorize(Roles = "IES")]
  145. public async Task<IActionResult> UpdateState(JsonElement request)
  146. {
  147. var client = _azureCosmos.GetCosmosClient();
  148. try
  149. {
  150. if (!request.TryGetProperty("id", out JsonElement stuId)) return BadRequest();
  151. if (!request.TryGetProperty("artId", out JsonElement artId)) return BadRequest();
  152. if (!request.TryGetProperty("isAnswer", out JsonElement isAnswer)) return BadRequest();
  153. var (userid, name, picture, school) = HttpContext.GetAuthTokenInfo();
  154. HttpContext.Items.TryGetValue("Scope", out object scope);
  155. int userType = $"{scope}".Equals(Constant.ScopeStudent) ? 2 : 1;
  156. StudentArtResult artResult = null;
  157. //long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  158. var res = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(stuId.ToString(), new PartitionKey($"ArtResult-{artId}"));
  159. if (res.Status == 200)
  160. {
  161. using var json = await JsonDocument.ParseAsync(res.ContentStream);
  162. artResult = json.ToObject<StudentArtResult>();
  163. //artResult.isAnswer = isAnswer.GetInt32();
  164. await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(artResult, artResult.id, new PartitionKey($"{artResult.code}"));
  165. }
  166. return Ok();
  167. }
  168. catch (Exception e)
  169. {
  170. return BadRequest(new { msg = e.Message });
  171. }
  172. }
  173. [ProducesDefaultResponseType]
  174. [AuthToken(Roles = "teacher,admin,student")]
  175. [HttpPost("upload")]
  176. [Authorize(Roles = "IES")]
  177. public async Task<IActionResult> Upload(ArtRecord request)
  178. {
  179. try
  180. {
  181. var client = _azureCosmos.GetCosmosClient();
  182. var (userid, name, picture, school) = HttpContext.GetAuthTokenInfo();
  183. HttpContext.Items.TryGetValue("Scope", out object scope);
  184. int userType = $"{scope}".Equals(Constant.ScopeStudent) ? 2 : 1;
  185. request.school = school;
  186. request.stuId = userid;
  187. request.code = "ArtRecord";
  188. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  189. request.createTime = now;
  190. ArtRecord record;
  191. StudentArtResult artResult;
  192. ArtEvaluation art;
  193. List<string> classIds = new();
  194. List<GroupListGrp> groups = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, userid, userType, school, new List<string> { "class", "teach" });
  195. foreach (var grp in groups)
  196. {
  197. classIds.Add(grp.id);
  198. }
  199. /* if (string.IsNullOrEmpty(request.id))
  200. {
  201. request.id = Guid.NewGuid().ToString();
  202. record = await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(request, new PartitionKey($"{request.code}"));
  203. }
  204. else
  205. {
  206. record = await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
  207. }*/
  208. string rId = string.Format("{0}{1}{2}", request.school, "-", userid);
  209. //首先根据大ID获取整个活动得内容
  210. var aresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(request.artId, new PartitionKey($"Art-{school}"));
  211. if (aresponse.Status == 200)
  212. {
  213. using var json = await JsonDocument.ParseAsync(aresponse.ContentStream);
  214. art = json.ToObject<ArtEvaluation>();
  215. var response = await client.GetContainer("TEAMModelOS", "Student").ReadItemStreamAsync(rId, new PartitionKey($"ArtResult-{request.artId}"));
  216. if (response.Status == 200)
  217. {
  218. using var json_1 = await JsonDocument.ParseAsync(response.ContentStream);
  219. artResult = json_1.ToObject<StudentArtResult>();
  220. List<Attachment> files = new();
  221. files = request.attachments;
  222. //bool flage = artResult.results.Exists(a => a.taskId == request.acId);
  223. artResult.results.ForEach(a =>
  224. {
  225. if (a.taskId == request.acId)
  226. {
  227. a.files = files;
  228. }
  229. });
  230. await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(artResult, artResult.id, new PartitionKey($"{artResult.code}"));
  231. }
  232. else
  233. {
  234. artResult = new StudentArtResult
  235. {
  236. id = rId,
  237. pk = "ArtResult",
  238. code = $"ArtResult-{request.artId}",
  239. studentId = userid,
  240. picture = picture,
  241. studentName = name,
  242. school = school,
  243. userType = userType,
  244. artId = request.artId,
  245. classIds = classIds
  246. };
  247. foreach (var qIds in art.settings)
  248. {
  249. foreach (var task in qIds.task)
  250. {
  251. ArtQuotaResult quotaResult = new()
  252. {
  253. quotaId = qIds.id,
  254. quotaName = qIds.quotaname,
  255. quotaType = (int)task.type,
  256. subjectId = task.subject,
  257. taskId = task.acId
  258. };
  259. if (!string.IsNullOrEmpty(quotaResult.taskId))
  260. {
  261. if (quotaResult.taskId.Equals(request.acId))
  262. {
  263. quotaResult.files = request.attachments;
  264. }
  265. }
  266. artResult.results.Add(quotaResult);
  267. }
  268. }
  269. await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(artResult, new PartitionKey($"{artResult.code}"));
  270. }
  271. }
  272. return Ok(new { code = 200 });
  273. }
  274. catch (Exception ex)
  275. {
  276. await _dingDing.SendBotMsg($"OS,{_option.Location},art/upload()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  277. return Ok(new { code = 500, msg = ex.Message });
  278. }
  279. }
  280. [ProducesDefaultResponseType]
  281. [AuthToken(Roles = "teacher,admin,student")]
  282. [HttpPost("upload-all")]
  283. [Authorize(Roles = "IES")]
  284. public async Task<IActionResult> UploadAll(JsonElement element)
  285. {
  286. try
  287. {
  288. var client = _azureCosmos.GetCosmosClient();
  289. if (!element.TryGetProperty("stus", out JsonElement stus)) return BadRequest();
  290. List<stuFiles> stuFiles = stus.ToObject<List<stuFiles>>();
  291. List<string> value = new List<string>();
  292. await foreach (var s in stuTask(stuFiles, client))
  293. {
  294. if (s.code == 1)
  295. {
  296. value.Add(s.value);
  297. }
  298. }
  299. if (value.Count > 0)
  300. {
  301. return Ok(new { code = 1, msg = "学生ID导入异常", value = value });
  302. }
  303. else
  304. {
  305. return Ok(new { code = 0 });
  306. }
  307. }
  308. catch (Exception ex)
  309. {
  310. await _dingDing.SendBotMsg($"OS,{_option.Location},art/uploadAll()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  311. return Ok(new { code = 500, msg = ex.Message });
  312. }
  313. }
  314. private async IAsyncEnumerable<(int code, string value)> stuTask(List<stuFiles> stuFiles, CosmosClient client)
  315. {
  316. foreach (var files in stuFiles)
  317. {
  318. string value = "";
  319. int code = 0;
  320. try
  321. {
  322. if (string.IsNullOrEmpty(files.id))
  323. {
  324. ArtAttachment attachment = new()
  325. {
  326. id = Guid.NewGuid().ToString(),
  327. artId = files.artId,
  328. achievement = files.achievement,
  329. address = files.address,
  330. studentId = files.studentId,
  331. taskId = files.taskId,
  332. subjectId = files.subjectId,
  333. quotaId = files.quotaId,
  334. quotaName = files.quotaName,
  335. uploadName = files.uploadName,
  336. uploadTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  337. duration = files.duration,
  338. name = files.name,
  339. des = files.des,
  340. artType = files.artType,
  341. level = files.level,
  342. files = files.files,
  343. ttl = -1,
  344. code = "ArtAttachment-" + files.school
  345. };
  346. await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(attachment, new PartitionKey($"{attachment.code}"));
  347. }
  348. else
  349. {
  350. ArtAttachment attachment = new()
  351. {
  352. artId = files.artId,
  353. achievement = files.achievement,
  354. address = files.address,
  355. studentId = files.studentId,
  356. taskId = files.taskId,
  357. subjectId = files.subjectId,
  358. quotaId = files.quotaId,
  359. quotaName = files.quotaName,
  360. updateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  361. uploadName = files.uploadName,
  362. duration = files.duration,
  363. name = files.name,
  364. des = files.des,
  365. artType = files.artType,
  366. level = files.level,
  367. files = files.files,
  368. ttl = -1,
  369. code = "ArtAttachment-" + files.school
  370. };
  371. await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(attachment, attachment.id, new PartitionKey($"{attachment.code}"));
  372. }
  373. }
  374. catch (Exception e)
  375. {
  376. value = files.studentId;
  377. code = 1;
  378. }
  379. yield return (code, value);
  380. }
  381. }
  382. [ProducesDefaultResponseType]
  383. [AuthToken(Roles = "teacher,admin")]
  384. [HttpPost("delete")]
  385. [Authorize(Roles = "IES")]
  386. public async Task<IActionResult> Delete(JsonElement request)
  387. {
  388. try
  389. {
  390. //object userScope = null;
  391. //object _standard = null;
  392. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  393. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  394. /* string standard = null;
  395. HttpContext?.Items?.TryGetValue("Scope", out userScope);
  396. if (userScope != null && $"{userScope}".Equals(Constant.ScopeTeacher))
  397. {
  398. HttpContext?.Items?.TryGetValue("Standard", out _standard);
  399. standard = _standard != null && string.IsNullOrEmpty($"{userScope}") ? _standard.ToString() : null;
  400. }*/
  401. var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
  402. var client = _azureCosmos.GetCosmosClient();
  403. //TODO 区级活动的联动删除评测活动
  404. var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Art-{code}"));
  405. if (sresponse.Status == 200)
  406. {
  407. using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
  408. ArtEvaluation art = json.ToObject<ArtEvaluation>();
  409. //必须是本人或者这个学校的管理者才能删除
  410. bool flag = false;
  411. if (art.creatorId == userid)
  412. {
  413. flag = true;
  414. }
  415. else
  416. {
  417. if (art.scope == "school" && art.school.Equals(school))
  418. {
  419. flag = true;
  420. }
  421. }
  422. /*try
  423. {
  424. (List<RMember> members, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, null, art.school, null);
  425. await StatisticsService.DoChange(new TeacherTrainChange
  426. { standard = standard, tmdids = members.Select(x => x.id)?.ToList(), school = art.school, update = new HashSet<string> { StatisticsService.OfflineRecord }, statistics = 0 }, _azureCosmos);
  427. }
  428. catch (Exception ex)
  429. {
  430. await _dingDing.SendBotMsg($"OS,{_option.Location},art/delete()ex\n{ex.Message}\n{ex.StackTrace},\n", GroupNames.醍摩豆服務運維群組);
  431. }*/
  432. if (flag)
  433. {
  434. art.status = 404;
  435. foreach (var info in art.settings)
  436. {
  437. /* if (info.TryGetProperty("examId", out JsonElement eId)) {
  438. }*/
  439. foreach (var acs in info.task)
  440. {
  441. if (!string.IsNullOrEmpty(acs.acId))
  442. {
  443. if (acs.type == 1)
  444. {
  445. Azure.Response response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(acs.acId, new PartitionKey($"Exam-{code}"));
  446. if (response.Status == 200)
  447. {
  448. ExamInfo data = JsonDocument.Parse(response.Content).RootElement.Deserialize<ExamInfo>();
  449. data.status = 404;
  450. await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(data, data.id, new PartitionKey($"Exam-{code}"));
  451. }
  452. }
  453. }
  454. }
  455. }
  456. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(art, art.id, new PartitionKey($"{art.code}"));
  457. //如果是区级活动删除 先查询该区下面所有的艺术评测ID集合
  458. if (art.publish == 0)
  459. {
  460. List<string> artIds = new();
  461. string sql = $"select c.id from c where c.pId = '{art.pId}'";
  462. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryStreamIterator
  463. (queryText: sql))
  464. {
  465. using var sjson = await JsonDocument.ParseAsync(item.ContentStream);
  466. if (sjson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  467. {
  468. foreach (var obj in sjson.RootElement.GetProperty("Documents").EnumerateArray())
  469. {
  470. if (obj.TryGetProperty("id", out JsonElement subScore))
  471. {
  472. string sId = obj.GetProperty("id").GetString();
  473. artIds.Add(sId);
  474. }
  475. }
  476. }
  477. }
  478. foreach (string artId in artIds)
  479. {
  480. await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(artId, new PartitionKey("ArtMusic"));
  481. await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(artId, new PartitionKey("ArtExam"));
  482. }
  483. /*string queryScore = $" select c.id from c where c.artId in ({string.Join(",", artIds.Select(o => $"'{o}'"))})";
  484. List<string> ids = new();
  485. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryStreamIterator
  486. (queryText: queryScore, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("ArtRecord") }))
  487. {
  488. using var sjson = await JsonDocument.ParseAsync(item.ContentStream);
  489. if (sjson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  490. {
  491. foreach (var obj in sjson.RootElement.GetProperty("Documents").EnumerateArray())
  492. {
  493. if (obj.TryGetProperty("id", out JsonElement subScore))
  494. {
  495. string sId = obj.GetProperty("id").GetString();
  496. ids.Add(sId);
  497. }
  498. }
  499. }
  500. }
  501. await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemsAsync<ArtRecord>(ids, "ArtRecord");*/
  502. }
  503. else
  504. {
  505. /* string queryScore = $" select c.id from c where c.artId = '{art.id})'";
  506. List<string> ids = new();
  507. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryStreamIterator
  508. (queryText: queryScore, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("ArtRecord") }))
  509. {
  510. using var sjson = await JsonDocument.ParseAsync(item.ContentStream);
  511. if (sjson.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  512. {
  513. foreach (var obj in sjson.RootElement.GetProperty("Documents").EnumerateArray())
  514. {
  515. if (obj.TryGetProperty("id", out JsonElement subScore))
  516. {
  517. string sId = obj.GetProperty("id").GetString();
  518. ids.Add(sId);
  519. }
  520. }
  521. }
  522. }
  523. await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemsAsync<ArtRecord>(ids, "ArtRecord");*/
  524. await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(art.id, new PartitionKey("ArtMusic"));
  525. }
  526. }
  527. }
  528. return Ok(new { id });
  529. }
  530. catch (Exception e)
  531. {
  532. await _dingDing.SendBotMsg($"OS,{_option.Location},art/delete()\n{e.Message}\n{e.StackTrace},\n", GroupNames.醍摩豆服務運維群組);
  533. return Ok(new { code = 500 });
  534. }
  535. }
  536. /// <param name="request"></param>
  537. /// <returns></returns>
  538. [ProducesDefaultResponseType]
  539. [Authorize(Roles = "IES")]
  540. [AuthToken(Roles = "teacher,admin")]
  541. [HttpPost("find")]
  542. public async Task<IActionResult> Find(JsonElement request)
  543. {
  544. try
  545. {
  546. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  547. request.TryGetProperty("periodId", out JsonElement period);
  548. request.TryGetProperty("periodType", out JsonElement periodType);
  549. if (string.IsNullOrWhiteSpace($"{period}") && string.IsNullOrWhiteSpace($"{periodType}"))
  550. {
  551. return BadRequest();
  552. }
  553. var client = _azureCosmos.GetCosmosClient();
  554. 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,c.uploadSTime,c.uploadETime from c where (c.status<>404 or IS_DEFINED(c.status) = false )");
  555. string continuationToken = string.Empty;
  556. string token = default;
  557. if (!string.IsNullOrWhiteSpace($"{period}") && !string.IsNullOrWhiteSpace($"{periodType}"))
  558. {
  559. stringBuilder.Append($" and (c.period.id = '{period}' or c.periodType = '{periodType}')");
  560. }
  561. if (string.IsNullOrWhiteSpace($"{period}") && !string.IsNullOrWhiteSpace($"{periodType}"))
  562. {
  563. stringBuilder.Append($" and c.periodType = '{periodType}' ");
  564. }
  565. if (!string.IsNullOrWhiteSpace($"{period}") && string.IsNullOrWhiteSpace($"{periodType}"))
  566. {
  567. stringBuilder.Append($" and c.period.id = '{period}' ");
  568. }
  569. stringBuilder.Append("order by c.createTime desc");
  570. //是否需要进行分页查询,默认不分页
  571. bool iscontinuation = false;
  572. if (request.TryGetProperty("token", out JsonElement token_1))
  573. {
  574. token = token_1.GetString();
  575. iscontinuation = true;
  576. };
  577. //默认不指定返回大小
  578. int? topcout = null;
  579. if (request.TryGetProperty("count", out JsonElement jcount))
  580. {
  581. if (!jcount.ValueKind.Equals(JsonValueKind.Undefined) && !jcount.ValueKind.Equals(JsonValueKind.Null) && jcount.TryGetInt32(out int data))
  582. {
  583. topcout = data;
  584. }
  585. }
  586. List<ArtEvaluation> arts = new();
  587. 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}") }))
  588. {
  589. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  590. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  591. {
  592. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  593. {
  594. arts.Add(obj.ToObject<ArtEvaluation>());
  595. }
  596. }
  597. if (iscontinuation)
  598. {
  599. continuationToken = item.GetContinuationToken();
  600. break;
  601. }
  602. }
  603. arts = arts.Where((x, i) => arts.FindIndex(z => z.id == x.id) == i).ToList();
  604. return Ok(new { arts });
  605. }
  606. catch (Exception e)
  607. {
  608. await _dingDing.SendBotMsg($"OS,{_option.Location},art/find()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  609. return Ok(new { code = 500 });
  610. }
  611. }
  612. [ProducesDefaultResponseType]
  613. [Authorize(Roles = "IES")]
  614. [AuthToken(Roles = "teacher,admin,student")]
  615. [HttpPost("find-summary")]
  616. public async Task<IActionResult> FindSummary(JsonElement request)
  617. {
  618. try
  619. {
  620. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  621. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  622. var client = _azureCosmos.GetCosmosClient();
  623. ArtEvaluation art = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ArtEvaluation>(id.GetString(), new PartitionKey($"Art-{code}"));
  624. if (art.owner.Equals("area") && string.IsNullOrEmpty(art.pId))
  625. {
  626. }
  627. else
  628. {
  629. List<(string eId, string sId)> ids = new();
  630. var examId = art.settings.SelectMany(x => x.task).Where(c => c.type == 1).Select(z => new { z.acId, z.subject }).ToList();
  631. examId.ForEach(x =>
  632. {
  633. ids.Add((x.acId, x.subject));
  634. });
  635. List<(string scode, string sub, List<string> stu)> stuInfo = await getLostAsync(ids, client, art.school);
  636. List<string> stus = new();
  637. foreach (var (scode, sub, stu) in stuInfo)
  638. {
  639. if (stus.Count == 0)
  640. {
  641. stus = stus.Union(stu).ToList();
  642. }
  643. else
  644. {
  645. stus = stus.Intersect(stu).ToList();
  646. }
  647. LostStudent lostStudent = new()
  648. {
  649. code = scode,
  650. subject = sub,
  651. stu = stu.Count
  652. };
  653. art.lost.Add(lostStudent);
  654. }
  655. art.miss.Add(stus.Count);
  656. }
  657. //art.miss = stus.Count;
  658. //art.pass = 1;
  659. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ArtEvaluation>(art, art.id, new PartitionKey(art.code));
  660. ArtMusic music = new();
  661. ArtExam ae = new();
  662. if (art != null)
  663. {
  664. string queryArtExam = $" select value(c) from c where c.activityId = '{art.pId}' ";
  665. //List<ArtExam> aes = new List<ArtExam>();
  666. /* await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIterator<ArtExam>
  667. (queryText: queryArtExam, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtExam") }))
  668. {
  669. aes.Add(item);
  670. }*/
  671. if (!string.IsNullOrWhiteSpace(art.pId))
  672. {
  673. var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.pId, new PartitionKey("ArtMusic"));
  674. var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.pId, new PartitionKey("ArtExam"));
  675. if (sresponse.Status == 200)
  676. {
  677. using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
  678. ae = json.ToObject<ArtExam>();
  679. }
  680. if (response.Status == 200)
  681. {
  682. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  683. music = json.ToObject<ArtMusic>();
  684. }
  685. }
  686. else
  687. {
  688. var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.id, new PartitionKey("ArtMusic"));
  689. if (response.Status == 200)
  690. {
  691. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  692. music = json.ToObject<ArtMusic>();
  693. }
  694. }
  695. (List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, art.classes, art.school,null,-1,art.startTime);
  696. var classes = art.classes.Select(c => new
  697. {
  698. id = c,
  699. groups.Where(g => g.id.Equals(c)).FirstOrDefault()?.name
  700. });
  701. rmembers.ForEach(x =>
  702. {
  703. groups.ForEach(z =>
  704. {
  705. if (z.members.Exists(y => y.id.Equals(x.id) && y.type == x.type))
  706. {
  707. x.groupListIds.Add(z.id);
  708. }
  709. });
  710. });
  711. List<ArtSubjectScore> subjectScores = new List<ArtSubjectScore>();
  712. art.subjects.ForEach(z => { subjectScores.Add(new ArtSubjectScore { subjectId = z.id, score = 0 }); });
  713. var students = rmembers.Select(z => new StudentArtResult
  714. {
  715. studentId = z.id,
  716. studentName = z.name,
  717. userType = z.type,
  718. classIds = z.groupListIds,
  719. school = z.schoolId,
  720. picture = z.picture,
  721. artId = $"{id}",
  722. id = $"{z.schoolId}-{z.id}",
  723. code = $"ArtResult-{id}",
  724. pk = "ArtResult",
  725. ttl = -1,
  726. subjectScores = subjectScores,
  727. }).ToList();
  728. //TODO 缺考人数的结算(多科评量检测,作业的提交)
  729. if (students.Any())
  730. {
  731. string query = $" select value c.id from c where c.id in({string.Join(",", students.Select(x => $"'{x.id}'"))}) ";
  732. List<string> list = new List<string>();
  733. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<string>
  734. (queryText: query, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtResult-{id}") }))
  735. {
  736. list.Add(item);
  737. }
  738. students.RemoveAll(x => list.Contains(x.id));
  739. students.ForEach(x =>
  740. {
  741. art.settings.ForEach(a =>
  742. {
  743. a.task.ForEach(z =>
  744. {
  745. ArtQuotaResult quotaResult = new ArtQuotaResult
  746. {
  747. taskId = z.acId,
  748. subjectId = z.subject,
  749. quotaId = a.id,
  750. quotaType = z.type.Value,
  751. quotaName = a.quotaname
  752. };
  753. x.results.Add(quotaResult);
  754. });
  755. });
  756. });
  757. List<Task<ItemResponse<StudentArtResult>>> responses = new();
  758. students.ForEach(z =>
  759. {
  760. responses.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemAsync(z, new PartitionKey(z.code)));
  761. });
  762. if (responses.Count > 0)
  763. {
  764. await responses.TaskPage(10);
  765. }
  766. }
  767. if (!string.IsNullOrWhiteSpace(ae.id))
  768. {
  769. return Ok(new { art, classes, ae, music, count = rmembers.Count, code = 200 });
  770. }
  771. else
  772. {
  773. return Ok(new { art, classes, music, count = rmembers.Count, code = 200 });
  774. }
  775. }
  776. else
  777. {
  778. return Ok(new { art, code = 404 });
  779. }
  780. }
  781. catch (CosmosException ex) when (ex.Status == 404)
  782. {
  783. return Ok(new { code = 404 });
  784. }
  785. catch (Exception e)
  786. {
  787. await _dingDing.SendBotMsg($"OS,{_option.Location},art/FindSummary()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  788. return Ok(new { code = 500 });
  789. }
  790. }
  791. public static async Task<List<(string code, string subject, List<string> stus)>> getLostAsync(List<(string eId, string sId)> examIds, CosmosClient client, string code)
  792. {
  793. List<(string code, string sub, List<string> stu)> stuInfo = new();
  794. if (examIds.Any())
  795. {
  796. string examSql = $"select c.id,c.school,c.lostStu from c where c.id in ({string.Join(",", examIds.Select(o => $"'{o.eId}'"))})";
  797. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: examSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Exam-{code}") }))
  798. {
  799. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  800. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  801. {
  802. var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
  803. while (accounts.MoveNext())
  804. {
  805. JsonElement account = accounts.Current;
  806. List<string> lostStu = account.GetProperty("lostStu").ToObject<List<string>>();
  807. string id = account.GetProperty("id").GetString();
  808. string sub = examIds.Where(c => c.eId.Equals(id)).FirstOrDefault().sId;
  809. stuInfo.Add((account.GetProperty("school").GetString(), sub, lostStu));
  810. }
  811. }
  812. }
  813. }
  814. return stuInfo;
  815. }
  816. [ProducesDefaultResponseType]
  817. [Authorize(Roles = "IES")]
  818. [AuthToken(Roles = "teacher,admin,student")]
  819. [HttpPost("find-summary-by-student")]
  820. public async Task<IActionResult> findByStudent(JsonElement request)
  821. {
  822. try
  823. {
  824. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  825. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  826. var client = _azureCosmos.GetCosmosClient();
  827. var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
  828. ArtEvaluation art = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ArtEvaluation>(id.GetString(), new PartitionKey($"Art-{code}"));
  829. ArtMusic music = new();
  830. if (art != null)
  831. {
  832. //List<StuActivity> stus = new();
  833. List<studentInfos> stus = new();
  834. List<string> wIds = new();
  835. List<StudentArtResult> works = new();
  836. if (!string.IsNullOrWhiteSpace(art.pId))
  837. {
  838. var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.pId, new PartitionKey("ArtMusic"));
  839. if (response.Status == 200)
  840. {
  841. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  842. music = json.ToObject<ArtMusic>();
  843. }
  844. }
  845. else
  846. {
  847. var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.id, new PartitionKey("ArtMusic"));
  848. if (response.Status == 200)
  849. {
  850. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  851. music = json.ToObject<ArtMusic>();
  852. }
  853. }
  854. var taskType1 = art.settings.SelectMany(z => z.task).Where(t => t.type == 1);
  855. //wIds = art.settings.SelectMany(z => z.task).Where(t => t.type == 2).Select(a => a.acId).ToList();
  856. if (taskType1 != null && taskType1.Any())
  857. {
  858. List<ExamClassResult> examClassResults = new();
  859. //string sql = $"select value(c) from c where c.examId in ({string.Join(",", taskType1.Select(z => $"'{z.acId}'"))})' and c.pk = 'ExamClassResult' and array_contains(c.studentIds,'{userid}')";
  860. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamClassResult>(
  861. queryText: $"select value(c) from c where c.examId in ({string.Join(",", taskType1.Select(z => $"'{z.acId}'"))}) and c.pk = 'ExamClassResult' and array_contains(c.studentIds,'{userid}')"))
  862. {
  863. examClassResults.Add(item);
  864. }
  865. foreach (ExamClassResult classResult in examClassResults)
  866. {
  867. int index = classResult.studentIds.IndexOf(userid);
  868. if (index != -1)
  869. {
  870. studentInfos infos = new()
  871. {
  872. id = classResult.id,
  873. paper = classResult.paper[index],
  874. subject = classResult.subjectId
  875. };
  876. stus.Add(infos);
  877. }
  878. }
  879. }
  880. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StudentArtResult>(
  881. queryText: $"select value(c) from c where c.id = '{code}-{userid}'",
  882. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ArtResult-{id}") }))
  883. {
  884. works.Add(item);
  885. }
  886. return Ok(new { art, stus, works, music, code = 200 });
  887. }
  888. else
  889. {
  890. return Ok(new { art, code = 404 });
  891. }
  892. }
  893. catch (CosmosException ex) when (ex.Status == 404)
  894. {
  895. return Ok(new { code = 404 });
  896. }
  897. catch (Exception e)
  898. {
  899. await _dingDing.SendBotMsg($"OS,{_option.Location},art/find-summary-by-student()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  900. return Ok(new { code = 500 });
  901. }
  902. }
  903. [ProducesDefaultResponseType]
  904. [Authorize(Roles = "IES")]
  905. [AuthToken(Roles = "teacher,admin")]
  906. [HttpPost("find-summary-by-work")]
  907. public async Task<IActionResult> findBywork(JsonElement request)
  908. {
  909. try
  910. {
  911. if (!request.TryGetProperty("classId", out JsonElement classId)) return BadRequest();
  912. if (!request.TryGetProperty("subject", out JsonElement subject)) return BadRequest();
  913. //艺术评测ID
  914. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  915. if (!request.TryGetProperty("taskId", out JsonElement taskId)) return BadRequest();
  916. string token = HttpContext.GetXAuth("authtoken");
  917. var client = _azureCosmos.GetCosmosClient();
  918. var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
  919. List<StudentArtResult> artResults = new();
  920. string sql = $"select value(c) from c where c.artId = '{id}' and array_contains(c.classIds,'{classId}') ";
  921. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(
  922. queryText: sql,
  923. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ArtResult-{id}") }))
  924. {
  925. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  926. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  927. {
  928. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  929. {
  930. artResults.Add(obj.ToObject<StudentArtResult>());
  931. }
  932. }
  933. }
  934. artResults.ForEach(x => x.results.RemoveAll(z => !string.IsNullOrWhiteSpace(z.subjectId) && !subject.GetString().Equals(z.subjectId)));
  935. artResults.ForEach(x => x.subjectScores.RemoveAll(z => !string.IsNullOrWhiteSpace(z.subjectId) && !subject.GetString().Equals(z.subjectId)));
  936. List<ArtAttachment> artAttachments = new();
  937. string sqlTask = $"select value(c) from c where c.artId = '{id}' and c.subjectId = '{subject}'";
  938. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).
  939. GetItemQueryIterator<ArtAttachment>(queryText: sqlTask, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtAttachment-{school}") }))
  940. {
  941. artAttachments.Add(item);
  942. }
  943. List<(string stuId, string url, long time)> zyUrl = new();
  944. foreach (StudentArtResult artResult in artResults)
  945. {
  946. if (!string.IsNullOrWhiteSpace(artResult.zyanswer.thirdAnswerId))
  947. {
  948. var data = new { busType = "aqd", artResult.zyanswer.thirdAnswerId };
  949. //byte[] inputBytes = Encoding.UTF8.GetBytes(artResult.zyanswer.thirdAnswerId);
  950. //string base64Str = Convert.ToBase64String(inputBytes);
  951. var base64Str = HttpUtility.UrlEncode(Convert.ToBase64String(Encoding.UTF8.GetBytes(data.ToJsonString())));
  952. //var date = Convert.FromBase64String(base64Str);
  953. StringBuilder url = new("https://amesopen.aimusic.art?appid=8a68f563f3384662acbc268336b98ae2");
  954. url.Append($"&data={base64Str}");
  955. url.Append($"&thirdToken={token}");
  956. zyUrl.Add((artResult.studentId, url.ToString(), artResult.zyanswer.time));
  957. }
  958. else
  959. {
  960. zyUrl.Add((artResult.studentId, string.Empty, 0));
  961. }
  962. }
  963. //if (string.IsNullOrWhiteSpace(artResult.zyanswer.thirdAnswerId)) { }
  964. if (subject.GetString().Equals("subject_music"))
  965. {
  966. var works = artResults.Select(x => new
  967. {
  968. stuId = x.studentId,
  969. x.studentName,
  970. x.classIds,
  971. x.artId,
  972. isAnswer = string.IsNullOrWhiteSpace(x.zyanswer.thirdAnswerId) ? 0 : 1,
  973. attachments = artAttachments.Count > 0 ?artAttachments.Where(c => c.taskId.Equals(taskId.GetString()) && c.studentId.Equals(x.studentId)).ToList() : null,
  974. 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 : "",
  975. 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
  976. });
  977. return Ok(new { works, code = 200 });
  978. }
  979. else
  980. {
  981. var works = artResults.Select(x => new
  982. {
  983. stuId = x.studentId,
  984. x.studentName,
  985. x.classIds,
  986. x.artId,
  987. isAnswer = string.IsNullOrWhiteSpace(x.zyanswer.thirdAnswerId) ? 0 : 1,
  988. attachments = artAttachments.Count > 0 ? artAttachments.Where(c => c.taskId.Equals(taskId.GetString()) && c.studentId.Equals(x.studentId)).ToList(): null,
  989. //time = artAttachments.Count > 0 ? artAttachments.Where(c => c.taskId.Equals(taskId.GetString()) && c.studentId.Equals(x.studentId))?.LastOrDefault().updateTime : 0,
  990. });
  991. return Ok(new { works, code = 200 });
  992. }
  993. }
  994. catch (CosmosException ex) when (ex.Status == 404)
  995. {
  996. return Ok(new { code = 404 });
  997. }
  998. catch (Exception e)
  999. {
  1000. await _dingDing.SendBotMsg($"OS,{_option.Location},art/find-summary-by-work()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1001. return Ok(new { code = 500 });
  1002. }
  1003. }
  1004. /// <param name="request"></param>
  1005. /// <returns></returns>
  1006. [ProducesDefaultResponseType]
  1007. [Authorize(Roles = "IES")]
  1008. [AuthToken(Roles = "teacher,admin")]
  1009. [HttpPost("find-by-teacher")]
  1010. public async Task<IActionResult> FindByTeacher(JsonElement request)
  1011. {
  1012. try
  1013. {
  1014. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  1015. if (!request.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
  1016. var client = _azureCosmos.GetCosmosClient();
  1017. 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}'";
  1018. List<object> arts = new();
  1019. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Art-{code}") }))
  1020. {
  1021. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  1022. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1023. {
  1024. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  1025. {
  1026. arts.Add(obj.ToObject<object>());
  1027. }
  1028. }
  1029. }
  1030. return Ok(new { arts });
  1031. }
  1032. catch (Exception e)
  1033. {
  1034. await _dingDing.SendBotMsg($"OS,{_option.Location},art/find-by-teacher()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  1035. return Ok(new { code = 500 });
  1036. }
  1037. }
  1038. [ProducesDefaultResponseType]
  1039. [Authorize(Roles = "IES")]
  1040. [AuthToken(Roles = "teacher,admin")]
  1041. [HttpPost("find-summary-by-teacher")]
  1042. public async Task<IActionResult> FindSummaryByTeacher(JsonElement request)
  1043. {
  1044. try
  1045. {
  1046. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  1047. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  1048. if (!request.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
  1049. var client = _azureCosmos.GetCosmosClient();
  1050. List<object> arts = new();
  1051. 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}") }))
  1052. {
  1053. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  1054. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1055. {
  1056. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  1057. {
  1058. arts.Add(obj.ToObject<object>());
  1059. }
  1060. }
  1061. }
  1062. return Ok(new { arts });
  1063. }
  1064. catch (Exception e)
  1065. {
  1066. await _dingDing.SendBotMsg($"OS,{_option.Location},art/find-summary-by-teacher()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  1067. return Ok(new { code = 500 });
  1068. }
  1069. }
  1070. private class stuFiles
  1071. {
  1072. public string id { get; set; }
  1073. public string school { get; set; }
  1074. public string artId { get; set; }
  1075. public string taskId { get; set; }
  1076. public string studentId { get; set; }
  1077. public string quotaId { get; set; }
  1078. public string quotaName { get; set; }
  1079. public string subjectId { get; set; }
  1080. public string address { get; set; }
  1081. public string time { get; set; }
  1082. public string duration { get; set; }
  1083. public string achievement { get; set; }
  1084. public string name { get; set; }
  1085. public string des { get; set; }
  1086. //0 艺术特长 1 艺术体验
  1087. public int artType { get; set; } = -1;
  1088. // 0 校级 1 区级 2 市级 3 省级 4 国家级
  1089. public int level { get; set; } = -1;
  1090. public long uploadTime { get; set; }
  1091. public string uploadName { get; set; }
  1092. public List<Attachment> files { get; set; } = new List<Attachment>();
  1093. }
  1094. private class studentInfos
  1095. {
  1096. public string id { get; set; }
  1097. public string paper { get; set; }
  1098. public string subject { get; set; }
  1099. // 评分状态,0,未评分, 1已评分
  1100. public int sStatus { get; set; }
  1101. //任务完成状态,-1 未参与,0,未完成, 1已完成
  1102. public int taskStatus { get; set; }
  1103. public long startTime { get; set; }
  1104. public long endTime { get; set; }
  1105. }
  1106. }
  1107. }