LessonService.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Azure.Cosmos;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Text.Json;
  6. using System.Threading.Tasks;
  7. using TEAMModelOS.SDK.DI;
  8. using TEAMModelOS.SDK.Extension;
  9. using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
  10. using TEAMModelOS.SDK.Models.Cosmos.Common;
  11. namespace TEAMModelOS.SDK.Models.Service
  12. {
  13. public class LessonService
  14. {
  15. /// <summary>
  16. ///
  17. /// </summary>
  18. /// <param name="client"></param>
  19. /// <param name="_dingDing"></param>
  20. /// <param name="data"></param>
  21. /// <returns></returns>
  22. public static LessonDis DisLessonCount( LessonRecord oldRecord, LessonRecord newRecord ) {
  23. //P分数量加减
  24. LessonDis lessonDis = new LessonDis();
  25. if (oldRecord.pScore >= 70)
  26. {
  27. if (newRecord.pScore < 70)
  28. {
  29. lessonDis. disPCount = -1;
  30. }
  31. }
  32. else
  33. {
  34. if (newRecord.pScore >= 70)
  35. {
  36. lessonDis.disPCount = 1;
  37. }
  38. }
  39. //T分数量加减
  40. if (oldRecord.tScore >= 70)
  41. {
  42. if (newRecord.tScore < 70)
  43. {
  44. lessonDis.disTCount = -1;
  45. }
  46. }
  47. else
  48. {
  49. if (newRecord.tScore >= 70)
  50. {
  51. lessonDis.disTCount = 1;
  52. }
  53. }
  54. //双绿灯数量
  55. if (oldRecord.tScore >= 70 && oldRecord.pScore >= 70)
  56. {
  57. if (newRecord.tScore < 70 || newRecord.pScore < 70)
  58. {
  59. lessonDis.disDCount = -1;
  60. }
  61. }
  62. else
  63. {
  64. if (newRecord.tScore >= 70 && newRecord.pScore >= 70)
  65. {
  66. lessonDis.disDCount = 1;
  67. }
  68. }
  69. return lessonDis;
  70. }
  71. public static async Task FixLessonCount(CosmosClient client, DingDing _dingDing, LessonRecord data)
  72. {
  73. try
  74. {
  75. int day = DateTimeOffset.FromUnixTimeMilliseconds(data.startTime).DayOfYear;
  76. int year = DateTimeOffset.FromUnixTimeMilliseconds(data.startTime).Year;
  77. int days = DateTimeHelper.getDays(year);
  78. //int years = DateTimeOffset.UtcNow.DayOfYear;
  79. string tbname = string.Empty;
  80. string code = string.Empty;
  81. if (data.scope.Equals("school"))
  82. {
  83. code = $"LessonCount-{data.school}";
  84. tbname = "School";
  85. }
  86. else
  87. {
  88. code = $"LessonCount";
  89. tbname = "Teacher";
  90. }
  91. var response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(data.id.ToString(), new PartitionKey(code));
  92. if (response.Status == 200)
  93. {
  94. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  95. LessonCount count = json.ToObject<LessonCount>();
  96. if (count.courseIds.Count > 0)
  97. {
  98. if (!count.courseIds.Contains(data.courseId))
  99. {
  100. count.courseIds.Add(data.courseId);
  101. count.beginCount[day] += 1;
  102. }
  103. }
  104. await client.GetContainer("TEAMModelOS", tbname).ReplaceItemAsync(count, count.id, new PartitionKey(code));
  105. }
  106. else
  107. {
  108. LessonCount count = new LessonCount
  109. {
  110. id = data.tmdid,
  111. code = code,
  112. year = year
  113. };
  114. double[] da = new double[days];
  115. List<double> list = new List<double>(da);
  116. list[day] += 1;
  117. count.beginCount.AddRange(list);
  118. count.courseIds.Add(data.courseId);
  119. await client.GetContainer("TEAMModelOS", "tbname").CreateItemAsync(count, new PartitionKey(code));
  120. }
  121. }
  122. catch (Exception ex)
  123. {
  124. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-LessonCount-FixLessonCount\n{ex.Message}{ex.StackTrace}{data.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
  125. }
  126. }
  127. }
  128. }