123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- using Azure.Messaging.ServiceBus;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Azure.Cosmos;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Options;
- using StackExchange.Redis;
- using System;
- using System.Collections.Generic;
- using System.Net.Http;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelBI.Tool;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos.Teacher;
- using TEAMModelOS.SDK.Models.Service;
- using static TEAMModelOS.SDK.Models.Teacher;
- namespace TEAMModelBI.Controllers.BITest
- {
- [Route("ies5test")]
- [ApiController]
- public class Ies5TestController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly AzureRedisFactory _azureRedis;
- private readonly AzureServiceBusFactory _serviceBus;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureStorageFactory _azureStorage;
- private readonly IWebHostEnvironment _environment; //读取文件
- //读取配置文件
- private readonly IConfiguration _configuration;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly IHttpClientFactory _httpClient;
- public Ies5TestController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, IHttpClientFactory httpClient)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _azureStorage = azureStorage;
- _option = option?.Value;
- _environment = hostingEnvironment;
- _configuration = configuration;
- _coreAPIHttpService = coreAPIHttpService;
- _httpClient = httpClient;
- _azureRedis = azureRedis;
- }
- [HttpPost("get-datetime")]
- public async Task<IActionResult> GetDateTime()
- {
- var dateHours = DateTimeOffset.UtcNow.Hour;
- var dateHours1 = DateTime.Now.Hour;
- var dateHours2 = DateTimeOffset.Now.Hour;
- var dateDays = DateTimeOffset.UtcNow.Month;
- var dateDay = DateTimeOffset.UtcNow.ToString("yyyyMMdd");
- var dateMonth = DateTimeOffset.UtcNow.ToString("yyyyMM");
- long expire = DateTimeOffset.UtcNow.AddHours(1).ToUnixTimeSeconds();
- long now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
- var cosmosClient = _azureCosmos.GetCosmosClient();
- //在线记录
- List<LoginInfo> loginInfos = new() { new LoginInfo() { time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), ip = "172.54.81.101", expire = expire } };
- //var tets = await LoginService.DoLoginInfo(loginInfos: loginInfos, school: "hbcn", scope: "teacher", id: "1636016499", ip: "172.168.52.102", _azureRedis, _azureStorage, expire: 1);
- OnLinRec olrec = new() { id = "1636016499", scope = Constant.ScopeTeacher, ip = "172.168.52.102", school = "hbcn", expire = 1 };
- var messageBatchCopyFile = new ServiceBusMessage(olrec.ToJsonString());
- messageBatchCopyFile.ApplicationProperties.Add("name", "OnLinRecord"); //Function名称
- var onlinRecTask = _configuration.GetValue<string>("Azue:ServiceBus:OnlinRecord");
- // await _serviceBus.GetServiceBusClient().SendMessageAsync(onlinRecTask, messageBatchCopyFile);
- return Ok(new { state = 200, dateHours, dateHours1, dateHours2, dateDay, dateDays, dateMonth, });
- }
- [HttpPost("get-fmember")]
- public async Task<IActionResult> GetFMember(JsonElement jsonElement)
- {
- var cosmosClient = _azureCosmos.GetCosmosClient();
- if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!jsonElement.TryGetProperty("code", out JsonElement code)) return BadRequest();
- if (!jsonElement.TryGetProperty("actType", out JsonElement actType)) return BadRequest();
- ExamInfo examInfo = new();
- ExamLite examLite = new();
- Survey survey = new();
- Homework work = new();
- Vote vote = new();
- Study study = new();
- object showAct = new();
- List<string> classes = new();
- List<string> stuLists = new();
- List<string> tchLists = new();
- List<(string pId, List<string> gid)> ps = new();
- string school = null;
- if ($"{actType}".Equals("Study"))
- {
- study = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Study>($"{id}", new PartitionKey($"Study-{code}"));
- if (study.groupLists.Count > 0)
- {
- var group = study.groupLists;
- foreach (var gp in group)
- {
- foreach (KeyValuePair<string, List<string>> pp in gp)
- {
- ps.Add((pp.Key, pp.Value));
- }
- }
- }
- classes = study.classes;
- stuLists = study.stuLists;
- tchLists = study.tchLists;
- school = study.school;
- }
- else if ($"{actType}".Equals("Vote"))
- {
- vote = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>($"{id}", new PartitionKey($"Vote-{code}"));
- classes = vote.classes;
- stuLists = vote.stuLists;
- tchLists = vote.tchLists;
- school = vote.school;
- }
- else if ($"{actType}".Equals("Homework"))
- {
- work = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Homework>($"{id}", new PartitionKey($"Homework-{code}"));
- classes = work.classes;
- stuLists = work.stuLists;
- tchLists = work.tchLists;
- school = work.school;
- }
- else if ($"{actType}".Equals("Survey"))
- {
- survey = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>($"{id}", new PartitionKey($"Survey-{code}"));
- classes = survey.classes;
- stuLists = survey.stuLists;
- tchLists = survey.tchLists;
- school = survey.school;
- }
- else if ($"{actType}".Equals("ExamLite"))
- {
- examLite = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamLite>($"{id}", new PartitionKey($"ExamLite-{code}"));
- classes = examLite.classes;
- stuLists = examLite.stuLists;
- tchLists = examLite.tchLists;
- school = examLite.school;
- }
- else if ($"{actType}".Equals("Exam"))
- {
- examInfo = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>($"{id}", new PartitionKey($"Exam-{code}"));
- classes = examInfo.classes;
- stuLists = examInfo.stuLists;
- school = examInfo.school;
- }
- List<FMember> idsList = await GroupListService.GetFinishMemberInfo(_coreAPIHttpService, cosmosClient, _dingDing, school, classes, stuLists, tchLists, ps);
- if ($"{actType}".Equals("Study"))
- {
- study.staffIds = idsList;
- study = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Study>(study, study.id, new PartitionKey($"Study-{code}"));
- showAct = study;
- }
- else if ($"{actType}".Equals("Vote"))
- {
- vote.staffIds = idsList;
- vote = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Vote>(vote, vote.id, new PartitionKey($"Vote-{code}"));
- showAct = vote;
- }
- else if ($"{actType}".Equals("Homework"))
- {
- work.staffIds = idsList;
- work = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Homework>(work, work.id, new PartitionKey($"Homework-{code}"));
- showAct = work;
- }
- else if ($"{actType}".Equals("Survey"))
- {
- survey.staffIds = idsList;
- survey = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Survey>(survey, survey.id, new PartitionKey($"Survey-{code}"));
- showAct = work;
- }
- else if ($"{actType}".Equals("ExamLite"))
- {
- examLite.staffIds = idsList;
- examLite = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<ExamLite>(examLite, examLite.id, new PartitionKey($"ExamLite-{code}"));
- showAct = work;
- }
- else if ($"{actType}".Equals("Exam"))
- {
- examInfo.staffIds = idsList;
- examInfo = await cosmosClient.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<ExamInfo>(examInfo, examInfo.id, new PartitionKey($"Exam-{code}"));
- showAct = work;
- }
- return Ok(new { state = 200, showAct, idsList });
- }
- }
- }
|