NormalController.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Microsoft.Azure.Cosmos;
  2. using DinkToPdf;
  3. using Microsoft.AspNetCore.Hosting;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.Extensions.Configuration;
  7. using Microsoft.Extensions.Options;
  8. using System.Net.Http;
  9. using System.Text.Json;
  10. using System.Threading.Tasks;
  11. using TEAMModelOS.Models;
  12. using TEAMModelOS.SDK;
  13. using TEAMModelOS.SDK.Context.Constant;
  14. using TEAMModelOS.SDK.DI;
  15. using TEAMModelOS.SDK.Models;
  16. namespace TEAMModelBI.Controllers.RepairApi
  17. {
  18. [Route("normal")]
  19. [ApiController]
  20. public class NormalController : ControllerBase
  21. {
  22. private readonly AzureCosmosFactory _azureCosmos;
  23. private readonly DingDing _dingDing;
  24. private readonly Option _option;
  25. private readonly AzureStorageFactory _azureStorage;
  26. private readonly IConfiguration _configuration;
  27. private readonly AzureServiceBusFactory _serviceBus;
  28. private readonly IHttpClientFactory _http;
  29. private readonly CoreAPIHttpService _coreAPIHttpService;
  30. private readonly IWebHostEnvironment _environment; //读取文件
  31. public NormalController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, AzureServiceBusFactory serviceBus, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService, IWebHostEnvironment hostingEnvironment)
  32. {
  33. _azureCosmos = azureCosmos;
  34. _dingDing = dingDing;
  35. _azureStorage = azureStorage;
  36. _option = option?.Value;
  37. _configuration = configuration;
  38. _serviceBus = serviceBus;
  39. _http = http;
  40. _coreAPIHttpService = coreAPIHttpService;
  41. _environment = hostingEnvironment;
  42. }
  43. /// <summary>
  44. /// 修改学区名称、标准名称、单位
  45. /// </summary>
  46. /// <param name="jsonElement"></param>
  47. /// <returns></returns>
  48. [ProducesDefaultResponseType]
  49. [HttpPost("set-areabase")]
  50. public async Task<IActionResult> SetAreaBase(JsonElement jsonElement)
  51. {
  52. if (!jsonElement.TryGetProperty("oldName", out JsonElement oldName)) return BadRequest();
  53. if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
  54. if(!jsonElement.TryGetProperty("type", out JsonElement type)) return BadRequest();
  55. var cosmosClient = _azureCosmos.GetCosmosClient();
  56. string sql = $"select value(c) from c where c.name = '{oldName}'";
  57. Area area = new();
  58. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIteratorSql<Area>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
  59. {
  60. area = item;
  61. };
  62. if (!string.IsNullOrEmpty(area.id))
  63. {
  64. area.name = $"{name}";
  65. switch ($"{type}")
  66. {
  67. case "all":
  68. area.institution = $"{name}";
  69. area.standardName = $"{name}";
  70. break;
  71. case "unit":
  72. area.institution = $"{name}";
  73. break;
  74. case "standard":
  75. area.standardName = $"{name}";
  76. break;
  77. }
  78. area = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReplaceItemAsync<Area>(area, area.id, new PartitionKey("Base-Area"));
  79. }
  80. return Ok(new { state = RespondCode.Ok, area });
  81. }
  82. }
  83. }