LessonService.cs 32 KB

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