Ies5TestController.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using Azure.Messaging.ServiceBus;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.Options;
  7. using StackExchange.Redis;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Net.Http;
  11. using System.Text.Json;
  12. using System.Threading.Tasks;
  13. using TEAMModelBI.Tool;
  14. using TEAMModelOS.Models;
  15. using TEAMModelOS.SDK;
  16. using TEAMModelOS.SDK.DI;
  17. using TEAMModelOS.SDK.Extension;
  18. using TEAMModelOS.SDK.Models;
  19. using TEAMModelOS.SDK.Models.Cosmos.Teacher;
  20. using TEAMModelOS.SDK.Models.Service;
  21. using static TEAMModelOS.SDK.Models.Teacher;
  22. namespace TEAMModelBI.Controllers.BITest
  23. {
  24. [Route("ies5test")]
  25. [ApiController]
  26. public class Ies5TestController : ControllerBase
  27. {
  28. private readonly AzureCosmosFactory _azureCosmos;
  29. private readonly AzureRedisFactory _azureRedis;
  30. private readonly AzureServiceBusFactory _serviceBus;
  31. private readonly DingDing _dingDing;
  32. private readonly Option _option;
  33. private readonly AzureStorageFactory _azureStorage;
  34. private readonly IWebHostEnvironment _environment; //读取文件
  35. //读取配置文件
  36. private readonly IConfiguration _configuration;
  37. private readonly CoreAPIHttpService _coreAPIHttpService;
  38. private readonly HttpClient _httpClient;
  39. public Ies5TestController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, HttpClient httpClient)
  40. {
  41. _azureCosmos = azureCosmos;
  42. _dingDing = dingDing;
  43. _azureStorage = azureStorage;
  44. _option = option?.Value;
  45. _environment = hostingEnvironment;
  46. _configuration = configuration;
  47. _coreAPIHttpService = coreAPIHttpService;
  48. _httpClient = httpClient;
  49. _azureRedis = azureRedis;
  50. }
  51. [HttpPost("get-datetime")]
  52. public async Task<IActionResult> GetDateTime()
  53. {
  54. var dateHours = DateTimeOffset.UtcNow.Hour;
  55. var dateHours1 = DateTime.Now.Hour;
  56. var dateHours2 = DateTimeOffset.Now.Hour;
  57. var dateDays = DateTimeOffset.UtcNow.Month;
  58. var dateDay = DateTimeOffset.UtcNow.ToString("yyyyMMdd");
  59. var dateMonth = DateTimeOffset.UtcNow.ToString("yyyyMM");
  60. long expire = DateTimeOffset.UtcNow.AddHours(1).ToUnixTimeSeconds();
  61. long now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
  62. var cosmosClient = _azureCosmos.GetCosmosClient();
  63. //在线记录
  64. List<LoginInfo> loginInfos = new() { new LoginInfo() { time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), ip = "172.54.81.101", expire = expire } };
  65. //var tets = await LoginService.DoLoginInfo(loginInfos: loginInfos, school: "hbcn", scope: "teacher", id: "1636016499", ip: "172.168.52.102", _azureRedis, _azureStorage, expire: 1);
  66. OnLinRec olrec = new() { id = "1636016499", scope = Constant.ScopeTeacher, ip = "172.168.52.102", school = "hbcn", expire = 1 };
  67. var messageBatchCopyFile = new ServiceBusMessage(olrec.ToJsonString());
  68. messageBatchCopyFile.ApplicationProperties.Add("name", "OnLinRecord"); //Function名称
  69. var onlinRecTask = _configuration.GetValue<string>("Azue:ServiceBus:OnlinRecord");
  70. await _serviceBus.GetServiceBusClient().SendMessageAsync(onlinRecTask, messageBatchCopyFile);
  71. return Ok(new { state = 200, dateHours, dateHours1, dateHours2, dateDay, dateDays, dateMonth, });
  72. }
  73. [HttpPost("get-fmember")]
  74. public async Task<IActionResult> GetFMember(JsonElement jsonElement)
  75. {
  76. var cosmosClient = _azureCosmos.GetCosmosClient();
  77. if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
  78. if (!jsonElement.TryGetProperty("code", out JsonElement code)) return BadRequest();
  79. if (!jsonElement.TryGetProperty("actType", out JsonElement actType)) return BadRequest();
  80. List<string> classes = new();
  81. List<string> stuLists = new();
  82. List<string> tchLists = new();
  83. List<(string pId, List<string> gid)> ps = new();
  84. string school = null;
  85. if ($"{actType}".Equals("Study"))
  86. {
  87. Study study = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Study>($"{id}", new Azure.Cosmos.PartitionKey($"Study-{code}"));
  88. if (study.groupLists.Count > 0)
  89. {
  90. var group = study.groupLists;
  91. foreach (var gp in group)
  92. {
  93. foreach (KeyValuePair<string, List<string>> pp in gp)
  94. {
  95. ps.Add((pp.Key, pp.Value));
  96. }
  97. }
  98. }
  99. classes = study.classes;
  100. stuLists = study.stuLists;
  101. tchLists = study.tchLists;
  102. school = study.school;
  103. }
  104. else if ($"{actType}".Equals("Vote"))
  105. {
  106. Vote vote = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>($"{id}", new Azure.Cosmos.PartitionKey($"Vote-{code}"));
  107. classes = vote.classes;
  108. stuLists = vote.stuLists;
  109. tchLists = vote.tchLists;
  110. school = vote.school;
  111. }
  112. else if ($"{actType}".Equals("Homework"))
  113. {
  114. Homework work = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Homework>($"{id}", new Azure.Cosmos.PartitionKey($"Homework-{code}"));
  115. classes = work.classes;
  116. stuLists = work.stuLists;
  117. tchLists = work.tchLists;
  118. school = work.school;
  119. }
  120. else if ($"{actType}".Equals("Survey"))
  121. {
  122. Survey survey = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>($"{id}", new Azure.Cosmos.PartitionKey($"Survey-{code}"));
  123. classes = survey.classes;
  124. stuLists = survey.stuLists;
  125. tchLists = survey.tchLists;
  126. school = survey.school;
  127. }
  128. else if ($"{actType}".Equals("ExamLite"))
  129. {
  130. ExamLite examLite = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamLite>($"{id}", new Azure.Cosmos.PartitionKey($"ExamLite-{code}"));
  131. classes = examLite.classes;
  132. stuLists = examLite.stuLists;
  133. tchLists = examLite.tchLists;
  134. school = examLite.school;
  135. }
  136. else if ($"{actType}".Equals("Exam"))
  137. {
  138. ExamInfo examInfo = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>($"{id}", new Azure.Cosmos.PartitionKey($"ExamLite-{code}"));
  139. classes = examInfo.classes;
  140. stuLists = examInfo.stuLists;
  141. school = examInfo.school;
  142. }
  143. List<FMember> idsList = await GroupListService.GetFinishMemberInfo(_coreAPIHttpService, cosmosClient, _dingDing, school, classes, stuLists, tchLists, ps);
  144. return Ok(new { state = 200, idsList });
  145. }
  146. }
  147. }