123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639 |
- using Azure.Cosmos;
- 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.Text;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelBI.DI.BIAzureStorage;
- using TEAMModelBI.Filter;
- using TEAMModelBI.Models.Extension;
- using TEAMModelBI.Tool.Context;
- using TEAMModelBI.Tool.Extension;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models.Cosmos.BI;
- using TEAMModelOS.SDK.Models.Service;
- namespace TEAMModelBI.Controllers.BINormal
- {
- [Route("appcompany")]
- [ApiController]
- public class AppCompanyController : ControllerBase
- {
- public readonly AzureCosmosFactory _azureCosmos;
- public readonly AzureStorageFactory _azureStorage;
- public readonly DingDing _dingDing;
- public readonly Option _option;
- private readonly IConfiguration _configuration;
- private readonly NotificationService _notificationService;
- public AppCompanyController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService)
- {
- _azureCosmos = azureCosmos;
- _azureStorage = azureStorage;
- _dingDing = dingDing;
- _option = option?.Value;
- _configuration = configuration;
- _notificationService = notificationService;
- }
- /// <summary>
- /// 查询应用信息
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-info")]
- public async Task<IActionResult> GetInfo(JsonElement jsonElement)
- {
- jsonElement.TryGetProperty("appId", out JsonElement appId);
- jsonElement.TryGetProperty("eid", out JsonElement eid);
- jsonElement.TryGetProperty("audit", out JsonElement audit);
- jsonElement.TryGetProperty("site", out JsonElement site);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- if ($"{site}".Equals(BIConst.Global))
- cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- StringBuilder sqlTxt = new($"select c.id,c.pk,c.code,c.name,c.descr,c.picture,c.jwtKey,c.status,c.audit,c.refuseDesc,c.gateways,c.apis,c.webhookDomain,c.webHooks,c.schools from c where c.pk='App'");
- if (!string.IsNullOrEmpty($"{appId}"))
- {
- sqlTxt.Append($" and id='{appId}'");
- }
- if (!string.IsNullOrEmpty($"{audit}"))
- {
- sqlTxt.Append($" and audit='{audit}'");
- }
- List<ReadCompany> appCompanys = new();
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: string.IsNullOrEmpty($"{eid}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"App-{eid}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- ReadCompany readCompany = new()
- {
- id = obj.GetProperty("id").GetString(),
- pk = obj.GetProperty("pk").GetString(),
- code = obj.GetProperty("code").GetString(),
- name = obj.GetProperty("name").GetString(),
- descr = obj.GetProperty("descr").GetString(),
- picture = obj.GetProperty("picture").GetString(),
- jwtKey = obj.GetProperty("jwtKey").GetString(),
- status = obj.GetProperty("status").GetInt32(),
- audit = obj.GetProperty("audit").GetInt32(),
- refuseDesc = obj.GetProperty("refuseDesc").GetString(),
- gateways = obj.GetProperty("gateways").GetString(),
- apis = obj.GetProperty("apis").ToObject<List<AppApiState>>(),
- webhookDomain = obj.GetProperty("webhookDomain").GetString(),
- webHooks = obj.GetProperty("webHooks").ToObject<List<WebHookState>>(),
- schools = obj.GetProperty("schools").ToObject<List<ApplySchool>>()
- };
- appCompanys.Add(readCompany);
- }
- }
- }
- return Ok(new { state = 200, appCompanys });
- }
- /// <summary>
- /// 新增或者修改应用
- /// </summary>
- /// <param name="appCompany"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "admin,rdc,company")]
- [HttpPost("set-info")]
- public async Task<IActionResult> SetAppInfo(AppCompany appCompany, [FromHeader] string site)
- {
- try
- {
- var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- var tableClient = _azureStorage.GetCloudTableClient();
- var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
- if ($"{site}".Equals(BIConst.Global))
- {
- cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
- blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
- }
- StringBuilder stringBuilder = new($"{loginName}【{loginId}】");
- string type = "";
- //新建
- if (string.IsNullOrEmpty($"{appCompany.id}"))
- {
- appCompany.id = GenerateRandom.StrRandom(8, large: true, small: true);
- appCompany.code = $"App-{appCompany.code}";
- appCompany.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- appCompany.status = -1;
- appCompany.audit = -1;
- appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").CreateItemAsync<AppCompany>(appCompany, new PartitionKey(appCompany.code));
- stringBuilder.Append($"新增应用,应用ID:{appCompany.id},应用名称:{appCompany.name}");
- type = "appCompany-add";
- }
- //修改
- else
- {
- var response = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync(appCompany.id, new PartitionKey(appCompany.code));
- if (response.Status == 200)
- {
- appCompany.pk = "App";
- appCompany.ttl = -1;
- appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<AppCompany>(appCompany, appCompany.id, new PartitionKey(appCompany.code));
- stringBuilder.Append($"修改应用,应用ID:{appCompany.id},应用名称:{appCompany.name}");
- type = "appCompany-update";
- }
- else return Ok(new { state = 404, msg = "未找到该id相关的企业应用信息" });
- }
- //保存操作记录
- //await _azureStorage.SaveBILog(type, stringBuilder.ToString(), _dingDing, httpContext: HttpContext);
- await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, type, stringBuilder.ToString(), _dingDing, httpContext: HttpContext);
- return Ok(new { state = 200, appCompany });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} , /appcompany/set-info \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 查询未审核的信息
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-noaudit")]
- public async Task<IActionResult> GetNoAudit(JsonElement jsonElement)
- {
- if(!jsonElement.TryGetProperty("operate", out JsonElement operate)) return BadRequest();
- jsonElement.TryGetProperty("site", out JsonElement site);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- var tableClient = _azureStorage.GetCloudTableClient();
- var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
- if ($"{site}".Equals(BIConst.Global))
- {
- cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
- blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
- }
- StringBuilder sqlTxt = new();
- switch (operate.GetString())
- {
- case "api":
- sqlTxt.Append($"SELECT c.id, c.code,c.name,c.pk,c.audit,ARRAY(SELECT VALUE a FROM a in c.apis where a.status = -1) as operate FROM c where c.pk='App' and c.audit=1");
- break;
- case "school":
- sqlTxt.Append($"SELECT c.id, c.code,c.name,c.pk,c.audit,ARRAY(SELECT VALUE a FROM a in c.schools where a.status = -1) as operate FROM c where c.pk='App' and c.audit=1");
- break;
- default:
- sqlTxt.Append($"select c.id,c.code,c.name,c.pk,c.audit from c where c.audit=-1 and c.pk='App'");
- break;
- }
- List<NoAudit> noAudits = new();
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
- {
- var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- NoAudit noAudit = new();
- noAudit.id = obj.GetProperty("id").GetString();
- noAudit.code = obj.GetProperty("code").GetString();
- noAudit.pk = obj.GetProperty("pk").GetString();
- noAudit.name = obj.GetProperty("name").GetString();
- if (!string.IsNullOrEmpty($"{operate}"))
- {
- noAudit.operate = obj.GetProperty("operate").ToObject<List<object>>();
- }
- noAudit.audit = obj.GetProperty("audit").GetInt32();
- noAudits.Add(noAudit);
- }
- }
- }
- return Ok(new { state = 200, noAudits });
- }
- /// <summary>
- /// 审核应用是否通过
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [AuthToken(Roles = "admin,rdc")]
- [HttpPost("get-apply")]
- public async Task<IActionResult> SetAuditApp(JsonElement jsonElement)
- {
- try
- {
- var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
- if (!jsonElement.TryGetProperty("appIds", out JsonElement appIds)) return BadRequest();
- if (!jsonElement.TryGetProperty("isAudit", out JsonElement isAudit)) return BadRequest();
- jsonElement.TryGetProperty("refuseDesc", out JsonElement refuseDesc);
- jsonElement.TryGetProperty("site", out JsonElement site);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- var tableClient = _azureStorage.GetCloudTableClient();
- var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
- if ($"{site}".Equals(BIConst.Global))
- {
- cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
- blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
- }
- StringBuilder strMsg = new($"{loginName}【{loginId}】");
- List<AppIdOrCode> idOrCode = appIds.ToObject<List<AppIdOrCode>>();
- List<AppIdOrCode> haveIds = new();
- if (idOrCode.Count > 0)
- {
- foreach (var idCode in idOrCode)
- {
- AppCompany appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AppCompany>(idCode.id, new PartitionKey(idCode.code));
- strMsg.Append($"审核应用{appCompany.name}【{appCompany.id}】,审核状态:");
- //var response = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync(idCode.id, new PartitionKey(idCode.code));
- if (bool.Parse($"{isAudit}") == true)
- {
- appCompany.audit = 1;
- appCompany.jwtKey = JwtAuth.CreateApplyJwtKeyBI(_option.HostName, _option.JwtSecretKey, appCompany);
- strMsg.Append("通过。");
- }
- else
- {
- appCompany.audit = 0;
- appCompany.refuseDesc = $"{refuseDesc}";
- strMsg.Append("拒绝通过。");
- }
- try
- {
-
- await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<AppCompany>(appCompany, appCompany.id, new PartitionKey(idCode.code));
- }
- catch
- {
- haveIds.Add(idCode);
- strMsg.Append($"异常:id:{idCode.id},code:{idCode.code};");
- }
- }
- }
- else return Ok(new { state = 404, msg = "appIds参数错误" });
- //保存操作记录
- //await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
- await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
- if (haveIds.Count > 0)
- return Ok(new { state = 201, msg = "部分应用审核失败!", haveIds });
- else return Ok(new { state = 200 });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} , /appcompany/get-applyapi \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 应用申请Api接口信息
- /// 审核应用api接口信息
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "admin,rdc,company")]
- [HttpPost("set-applyapi")]
- public async Task<IActionResult> SetApplyApi(JsonElement jsonElement)
- {
- try
- {
- var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
- if (!jsonElement.TryGetProperty("applyApis", out JsonElement jsApplyApis)) return BadRequest();
- if (!jsonElement.TryGetProperty("operate", out JsonElement operate)) return BadRequest();
- jsonElement.TryGetProperty("site", out JsonElement site);
- StringBuilder strMsg = new($"{loginName}【{loginId}】");
- var cosmosClient = _azureCosmos.GetCosmosClient();
- var tableClient = _azureStorage.GetCloudTableClient();
- var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
- if ($"{site}".Equals(BIConst.Global))
- {
- cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
- blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
- }
- string bizcode = ""; //消息名称
- List<string> sendWhom = new();//消息分发给谁 待完善
- List<ApplyApi> applyApis = jsApplyApis.ToObject<List<ApplyApi>>();
- List<ApplyApi> haveApi = new(); //存在api接口
- Dictionary<string,string> noAudit = new();
- foreach (var tempApp in applyApis)
- {
- AppCompany appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AppCompany>($"{tempApp.appId}", new PartitionKey($"{tempApp.appCode}"));
- if (appCompany != null || appCompany.audit != -1 || appCompany.audit != 0)
- {
- switch (operate.GetString())
- {
- case "apply":
- strMsg.Append($"申请:{appCompany.name}【{appCompany.id}】应用的Api:");
- if (!jsonElement.TryGetProperty("applyDesc", out JsonElement applyDesc)) return BadRequest();
- tempApp.apiIds.ForEach(x =>
- {
- var strt = appCompany.apis.Find(y => y.no.Equals($"{x}"));
- if (strt == null)
- {
- appCompany.apis.Add(new AppApiState() { no = $"{x}", applyDesc = $"{applyDesc}", status = -1 });
- strMsg.Append($"{x},");
- }
- else haveApi.Add(tempApp);
- });
- sendWhom.Add(appCompany.id);
- bizcode = "applyapi";
- if (haveApi.Count > 0) strMsg.Append($"已有存在的api:{haveApi.ToJsonString()}。");
- break;
- case "audit":
- if (!jsonElement.TryGetProperty("isAudit", out JsonElement isAudit)) return BadRequest();
- string refuseDesc = "";
- if (bool.Parse($"{isAudit}") == false)
- {
- if (!jsonElement.TryGetProperty("refuseDesc", out JsonElement jsonRefuseDesc)) return BadRequest();
- refuseDesc = jsonRefuseDesc.GetString();
- }
- strMsg.Append($"审核{appCompany.name}【{appCompany.id}】应用的Api:");
- tempApp.apiIds.ForEach(x =>
- {
- var temp = appCompany.apis.Find(n => n.no == x);
- if (temp != null)
- {
- AppApiState appApiState = appCompany.apis.Single(a => a.no == x);
- if (bool.Parse($"{isAudit}") == true)
- {
- appApiState.status = 1;
- appApiState.refuseDesc = null;
- appCompany.jwtKey = JwtAuth.CreateApplyJwtKeyBI(_option.HostName, _option.JwtSecretKey, appCompany);
- strMsg.Append($"{appApiState.no}通过,");
- }
- else
- {
- appApiState.status = 0;
- appApiState.refuseDesc = $"{refuseDesc}";
- strMsg.Append($"{appApiState.no}失败,");
- }
- }
- else haveApi.Add(tempApp);
- });
- if (haveApi.Count > 0) strMsg.Append($"该应用没有申请相关API接口:{haveApi.ToJsonString()}。");
- sendWhom.Add(appCompany.id);
- bizcode = "auditapi";
- break;
- default:
- return Ok(new { state = 400, msg = "operate参数错误" });
- }
- appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<AppCompany>(appCompany, appCompany.id, new PartitionKey(appCompany.code));
- }
- else noAudit.Add($"{appCompany.id}", $"{appCompany.name}");
- }
- //发送消息
- var location = _option.Location;
- Notification notification = new()
- {
- hubName = bizcode,
- type = "msg",
- from = $"BI:{_option.Location}:private",
- to = sendWhom,
- label = $"{bizcode}-appCompany",
- body = new { location = location, biz = bizcode, appid = sendWhom, appName = sendWhom, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
- };
- var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
- var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
- var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
- await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
- //保存操作记录
- //await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
- await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
- if (haveApi.Count > 0 || noAudit.Count > 0)
- return Ok(new { state = 201, msg = "部分成功", haveApi, noAudit });
- else return Ok(new { state = 200 });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} , /appcompany/get-applyapi \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 应用申请学校
- /// 应用审核申请的学校
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "admin,rdc,company")]
- [HttpPost("set-applyschool")]
- public async Task<IActionResult> SetAuditSchool(JsonElement jsonElement)
- {
- try
- {
- var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
- if (!jsonElement.TryGetProperty("appId", out JsonElement appId)) return BadRequest();
- if (!jsonElement.TryGetProperty("appCode", out JsonElement appCode)) return BadRequest();
- if (!jsonElement.TryGetProperty("schooCode", out JsonElement schooCode)) return BadRequest();
- if (!jsonElement.TryGetProperty("operate", out JsonElement operate)) return BadRequest();
- jsonElement.TryGetProperty("site", out JsonElement site);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- var tableClient = _azureStorage.GetCloudTableClient();
- var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
- if ($"{site}".Equals(BIConst.Global))
- {
- cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
- blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
- }
- StringBuilder strMsg = new($"{loginName}【{loginId}】操作:");
- List<string> haveSchool = new();
- List<string> sendWhom = new();//消息分发给谁 待完善
- string bizcode = ""; //消息名称
- AppCompany appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AppCompany>($"{appId}", new PartitionKey($"{appCode}"));
- if (appCompany.audit == -1 || appCompany.audit == 0)
- {
- return Ok(new { state = 401, msg = "应用未审核请先审核应用程序" });
- }
- if (appCompany != null)
- {
- switch (operate.GetString())
- {
- case "apply":
- var aSchool = appCompany.schools.Find(x => x.id.Equals($"{schooCode}"));
- if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
- if (aSchool == null)
- {
- jsonElement.TryGetProperty("picture", out JsonElement picture);
- strMsg.Append($"应用{appCompany.name}【{appCompany.id}】申请学校{name}【{schooCode}】,申请成功。");
- appCompany.schools.Add(new ApplySchool() { id = $"{schooCode}", name = $"{name}", picture = $"{picture}" });
- }
- else
- {
- haveSchool.Add(schooCode.GetString());
- strMsg.Append($"应用{appCompany.name}【{appCompany.id}】申请的学校{name}【{schooCode}】已存在。");
- }
- sendWhom = new List<string> { "1528783103", "1636016499" };
- bizcode = "applyschool";
- break;
- case "audit":
- if (!jsonElement.TryGetProperty("isAudit", out JsonElement isAudit)) return BadRequest();
- string refuseDesc = "";
- if (bool.Parse($"{isAudit}") == false)
- {
- if (!jsonElement.TryGetProperty("refuseDesc", out JsonElement jsonRefuseDesc)) return BadRequest();
- refuseDesc = jsonRefuseDesc.GetString();
- }
- var applySchool = appCompany.schools.Find(x => x.id.Equals($"{schooCode}"));
- strMsg.Append($"审核应用{appCompany.name}【{appCompany.id}】状态:");
- if (applySchool != null)
- {
- if (bool.Parse($"{isAudit}") == true)
- {
- applySchool.status = 1;
- applySchool.refuseDesc = null;
- appCompany.jwtKey = JwtAuth.CreateApplyJwtKeyBI(_option.HostName, _option.JwtSecretKey, appCompany);
- strMsg.Append($"审核成功。");
- }
- else
- {
- applySchool.status = 0;
- applySchool.refuseDesc = $"{refuseDesc}";
- strMsg.Append($"审核失败。");
- }
- }
- else
- {
- haveSchool.Add(schooCode.GetString());
- strMsg.Append($"已审核状态!");
- }
- sendWhom = new List<string> { "1528783103", "1636016499" };
- bizcode = "auditschool";
- break;
- default:
- return Ok(new { state = 400, msg = "operate参数错误" });
- }
- appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<AppCompany>(appCompany, appCompany.id, new PartitionKey(appCompany.code));
- }
- else return Ok(new { state = 404, msg = "未找到该应用" });
- //发送消息
- var location = _option.Location;
- Notification notification = new()
- {
- hubName = bizcode,
- type = "msg",
- from = $"BI:{_option.Location}:private",
- to = sendWhom,
- label = $"{bizcode}-appCompany",
- body = new { location = location, biz = bizcode, appid = appCompany.id, appName = appCompany.name, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
- };
- var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
- var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
- var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
- await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
- //保存操作记录
- //await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
- await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
- if (haveSchool.Count > 0) return Ok(new { state = 201, msg = "已存在学校,无须申请!", haveSchool });
- else return Ok(new { state = 200 });
- }
- catch (Exception e)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} , /appcompany/set-auditschool \n {e.Message}\n{e.StackTrace}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 应用申请和审核api信息
- /// </summary>
- public record ApplyApi
- {
- public string appId { get; set; }
- public string appCode { get; set; }
- public List<string> apiIds { get; set; }
- }
- /// <summary>
- /// 审核应用
- /// </summary>
- public record AppIdOrCode
- {
- public string id { get; set; }
- public string code { get; set; }
- }
- /// <summary>
- /// 未审核应用
- /// </summary>
- public record NoAudit
- {
- public string id { get; set; }
- public string code { get; set; }
- public string pk { get; set; }
- public string name { get;set; }
- public List<object> operate { get; set; }
- public int audit { get; set; }
- }
- /// <summary>
- /// 显示应用
- /// </summary>
- public record ReadCompany
- {
- public string id { get; set; }
- public string pk { get; set; }
- public string code { get; set; }
- public string name { get; set; }
- public string descr { get; set; }
- public string picture { get; set; }
- public string jwtKey { get; set; }
- public int status { get; set; }
- public int audit { get; set; }
- public string refuseDesc { get; set; }
- public string gateways { get; set; }
- public List<AppApiState> apis { get; set; }
- public string webhookDomain { get; set; }
- public List<WebHookState> webHooks { get; set; }
- public List<ApplySchool> schools { get; set; }
- }
- }
- }
|