GenPDFController.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.Extensions.Options;
  5. using TEAMModelOS.SDK.DI;
  6. using TEAMModelOS.SDK;
  7. using TEAMModelOS.Models;
  8. using System.Net.Http;
  9. using System.Collections.Generic;
  10. using System.Text.Json;
  11. using System.Threading.Tasks;
  12. using TEAMModelOS.SDK.Models.Service;
  13. using DocumentFormat.OpenXml.Vml;
  14. using TEAMModelOS.Filter;
  15. using Microsoft.AspNetCore.Authorization;
  16. using FastJSON;
  17. using Microsoft.Azure.Cosmos.Linq;
  18. using TEAMModelOS.SDK.Extension;
  19. namespace TEAMModelOS.Controllers
  20. {
  21. [ProducesResponseType(StatusCodes.Status200OK)]
  22. [ProducesResponseType(StatusCodes.Status400BadRequest)]
  23. [Route("gen-pdf")]
  24. [ApiController]
  25. public class GenPDFController : ControllerBase
  26. {
  27. private readonly DingDing _dingDing;
  28. private readonly IHttpClientFactory _httpClient;
  29. private readonly IConfiguration _configuration;
  30. private readonly AzureStorageFactory _azureStorage;
  31. private readonly AzureRedisFactory _azureRedis;
  32. private readonly AzureServiceBusFactory _azureServiceBus ;
  33. private readonly IPSearcher _ipSearcher;
  34. private readonly Option _option;
  35. private readonly AzureCosmosFactory _azureCosmos;
  36. private readonly CoreAPIHttpService _coreAPIHttpService;
  37. private readonly Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator;
  38. public GenPDFController( AzureServiceBusFactory azureServiceBus,AzureRedisFactory azureRedis,
  39. Region2LongitudeLatitudeTranslator longitudeLatitudeTranslator, IHttpClientFactory httpClient,
  40. IConfiguration configuration, AzureStorageFactory azureStorage, IPSearcher searcher, DingDing dingDing,
  41. IOptionsSnapshot<Option> option,AzureCosmosFactory azureCosmos,CoreAPIHttpService coreAPIHttpService)
  42. {
  43. _httpClient = httpClient;
  44. _configuration = configuration;
  45. _azureStorage = azureStorage;
  46. _ipSearcher = searcher;
  47. _dingDing = dingDing;
  48. _option = option.Value;
  49. _azureRedis=azureRedis;
  50. _longitudeLatitudeTranslator = longitudeLatitudeTranslator;
  51. _azureServiceBus = azureServiceBus;
  52. _azureCosmos = azureCosmos;
  53. _coreAPIHttpService = coreAPIHttpService;
  54. }
  55. /// <summary>
  56. /// 艺术评测报告生成
  57. /// </summary>
  58. /// <param name="request"></param>
  59. /// <returns></returns>
  60. [ProducesDefaultResponseType]
  61. [HttpPost("art-report")]
  62. //#if !DEBUG
  63. // [AuthToken(Roles = "teacher,admin")]
  64. // [Authorize(Roles = "IES")]
  65. //#endif
  66. public async Task<IActionResult> ArtReport (GenPDFData request)
  67. {
  68. var data = await GenPDFService.AddGenPdfQueue( _azureRedis, request);
  69. return Ok(new { total= data.total,add= data .add});
  70. }
  71. /// <summary>
  72. /// 艺术评测报告生成
  73. /// </summary>
  74. /// <param name="request"></param>
  75. /// <returns></returns>
  76. [ProducesDefaultResponseType]
  77. [HttpPost("art-pdf")]
  78. //#if !DEBUG
  79. // [AuthToken(Roles = "teacher,admin")]
  80. // [Authorize(Roles = "IES")]
  81. //#endif
  82. public async Task<IActionResult> GenArtStudentPdf(JsonElement json)
  83. {
  84. if (!json.TryGetProperty("artId", out JsonElement _artId))
  85. {
  86. return BadRequest();
  87. }
  88. if (!json.TryGetProperty("schoolId", out JsonElement _schoolId))
  89. {
  90. return BadRequest();
  91. }
  92. List<string> studentIds = new List<string>();
  93. if (json.TryGetProperty("studentIds", out JsonElement _studentIds) && _studentIds.ValueKind.Equals(JsonValueKind.Array))
  94. {
  95. studentIds = _studentIds.ToObject<List<string>>();
  96. }
  97. string head_lang = string.Empty;
  98. if (HttpContext.Request.Headers.TryGetValue("lang", out var _lang))
  99. {
  100. head_lang = $"{_lang}";
  101. }
  102. if (string.IsNullOrWhiteSpace(head_lang))
  103. {
  104. head_lang = _option.Location.Contains("China") ? "zh-cn" : "en-us";
  105. }
  106. var data = await GenPDFService.GenArtStudentPdf(_azureRedis, _azureCosmos, _coreAPIHttpService, _dingDing, _azureStorage, _configuration, studentIds, $"{_artId}", $"{_schoolId}", $"{head_lang}");
  107. await GenPDFService.PushScreenTask(_azureRedis, _configuration, $"{_artId}", data.art, data.studentPdfs);
  108. return Ok();
  109. }
  110. }
  111. }