LessonService.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. using Azure.Cosmos;
  2. using Azure.Messaging.ServiceBus;
  3. using HTEXLib.COMM.Helpers;
  4. using Microsoft.Extensions.Configuration;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Text.Json;
  10. using System.Threading.Tasks;
  11. using TEAMModelOS.SDK.DI;
  12. using TEAMModelOS.SDK.Extension;
  13. using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
  14. using TEAMModelOS.SDK.Models.Cosmos.Common;
  15. namespace TEAMModelOS.SDK.Models.Service
  16. {
  17. public class LessonService
  18. {
  19. public static async void DoLessonStudentRecord(LessonRecord lessonRecord, string scope, CosmosClient client, string school, string tmdid,
  20. Teacher teacher, NotificationService _notificationService, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration, LessonBase lessonBase)
  21. {
  22. var stuids = lessonBase.student.Where(x => x.type == 2).Select(x => new IdNameCode { id = x.id ,code=x.school});
  23. if (stuids.Any()) {
  24. stuids.ToList().ForEach(x => {
  25. x.code = string.IsNullOrWhiteSpace(x.code) ? school : x.code;
  26. });
  27. }
  28. var groups= stuids.Where(z=>!string.IsNullOrWhiteSpace(z.code)).GroupBy(x => x.code).Select(y=>new { code=y.Key,list=y.ToList()});
  29. List<LessonStudentRecord> lessonStudentRecords = new List<LessonStudentRecord>();
  30. foreach (var group in groups) {
  31. string stusql = $"select value(c) from c where c.id in({string.Join(",",group.list.Select(x=>$"'{x.id}'"))})";
  32. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<LessonStudentRecord>(queryText: stusql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"LessonStudentRecord-{group.code}") })) {
  33. lessonStudentRecords.Add(item);
  34. }
  35. }
  36. var tmdids = lessonBase.student.Where(x => x.type == 1).Select(x => new { id = x.id });
  37. if (tmdids.Any()) {
  38. string tmdsql = $"select value(c) from c where c.id in({string.Join(",", tmdids.Select(x => $"'{x}'"))})";
  39. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<LessonStudentRecord>(queryText: tmdsql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"LessonStudentRecord") }))
  40. {
  41. lessonStudentRecords.Add(item);
  42. }
  43. }
  44. List<Task<ItemResponse<LessonStudentRecord>>> records = new List<Task<ItemResponse<LessonStudentRecord>>>();
  45. stuids.ToList().ForEach(x => {
  46. var record = lessonStudentRecords.Find(l => l.id.Equals(x.id) && l.code.Equals($"LessonStudentRecord-{x.code}"));
  47. if (record != null)
  48. {
  49. record.records.Add(new StudentRecord {
  50. tmdid = teacher.id,
  51. tmdname = teacher.name,
  52. name = lessonRecord.name,
  53. school = lessonRecord.school,
  54. scope = lessonRecord.scope,
  55. lessonId = lessonRecord.id,
  56. courseId = lessonRecord.courseId,
  57. periodId = lessonRecord.periodId,
  58. subjectId = lessonRecord.subjectId,
  59. });
  60. }
  61. else {
  62. }
  63. });
  64. tmdids.ToList().ForEach(x => {
  65. var record = lessonStudentRecords.Find(l => l.id.Equals(x.id) && l.code.Equals($"LessonStudentRecord"));
  66. });
  67. }
  68. public static async void DoAutoDeleteSchoolLessonRecord(LessonRecord lessonRecord,string scope ,CosmosClient client,string school,string tmdid,
  69. Teacher teacher, NotificationService _notificationService, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, IConfiguration _configuration) {
  70. if (lessonRecord.scope.Equals("school"))
  71. {
  72. SchoolSetting setting = null;
  73. Azure.Response schoolSetting = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(school, new PartitionKey("SchoolSetting"));
  74. School schoolBase = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
  75. if (schoolSetting.Status == 200)
  76. {
  77. setting = JsonDocument.Parse(schoolSetting.Content).RootElement.Deserialize<SchoolSetting>();
  78. if (setting.lessonSetting != null)
  79. {
  80. if (setting.lessonSetting.openAutoClean != 0 || setting.lessonSetting.openAutoClean != 1)
  81. {
  82. setting.lessonSetting.openAutoClean = 0;
  83. setting.lessonSetting.expireDays = Constant.school_lesson_expire;
  84. }
  85. }
  86. else
  87. {
  88. setting.lessonSetting = new LessonSetting() { openAutoClean = 0, expireDays = Constant.school_lesson_expire };
  89. }
  90. }
  91. else
  92. {
  93. setting = new SchoolSetting() { lessonSetting = new LessonSetting { openAutoClean = 0, expireDays = Constant.school_lesson_expire } };
  94. }
  95. int school_lesson_expire =0;
  96. bool save = true;
  97. List<string> msg = new List<string>();
  98. if (setting.lessonSetting.openAutoClean == 1)
  99. {
  100. if (setting.lessonSetting.conds.IsEmpty())
  101. {
  102. save = false;
  103. }
  104. else {
  105. school_lesson_expire = setting.lessonSetting.expireDays;
  106. foreach (var item in setting.lessonSetting.conds)
  107. {
  108. switch (item.type)
  109. {
  110. case ">=":
  111. switch (item.key)
  112. {
  113. case "attendRate":
  114. if (!(lessonRecord.attendRate >= item.val))
  115. {
  116. save = false;
  117. msg.Add($"{item.key}:{lessonRecord.attendRate}{item.type}{item.val}");
  118. }
  119. break;
  120. case "groupCount":
  121. if (!(lessonRecord.groupCount >= item.val))
  122. {
  123. save = false;
  124. msg.Add($"{item.key}:{lessonRecord.groupCount}{item.type}{item.val}");
  125. }
  126. break;
  127. case "totalPoint":
  128. if (!(lessonRecord.totalPoint >= item.val))
  129. {
  130. save = false;
  131. msg.Add($"{item.key}:{lessonRecord.totalPoint}{item.type}{item.val}");
  132. }
  133. break;
  134. case "collateTaskCount":
  135. if (!(lessonRecord.collateTaskCount >= item.val))
  136. {
  137. save = false;
  138. msg.Add($"{item.key}:{lessonRecord.collateTaskCount}{item.type}{item.val}");
  139. }
  140. break;
  141. case "collateCount":
  142. if (!(lessonRecord.collateCount >= item.val))
  143. {
  144. save = false;
  145. msg.Add($"{item.key}:{lessonRecord.collateCount}{item.type}{item.val}");
  146. }
  147. break;
  148. case "pushCount":
  149. if (!(lessonRecord.pushCount >= item.val))
  150. {
  151. save = false;
  152. msg.Add($"{item.key}:{lessonRecord.pushCount}{item.type}{item.val}");
  153. }
  154. break;
  155. case "totalInteractPoint":
  156. if (!(lessonRecord.totalInteractPoint >= item.val))
  157. {
  158. save = false;
  159. msg.Add($"{item.key}:{lessonRecord.totalInteractPoint}{item.type}{item.val}");
  160. }
  161. break;
  162. case "interactionCount":
  163. if (!(lessonRecord.interactionCount >= item.val))
  164. {
  165. save = false;
  166. msg.Add($"{item.key}:{lessonRecord.interactionCount}{item.type}{item.val}");
  167. }
  168. break;
  169. case "clientInteractionCount":
  170. if (!(lessonRecord.clientInteractionCount >= item.val))
  171. {
  172. save = false;
  173. msg.Add($"{item.key}:{lessonRecord.clientInteractionCount}{item.type}{item.val}");
  174. }
  175. break;
  176. case "examQuizCount":
  177. if (!(lessonRecord.examQuizCount >= item.val))
  178. {
  179. save = false;
  180. msg.Add($"{item.key}:{lessonRecord.examQuizCount}{item.type}{item.val}");
  181. }
  182. break;
  183. case "examPointRate":
  184. if (!(lessonRecord.examPointRate >= item.val))
  185. {
  186. save = false;
  187. msg.Add($"{item.key}:{lessonRecord.examPointRate}{item.type}{item.val}");
  188. }
  189. break;
  190. }
  191. break;
  192. case "<=":
  193. switch (item.key)
  194. {
  195. case "attendRate":
  196. if (!(lessonRecord.attendRate <= item.val))
  197. {
  198. save = false;
  199. msg.Add($"{item.key}:{lessonRecord.attendRate}{item.type}{item.val}");
  200. }
  201. break;
  202. case "groupCount":
  203. if (!(lessonRecord.groupCount <= item.val))
  204. {
  205. save = false;
  206. msg.Add($"{item.key}:{lessonRecord.groupCount}{item.type}{item.val}");
  207. }
  208. break;
  209. case "totalPoint":
  210. if (!(lessonRecord.totalPoint <= item.val))
  211. {
  212. save = false;
  213. msg.Add($"{item.key}:{lessonRecord.totalPoint}{item.type}{item.val}");
  214. }
  215. break;
  216. case "collateTaskCount":
  217. if (!(lessonRecord.collateTaskCount <= item.val))
  218. {
  219. save = false;
  220. msg.Add($"{item.key}:{lessonRecord.collateTaskCount}{item.type}{item.val}");
  221. }
  222. break;
  223. case "collateCount":
  224. if (!(lessonRecord.collateCount <= item.val))
  225. {
  226. save = false;
  227. msg.Add($"{item.key}:{lessonRecord.collateCount}{item.type}{item.val}");
  228. }
  229. break;
  230. case "pushCount":
  231. if (!(lessonRecord.pushCount <= item.val))
  232. {
  233. save = false;
  234. msg.Add($"{item.key}:{lessonRecord.pushCount}{item.type}{item.val}");
  235. }
  236. break;
  237. case "totalInteractPoint":
  238. if (!(lessonRecord.totalInteractPoint <= item.val))
  239. {
  240. save = false;
  241. msg.Add($"{item.key}:{lessonRecord.totalInteractPoint}{item.type}{item.val}");
  242. }
  243. break;
  244. case "interactionCount":
  245. if (!(lessonRecord.interactionCount <= item.val))
  246. {
  247. save = false;
  248. msg.Add($"{item.key}:{lessonRecord.interactionCount}{item.type}{item.val}");
  249. }
  250. break;
  251. case "clientInteractionCount":
  252. if (!(lessonRecord.clientInteractionCount <= item.val))
  253. {
  254. save = false;
  255. msg.Add($"{item.key}:{lessonRecord.clientInteractionCount}{item.type}{item.val}");
  256. }
  257. break;
  258. case "examQuizCount":
  259. if (!(lessonRecord.examQuizCount <= item.val))
  260. {
  261. save = false;
  262. msg.Add($"{item.key}:{lessonRecord.examQuizCount}{item.type}{item.val}");
  263. }
  264. break;
  265. case "examPointRate":
  266. if (!(lessonRecord.examPointRate <= item.val))
  267. {
  268. save = false;
  269. msg.Add($"{item.key}:{lessonRecord.examPointRate}{item.type}{item.val}");
  270. }
  271. break;
  272. }
  273. break;
  274. }
  275. }
  276. }
  277. }
  278. else {
  279. save = false;
  280. school_lesson_expire = Constant.school_lesson_expire;
  281. }
  282. if (!save && school_lesson_expire > 0)
  283. {
  284. // 1-时间戳,7-时间戳
  285. Dictionary<int, ExpireTag> result = new Dictionary<int, ExpireTag>();
  286. //暂定7天
  287. var now = DateTimeOffset.UtcNow;
  288. //剩余3天的通知
  289. //var day3= now.AddDays(school_lesson_expire - 3).ToUnixTimeMilliseconds();
  290. //result.Add(3, day3);
  291. //剩余1天的通知
  292. var day1 = now.AddDays(school_lesson_expire - (school_lesson_expire - 1)).ToUnixTimeMilliseconds();
  293. result.Add(1, new ExpireTag { expire= day1 ,tag= "notification" });
  294. //到期通知
  295. //不到五点上传的课例,七天之后直接删除。
  296. int addSecond = 0;
  297. if (now.Hour > 5)
  298. {
  299. // 到凌晨00点还差 (24 - now.Hour) *60 * 60 分钟,再加天数;
  300. addSecond = school_lesson_expire * 86400 + (24 - now.Hour) * 3600-(now.Hour* 3600);
  301. //再加 00到05小时内的 随机秒数
  302. Random rand = new Random();
  303. int randInt = rand.Next(0, 18000);
  304. addSecond += randInt;
  305. }
  306. else
  307. {
  308. addSecond = school_lesson_expire * 24 * 60 * 60;
  309. }
  310. lessonRecord.expire = now.AddSeconds(addSecond).ToUnixTimeMilliseconds();
  311. result.Add(school_lesson_expire, new ExpireTag { expire = lessonRecord.expire, tag = "delete" });
  312. // result.Add(school_lesson_expire, lessonRecord.expire);
  313. string biz = "expire";
  314. Notification notification = new Notification
  315. {
  316. hubName = "hita",
  317. type = "msg",
  318. from = $"ies5:{ Environment.GetEnvironmentVariable("Option:Location")}:private",
  319. to = new List<string> { tmdid },
  320. label = $"{biz}_lessonRecord",
  321. body = new
  322. {
  323. location = $"{Environment.GetEnvironmentVariable("Option:Location")}",
  324. biz = biz,
  325. tmdid = tmdid,
  326. tmdname = teacher.name,
  327. scope = scope,
  328. school = school,
  329. schoolName = schoolBase.name,
  330. sid = lessonRecord.id,
  331. sname = lessonRecord.name,
  332. stime = lessonRecord.startTime,
  333. expire = lessonRecord.expire,
  334. status = 1,
  335. //day = school_lesson_expire,
  336. time = now
  337. }.ToJsonString(),
  338. expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
  339. };
  340. var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
  341. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  342. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  343. var location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  344. await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
  345. var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  346. List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", lessonRecord.id } });
  347. if (records.Count <= 0)
  348. {
  349. foreach (var item in result)
  350. {
  351. string PartitionKey = string.Format("{0}{1}{2}", lessonRecord.code, "-", $"expire-{item.Key}");
  352. //课堂的id ,
  353. //课堂的通知时间类型progress, 默认就会发送一条,到期前一天发送一条,最后已到期发送一条。
  354. var message = new ServiceBusMessage(new
  355. {
  356. id = lessonRecord.id,
  357. progress = item.Key,
  358. code = lessonRecord.code,
  359. scope = lessonRecord.scope,
  360. school = lessonRecord.school,
  361. opt = "delete",
  362. expire = lessonRecord.expire,
  363. tmdid = tmdid,
  364. tmdname = teacher.name,
  365. name = lessonRecord.name,
  366. startTime = lessonRecord.startTime,
  367. tag = item.Value.tag
  368. }.ToJsonString());
  369. message.ApplicationProperties.Add("name", "LessonRecordExpire");
  370. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(item.Value.expire));
  371. ChangeRecord changeRecord = new ChangeRecord
  372. {
  373. RowKey = lessonRecord.id,
  374. PartitionKey = PartitionKey,
  375. sequenceNumber = start,
  376. msgId = message.MessageId
  377. };
  378. await table.Save<ChangeRecord>(changeRecord);
  379. }
  380. }
  381. }
  382. else {
  383. if (lessonRecord.expire > 0)
  384. {
  385. var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  386. List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", lessonRecord.id } });
  387. foreach (var record in records)
  388. {
  389. try
  390. {
  391. await table.DeleteSingle<ChangeRecord>(record.PartitionKey, record.RowKey);
  392. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
  393. }
  394. catch (Exception)
  395. {
  396. continue;
  397. }
  398. }
  399. }
  400. lessonRecord.save = 1;
  401. lessonRecord.expire = -1;
  402. }
  403. }
  404. }
  405. public record ExpireTag {
  406. public long expire { get; set; }
  407. public string tag { get; set; }
  408. }
  409. /// <summary>
  410. ///
  411. /// </summary>
  412. /// <param name="client"></param>
  413. /// <param name="_dingDing"></param>
  414. /// <param name="data"></param>
  415. /// <returns></returns>
  416. public static LessonDis DisLessonCount(LessonRecord oldRecord, LessonRecord newRecord, LessonDis lessonDis)
  417. {
  418. //创建课堂的情况
  419. if (oldRecord == null && newRecord != null)
  420. {
  421. lessonDis.record = 1;
  422. }
  423. //删除数据的情况
  424. else if (oldRecord != null && newRecord == null)
  425. {
  426. lessonDis.record = -1;
  427. //P分数量加减
  428. if (oldRecord.pScore >= 70)
  429. {
  430. lessonDis.disPCount = -1;
  431. }
  432. //T分数量加减
  433. if (oldRecord.tScore >= 70)
  434. {
  435. lessonDis.disTCount = -1;
  436. }
  437. if (oldRecord.tScore >= 70 && oldRecord.pScore >= 70)
  438. {
  439. lessonDis.disTCount = -1;
  440. }
  441. }
  442. //无效操作
  443. else if (oldRecord == null && newRecord == null)
  444. {
  445. }
  446. //前后操作都有值,则表示更新
  447. else
  448. {
  449. //P分数量加减
  450. if (oldRecord.pScore >= 70)
  451. {
  452. if (newRecord.pScore < 70)
  453. {
  454. lessonDis.disPCount = -1;
  455. }
  456. }
  457. else
  458. {
  459. if (newRecord.pScore >= 70)
  460. {
  461. lessonDis.disPCount = 1;
  462. }
  463. }
  464. //T分数量加减
  465. if (oldRecord.tScore >= 70)
  466. {
  467. if (newRecord.tScore < 70)
  468. {
  469. lessonDis.disTCount = -1;
  470. }
  471. }
  472. else
  473. {
  474. if (newRecord.tScore >= 70)
  475. {
  476. lessonDis.disTCount = 1;
  477. }
  478. }
  479. //双绿灯数量
  480. if (oldRecord.tScore >= 70 && oldRecord.pScore >= 70)
  481. {
  482. if (newRecord.tScore < 70 || newRecord.pScore < 70)
  483. {
  484. lessonDis.disDCount = -1;
  485. }
  486. }
  487. else
  488. {
  489. if (newRecord.tScore >= 70 && newRecord.pScore >= 70)
  490. {
  491. lessonDis.disDCount = 1;
  492. }
  493. }
  494. }
  495. return lessonDis;
  496. }
  497. public static LessonDis DisLessonCount_2(LessonRecord oldRecord, LessonRecord newRecord, LessonDis lessonDis)
  498. {
  499. //创建课堂的情况
  500. if (oldRecord == null && newRecord != null)
  501. {
  502. lessonDis.record = 1;
  503. //P分数量加减
  504. if (newRecord.pScore >= 70)
  505. {
  506. lessonDis.disPCount = 1;
  507. }
  508. //T分数量加减
  509. if (newRecord.tScore >= 70)
  510. {
  511. lessonDis.disTCount = 1;
  512. }
  513. //双绿灯数量
  514. if (newRecord.tScore >= 70 && newRecord.pScore >= 70)
  515. {
  516. lessonDis.disDCount = 1;
  517. }
  518. }
  519. return lessonDis;
  520. }
  521. public static async Task FixLessonCount(CosmosClient client, DingDing _dingDing, LessonRecord record, LessonRecord oldRecord, LessonDis lessonDis)
  522. {
  523. LessonRecord data = null;
  524. try
  525. {
  526. if (record != null && oldRecord == null)
  527. {
  528. data = record;
  529. }
  530. if (record == null && oldRecord != null)
  531. {
  532. data = oldRecord;
  533. }
  534. if (record != null && oldRecord != null)
  535. {
  536. data = record;
  537. }
  538. int day = DateTimeOffset.FromUnixTimeMilliseconds(data.startTime).DayOfYear;
  539. int year = DateTimeOffset.FromUnixTimeMilliseconds(data.startTime).Year;
  540. int days = DateTimeHelper.getDays(year);
  541. //int years = DateTimeOffset.UtcNow.DayOfYear;
  542. string tbname = string.Empty;
  543. string code = string.Empty;
  544. if (data.scope != null && data.scope.Equals("school"))
  545. {
  546. code = $"LessonCount-{data.school}-{year}-{data.periodId}";
  547. tbname = "School";
  548. }
  549. else
  550. {
  551. code = $"LessonCount-{year}";
  552. tbname = "Teacher";
  553. }
  554. var response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(data.tmdid.ToString(), new PartitionKey(code));
  555. if (response.Status == 200)
  556. {
  557. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  558. LessonCount count = json.ToObject<LessonCount>();
  559. count.tCount[day - 1] += lessonDis.disTCount;
  560. count.pCount[day - 1] += lessonDis.disPCount;
  561. count.ptCount[day - 1] += lessonDis.disDCount;
  562. count.beginCount[day - 1] += lessonDis.record;
  563. /*if (!count.courseIds.Contains(data.courseId))
  564. {
  565. count.courseIds.Add(data.courseId);
  566. count.beginCount[day] += 1;
  567. }*/
  568. await client.GetContainer("TEAMModelOS", tbname).ReplaceItemAsync(count, count.id, new PartitionKey(code));
  569. }
  570. else
  571. {
  572. LessonCount count = new LessonCount
  573. {
  574. id = data.tmdid,
  575. code = code,
  576. ttl = -1
  577. };
  578. double[] da = new double[days];
  579. List<double> list = new (da);
  580. List<double> listT = new (da);
  581. List<double> listP = new (da);
  582. List<double> listPT = new (da);
  583. list[day - 1] += lessonDis.record;
  584. listT[day - 1] += lessonDis.disTCount;
  585. listP[day - 1] += lessonDis.disPCount;
  586. listPT[day - 1] += lessonDis.disDCount;
  587. count.beginCount.AddRange(list);
  588. count.tCount.AddRange(listT);
  589. count.pCount.AddRange(listP);
  590. count.ptCount.AddRange(listPT);
  591. //count.courseIds.Add(data.courseId);
  592. await client.GetContainer("TEAMModelOS", tbname).CreateItemAsync(count, new PartitionKey(code));
  593. }
  594. }
  595. catch (Exception ex)
  596. {
  597. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-LessonCount-FixLessonCount\n{ex.Message}\n{ex.StackTrace}{data.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
  598. }
  599. }
  600. }
  601. }