|
@@ -1,11 +1,136 @@
|
|
|
-namespace TEAMModelOS.Controllers
|
|
|
+using Azure.Cosmos;
|
|
|
+using DinkToPdf.Contracts;
|
|
|
+using DocumentFormat.OpenXml.Office2013.Excel;
|
|
|
+using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
+using HTEXLib.COMM.Helpers;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using OpenXmlPowerTools;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Net;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.Filter;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using TEAMModelOS.SDK;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
/// <summary>
|
|
|
- /// SELECT distinct value c FROM c join b in c.results where c.code='ArtResult-e4864b04-7e3d-47ac-8a00-4395569c5860'
|
|
|
- /// and array_contains(c.classes,'26a8d509-ce01-406e-b962-b53474ea3e58' ) and b.subjectId='subject_music'
|
|
|
+ /// SELECT distinct value c FROM c join b in c.results where c.code='ArtResult-e4864b04-7e3d-47ac-8a00-4395569c5860' and array_contains(c.classes,'26a8d509-ce01-406e-b962-b53474ea3e58' ) and b.subjectId='subject_music'
|
|
|
/// </summary>
|
|
|
- public class ArtReviewController
|
|
|
+ [ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
+ [ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
+
|
|
|
+ [Route("school/art")]
|
|
|
+ [ApiController]
|
|
|
+ public class ArtReviewController : ControllerBase
|
|
|
{
|
|
|
-
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly SnowflakeId _snowflakeId;
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ private readonly AzureRedisFactory _azureRedis;
|
|
|
+ private readonly IConverter _converter;
|
|
|
+ public IConfiguration _configuration { get; set; }
|
|
|
+ private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
+ public ArtReviewController(IConverter converter, CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
|
|
|
+ IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, IConfiguration configuration)
|
|
|
+ {
|
|
|
+ _coreAPIHttpService = coreAPIHttpService;
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _serviceBus = serviceBus;
|
|
|
+ _snowflakeId = snowflakeId;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _option = option?.Value;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _azureRedis = azureRedis;
|
|
|
+ _configuration = configuration;
|
|
|
+ _converter = converter;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "teacher,admin")]
|
|
|
+ [HttpPost("review")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+ public async Task<IActionResult> Review(JsonElement request) {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+
|
|
|
+ if (!request.TryGetProperty("opt", out JsonElement _opt))
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ var (userid, name, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
+ try {
|
|
|
+ switch (true) {
|
|
|
+ case bool when $"{_opt}".Equals("find", StringComparison.OrdinalIgnoreCase) && request.TryGetProperty("artId", out JsonElement artId) :
|
|
|
+ {
|
|
|
+ string results_join = "";
|
|
|
+ string results_where = "";
|
|
|
+ string classes_join = "";
|
|
|
+ string classes_where = "";
|
|
|
+ request.TryGetProperty("studentName", out JsonElement studentName);
|
|
|
+ request.TryGetProperty("studentId", out JsonElement studentId);
|
|
|
+ request.TryGetProperty("classes", out JsonElement _classes);
|
|
|
+ request.TryGetProperty("subjects", out JsonElement _subjects);
|
|
|
+ if (_classes.ValueKind.Equals(JsonValueKind.Array)) {
|
|
|
+ var classes = _classes.Deserialize<List<string>>();
|
|
|
+ if (classes.IsNotEmpty()) {
|
|
|
+ classes_join = " join classes in c.classes ";
|
|
|
+ classes_where = $" and classes in({string.Join(",", classes.Select(x => $"'{x}'"))}) ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (_subjects.ValueKind.Equals(JsonValueKind.Array))
|
|
|
+ {
|
|
|
+ var subjects = _subjects.Deserialize<List<string>>();
|
|
|
+ if (subjects.IsNotEmpty())
|
|
|
+ {
|
|
|
+ results_join = " join results in c.results ";
|
|
|
+ results_where = $" and results.subjectId in({string.Join(",", subjects.Select(x => $"'{x}'"))}) ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string studentNameWhere = "";
|
|
|
+ if (string.IsNullOrWhiteSpace($"{studentName}")) {
|
|
|
+ studentNameWhere = $" and contains(c.studentName,'{studentName}') ";
|
|
|
+ }
|
|
|
+ string studentIdWhere = "";
|
|
|
+ if (string.IsNullOrWhiteSpace($"{studentId}"))
|
|
|
+ {
|
|
|
+ studentIdWhere = $" and c.id = '{school}-{studentId}' ";
|
|
|
+ }
|
|
|
+ string sql = $"SELECT distinct value c FROM c {classes_join} {results_join} where c.pk='ArtResult' {classes_where} {results_where} {studentIdWhere} {studentNameWhere} ";
|
|
|
+
|
|
|
+ List<StudentArtResult> results = new List<StudentArtResult>();
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<StudentArtResult>
|
|
|
+ (queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtResult-{artId}") })) {
|
|
|
+ results.Add(item);
|
|
|
+ }
|
|
|
+ return Ok(new { results= results, status = 1 });
|
|
|
+ }
|
|
|
+ case bool when $"{_opt}".Equals("save", StringComparison.OrdinalIgnoreCase):
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch(Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
}
|
|
|
}
|