123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Options;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK;
- using TEAMModelOS.Models;
- using System.Net.Http;
- using System.Collections.Generic;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.Models.Service;
- using DocumentFormat.OpenXml.Vml;
- using TEAMModelOS.Filter;
- using Microsoft.AspNetCore.Authorization;
- using FastJSON;
- using Microsoft.Azure.Cosmos.Linq;
- using TEAMModelOS.SDK.Extension;
- namespace TEAMModelOS.Controllers
- {
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
- [Route("gen-pdf")]
- [ApiController]
- public class GenPDFController : ControllerBase
- {
- private readonly DingDing _dingDing;
- private readonly IHttpClientFactory _httpClient;
- private readonly IConfiguration _configuration;
- private readonly AzureStorageFactory _azureStorage;
- private readonly AzureRedisFactory _azureRedis;
- private readonly AzureServiceBusFactory _azureServiceBus ;
- private readonly IPSearcher _ipSearcher;
- private readonly Option _option;
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator;
- public GenPDFController( AzureServiceBusFactory azureServiceBus,AzureRedisFactory azureRedis,
- Region2LongitudeLatitudeTranslator longitudeLatitudeTranslator, IHttpClientFactory httpClient,
- IConfiguration configuration, AzureStorageFactory azureStorage, IPSearcher searcher, DingDing dingDing,
- IOptionsSnapshot<Option> option,AzureCosmosFactory azureCosmos,CoreAPIHttpService coreAPIHttpService)
- {
- _httpClient = httpClient;
- _configuration = configuration;
- _azureStorage = azureStorage;
- _ipSearcher = searcher;
- _dingDing = dingDing;
- _option = option.Value;
- _azureRedis=azureRedis;
- _longitudeLatitudeTranslator = longitudeLatitudeTranslator;
- _azureServiceBus = azureServiceBus;
- _azureCosmos = azureCosmos;
- _coreAPIHttpService = coreAPIHttpService;
- }
- /// <summary>
- /// 艺术评测报告生成
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("art-report")]
- //#if !DEBUG
- // [AuthToken(Roles = "teacher,admin")]
- // [Authorize(Roles = "IES")]
- //#endif
- public async Task<IActionResult> ArtReport (GenPDFData request)
- {
-
- var data = await GenPDFService.AddGenPdfQueue( _azureRedis, request);
- return Ok(new { total= data.total,add= data .add});
- }
- /// <summary>
- /// 艺术评测报告生成
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("art-pdf")]
- //#if !DEBUG
- // [AuthToken(Roles = "teacher,admin")]
- // [Authorize(Roles = "IES")]
- //#endif
- public async Task<IActionResult> GenArtStudentPdf(JsonElement json)
- {
- if (!json.TryGetProperty("artId", out JsonElement _artId))
- {
- return BadRequest();
- }
- if (!json.TryGetProperty("schoolId", out JsonElement _schoolId))
- {
- return BadRequest();
- }
- List<string> studentIds = new List<string>();
- if (json.TryGetProperty("studentIds", out JsonElement _studentIds) && _studentIds.ValueKind.Equals(JsonValueKind.Array))
- {
- studentIds = _studentIds.ToObject<List<string>>();
- }
- string head_lang = string.Empty;
- if (HttpContext.Request.Headers.TryGetValue("lang", out var _lang))
- {
- head_lang = $"{_lang}";
- }
- if (string.IsNullOrWhiteSpace(head_lang))
- {
- head_lang = _option.Location.Contains("China") ? "zh-cn" : "en-us";
- }
- var data = await GenPDFService.GenArtStudentPdf(_azureRedis, _azureCosmos, _coreAPIHttpService, _dingDing, _azureStorage, _configuration, studentIds, $"{_artId}", $"{_schoolId}", $"{head_lang}");
- await GenPDFService.PushScreenTask(_azureRedis, _configuration, $"{_artId}", data.art, data.studentPdfs);
- return Ok();
- }
-
- }
- }
|