Ies5TestController.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 IHttpClientFactory _httpClient;
  39. public Ies5TestController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, IHttpClientFactory 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. ExamInfo examInfo = new();
  81. ExamLite examLite = new();
  82. Survey survey = new();
  83. Homework work = new();
  84. Vote vote = new();
  85. Study study = new();
  86. object showAct = new();
  87. List<string> classes = new();
  88. List<string> stuLists = new();
  89. List<string> tchLists = new();
  90. List<(string pId, List<string> gid)> ps = new();
  91. string school = null;
  92. if ($"{actType}".Equals("Study"))
  93. {
  94. study = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Study>($"{id}", new PartitionKey($"Study-{code}"));
  95. if (study.groupLists.Count > 0)
  96. {
  97. var group = study.groupLists;
  98. foreach (var gp in group)
  99. {
  100. foreach (KeyValuePair<string, List<string>> pp in gp)
  101. {
  102. ps.Add((pp.Key, pp.Value));
  103. }
  104. }
  105. }
  106. classes = study.classes;
  107. stuLists = study.stuLists;
  108. tchLists = study.tchLists;
  109. school = study.school;
  110. }
  111. else if ($"{actType}".Equals("Vote"))
  112. {
  113. vote = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>($"{id}", new PartitionKey($"Vote-{code}"));
  114. classes = vote.classes;
  115. stuLists = vote.stuLists;
  116. tchLists = vote.tchLists;
  117. school = vote.school;
  118. }
  119. else if ($"{actType}".Equals("Homework"))
  120. {
  121. work = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Homework>($"{id}", new PartitionKey($"Homework-{code}"));
  122. classes = work.classes;
  123. stuLists = work.stuLists;
  124. tchLists = work.tchLists;
  125. school = work.school;
  126. }
  127. else if ($"{actType}".Equals("Survey"))
  128. {
  129. survey = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>($"{id}", new PartitionKey($"Survey-{code}"));
  130. classes = survey.classes;
  131. stuLists = survey.stuLists;
  132. tchLists = survey.tchLists;
  133. school = survey.school;
  134. }
  135. else if ($"{actType}".Equals("ExamLite"))
  136. {
  137. examLite = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamLite>($"{id}", new PartitionKey($"ExamLite-{code}"));
  138. classes = examLite.classes;
  139. stuLists = examLite.stuLists;
  140. tchLists = examLite.tchLists;
  141. school = examLite.school;
  142. }
  143. else if ($"{actType}".Equals("Exam"))
  144. {
  145. examInfo = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>($"{id}", new PartitionKey($"Exam-{code}"));
  146. classes = examInfo.classes;
  147. stuLists = examInfo.stuLists;
  148. school = examInfo.school;
  149. }
  150. List<FMember> idsList = await GroupListService.GetFinishMemberInfo(_coreAPIHttpService, cosmosClient, _dingDing, school, classes, stuLists, tchLists, ps);
  151. if ($"{actType}".Equals("Study"))
  152. {
  153. study.staffIds = idsList;
  154. study = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Study>(study, study.id, new PartitionKey($"Study-{code}"));
  155. showAct = study;
  156. }
  157. else if ($"{actType}".Equals("Vote"))
  158. {
  159. vote.staffIds = idsList;
  160. vote = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Vote>(vote, vote.id, new PartitionKey($"Vote-{code}"));
  161. showAct = vote;
  162. }
  163. else if ($"{actType}".Equals("Homework"))
  164. {
  165. work.staffIds = idsList;
  166. work = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Homework>(work, work.id, new PartitionKey($"Homework-{code}"));
  167. showAct = work;
  168. }
  169. else if ($"{actType}".Equals("Survey"))
  170. {
  171. survey.staffIds = idsList;
  172. survey = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Survey>(survey, survey.id, new PartitionKey($"Survey-{code}"));
  173. showAct = work;
  174. }
  175. else if ($"{actType}".Equals("ExamLite"))
  176. {
  177. examLite.staffIds = idsList;
  178. examLite = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<ExamLite>(examLite, examLite.id, new PartitionKey($"ExamLite-{code}"));
  179. showAct = work;
  180. }
  181. else if ($"{actType}".Equals("Exam"))
  182. {
  183. examInfo.staffIds = idsList;
  184. examInfo = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<ExamInfo>(examInfo, examInfo.id, new PartitionKey($"Exam-{code}"));
  185. showAct = work;
  186. }
  187. return Ok(new { state = 200, showAct, idsList });
  188. }
  189. }
  190. }