12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using Azure.Cosmos;
- using DinkToPdf;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Options;
- using System.Net.Http;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.Context.Constant;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.DI.CoreAPI;
- using TEAMModelOS.SDK.Models;
- namespace TEAMModelBI.Controllers.RepairApi
- {
- [Route("normal")]
- [ApiController]
- public class NormalController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureStorageFactory _azureStorage;
- private readonly IConfiguration _configuration;
- private readonly NotificationService _notificationService;
- private readonly AzureServiceBusFactory _serviceBus;
- private readonly IHttpClientFactory _http;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly IWebHostEnvironment _environment; //读取文件
- public NormalController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService, AzureServiceBusFactory serviceBus, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService, IWebHostEnvironment hostingEnvironment)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _azureStorage = azureStorage;
- _option = option?.Value;
- _configuration = configuration;
- _notificationService = notificationService;
- _serviceBus = serviceBus;
- _http = http;
- _coreAPIHttpService = coreAPIHttpService;
- _environment = hostingEnvironment;
- }
- /// <summary>
- /// 修改学区名称、标准名称、单位
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("set-areabase")]
- public async Task<IActionResult> SetAreaBase(JsonElement jsonElement)
- {
- if (!jsonElement.TryGetProperty("oldName", out JsonElement oldName)) return BadRequest();
- if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
- if(!jsonElement.TryGetProperty("type", out JsonElement type)) return BadRequest();
- var cosmosClient = _azureCosmos.GetCosmosClient();
- string sql = $"select value(c) from c where c.name = '{oldName}'";
- Area area = new();
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
- {
- area = item;
- };
- if (!string.IsNullOrEmpty(area.id))
- {
- area.name = $"{name}";
- switch ($"{type}")
- {
- case "all":
- area.institution = $"{name}";
- area.standardName = $"{name}";
- break;
- case "unit":
- area.institution = $"{name}";
- break;
- case "standard":
- area.standardName = $"{name}";
- break;
- }
- area = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<Area>(area, area.id, new PartitionKey("Base-Area"));
- }
- return Ok(new { state = RespondCode.Ok, area });
- }
- }
- }
|