Ies5TestController.cs 9.5 KB

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