AppCompanyController.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. using Azure.Cosmos;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.Extensions.Configuration;
  5. using Microsoft.Extensions.Options;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Text.Json;
  11. using System.Threading.Tasks;
  12. using TEAMModelBI.Filter;
  13. using TEAMModelBI.Tool.Extension;
  14. using TEAMModelOS.Models;
  15. using TEAMModelOS.SDK.DI;
  16. using TEAMModelOS.SDK.Extension;
  17. using TEAMModelOS.SDK.Models.Cosmos.BI;
  18. using TEAMModelOS.SDK.Models.Service;
  19. namespace TEAMModelBI.Controllers.BINormal
  20. {
  21. [Route("appcompany")]
  22. [ApiController]
  23. public class AppCompanyController : ControllerBase
  24. {
  25. public readonly AzureCosmosFactory _azureCosmos;
  26. public readonly AzureStorageFactory _azureStorage;
  27. public readonly DingDing _dingDing;
  28. public readonly Option _option;
  29. private readonly IConfiguration _configuration;
  30. private readonly NotificationService _notificationService;
  31. public AppCompanyController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService)
  32. {
  33. _azureCosmos = azureCosmos;
  34. _azureStorage = azureStorage;
  35. _dingDing = dingDing;
  36. _option = option?.Value;
  37. _configuration = configuration;
  38. _notificationService = notificationService;
  39. }
  40. /// <summary>
  41. /// 查询应用信息
  42. /// </summary>
  43. /// <param name="jsonElement"></param>
  44. /// <returns></returns>
  45. [ProducesDefaultResponseType]
  46. [HttpPost("get-info")]
  47. public async Task<IActionResult> GetInfo(JsonElement jsonElement)
  48. {
  49. jsonElement.TryGetProperty("appId", out JsonElement appId);
  50. jsonElement.TryGetProperty("eid", out JsonElement eid);
  51. jsonElement.TryGetProperty("audit", out JsonElement audit);
  52. var cosmosClient = _azureCosmos.GetCosmosClient();
  53. 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'");
  54. if (!string.IsNullOrEmpty($"{appId}"))
  55. {
  56. sqlTxt.Append($" and id='{appId}'");
  57. }
  58. if (!string.IsNullOrEmpty($"{audit}"))
  59. {
  60. sqlTxt.Append($" and audit='{audit}'");
  61. }
  62. List<ReadCompany> appCompanys = new();
  63. 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}") }))
  64. {
  65. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  66. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  67. {
  68. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  69. {
  70. ReadCompany readCompany = new()
  71. {
  72. id = obj.GetProperty("id").GetString(),
  73. pk = obj.GetProperty("pk").GetString(),
  74. code = obj.GetProperty("code").GetString(),
  75. name = obj.GetProperty("name").GetString(),
  76. descr = obj.GetProperty("descr").GetString(),
  77. picture = obj.GetProperty("picture").GetString(),
  78. jwtKey = obj.GetProperty("jwtKey").GetString(),
  79. status = obj.GetProperty("status").GetInt32(),
  80. audit = obj.GetProperty("audit").GetInt32(),
  81. refuseDesc = obj.GetProperty("refuseDesc").GetString(),
  82. gateways = obj.GetProperty("gateways").GetString(),
  83. apis = obj.GetProperty("apis").ToObject<List<AppApiState>>(),
  84. webhookDomain = obj.GetProperty("webhookDomain").GetString(),
  85. webHooks = obj.GetProperty("webHooks").ToObject<List<WebHookState>>(),
  86. schools = obj.GetProperty("schools").ToObject<List<ApplySchool>>()
  87. };
  88. appCompanys.Add(readCompany);
  89. }
  90. }
  91. }
  92. return Ok(new { state = 200, appCompanys });
  93. }
  94. /// <summary>
  95. /// 新增或者修改应用
  96. /// </summary>
  97. /// <param name="appCompany"></param>
  98. /// <returns></returns>
  99. [ProducesDefaultResponseType]
  100. [AuthToken(Roles = "assist,company")]
  101. [HttpPost("set-info")]
  102. public async Task<IActionResult> SetAppInfo(AppCompany appCompany)
  103. {
  104. try
  105. {
  106. var cosmosClient = _azureCosmos.GetCosmosClient();
  107. var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  108. StringBuilder stringBuilder = new($"{loginName}【{loginId}】");
  109. string type = "";
  110. //新建
  111. if (string.IsNullOrEmpty($"{appCompany.id}"))
  112. {
  113. appCompany.id = GenerateRandom.StrRandom(8, large: true, small: true);
  114. appCompany.code = $"App-{appCompany.code}";
  115. appCompany.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  116. appCompany.status = -1;
  117. appCompany.audit = -1;
  118. appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").CreateItemAsync<AppCompany>(appCompany, new PartitionKey(appCompany.code));
  119. stringBuilder.Append($"新增应用,应用ID:{appCompany.id},应用名称:{appCompany.name}");
  120. type = "appCompany-add";
  121. }
  122. //修改
  123. else
  124. {
  125. var response = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync(appCompany.id, new PartitionKey(appCompany.code));
  126. if (response.Status == 200)
  127. {
  128. appCompany.pk = "App";
  129. appCompany.ttl = -1;
  130. appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<AppCompany>(appCompany, appCompany.id, new PartitionKey(appCompany.code));
  131. stringBuilder.Append($"修改应用,应用ID:{appCompany.id},应用名称:{appCompany.name}");
  132. type = "appCompany-update";
  133. }
  134. else return Ok(new { state = 404, msg = "未找到该id相关的企业应用信息" });
  135. }
  136. //保存操作记录
  137. await _azureStorage.SaveBILog(type, stringBuilder.ToString(), _dingDing, httpContext: HttpContext);
  138. return Ok(new { state = 200, appCompany });
  139. }
  140. catch (Exception e)
  141. {
  142. await _dingDing.SendBotMsg($"BI,{_option.Location} , /appcompany/set-info \n {e.Message} \n {e.StackTrace}", GroupNames.成都开发測試群組);
  143. return BadRequest();
  144. }
  145. }
  146. /// <summary>
  147. /// 查询未审核的信息
  148. /// </summary>
  149. /// <param name="jsonElement"></param>
  150. /// <returns></returns>
  151. [ProducesDefaultResponseType]
  152. [HttpPost("get-noaudit")]
  153. public async Task<IActionResult> GetNoAudit(JsonElement jsonElement)
  154. {
  155. if(!jsonElement.TryGetProperty("operate", out JsonElement operate)) return BadRequest();
  156. var cosmosClient = _azureCosmos.GetCosmosClient();
  157. StringBuilder sqlTxt = new();
  158. switch (operate.GetString())
  159. {
  160. case "api":
  161. 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");
  162. break;
  163. case "school":
  164. 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");
  165. break;
  166. default:
  167. sqlTxt.Append($"select c.id,c.code,c.name,c.pk,c.audit from c where c.audit=-1 and c.pk='App'");
  168. break;
  169. }
  170. List<NoAudit> noAudits = new();
  171. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
  172. {
  173. var json = await JsonDocument.ParseAsync(item.ContentStream);
  174. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
  175. {
  176. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  177. {
  178. NoAudit noAudit = new();
  179. noAudit.id = obj.GetProperty("id").GetString();
  180. noAudit.code = obj.GetProperty("code").GetString();
  181. noAudit.pk = obj.GetProperty("pk").GetString();
  182. noAudit.name = obj.GetProperty("name").GetString();
  183. if (!string.IsNullOrEmpty($"{operate}"))
  184. {
  185. noAudit.operate = obj.GetProperty("operate").ToObject<List<object>>();
  186. }
  187. noAudit.audit = obj.GetProperty("audit").GetInt32();
  188. noAudits.Add(noAudit);
  189. }
  190. }
  191. }
  192. return Ok(new { state = 200, noAudits });
  193. }
  194. /// <summary>
  195. /// 审核应用是否通过
  196. /// </summary>
  197. /// <param name="jsonElement"></param>
  198. /// <returns></returns>
  199. [AuthToken(Roles = "assist")]
  200. [HttpPost("get-apply")]
  201. public async Task<IActionResult> SetAuditApp(JsonElement jsonElement)
  202. {
  203. try
  204. {
  205. if (!jsonElement.TryGetProperty("appIds", out JsonElement appIds)) return BadRequest();
  206. if (!jsonElement.TryGetProperty("isAudit", out JsonElement isAudit)) return BadRequest();
  207. jsonElement.TryGetProperty("refuseDesc", out JsonElement refuseDesc);
  208. var cosmosClient = _azureCosmos.GetCosmosClient();
  209. var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  210. StringBuilder strMsg = new($"{loginName}【{loginId}】");
  211. List<AppIdOrCode> idOrCode = appIds.ToObject<List<AppIdOrCode>>();
  212. List<AppIdOrCode> haveIds = new();
  213. if (idOrCode.Count > 0)
  214. {
  215. foreach (var idCode in idOrCode)
  216. {
  217. AppCompany appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AppCompany>(idCode.id, new PartitionKey(idCode.code));
  218. strMsg.Append($"审核应用{appCompany.name}【{appCompany.id}】,审核状态:");
  219. //var response = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync(idCode.id, new PartitionKey(idCode.code));
  220. if (bool.Parse($"{isAudit}") == true)
  221. {
  222. appCompany.audit = 1;
  223. strMsg.Append("通过。");
  224. }
  225. else
  226. {
  227. appCompany.audit = 0;
  228. appCompany.refuseDesc = $"{refuseDesc}";
  229. strMsg.Append("失败。");
  230. }
  231. try
  232. {
  233. await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<AppCompany>(appCompany, appCompany.id, new PartitionKey(idCode.code));
  234. }
  235. catch
  236. {
  237. haveIds.Add(idCode);
  238. strMsg.Append($"异常:id:{idCode.id},code:{idCode.code};");
  239. }
  240. }
  241. }
  242. else return Ok(new { state = 404, msg = "appIds参数错误" });
  243. //保存操作记录
  244. await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
  245. if (haveIds.Count > 0)
  246. return Ok(new { state = 201, msg = "部分应用审核失败!", haveIds });
  247. else return Ok(new { state = 200 });
  248. }
  249. catch (Exception e)
  250. {
  251. await _dingDing.SendBotMsg($"BI,{_option.Location} , /appcompany/get-applyapi \n {e.Message} \n {e.StackTrace}", GroupNames.成都开发測試群組);
  252. return BadRequest();
  253. }
  254. }
  255. /// <summary>
  256. /// 应用申请Api接口信息
  257. /// 审核应用api接口信息
  258. /// </summary>
  259. /// <param name="jsonElement"></param>
  260. /// <returns></returns>
  261. [ProducesDefaultResponseType]
  262. [AuthToken(Roles = "assist,company")]
  263. [HttpPost("set-applyapi")]
  264. public async Task<IActionResult> SetApplyApi(JsonElement jsonElement)
  265. {
  266. try
  267. {
  268. if (!jsonElement.TryGetProperty("applyApis", out JsonElement jsApplyApis)) return BadRequest();
  269. if (!jsonElement.TryGetProperty("operate", out JsonElement operate)) return BadRequest();
  270. var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  271. StringBuilder strMsg = new($"{loginName}【{loginId}】");
  272. var cosmosClient = _azureCosmos.GetCosmosClient();
  273. string bizcode = ""; //消息名称
  274. List<string> sendWhom = new();//消息分发给谁 待完善
  275. List<ApplyApi> applyApis = jsApplyApis.ToObject<List<ApplyApi>>();
  276. List<ApplyApi> haveApi = new(); //存在api接口
  277. Dictionary<string,string> noAudit = new();
  278. foreach (var tempApp in applyApis)
  279. {
  280. AppCompany appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AppCompany>($"{tempApp.appId}", new PartitionKey($"{tempApp.appCode}"));
  281. if (appCompany != null || appCompany.audit != -1 || appCompany.audit != 0)
  282. {
  283. switch (operate.GetString())
  284. {
  285. case "apply":
  286. strMsg.Append($"申请:{appCompany.name}【{appCompany.id}】应用的Api:");
  287. if (!jsonElement.TryGetProperty("applyDesc", out JsonElement applyDesc)) return BadRequest();
  288. tempApp.apiIds.ForEach(x =>
  289. {
  290. var strt = appCompany.apis.Find(y => y.no.Equals($"{x}"));
  291. if (strt == null)
  292. {
  293. appCompany.apis.Add(new AppApiState() { no = $"{x}", applyDesc = $"{applyDesc}", status = -1 });
  294. strMsg.Append($"{x},");
  295. }
  296. else haveApi.Add(tempApp);
  297. });
  298. sendWhom.Add(appCompany.id);
  299. bizcode = "applyapi";
  300. if (haveApi.Count > 0) strMsg.Append($"已有存在的api:{haveApi.ToJsonString()}。");
  301. break;
  302. case "audit":
  303. if (!jsonElement.TryGetProperty("isAudit", out JsonElement isAudit)) return BadRequest();
  304. string refuseDesc = "";
  305. if (bool.Parse($"{isAudit}") == false)
  306. {
  307. if (!jsonElement.TryGetProperty("refuseDesc", out JsonElement jsonRefuseDesc)) return BadRequest();
  308. refuseDesc = jsonRefuseDesc.GetString();
  309. }
  310. strMsg.Append($"审核{appCompany.name}【{appCompany.id}】应用的Api:");
  311. tempApp.apiIds.ForEach(x =>
  312. {
  313. var temp = appCompany.apis.Find(n => n.no == x);
  314. if (temp != null)
  315. {
  316. AppApiState appApiState = appCompany.apis.Single(a => a.no == x);
  317. if (bool.Parse($"{isAudit}") == true)
  318. {
  319. appApiState.status = 1;
  320. appApiState.refuseDesc = null;
  321. strMsg.Append($"{appApiState.no}通过,");
  322. }
  323. else
  324. {
  325. appApiState.status = 0;
  326. appApiState.refuseDesc = $"{refuseDesc}";
  327. strMsg.Append($"{appApiState.no}失败,");
  328. }
  329. }
  330. else haveApi.Add(tempApp);
  331. });
  332. if (haveApi.Count > 0) strMsg.Append($"该应用没有申请相关API接口:{haveApi.ToJsonString()}。");
  333. sendWhom.Add(appCompany.id);
  334. bizcode = "auditapi";
  335. break;
  336. default:
  337. return Ok(new { state = 400, msg = "operate参数错误" });
  338. }
  339. appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<AppCompany>(appCompany, appCompany.id, new PartitionKey(appCompany.code));
  340. }
  341. else noAudit.Add($"{appCompany.id}", $"{appCompany.name}");
  342. }
  343. //发送消息
  344. var location = _option.Location;
  345. Notification notification = new()
  346. {
  347. hubName = bizcode,
  348. type = "msg",
  349. from = $"BI:{_option.Location}:private",
  350. to = sendWhom,
  351. label = $"{bizcode}-appCompany",
  352. body = new { location = location, biz = bizcode, appid = sendWhom, appName = sendWhom, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
  353. };
  354. var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
  355. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  356. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  357. await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
  358. //保存操作记录
  359. await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
  360. if (haveApi.Count > 0 || noAudit.Count > 0)
  361. return Ok(new { state = 201, msg = "部分成功", haveApi, noAudit });
  362. else return Ok(new { state = 200 });
  363. }
  364. catch (Exception e)
  365. {
  366. await _dingDing.SendBotMsg($"BI,{_option.Location} , /appcompany/get-applyapi \n {e.Message} \n {e.StackTrace}", GroupNames.成都开发測試群組);
  367. return BadRequest();
  368. }
  369. }
  370. /// <summary>
  371. /// 应用申请学校
  372. /// 应用审核申请的学校
  373. /// </summary>
  374. /// <param name="jsonElement"></param>
  375. /// <returns></returns>
  376. [ProducesDefaultResponseType]
  377. [AuthToken(Roles = "assist,company")]
  378. [HttpPost("set-applyschool")]
  379. public async Task<IActionResult> SetAuditSchool(JsonElement jsonElement)
  380. {
  381. try
  382. {
  383. if (!jsonElement.TryGetProperty("appId", out JsonElement appId)) return BadRequest();
  384. if (!jsonElement.TryGetProperty("appCode", out JsonElement appCode)) return BadRequest();
  385. if (!jsonElement.TryGetProperty("schooCode", out JsonElement schooCode)) return BadRequest();
  386. if (!jsonElement.TryGetProperty("operate", out JsonElement operate)) return BadRequest();
  387. var cosmosClient = _azureCosmos.GetCosmosClient();
  388. var (loginId, loginName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  389. StringBuilder strMsg = new($"{loginName}【{loginId}】操作:");
  390. List<string> haveSchool = new();
  391. List<string> sendWhom = new();//消息分发给谁 待完善
  392. string bizcode = ""; //消息名称
  393. AppCompany appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AppCompany>($"{appId}", new PartitionKey($"{appCode}"));
  394. if (appCompany.audit == -1 || appCompany.audit == 0)
  395. {
  396. return Ok(new { state = 401, msg = "应用未审核请先审核应用程序" });
  397. }
  398. if (appCompany != null)
  399. {
  400. switch (operate.GetString())
  401. {
  402. case "apply":
  403. var aSchool = appCompany.schools.Find(x => x.id.Equals($"{schooCode}"));
  404. if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
  405. if (aSchool == null)
  406. {
  407. jsonElement.TryGetProperty("picture", out JsonElement picture);
  408. strMsg.Append($"应用{appCompany.name}【{appCompany.id}】申请学校{name}【{schooCode}】,申请成功。");
  409. appCompany.schools.Add(new ApplySchool() { id = $"{schooCode}", name = $"{name}", picture = $"{picture}" });
  410. }
  411. else
  412. {
  413. haveSchool.Add(schooCode.GetString());
  414. strMsg.Append($"应用{appCompany.name}【{appCompany.id}】申请的学校{name}【{schooCode}】已存在。");
  415. }
  416. sendWhom = new List<string> { "1528783103", "1636016499" };
  417. bizcode = "applyschool";
  418. break;
  419. case "audit":
  420. if (!jsonElement.TryGetProperty("isAudit", out JsonElement isAudit)) return BadRequest();
  421. string refuseDesc = "";
  422. if (bool.Parse($"{isAudit}") == false)
  423. {
  424. if (!jsonElement.TryGetProperty("refuseDesc", out JsonElement jsonRefuseDesc)) return BadRequest();
  425. refuseDesc = jsonRefuseDesc.GetString();
  426. }
  427. var applySchool = appCompany.schools.Find(x => x.id.Equals($"{schooCode}"));
  428. strMsg.Append($"审核应用{appCompany.name}【{appCompany.id}】状态:");
  429. if (applySchool != null)
  430. {
  431. if (bool.Parse($"{isAudit}") == true)
  432. {
  433. applySchool.status = 1;
  434. applySchool.refuseDesc = null;
  435. strMsg.Append($"审核成功。");
  436. }
  437. else
  438. {
  439. applySchool.status = 0;
  440. applySchool.refuseDesc = $"{refuseDesc}";
  441. strMsg.Append($"审核失败。");
  442. }
  443. }
  444. else
  445. {
  446. haveSchool.Add(schooCode.GetString());
  447. strMsg.Append($"已审核状态!");
  448. }
  449. sendWhom = new List<string> { "1528783103", "1636016499" };
  450. bizcode = "auditschool";
  451. break;
  452. default:
  453. return Ok(new { state = 400, msg = "operate参数错误" });
  454. }
  455. appCompany = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReplaceItemAsync<AppCompany>(appCompany, appCompany.id, new PartitionKey(appCompany.code));
  456. }
  457. else return Ok(new { state = 404, msg = "未找到该应用" });
  458. //发送消息
  459. var location = _option.Location;
  460. Notification notification = new()
  461. {
  462. hubName = bizcode,
  463. type = "msg",
  464. from = $"BI:{_option.Location}:private",
  465. to = sendWhom,
  466. label = $"{bizcode}-appCompany",
  467. body = new { location = location, biz = bizcode, appid = appCompany.id, appName = appCompany.name, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
  468. };
  469. var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
  470. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  471. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  472. await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
  473. //保存操作记录
  474. await _azureStorage.SaveBILog("appCompany-update", strMsg.ToString(), _dingDing, httpContext: HttpContext);
  475. if (haveSchool.Count > 0) return Ok(new { state = 201, msg = "已存在学校,无须申请!", haveSchool });
  476. else return Ok(new { state = 200 });
  477. }
  478. catch (Exception e)
  479. {
  480. await _dingDing.SendBotMsg($"BI,{_option.Location} , /appcompany/set-auditschool \n {e.Message} \n {e.StackTrace}", GroupNames.成都开发測試群組);
  481. return BadRequest();
  482. }
  483. }
  484. /// <summary>
  485. /// 应用申请和审核api信息
  486. /// </summary>
  487. public record ApplyApi
  488. {
  489. public string appId { get; set; }
  490. public string appCode { get; set; }
  491. public List<string> apiIds { get; set; }
  492. }
  493. /// <summary>
  494. /// 审核应用
  495. /// </summary>
  496. public record AppIdOrCode
  497. {
  498. public string id { get; set; }
  499. public string code { get; set; }
  500. }
  501. public record NoAudit
  502. {
  503. public string id { get; set; }
  504. public string code { get; set; }
  505. public string pk { get; set; }
  506. public string name { get;set; }
  507. public List<object> operate { get; set; }
  508. public int audit { get; set; }
  509. }
  510. /// <summary>
  511. /// 显示应用
  512. /// </summary>
  513. public record ReadCompany
  514. {
  515. public string id { get; set; }
  516. public string pk { get; set; }
  517. public string code { get; set; }
  518. public string name { get; set; }
  519. public string descr { get; set; }
  520. public string picture { get; set; }
  521. public string jwtKey { get; set; }
  522. public int status { get; set; }
  523. public int audit { get; set; }
  524. public string refuseDesc { get; set; }
  525. public string gateways { get; set; }
  526. public List<AppApiState> apis { get; set; }
  527. public string webhookDomain { get; set; }
  528. public List<WebHookState> webHooks { get; set; }
  529. public List<ApplySchool> schools { get; set; }
  530. }
  531. }
  532. }