StudyController.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using Azure.Cosmos;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.Extensions.Options;
  5. using System.Collections.Generic;
  6. using System.Text.Json;
  7. using System.Threading.Tasks;
  8. using TEAMModelBI.Tool;
  9. using TEAMModelOS.Models;
  10. using TEAMModelOS.SDK.DI;
  11. using TEAMModelOS.SDK.Models;
  12. namespace TEAMModelBI.Controllers.Census
  13. {
  14. [Route("study")]
  15. [ApiController]
  16. public class StudyController : ControllerBase
  17. {
  18. private readonly AzureCosmosFactory _azureCosmos;
  19. private readonly AzureStorageFactory _azureStorage;
  20. private readonly DingDing _dingDing;
  21. private readonly Option _option;
  22. public StudyController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option)
  23. {
  24. _azureCosmos = azureCosmos;
  25. _azureStorage = azureStorage;
  26. _dingDing = dingDing;
  27. _option = option?.Value;
  28. }
  29. /// <summary>
  30. /// 统计区级线上研修
  31. /// </summary>
  32. /// <param name="jsonElement"></param>
  33. /// <returns></returns>
  34. [HttpPost("get-area")]
  35. public async Task<IActionResult> GetArea(JsonElement jsonElement)
  36. {
  37. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  38. int onLineCount = 0; //线上研修人数
  39. int offlineCount = 0; //线下研修人数
  40. int classRoomCount = 0; //课堂实录人数
  41. int submitCount = 0; //认证材料人数
  42. int fulfilCount = 0; //已完成
  43. int carryOnCount = 0; //进行中
  44. int noCount = 0; //未开始
  45. List<TeacherTrain> trains = new();
  46. var cosmosClient = _azureCosmos.GetCosmosClient();
  47. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.areaId='{areaId}'", "Base");
  48. AreaSetting setting = null;
  49. try
  50. {
  51. setting = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AreaSetting>($"{areaId}", new PartitionKey("AreaSetting"));
  52. }
  53. catch (CosmosException)
  54. {
  55. setting = null;
  56. }
  57. if (setting == null)
  58. {
  59. setting = new AreaSetting
  60. {
  61. allTime = 50,
  62. classTime = 5,
  63. submitTime = 15,
  64. onlineTime = 20,
  65. offlineTime = 10,
  66. lessonMinutes = 45,
  67. };
  68. }
  69. foreach (var schoolId in schoolIds)
  70. {
  71. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher")
  72. .GetItemQueryIterator<TeacherTrain>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{schoolId}") }))
  73. {
  74. trains.Add(item);
  75. }
  76. }
  77. trains.ForEach(x =>
  78. {
  79. //线上研修
  80. if (x.onlineTime == 0) onLineCount++; else if (x.onlineTime >= setting.onlineTime) onLineCount++; else onLineCount++;
  81. //线下研修
  82. if (x.offlineTime == 0) offlineCount++; else if (x.onlineTime >= setting.offlineTime) offlineCount++; else offlineCount++;
  83. //课堂实录
  84. if (x.classTime == 0) classRoomCount++; else if (x.classTime >= setting.classTime) classRoomCount++; else classRoomCount++;
  85. //认证材料
  86. if (x.currency.submitTime == 0) submitCount++; else if (x.currency.submitTime >= setting.submitTime) submitCount++; else submitCount++;
  87. if (x.currency.submitTime == 0 && x.classTime == 0 && x.offlineTime == 0 && x.onlineTime == 0) noCount++;
  88. else if (x.currency.submitTime >= setting.submitTime && x.classTime >= setting.classTime && x.onlineTime >= setting.offlineTime && x.onlineTime >= setting.onlineTime) fulfilCount++;
  89. else carryOnCount++;
  90. });
  91. return Ok(new { state = 200, onLineCount, offlineCount, classRoomCount, submitCount, fulfilCount, carryOnCount, noCount });
  92. }
  93. }
  94. }