BizArtController.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Azure.Cosmos;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.Extensions.Configuration;
  5. using Microsoft.Extensions.Options;
  6. using System.Collections.Generic;
  7. using System.Text.Json;
  8. using System.Threading.Tasks;
  9. using TEAMModelOS.Filter;
  10. using TEAMModelOS.Models;
  11. using TEAMModelOS.SDK;
  12. using TEAMModelOS.SDK.Context.Constant;
  13. using TEAMModelOS.SDK.DI;
  14. using TEAMModelOS.SDK.Extension;
  15. using TEAMModelOS.SDK.Models;
  16. using TEAMModelOS.SDK.Models.Cosmos.Common;
  17. using TEAMModelOS.SDK.Models.Dtos;
  18. namespace TEAMModelOS.Controllers
  19. {
  20. [Route("business")]
  21. [ApiController]
  22. public class BizArtController : ControllerBase
  23. {
  24. private readonly AzureCosmosFactory _azureCosmos;
  25. private readonly AzureStorageFactory _azureStorage;
  26. private readonly AzureRedisFactory _azureRedis;
  27. private readonly DingDing _dingDing;
  28. private readonly Option _option;
  29. private readonly IConfiguration _configuration;
  30. private readonly CoreAPIHttpService _coreAPIHttpService;
  31. private readonly AzureServiceBusFactory _serviceBus;
  32. public BizArtController(CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, AzureServiceBusFactory serviceBus)
  33. {
  34. _azureCosmos = azureCosmos;
  35. _azureStorage = azureStorage;
  36. _azureRedis = azureRedis;
  37. _dingDing = dingDing;
  38. _option = option?.Value;
  39. _configuration = configuration;
  40. _coreAPIHttpService = coreAPIHttpService;
  41. _serviceBus = serviceBus;
  42. }
  43. /// <summary>
  44. /// 获取艺术评测标准信息
  45. /// </summary>
  46. /// <param name="jsonElement"></param>
  47. /// <returns></returns>
  48. [ProducesDefaultResponseType]
  49. [HttpPost("get-artseting")]
  50. [ApiToken(Auth = "2100", Name = "获取艺术评测标准信息", TName = "取得藝術評量標準資訊", EName = "Get art assessment standard", RWN = "R", Limit = false)]
  51. public async Task<IActionResult> GetArtSetting(JsonElement jsonElement)
  52. {
  53. var (id, school) = HttpContext.GetApiTokenInfo();
  54. if (!jsonElement.TryGetProperty("artId", out JsonElement artId)) return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误" } });
  55. var cosmosClient = _azureCosmos.GetCosmosClient();
  56. string areaId = null;
  57. List<MusicZystd> musicScores = new();
  58. ArtEvaluation artEvaluation = new();
  59. var artEva = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync($"{artId}", new PartitionKey($"Art-{school}"));
  60. if (artEva.Status == 200)
  61. {
  62. JsonDocument document = JsonDocument.Parse(artEva.Content);
  63. artEvaluation = document.RootElement.Deserialize<ArtEvaluation>();
  64. areaId = artEvaluation.areaId;
  65. }
  66. else
  67. return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "未找到艺术评测信息" } });
  68. if (string.IsNullOrEmpty(areaId))
  69. {
  70. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<string>(queryText: $"select value(c.areaId) from c where c.id='{school}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  71. {
  72. areaId = item;
  73. }
  74. }
  75. if (!string.IsNullOrEmpty(areaId))
  76. {
  77. ArtSetting artSetting = new();
  78. var resArt = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(areaId, new PartitionKey("ArtSetting"));
  79. if (resArt.Status == 200)
  80. {
  81. JsonDocument document = JsonDocument.Parse(resArt.Content);
  82. artSetting = document.RootElement.Deserialize<ArtSetting>();
  83. }
  84. else
  85. artSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<ArtSetting>("default", new PartitionKey("ArtSetting"));
  86. if (artEvaluation.zymusicstds.Count > 0)
  87. {
  88. foreach (var item in artEvaluation.zymusicstds)
  89. {
  90. MusicZystd tempMusic = artSetting.musicZystds.Find(f => f.code.Equals(item.code));
  91. MusicZystd musicZystd = new() { code = tempMusic.code, label = tempMusic.label, percent = item.percent, child = tempMusic.child, points = tempMusic.points };
  92. musicScores.Add(musicZystd);
  93. }
  94. }
  95. else
  96. return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "活动中暂未有评分标准" } });
  97. }
  98. return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = musicScores } });
  99. }
  100. }
  101. }