LessonService.cs 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. using Azure.Core;
  2. using Azure.Cosmos;
  3. using Azure.Messaging.ServiceBus;
  4. using DocumentFormat.OpenXml.Drawing.Charts;
  5. using DocumentFormat.OpenXml.VariantTypes;
  6. using HTEXLib.COMM.Helpers;
  7. using MathNet.Numerics.Distributions;
  8. using Microsoft.Extensions.Configuration;
  9. using Microsoft.Extensions.Hosting;
  10. using OpenXmlPowerTools;
  11. using StackExchange.Redis;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Text.Json;
  17. using System.Threading.Tasks;
  18. using TEAMModelOS.SDK.DI;
  19. using TEAMModelOS.SDK.Extension;
  20. using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
  21. using TEAMModelOS.SDK.Models.Cosmos.Common;
  22. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  23. using TEAMModelOS.SDK.Services;
  24. namespace TEAMModelOS.SDK.Models.Service
  25. {
  26. public class LessonService
  27. {
  28. public static readonly DateTime dateTime1970 = new DateTime(1970, 1, 1).ToLocalTime();
  29. public static Dictionary<string, object> GetLessonCond(JsonElement request)
  30. {
  31. Dictionary<string, object> dict = new Dictionary<string, object>();
  32. if (request.TryGetProperty("tmdid", out JsonElement tmdid))
  33. {
  34. if (tmdid.ValueKind.Equals(JsonValueKind.String) && !string.IsNullOrWhiteSpace($"{tmdid}"))
  35. {
  36. dict.Add("tmdid", tmdid);
  37. }
  38. else if(tmdid.ValueKind.Equals(JsonValueKind.Array)) {
  39. dict.Add("tmdid", tmdid);
  40. }
  41. }
  42. if (request.TryGetProperty("courseId", out JsonElement courseId) && !string.IsNullOrWhiteSpace($"{courseId}"))
  43. {
  44. dict.Add("courseId", courseId);
  45. }
  46. if (request.TryGetProperty("courseIds", out JsonElement courseIds))
  47. {
  48. dict.Add("courseId[*]", courseIds);
  49. }
  50. if (request.TryGetProperty("periodId", out JsonElement periodId) && !string.IsNullOrWhiteSpace($"{periodId}"))
  51. {
  52. dict.Add("periodId", periodId);
  53. }
  54. if (request.TryGetProperty("subjectId", out JsonElement subjectId))
  55. {
  56. dict.Add("subjectId", subjectId);
  57. }
  58. if (request.TryGetProperty("groupIds", out JsonElement groupIds))
  59. {
  60. dict.Add("groupIds[*]", groupIds);
  61. }
  62. if (request.TryGetProperty("grade", out JsonElement grade))
  63. {
  64. dict.Add("grade[*]", grade);
  65. }
  66. if (request.TryGetProperty("category", out JsonElement category))
  67. {
  68. dict.Add("category[*]", category);
  69. }
  70. if (request.TryGetProperty("doubleGreen", out JsonElement doubleGreen) && doubleGreen.GetBoolean())
  71. {
  72. dict.Add("=.tLevel", 2);
  73. dict.Add("=.pLevel", 2);
  74. //dict.Add(">=.tScore", 70);
  75. //dict.Add(">=.pScore", 70);
  76. }
  77. if (request.TryGetProperty("doubleRed", out JsonElement doubleRed) && doubleRed.GetBoolean())
  78. {
  79. dict.Add("=.tLevel", 0);
  80. dict.Add("=.pLevel", 0);
  81. //dict.Add(">=.tScore", 70);
  82. //dict.Add(">=.pScore", 70);
  83. }
  84. if (request.TryGetProperty("quality", out JsonElement quality) && quality.GetBoolean())
  85. {
  86. dict.Add(">=.discuss", 1);
  87. }
  88. if (request.TryGetProperty("excellent", out JsonElement excellent) && excellent.GetBoolean())
  89. {
  90. dict.Add(">=.excellent", 1);
  91. }
  92. if (request.TryGetProperty("name", out JsonElement name) && !string.IsNullOrWhiteSpace($"{name}"))
  93. {
  94. dict.Add("$.name", name);
  95. }
  96. if (request.TryGetProperty("today", out JsonElement today) && today.GetBoolean())
  97. {
  98. DateTime dateTimeA = Convert.ToDateTime(DateTimeOffset.UtcNow.ToString("D"));
  99. DateTime dateTimeB = Convert.ToDateTime(DateTimeOffset.UtcNow.ToString("D")).AddDays(1);
  100. double dayOf00_00_00 = (dateTimeA - dateTime1970).TotalMilliseconds;
  101. double day1Of00_00_00 = (dateTimeB - dateTime1970).TotalMilliseconds;
  102. dict.Add(">=.startTime", dayOf00_00_00);
  103. dict.Add("<.startTime", day1Of00_00_00);
  104. }
  105. if (request.TryGetProperty("week", out JsonElement week) && week.GetBoolean())
  106. {
  107. // DateTime dateTimeA = Convert.ToDateTime(DateTimeOffset.UtcNow.ToString("D"));
  108. DateTime dateTimeB = Convert.ToDateTime(DateTimeOffset.UtcNow.ToString("D")).AddDays(-7);
  109. double now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  110. double dayB = (dateTimeB - dateTime1970).TotalMilliseconds;
  111. dict.Add("<=.startTime", now);
  112. dict.Add(">=.startTime", dayB);
  113. }
  114. //查询即将到期的且没有被清理的。
  115. if (request.TryGetProperty("expire", out JsonElement expire) && expire.ValueKind.Equals(JsonValueKind.True))
  116. {
  117. dict.Add(">.expire", 0);
  118. dict.Add("!=.status", 404);
  119. }
  120. //查询已经清理的
  121. if (request.TryGetProperty("is404", out JsonElement is404) && is404.ValueKind.Equals(JsonValueKind.True))
  122. {
  123. dict.Add("=.status", 404);
  124. }
  125. //只查有效的
  126. if (request.TryGetProperty("isOk", out JsonElement isOk) && isOk.ValueKind.Equals(JsonValueKind.True))
  127. {
  128. dict.Add("<=.expire", 0);
  129. dict.Add("!=.status", 404);
  130. }
  131. if (request.TryGetProperty("month", out JsonElement month) && month.GetBoolean())
  132. {
  133. //DateTime dateTimeA = Convert.ToDateTime(DateTimeOffset.UtcNow.ToString("D"));
  134. DateTime dateTimeB = Convert.ToDateTime(DateTimeOffset.UtcNow.ToString("D")).AddDays(-30);
  135. double now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  136. double dayB = (dateTimeB - dateTime1970).TotalMilliseconds;
  137. dict.Add("<=.startTime", now);
  138. dict.Add(">=.startTime", dayB);
  139. }
  140. if (request.TryGetProperty("stime", out JsonElement stime) && !string.IsNullOrWhiteSpace($"{stime}"))
  141. {
  142. dict.Add(">=.startTime", stime);
  143. }
  144. if (request.TryGetProperty("etime", out JsonElement etime) && !string.IsNullOrWhiteSpace($"{etime}"))
  145. {
  146. dict.Add("<=.startTime", etime);
  147. }
  148. if (request.TryGetProperty("conds", out JsonElement conds) && conds.ValueKind.Equals(JsonValueKind.Array))
  149. {
  150. List<LessonSettingCond> settingConds = conds.Deserialize<List<LessonSettingCond>>();
  151. foreach (var item in settingConds)
  152. {
  153. dict.TryAdd($"{item.type}.{item.key}", item.val);
  154. //switch (item.type)
  155. //{
  156. // case ">=":
  157. // dict.TryAdd($">=.{item.key}",item.val);
  158. // break;
  159. // case "<=":
  160. // dict.TryAdd($"<=.{item.key}", item.val);
  161. // break;
  162. //}
  163. }
  164. }
  165. return dict;
  166. }
  167. public static async void DoLessonStudentRecord(DingDing _dingding, SnowflakeId snowflakeId, LessonRecord lessonRecord, string scope, CosmosClient client, string school, string tmdid,
  168. Teacher teacher, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, LessonBase lessonBase,AzureRedisFactory _azureRedis, List<string> pickupMemberIds, List<TaskData> taskDatas, List<IRSData> iRSDatas)
  169. {
  170. School schoolBase = null;
  171. Period period = null;
  172. try
  173. {
  174. int year = DateTimeOffset.UtcNow.Year;
  175. string hs = lessonBase?.report?.clientSummaryList.ToJsonString();
  176. var clientSummaryLists = lessonBase?.report?.clientSummaryList?.Where(x => x.groupTaskCompleteCount != 0 || x.groupScore != 0 || x.score != 0 || x.interactScore != 0 || x.taskCompleteCount != 0);
  177. IEnumerable<LessonStudent> students = new List<LessonStudent>();
  178. if (clientSummaryLists.Any())
  179. {
  180. var ids = clientSummaryLists.Select(x => x.seatID);
  181. students = lessonBase.student.Where(x => ids.Contains(x.seatID));
  182. }
  183. List<Student> studentsBase = new List<Student>();
  184. var stuids = students.Where(x => x.type == 2);
  185. if (stuids.Any())
  186. {
  187. stuids.ToList().ForEach(x => {
  188. x.school = string.IsNullOrWhiteSpace(x.school) ? school : x.school;
  189. });
  190. var result= await client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>($"select value c from c where c.id in ({string.Join(",",stuids.Select(d=>$"'{d.id}'"))})", $"Base-{school}");
  191. if (result.list.Any()) {
  192. studentsBase = result.list;
  193. }
  194. }
  195. var groups = stuids.Where(z => !string.IsNullOrWhiteSpace(z.school)).GroupBy(x => x.school).Select(y => new { code = y.Key, list = y.ToList() });
  196. List<StudentScoreRecord> lessonStudentRecords = new List<StudentScoreRecord>();
  197. foreach (var group in groups)
  198. {
  199. string stusql = $"select value(c) from c where c.stuid in({string.Join(",", group.list.Select(x => $"'{x.id}'"))}) and c.school='{group.code}' and c.year={year}";
  200. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<StudentScoreRecord>(queryText: stusql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"StudentScoreRecord") }))
  201. {
  202. lessonStudentRecords.Add(item);
  203. }
  204. }
  205. var tmdids = students.Where(x => x.type == 1);
  206. if (tmdids.Any())
  207. {
  208. string tmdsql = $"select value(c) from c where c.tmdid in({string.Join(",", tmdids.Select(x => $"'{x}'"))}) and c.year={year}";
  209. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<StudentScoreRecord>(queryText: tmdsql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"StudentScoreRecord") }))
  210. {
  211. lessonStudentRecords.Add(item);
  212. }
  213. }
  214. (Semester currSemester, int studyYear, DateTimeOffset currSemesterDate, DateTimeOffset date, DateTimeOffset nextSemester) dataSemester = new(null,-1, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow) ;
  215. if (!string.IsNullOrWhiteSpace(school)) {
  216. schoolBase = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
  217. period = schoolBase.period.Find(x => x.id.Equals($"{lessonRecord.periodId}"));
  218. if (period!= null) {
  219. dataSemester= SchoolService.GetSemester(period);
  220. }
  221. }
  222. List <Task<ItemResponse<StudentScoreRecord>>> records = new List<Task<ItemResponse<StudentScoreRecord>>>();
  223. HashSet <OverallEducation> overallEducations = new HashSet<OverallEducation>();
  224. // 互动次数,-1 表示没有进行互动。 与 0 不同
  225. int interactCount = -1;
  226. if (iRSDatas.IsNotEmpty()) {
  227. interactCount= iRSDatas.Where(z => z.isBuzz==false).SelectMany(v => v.clientAnswers).Count();
  228. }
  229. //任务发布次数 ,-1 表示没有进行互动。 与 0 不同
  230. int taskCount = -1;
  231. var groupNames = lessonBase.report.clientSummaryList.Where(z => !string.IsNullOrEmpty(z.groupName))?.Select(z=>z.groupName)?.ToHashSet()?.OrderBy(z=>z)?.ToList();
  232. List<IdCodeCount> groupTaskJoinCounts = new List<IdCodeCount>();
  233. if (groupNames.IsNotEmpty()) {
  234. groupTaskJoinCounts = groupNames.Select(z => new IdCodeCount { name=z, count = 0 }).ToList();
  235. }
  236. //組任務發佈數
  237. int groupTaskCount = -1;
  238. if (taskDatas.IsNotEmpty())
  239. {
  240. taskCount=0;
  241. bool hasGroupTask = false;
  242. int groupTaksCountTemp = 0;
  243. foreach (var taskData in taskDatas)
  244. {
  245. var isGroupItem = taskData.clientWorks.FindAll(z => z.isGroupItem);
  246. if (isGroupItem.IsNotEmpty())
  247. {
  248. //有组任务
  249. hasGroupTask = true;
  250. groupTaksCountTemp += 1;
  251. foreach (var item in isGroupItem)
  252. {
  253. int groupIndex = 0;
  254. int.TryParse(item.groupID,out groupIndex);
  255. //由于分组下标从1 开始,则需要判断是否与分组数组大小一致,且提交了作品,则数量+1
  256. if ( groupIndex>0 && item.blobFiles.IsNotEmpty() && groupIndex <= groupTaskJoinCounts.Count) {
  257. groupTaskJoinCounts[groupIndex-1].count+=1;
  258. }
  259. }
  260. }
  261. else
  262. {
  263. //没有组任务
  264. taskCount += 1;
  265. }
  266. }
  267. if (hasGroupTask) {
  268. groupTaskCount=groupTaksCountTemp;
  269. }
  270. }
  271. foreach (var x in stuids) {
  272. var record = lessonStudentRecords.Find(l => l.stuid.Equals(x.id) && l.code.Equals($"StudentScoreRecord") && l.school.Equals(x.school));
  273. ClientSummaryList clientSummaryList = lessonBase.report.clientSummaryList.Find(c => c.seatID == x.seatID);
  274. if (record != null)
  275. {
  276. if (clientSummaryList != null)
  277. {
  278. var hasrecord = record.lessonRecords.Find(x => x.lessonId.Equals(lessonRecord.id));
  279. if (hasrecord != null)
  280. {
  281. hasrecord.gscore = clientSummaryList.groupScore;
  282. hasrecord.pscore = clientSummaryList.score;
  283. hasrecord.tscore = clientSummaryList.interactScore;
  284. hasrecord.tmdid = teacher.id;
  285. hasrecord.school = school;
  286. hasrecord.scope = lessonRecord.scope;
  287. hasrecord.lessonId = lessonRecord.id;
  288. hasrecord.courseId = lessonRecord.courseId;
  289. hasrecord.periodId = lessonRecord.periodId;
  290. hasrecord.subjectId = lessonRecord.subjectId;
  291. hasrecord.time = lessonRecord.startTime;
  292. }
  293. else
  294. {
  295. record.lessonRecords.Add(
  296. new StudentLessonRecord
  297. {
  298. gscore = clientSummaryList.groupScore,
  299. pscore = clientSummaryList.score,
  300. tscore = clientSummaryList.interactScore,
  301. tmdid = teacher.id,
  302. school = school,
  303. scope = lessonRecord.scope,
  304. lessonId = lessonRecord.id,
  305. courseId = lessonRecord.courseId,
  306. periodId = lessonRecord.periodId,
  307. subjectId = lessonRecord.subjectId,
  308. time = lessonRecord.startTime
  309. }
  310. );
  311. }
  312. }
  313. }
  314. else
  315. {
  316. record = new StudentScoreRecord
  317. {
  318. userType = Constant.ScopeStudent,
  319. id = $"{snowflakeId.NextId()}",
  320. year = year,
  321. stuid = x.id,
  322. school = x.school,
  323. code = $"StudentScoreRecord",
  324. pk = "StudentScoreRecord",
  325. ttl = -1,
  326. lessonRecords = new List<StudentLessonRecord> { new StudentLessonRecord
  327. {
  328. gscore = clientSummaryList.groupScore,
  329. pscore = clientSummaryList.score,
  330. tscore = clientSummaryList.interactScore,
  331. tmdid = teacher.id,
  332. school = school,
  333. scope = lessonRecord.scope,
  334. lessonId = lessonRecord.id,
  335. courseId = lessonRecord.courseId,
  336. periodId = lessonRecord.periodId,
  337. subjectId = lessonRecord.subjectId,
  338. time= lessonRecord.startTime
  339. }}
  340. };
  341. }
  342. record.userType = Constant.ScopeStudent;
  343. record.gscore = record.lessonRecords.Select(x => x.gscore).Sum();
  344. record.pscore = record.lessonRecords.Select(x => x.pscore).Sum();
  345. record.tscore = record.lessonRecords.Select(x => x.tscore).Sum();
  346. if (dataSemester.currSemester != null && (clientSummaryList.groupScore>0 || clientSummaryList.score > 0 || clientSummaryList.interactScore > 0))
  347. {
  348. string oid = $"{dataSemester.studyYear}-{dataSemester.currSemester.id}-{record.stuid}";
  349. string ocode = $"OverallEducation-{school}";
  350. var student = studentsBase.Find(stu => stu.id.Equals(x.id));
  351. Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemStreamAsync(oid, new PartitionKey(ocode));
  352. OverallEducation overallEducation = null;
  353. if (response.Status != 200)
  354. {
  355. overallEducation = new OverallEducation
  356. {
  357. id =oid,
  358. code = $"OverallEducation-{school}",
  359. pk = "OverallEducation",
  360. ttl = -1,
  361. name = x.name,
  362. classId = student?.classId,
  363. schoolCode = $"{school}",
  364. semesterId = dataSemester.currSemester.id,
  365. year = dataSemester.studyYear,
  366. periodId = $"{period.id}",
  367. stuYear = student.year,
  368. studentId = x.id,
  369. lessonScore= new List<StudentLessonRecord> { new StudentLessonRecord
  370. {
  371. gscore = clientSummaryList.groupScore,
  372. pscore = clientSummaryList.score,
  373. tscore = clientSummaryList.interactScore,
  374. tmdid = teacher.id,
  375. school = school,
  376. scope = lessonRecord.scope,
  377. lessonId = lessonRecord.id,
  378. courseId = lessonRecord.courseId,
  379. periodId = lessonRecord.periodId,
  380. subjectId = lessonRecord.subjectId,
  381. time= lessonRecord.startTime
  382. }}
  383. };
  384. }
  385. else
  386. {
  387. overallEducation=JsonDocument.Parse(response.Content).RootElement.ToObject<OverallEducation>();
  388. var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(lessonRecord.id));
  389. if (hasrecord != null)
  390. {
  391. hasrecord.gscore = clientSummaryList.groupScore;
  392. hasrecord.pscore = clientSummaryList.score;
  393. hasrecord.tscore = clientSummaryList.interactScore;
  394. hasrecord.tmdid = teacher.id;
  395. hasrecord.school = school;
  396. hasrecord.scope = lessonRecord.scope;
  397. hasrecord.lessonId = lessonRecord.id;
  398. hasrecord.courseId = lessonRecord.courseId;
  399. hasrecord.periodId = lessonRecord.periodId;
  400. hasrecord.subjectId = lessonRecord.subjectId;
  401. hasrecord.time = lessonRecord.startTime;
  402. }
  403. else
  404. {
  405. overallEducation.lessonScore.Add(
  406. new StudentLessonRecord
  407. {
  408. gscore = clientSummaryList.groupScore,
  409. pscore = clientSummaryList.score,
  410. tscore = clientSummaryList.interactScore,
  411. tmdid = teacher.id,
  412. school = school,
  413. scope = lessonRecord.scope,
  414. lessonId = lessonRecord.id,
  415. courseId = lessonRecord.courseId,
  416. periodId = lessonRecord.periodId,
  417. subjectId = lessonRecord.subjectId,
  418. time = lessonRecord.startTime
  419. }
  420. );
  421. }
  422. }
  423. overallEducations.Add(overallEducation);
  424. }
  425. records.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(record, partitionKey: new PartitionKey(record.code)));
  426. }
  427. foreach (var x in tmdids) {
  428. var record = lessonStudentRecords.Find(l => l.tmdid.Equals(x.id) && l.code.Equals($"StudentScoreRecord"));
  429. ClientSummaryList clientSummaryList = lessonBase.report.clientSummaryList.Find(c => c.seatID == x.seatID);
  430. if (record != null)
  431. {
  432. if (clientSummaryList != null)
  433. {
  434. var hasrecord = record.lessonRecords.Find(x => x.lessonId.Equals(lessonRecord.id));
  435. if (hasrecord != null)
  436. {
  437. hasrecord.gscore = clientSummaryList.groupScore;
  438. hasrecord.pscore = clientSummaryList.score;
  439. hasrecord.tscore = clientSummaryList.interactScore;
  440. hasrecord.tmdid = teacher.id;
  441. hasrecord.school = school;
  442. hasrecord.scope = lessonRecord.scope;
  443. hasrecord.lessonId = lessonRecord.id;
  444. hasrecord.courseId = lessonRecord.courseId;
  445. hasrecord.periodId = lessonRecord.periodId;
  446. hasrecord.subjectId = lessonRecord.subjectId;
  447. hasrecord.time = lessonRecord.startTime;
  448. }
  449. else
  450. {
  451. record.lessonRecords.Add(
  452. new StudentLessonRecord
  453. {
  454. gscore = clientSummaryList.groupScore,
  455. pscore = clientSummaryList.score,
  456. tscore = clientSummaryList.interactScore,
  457. tmdid = teacher.id,
  458. school = school,
  459. scope = lessonRecord.scope,
  460. lessonId = lessonRecord.id,
  461. courseId = lessonRecord.courseId,
  462. periodId = lessonRecord.periodId,
  463. subjectId = lessonRecord.subjectId,
  464. time = lessonRecord.startTime
  465. }
  466. );
  467. }
  468. }
  469. }
  470. else
  471. {
  472. record = new StudentScoreRecord
  473. {
  474. userType = Constant.ScopeTmdUser,
  475. id = $"{snowflakeId.NextId()}",
  476. code = $"StudentScoreRecord",
  477. pk = "StudentScoreRecord",
  478. ttl = -1,
  479. year = year,
  480. tmdid = x.id,
  481. lessonRecords = new List<StudentLessonRecord>
  482. {
  483. new StudentLessonRecord
  484. {
  485. gscore = clientSummaryList.groupScore,
  486. pscore = clientSummaryList.score,
  487. tscore = clientSummaryList.interactScore,
  488. tmdid = teacher.id,
  489. school = school,
  490. scope = lessonRecord.scope,
  491. lessonId = lessonRecord.id,
  492. courseId = lessonRecord.courseId,
  493. periodId = lessonRecord.periodId,
  494. subjectId = lessonRecord.subjectId,
  495. time=lessonRecord.startTime
  496. }
  497. }
  498. };
  499. }
  500. record.userType = Constant.ScopeStudent;
  501. record.gscore = record.lessonRecords.Select(x => x.gscore).Sum();
  502. record.pscore = record.lessonRecords.Select(x => x.pscore).Sum();
  503. record.tscore = record.lessonRecords.Select(x => x.tscore).Sum();
  504. records.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(record, partitionKey: new PartitionKey(record.code)));
  505. }
  506. if (records.Any())
  507. {
  508. await Task.WhenAll(records);
  509. }
  510. if (overallEducations.Any())
  511. {
  512. foreach (var item in overallEducations) {
  513. await client.GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(item, partitionKey: new PartitionKey(item.code));
  514. string key = $"OverallEducation:{item.schoolCode}:{item.periodId}:{item.year}:{item.semesterId}:{item.classId}";
  515. await _azureRedis.GetRedisClient(8).HashSetAsync(key, item.studentId, item.ToJsonString());
  516. await _azureRedis.GetRedisClient(8).KeyExpireAsync(key,new TimeSpan(180 *24 ,0,0));
  517. }
  518. }
  519. }
  520. catch (Exception ex)
  521. {
  522. await _dingding.SendBotMsg($"学生个人课例统计信息异常,{ex.Message}\n{ex.StackTrace},{lessonRecord?.ToJsonString()}{school}", GroupNames.醍摩豆服務運維群組);
  523. }
  524. }
  525. public static async void DoAutoDeleteSchoolLessonRecord(LessonRecord lessonRecord, string scope, CosmosClient client, string school, string tmdid,
  526. Teacher teacher, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, CoreAPIHttpService _coreAPIHttpService,DingDing _dingDing,AzureRedisFactory _azureRedis)
  527. {
  528. if (lessonRecord.scope.Equals("school"))
  529. {
  530. SchoolSetting setting = null;
  531. Azure.Response schoolSetting = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(school, new PartitionKey("SchoolSetting"));
  532. School schoolBase = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
  533. if (schoolSetting.Status == 200)
  534. {
  535. setting = JsonDocument.Parse(schoolSetting.Content).RootElement.Deserialize<SchoolSetting>();
  536. if (setting.lessonSetting != null)
  537. {
  538. //两种状态都不属于,则默认未开启。
  539. if (setting.lessonSetting.openAutoClean != 0 && setting.lessonSetting.openAutoClean != 1)
  540. {
  541. setting.lessonSetting.openAutoClean = 0;
  542. setting.lessonSetting.expireDays = Constant.school_lesson_expire;
  543. }
  544. else {
  545. //属于 要么开启1,要么关闭0
  546. }
  547. }
  548. else
  549. {
  550. setting.lessonSetting = new LessonSetting() { openAutoClean = 0, expireDays = Constant.school_lesson_expire };
  551. }
  552. }
  553. else
  554. {
  555. setting = new SchoolSetting() { lessonSetting = new LessonSetting { openAutoClean = 0, expireDays = Constant.school_lesson_expire } };
  556. }
  557. int school_lesson_expire = 0;
  558. bool save = true;
  559. List<string> msg = new List<string>();
  560. if (setting.lessonSetting.openAutoClean == 1)
  561. {
  562. if (setting.lessonSetting.conds.IsEmpty())
  563. {
  564. save = false;
  565. }
  566. else
  567. {
  568. school_lesson_expire = setting.lessonSetting.expireDays;
  569. foreach (var item in setting.lessonSetting.conds)
  570. {
  571. switch (item.type)
  572. {
  573. case ">=":
  574. switch (item.key)
  575. {
  576. case "attendRate":
  577. if (!(lessonRecord.attendRate >= item.val))
  578. {
  579. save = false;
  580. msg.Add($"{item.key}:{lessonRecord.attendRate}{item.type}{item.val}");
  581. }
  582. break;
  583. case "groupCount":
  584. if (!(lessonRecord.groupCount >= item.val))
  585. {
  586. save = false;
  587. msg.Add($"{item.key}:{lessonRecord.groupCount}{item.type}{item.val}");
  588. }
  589. break;
  590. case "totalPoint":
  591. if (!(lessonRecord.totalPoint >= item.val))
  592. {
  593. save = false;
  594. msg.Add($"{item.key}:{lessonRecord.totalPoint}{item.type}{item.val}");
  595. }
  596. break;
  597. case "collateTaskCount":
  598. if (!(lessonRecord.collateTaskCount >= item.val))
  599. {
  600. save = false;
  601. msg.Add($"{item.key}:{lessonRecord.collateTaskCount}{item.type}{item.val}");
  602. }
  603. break;
  604. case "collateCount":
  605. if (!(lessonRecord.collateCount >= item.val))
  606. {
  607. save = false;
  608. msg.Add($"{item.key}:{lessonRecord.collateCount}{item.type}{item.val}");
  609. }
  610. break;
  611. case "pushCount":
  612. if (!(lessonRecord.pushCount >= item.val))
  613. {
  614. save = false;
  615. msg.Add($"{item.key}:{lessonRecord.pushCount}{item.type}{item.val}");
  616. }
  617. break;
  618. case "totalInteractPoint":
  619. if (!(lessonRecord.totalInteractPoint >= item.val))
  620. {
  621. save = false;
  622. msg.Add($"{item.key}:{lessonRecord.totalInteractPoint}{item.type}{item.val}");
  623. }
  624. break;
  625. case "interactionCount":
  626. if (!(lessonRecord.interactionCount >= item.val))
  627. {
  628. save = false;
  629. msg.Add($"{item.key}:{lessonRecord.interactionCount}{item.type}{item.val}");
  630. }
  631. break;
  632. case "clientInteractionCount":
  633. if (!(lessonRecord.clientInteractionCount >= item.val))
  634. {
  635. save = false;
  636. msg.Add($"{item.key}:{lessonRecord.clientInteractionCount}{item.type}{item.val}");
  637. }
  638. break;
  639. case "examQuizCount":
  640. if (!(lessonRecord.examQuizCount >= item.val))
  641. {
  642. save = false;
  643. msg.Add($"{item.key}:{lessonRecord.examQuizCount}{item.type}{item.val}");
  644. }
  645. break;
  646. case "examPointRate":
  647. if (!(lessonRecord.examPointRate >= item.val))
  648. {
  649. save = false;
  650. msg.Add($"{item.key}:{lessonRecord.examPointRate}{item.type}{item.val}");
  651. }
  652. break;
  653. }
  654. break;
  655. case "<=":
  656. switch (item.key)
  657. {
  658. case "attendRate":
  659. if (!(lessonRecord.attendRate <= item.val))
  660. {
  661. save = false;
  662. msg.Add($"{item.key}:{lessonRecord.attendRate}{item.type}{item.val}");
  663. }
  664. break;
  665. case "groupCount":
  666. if (!(lessonRecord.groupCount <= item.val))
  667. {
  668. save = false;
  669. msg.Add($"{item.key}:{lessonRecord.groupCount}{item.type}{item.val}");
  670. }
  671. break;
  672. case "totalPoint":
  673. if (!(lessonRecord.totalPoint <= item.val))
  674. {
  675. save = false;
  676. msg.Add($"{item.key}:{lessonRecord.totalPoint}{item.type}{item.val}");
  677. }
  678. break;
  679. case "collateTaskCount":
  680. if (!(lessonRecord.collateTaskCount <= item.val))
  681. {
  682. save = false;
  683. msg.Add($"{item.key}:{lessonRecord.collateTaskCount}{item.type}{item.val}");
  684. }
  685. break;
  686. case "collateCount":
  687. if (!(lessonRecord.collateCount <= item.val))
  688. {
  689. save = false;
  690. msg.Add($"{item.key}:{lessonRecord.collateCount}{item.type}{item.val}");
  691. }
  692. break;
  693. case "pushCount":
  694. if (!(lessonRecord.pushCount <= item.val))
  695. {
  696. save = false;
  697. msg.Add($"{item.key}:{lessonRecord.pushCount}{item.type}{item.val}");
  698. }
  699. break;
  700. case "totalInteractPoint":
  701. if (!(lessonRecord.totalInteractPoint <= item.val))
  702. {
  703. save = false;
  704. msg.Add($"{item.key}:{lessonRecord.totalInteractPoint}{item.type}{item.val}");
  705. }
  706. break;
  707. case "interactionCount":
  708. if (!(lessonRecord.interactionCount <= item.val))
  709. {
  710. save = false;
  711. msg.Add($"{item.key}:{lessonRecord.interactionCount}{item.type}{item.val}");
  712. }
  713. break;
  714. case "clientInteractionCount":
  715. if (!(lessonRecord.clientInteractionCount <= item.val))
  716. {
  717. save = false;
  718. msg.Add($"{item.key}:{lessonRecord.clientInteractionCount}{item.type}{item.val}");
  719. }
  720. break;
  721. case "examQuizCount":
  722. if (!(lessonRecord.examQuizCount <= item.val))
  723. {
  724. save = false;
  725. msg.Add($"{item.key}:{lessonRecord.examQuizCount}{item.type}{item.val}");
  726. }
  727. break;
  728. case "examPointRate":
  729. if (!(lessonRecord.examPointRate <= item.val))
  730. {
  731. save = false;
  732. msg.Add($"{item.key}:{lessonRecord.examPointRate}{item.type}{item.val}");
  733. }
  734. break;
  735. }
  736. break;
  737. }
  738. }
  739. }
  740. }
  741. /* 注释start 2023.3.22,该段逻辑在开课的时候已经处理,详见ActiveTaskTopic. LessonRecordEvent create ,无论有没有开启setting.lessonSetting.openAutoClean 自动删除策略,只要空间不足都会对课例进行自动清理管理。
  742. else
  743. {
  744. ///未设置openAutoClean=1时,则检查学校使用空间是否充足。
  745. double usize = 0;
  746. int tsize = schoolBase.tsize;
  747. //schoolBase.tsize
  748. //計算學校或個人的使用空間
  749. RedisValue redisValue = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", $"{schoolBase.id}");
  750. if (redisValue.HasValue && long.TryParse(redisValue.ToString(), out var bsize))
  751. {
  752. usize = Math.Round(bsize / 1073741824.0 - (tsize), 2, MidpointRounding.AwayFromZero); //1073741824 1G
  753. }
  754. else //如果檢測不到緩存,觸發刷新計算空間
  755. {
  756. await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = "records", name = $"{schoolBase.id}" }, _serviceBus, _configuration, _azureRedis);
  757. }
  758. ///空间充足的情况保存。
  759. if (schoolBase.size - usize > 0)
  760. {
  761. save = true;
  762. }
  763. else {
  764. save = false;
  765. school_lesson_expire = Constant.school_lesson_expire;
  766. }
  767. } 注释end 2023.3.22,该段逻辑在开课的时候已经处理,详见ActiveTaskTopic. LessonRecordEvent create ,无论有没有开启setting.lessonSetting.openAutoClean 自动删除策略,只要空间不足都会对课例进行自动清理管理。
  768. */
  769. if (!save && school_lesson_expire > 0)
  770. {
  771. // 1-时间戳,7-时间戳
  772. Dictionary<int, ExpireTag> result = new Dictionary<int, ExpireTag>();
  773. //暂定7天
  774. var now = DateTimeOffset.UtcNow;
  775. //剩余3天的通知
  776. //var day3= now.AddDays(school_lesson_expire - 3).ToUnixTimeMilliseconds();
  777. //result.Add(3, day3);
  778. //剩余1天的通知
  779. var day1 = now.AddDays(school_lesson_expire - (school_lesson_expire - 1)).ToUnixTimeMilliseconds();
  780. result.Add(1, new ExpireTag { expire = day1, tag = "notification" });
  781. //到期通知
  782. //不到五点上传的课例,七天之后直接删除。
  783. int addSecond = 0;
  784. if (now.Hour > 5)
  785. {
  786. // 到凌晨00点还差 (24 - now.Hour) *60 * 60 分钟,再加天数;
  787. addSecond = school_lesson_expire * 86400 + (24 - now.Hour) * 3600 - (now.Hour * 3600);
  788. //再加 00到05小时内的 随机秒数
  789. Random rand = new Random();
  790. int randInt = rand.Next(0, 18000);
  791. addSecond += randInt;
  792. }
  793. else
  794. {
  795. addSecond = school_lesson_expire * 24 * 60 * 60;
  796. }
  797. lessonRecord.expire = now.AddSeconds(addSecond).ToUnixTimeMilliseconds();
  798. result.Add(school_lesson_expire, new ExpireTag { expire = lessonRecord.expire, tag = "delete" });
  799. // result.Add(school_lesson_expire, lessonRecord.expire);
  800. string biz = "expire";
  801. string expireTime = DateTimeOffset.FromUnixTimeMilliseconds(lessonRecord.expire).ToString("yyyy-MM-dd HH:mm:ss");
  802. Teacher targetTeacher = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>($"{tmdid}", new PartitionKey($"Base"));
  803. _coreAPIHttpService.PushNotify(new List<IdNameCode> { new IdNameCode { id = targetTeacher.id, name = targetTeacher.name, code = targetTeacher.lang } }, "expire-school_lessonRecord", Constant.NotifyType_IES5_Course,
  804. new Dictionary<string, object> { { "tmdid", teacher.id }, { "tmdname", teacher.name }, { "schoolName", schoolBase.name },
  805. { "schoolId", $"{school}" },{ "lessonId",lessonRecord.id }, { "expireTime", expireTime },{ "lessonName",lessonRecord.name } }, $"{Environment.GetEnvironmentVariable("Option:Location")}", _configuration, _dingDing, "");
  806. var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  807. List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", lessonRecord.id } });
  808. if (records.Count <= 0)
  809. {
  810. foreach (var item in result)
  811. {
  812. string PartitionKey = string.Format("{0}{1}{2}", lessonRecord.code, "-", $"expire-{item.Key}");
  813. //课堂的id ,
  814. //课堂的通知时间类型progress, 默认就会发送一条,到期前一天发送一条,最后已到期发送一条。
  815. var message = new ServiceBusMessage(new
  816. {
  817. id = lessonRecord.id,
  818. progress = item.Key,
  819. code = lessonRecord.code,
  820. scope = lessonRecord.scope,
  821. school = lessonRecord.school,
  822. opt = "delete",
  823. expire = lessonRecord.expire,
  824. tmdid = tmdid,
  825. tmdname = teacher.name,
  826. name = lessonRecord.name,
  827. startTime = lessonRecord.startTime,
  828. tag = item.Value.tag
  829. }.ToJsonString());
  830. message.ApplicationProperties.Add("name", "LessonRecordExpire");
  831. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(item.Value.expire));
  832. ChangeRecord changeRecord = new ChangeRecord
  833. {
  834. RowKey = lessonRecord.id,
  835. PartitionKey = PartitionKey,
  836. sequenceNumber = start,
  837. msgId = message.MessageId
  838. };
  839. await table.Save<ChangeRecord>(changeRecord);
  840. }
  841. }
  842. }
  843. else
  844. {
  845. if (lessonRecord.expire > 0)
  846. {
  847. var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  848. List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", lessonRecord.id } });
  849. foreach (var record in records)
  850. {
  851. try
  852. {
  853. await table.DeleteSingle<ChangeRecord>(record.PartitionKey, record.RowKey);
  854. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
  855. }
  856. catch (Exception)
  857. {
  858. continue;
  859. }
  860. }
  861. }
  862. lessonRecord.save = 1;
  863. lessonRecord.expire = -1;
  864. }
  865. }
  866. }
  867. public record ExpireTag
  868. {
  869. public long expire { get; set; }
  870. public string tag { get; set; }
  871. }
  872. /// <summary>
  873. ///
  874. /// </summary>
  875. /// <param name="client"></param>
  876. /// <param name="_dingDing"></param>
  877. /// <param name="data"></param>
  878. /// <returns></returns>
  879. public static LessonDis DisLessonCount(LessonRecord oldRecord, LessonRecord newRecord, LessonDis lessonDis)
  880. {
  881. //创建课堂的情况
  882. if (oldRecord == null && newRecord != null)
  883. {
  884. lessonDis.record = 1;
  885. }
  886. //删除数据的情况
  887. //不再对LessonCount进行减
  888. else if (oldRecord != null && newRecord == null)
  889. {
  890. /*lessonDis.record = -1;
  891. //P分数量加减
  892. if (oldRecord.pScore >= 70)
  893. {
  894. lessonDis.disPCount = -1;
  895. }
  896. //T分数量加减
  897. if (oldRecord.tScore >= 70)
  898. {
  899. lessonDis.disTCount = -1;
  900. }
  901. if (oldRecord.tScore >= 70 && oldRecord.pScore >= 70)
  902. {
  903. lessonDis.disTCount = -1;
  904. }*/
  905. }
  906. //无效操作
  907. else if (oldRecord == null && newRecord == null)
  908. {
  909. }
  910. //前后操作都有值,则表示更新
  911. else
  912. {
  913. //P分数量加减
  914. if (oldRecord.pScore >= 70)
  915. {
  916. if (newRecord.pScore < 70)
  917. {
  918. lessonDis.disPCount = -1;
  919. }
  920. }
  921. else
  922. {
  923. if (newRecord.pScore >= 70)
  924. {
  925. lessonDis.disPCount = 1;
  926. }
  927. }
  928. //T分数量加减
  929. if (oldRecord.tScore >= 70)
  930. {
  931. if (newRecord.tScore < 70)
  932. {
  933. lessonDis.disTCount = -1;
  934. }
  935. }
  936. else
  937. {
  938. if (newRecord.tScore >= 70)
  939. {
  940. lessonDis.disTCount = 1;
  941. }
  942. }
  943. //双绿灯数量
  944. if (oldRecord.tScore >= 70 && oldRecord.pScore >= 70)
  945. {
  946. if (newRecord.tScore < 70 || newRecord.pScore < 70)
  947. {
  948. lessonDis.disDCount = -1;
  949. }
  950. }
  951. else
  952. {
  953. if (newRecord.tScore >= 70 && newRecord.pScore >= 70)
  954. {
  955. lessonDis.disDCount = 1;
  956. }
  957. }
  958. }
  959. return lessonDis;
  960. }
  961. public static LessonDis DisLessonCount_2(LessonRecord oldRecord, LessonRecord newRecord, LessonDis lessonDis)
  962. {
  963. //创建课堂的情况
  964. if (oldRecord == null && newRecord != null)
  965. {
  966. lessonDis.record = 1;
  967. //P分数量加减
  968. if (newRecord.pScore >= 70)
  969. {
  970. lessonDis.disPCount = 1;
  971. }
  972. //T分数量加减
  973. if (newRecord.tScore >= 70)
  974. {
  975. lessonDis.disTCount = 1;
  976. }
  977. //双绿灯数量
  978. if (newRecord.tScore >= 70 && newRecord.pScore >= 70)
  979. {
  980. lessonDis.disDCount = 1;
  981. }
  982. }
  983. return lessonDis;
  984. }
  985. public static async Task FixLessonCount(CosmosClient client, DingDing _dingDing, LessonRecord record, LessonRecord oldRecord, LessonDis lessonDis)
  986. {
  987. LessonRecord data = null;
  988. try
  989. {
  990. if (record != null && oldRecord == null)
  991. {
  992. data = record;
  993. }
  994. if (record == null && oldRecord != null)
  995. {
  996. data = oldRecord;
  997. }
  998. if (record != null && oldRecord != null)
  999. {
  1000. data = record;
  1001. }
  1002. int day = DateTimeOffset.FromUnixTimeMilliseconds(data.startTime).DayOfYear;
  1003. int year = DateTimeOffset.FromUnixTimeMilliseconds(data.startTime).Year;
  1004. int days = DateTimeHelper.getDays(year);
  1005. //int years = DateTimeOffset.UtcNow.DayOfYear;
  1006. string tbname = string.Empty;
  1007. string code = string.Empty;
  1008. if (data.groupIds.Any()) {
  1009. if (data.scope != null && data.scope.Equals("school"))
  1010. {
  1011. if (string.IsNullOrEmpty(data.periodId))
  1012. {
  1013. code = $"LessonCount-{data.school}-{year}";
  1014. tbname = "School";
  1015. }
  1016. else
  1017. {
  1018. code = $"LessonCount-{data.school}-{year}-{data.periodId}";
  1019. tbname = "School";
  1020. }
  1021. }
  1022. else
  1023. {
  1024. code = $"LessonCount-{year}";
  1025. tbname = "Teacher";
  1026. }
  1027. var response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(data.tmdid.ToString(), new PartitionKey(code));
  1028. if (response.Status == 200)
  1029. {
  1030. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  1031. LessonCount count = json.ToObject<LessonCount>();
  1032. count.tCount[day - 1] += lessonDis.disTCount;
  1033. count.pCount[day - 1] += lessonDis.disPCount;
  1034. count.ptCount[day - 1] += lessonDis.disDCount;
  1035. count.beginCount[day - 1] += lessonDis.record;
  1036. await client.GetContainer("TEAMModelOS", tbname).ReplaceItemAsync(count, count.id, new PartitionKey(code));
  1037. }
  1038. else
  1039. {
  1040. LessonCount count = new()
  1041. {
  1042. id = data.tmdid,
  1043. code = code,
  1044. ttl = -1
  1045. };
  1046. double[] da = new double[days];
  1047. List<double> list = new(da);
  1048. List<double> listT = new(da);
  1049. List<double> listP = new(da);
  1050. List<double> listPT = new(da);
  1051. list[day - 1] += lessonDis.record;
  1052. listT[day - 1] += lessonDis.disTCount;
  1053. listP[day - 1] += lessonDis.disPCount;
  1054. listPT[day - 1] += lessonDis.disDCount;
  1055. count.beginCount.AddRange(list);
  1056. count.tCount.AddRange(listT);
  1057. count.pCount.AddRange(listP);
  1058. count.ptCount.AddRange(listPT);
  1059. //count.courseIds.Add(data.courseId);
  1060. await client.GetContainer("TEAMModelOS", tbname).CreateItemAsync(count, new PartitionKey(code));
  1061. }
  1062. }
  1063. }
  1064. catch (Exception ex)
  1065. {
  1066. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-LessonCount-FixLessonCount\n{ex.Message}\n{ex.StackTrace}{data.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
  1067. }
  1068. }
  1069. }
  1070. }