123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Options;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Models;
- using Azure.Cosmos;
- using DingTalk.Api;
- using DingTalk.Api.Request;
- using DingTalk.Api.Response;
- namespace TEAMModeBI.Controllers.BISchool
- {
- [Route("batcharea")]
- [ApiController]
- public class BatchAreaController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureStorageFactory _azureStorage;
- private readonly IConfiguration _configuration;
- public BatchAreaController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _azureStorage = azureStorage;
- _option = option?.Value;
- _configuration = configuration;
- }
- /// <summary>
- /// 批量创区
- /// </summary>
- /// <param name="areas"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("batch-createarea")]
- public async Task<IActionResult> batchCreateArea(List<Area> areas)
- {
- try
- {
- List<Area> standards = new List<Area>();
- bool isCreate = true;
- if (areas.Count > 0)
- {
- foreach (Area itemarea in areas)
- {
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
- {
- if (item.standard.Equals(itemarea.standard))
- {
- standards.Add(itemarea);
- isCreate = false;
- }
- }
- if (isCreate == true)
- {
- Area addArea = new Area()
- {
- id = Guid.NewGuid().ToString(),
- code = $"Base-Area",
- name = itemarea.name,
- provCode = itemarea.provCode,
- provName = itemarea.provName,
- cityCode = itemarea.cityCode,
- cityName = itemarea.cityName,
- standard = itemarea.standard,
- standardName = itemarea.standardName,
- institution = itemarea.institution
- };
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync<Area>(addArea, new PartitionKey("Base-Area"));
- }
- }
- }
- else return Ok(new { sate = 1 ,message="区域参数为空"});
- if (standards.Count > 0)
- return Ok(new { state = 201, message = "已有部分区域批量创建成功;标准项已重复!请检查标准项!", standards = standards });
- else return Ok(new { state = 200, message = "批量创区全部完成", });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} batcharea/batch-createarea \n {ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- public record TempArea
- {
- public string name { get; set; }
- public string provCode { get; set; }
- public string provName { get; set; }
- public string cityCode { get; set; }
- public string cityName { get; set; }
- public string standard { get; set; }
- public string standardName { get; set; }
- public string institution { get; set; }
- }
- }
- }
|