|
@@ -0,0 +1,73 @@
|
|
|
|
+using Azure.Cosmos;
|
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
|
+using System;
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using System.Linq;
|
|
|
|
+using System.Text.Json;
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
+using TEAMModelOS.Filter;
|
|
|
|
+using TEAMModelOS.Models;
|
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos;
|
|
|
|
+using TEAMModelOS.SDK.Models.Table;
|
|
|
|
+
|
|
|
|
+namespace TEAMModelBI.Controllers
|
|
|
|
+{
|
|
|
|
+ [ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
+ [ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
+ [Route("openapi-config")]
|
|
|
|
+ [ApiController]
|
|
|
|
+ public class OpenApiConfigController : ControllerBase
|
|
|
|
+ {
|
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
|
+ private readonly AzureRedisFactory _azureRedis;
|
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
|
+ private readonly Option _option;
|
|
|
|
+ public OpenApiConfigController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
|
+ _azureStorage = azureStorage;
|
|
|
|
+ _azureRedis = azureRedis;
|
|
|
|
+ _dingDing = dingDing;
|
|
|
|
+ _option = option?.Value;
|
|
|
|
+ }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// {"id":"uuid","code":"hbcn学校编码"}
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="requert"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ //[AuthToken(Roles = "admin")]
|
|
|
|
+ [HttpPost("create-token")]
|
|
|
|
+ //[Authorize(Roles = "IES")]
|
|
|
|
+ public async Task<IActionResult> CreateToken(JsonElement request)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ { if (!request.TryGetProperty("id", out JsonElement _id)) { return BadRequest(); }
|
|
|
|
+ var table = _azureStorage.GetCloudTableClient().GetTableReference("IESOpenApi");
|
|
|
|
+ List<BusinessConfig> configs = table.FindListByDictSync<BusinessConfig>(new Dictionary<string, object> { { "PartitionKey", $"BusinessConfig" }, { "RowKey", $"{_id}" } });
|
|
|
|
+ string jtw = "";
|
|
|
|
+ if (configs.Any()) {
|
|
|
|
+ var auth_token = JwtAuthExtension.CreateBusinessApiToken(_option.HostName, configs[0].RowKey, _option.JwtSecretKey, "business");
|
|
|
|
+ jtw = auth_token.jtw;
|
|
|
|
+ configs[0].jti = auth_token.jti;
|
|
|
|
+ await table.SaveOrUpdate<BusinessConfig>(configs[0]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Ok(new {jtw });
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},open-api/upsert()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|