StudyController.cs 4.5 KB

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