123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using Azure.Cosmos;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Options;
- using System.Collections.Generic;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.Filter;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.Context.Constant;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos.Common;
- using TEAMModelOS.SDK.Models.Dtos;
- namespace TEAMModelOS.Controllers
- {
- [Route("business")]
- [ApiController]
- public class BizArtController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly AzureStorageFactory _azureStorage;
- private readonly AzureRedisFactory _azureRedis;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly IConfiguration _configuration;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly AzureServiceBusFactory _serviceBus;
- public BizArtController(CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, AzureServiceBusFactory serviceBus)
- {
- _azureCosmos = azureCosmos;
- _azureStorage = azureStorage;
- _azureRedis = azureRedis;
- _dingDing = dingDing;
- _option = option?.Value;
- _configuration = configuration;
- _coreAPIHttpService = coreAPIHttpService;
- _serviceBus = serviceBus;
- }
- /// <summary>
- /// 获取艺术评测标准信息
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-artseting")]
- [ApiToken(Auth = "2100", Name = "获取艺术评测标准信息", TName = "取得藝術評量標準資訊", EName = "Get art assessment standard", RWN = "R", Limit = false)]
- public async Task<IActionResult> GetArtSetting(JsonElement jsonElement)
- {
- var (id, school) = HttpContext.GetApiTokenInfo();
- if (!jsonElement.TryGetProperty("artId", out JsonElement artId)) return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误" } });
- var cosmosClient = _azureCosmos.GetCosmosClient();
- string areaId = null;
- List<MusicZystd> musicScores = new();
- ArtEvaluation artEvaluation = new();
- var artEva = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync($"{artId}", new PartitionKey($"Art-{school}"));
- if (artEva.Status == 200)
- {
- JsonDocument document = JsonDocument.Parse(artEva.Content);
- artEvaluation = document.RootElement.Deserialize<ArtEvaluation>();
- areaId = artEvaluation.areaId;
- }
- else
- return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "未找到艺术评测信息" } });
- if (string.IsNullOrEmpty(areaId))
- {
- 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") }))
- {
- areaId = item;
- }
- }
- if (!string.IsNullOrEmpty(areaId))
- {
- ArtSetting artSetting = new();
- var resArt = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync(areaId, new PartitionKey("ArtSetting"));
- if (resArt.Status == 200)
- {
- JsonDocument document = JsonDocument.Parse(resArt.Content);
- artSetting = document.RootElement.Deserialize<ArtSetting>();
- }
- else
- artSetting = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<ArtSetting>("default", new PartitionKey("ArtSetting"));
- if (artEvaluation.zymusicstds.Count > 0)
- {
- foreach (var item in artEvaluation.zymusicstds)
- {
- MusicZystd tempMusic = artSetting.musicZystds.Find(f => f.code.Equals(item.code));
- MusicZystd musicZystd = new() { code = tempMusic.code, label = tempMusic.label, percent = item.percent, child = tempMusic.child, points = tempMusic.points };
- musicScores.Add(musicZystd);
- }
- }
- else
- return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "活动中暂未有评分标准" } });
- }
- return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = musicScores } });
- }
- }
- }
|