ArtController.cs 59 KB

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