ActiveTaskTopic.cs 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.Json;
  5. using System.Threading.Tasks;
  6. using Azure.Cosmos;
  7. using Azure.Messaging.ServiceBus;
  8. using Microsoft.Extensions.Logging;
  9. using StackExchange.Redis;
  10. using TEAMModelOS.SDK.DI;
  11. using TEAMModelOS.SDK.Extension;
  12. using TEAMModelOS.SDK;
  13. using TEAMModelOS.SDK.Models;
  14. using TEAMModelOS.SDK.Models.Cosmos;
  15. using TEAMModelOS.SDK.Models.Cosmos.Common;
  16. using System.Linq;
  17. using TEAMModelOS.SDK.Models.Service;
  18. using TEAMModelOS.SDK.Models.Cosmos.BI;
  19. using TEAMModelOS.Models;
  20. using Microsoft.Extensions.Options;
  21. using Microsoft.Extensions.Configuration;
  22. using HTEXLib.COMM.Helpers;
  23. using Microsoft.Azure.Functions.Worker;
  24. using TEAMModelOS.SDK.Services;
  25. namespace TEAMModelOS.FunctionV4.ServiceBus
  26. {
  27. public class ActiveTaskTopic
  28. {
  29. private readonly AzureCosmosFactory _azureCosmos;
  30. private readonly DingDing _dingDing;
  31. private readonly AzureStorageFactory _azureStorage;
  32. private readonly AzureRedisFactory _azureRedis;
  33. private readonly AzureServiceBusFactory _serviceBus;
  34. private readonly Option _option;
  35. private readonly NotificationService _notificationService;
  36. private readonly IConfiguration _configuration;
  37. public ActiveTaskTopic(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IOptionsSnapshot<Option> option, NotificationService notificationService, IConfiguration configuration)
  38. {
  39. _azureCosmos = azureCosmos;
  40. _dingDing = dingDing;
  41. _azureStorage = azureStorage;
  42. _azureRedis = azureRedis;
  43. _serviceBus = serviceBus;
  44. _option = option?.Value;
  45. _notificationService = notificationService;
  46. _configuration = configuration;
  47. }
  48. [Function("Exam")]
  49. public async Task ExamFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  50. {
  51. try
  52. {
  53. var json = JsonDocument.Parse(msg);
  54. json.RootElement.TryGetProperty("id", out JsonElement id);
  55. json.RootElement.TryGetProperty("progress", out JsonElement progress);
  56. json.RootElement.TryGetProperty("code", out JsonElement code);
  57. //Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
  58. var client = _azureCosmos.GetCosmosClient();
  59. ExamInfo exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
  60. exam.progress = progress.ToString();
  61. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
  62. }
  63. catch (CosmosException e)
  64. {
  65. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamBus()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
  66. }
  67. catch (Exception ex)
  68. {
  69. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamBus()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  70. }
  71. }
  72. [Function("Vote")]
  73. public async Task VoteFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "vote", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  74. {
  75. try
  76. {
  77. var jsonMsg = JsonDocument.Parse(msg);
  78. jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
  79. jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
  80. jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
  81. var client = _azureCosmos.GetCosmosClient();
  82. Vote vote = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Vote>(id.ToString(), new PartitionKey($"{code}"));
  83. vote.progress = progress.ToString();
  84. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
  85. }
  86. catch (CosmosException e)
  87. {
  88. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,VoteBus()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
  89. }
  90. catch (Exception ex)
  91. {
  92. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,VoteBus()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  93. }
  94. }
  95. [Function("Correct")]
  96. public async Task CorrectFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "correct", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  97. {
  98. try
  99. {
  100. var jsonMsg = JsonDocument.Parse(msg);
  101. jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
  102. jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
  103. jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
  104. var client = _azureCosmos.GetCosmosClient();
  105. Correct correct = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Correct>(id.ToString(), new PartitionKey($"{code}"));
  106. correct.progress = progress.ToString();
  107. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(correct, id.ToString(), new PartitionKey($"{code}"));
  108. }
  109. catch (CosmosException e)
  110. {
  111. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Correct()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
  112. }
  113. catch (Exception ex)
  114. {
  115. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Correct()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  116. }
  117. }
  118. [Function("Survey")]
  119. public async Task SurveyFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "survey", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  120. {
  121. try
  122. {
  123. var jsonMsg = JsonDocument.Parse(msg);
  124. jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
  125. jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
  126. jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
  127. //Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
  128. var client = _azureCosmos.GetCosmosClient();
  129. Survey survey = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
  130. survey.progress = progress.ToString();
  131. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
  132. }
  133. catch (CosmosException e)
  134. {
  135. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,SurveyBus()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
  136. }
  137. catch (Exception ex)
  138. {
  139. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,SurveyBus()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  140. }
  141. }
  142. [Function("Homework")]
  143. public async Task HomeworkFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "homework", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  144. {
  145. try
  146. {
  147. var jsonMsg = JsonDocument.Parse(msg);
  148. jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
  149. jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
  150. jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
  151. var client = _azureCosmos.GetCosmosClient();
  152. Homework homework = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Homework>(id.ToString(), new PartitionKey($"{code}"));
  153. homework.progress = progress.ToString();
  154. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(homework, id.ToString(), new PartitionKey($"{code}"));
  155. }
  156. catch (CosmosException e)
  157. {
  158. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Homework()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
  159. }
  160. catch (Exception ex)
  161. {
  162. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Homework()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  163. }
  164. }
  165. [Function("Study")]
  166. public async Task StudyFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "study", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  167. {
  168. try
  169. {
  170. var jsonMsg = JsonDocument.Parse(msg);
  171. jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
  172. jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
  173. jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
  174. var client = _azureCosmos.GetCosmosClient();
  175. Study study = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Study>(id.ToString(), new PartitionKey($"{code}"));
  176. study.progress = progress.ToString();
  177. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(study, id.ToString(), new PartitionKey($"{code}"));
  178. }
  179. catch (CosmosException e)
  180. {
  181. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Study()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
  182. }
  183. catch (Exception ex)
  184. {
  185. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Study()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  186. }
  187. }
  188. [Function("ExamLite")]
  189. public async Task ExamLiteFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "examlite", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  190. {
  191. try
  192. {
  193. var jsonMsg = JsonDocument.Parse(msg);
  194. jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
  195. jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
  196. jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
  197. var client = _azureCosmos.GetCosmosClient();
  198. ExamLite lite = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamLite>(id.ToString(), new PartitionKey($"{code}"));
  199. lite.progress = progress.ToString();
  200. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(lite, id.ToString(), new PartitionKey($"{code}"));
  201. }
  202. catch (CosmosException e)
  203. {
  204. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamLite()-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
  205. }
  206. catch (Exception ex)
  207. {
  208. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamLite()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  209. }
  210. }
  211. /// <summary>
  212. /// 根据容器的根目录刷新redis并获取redis的最新使用情况
  213. /// </summary>
  214. /// <param name="msg"></param>
  215. /// <returns></returns>
  216. [Function("BlobRoot")]
  217. public async Task BlobRootFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "blobroot", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  218. {
  219. try
  220. {
  221. var jsonMsg = JsonDocument.Parse(msg);
  222. if (jsonMsg.RootElement.TryGetProperty("name", out JsonElement _name) && _name.ValueKind == JsonValueKind.String
  223. && jsonMsg.RootElement.TryGetProperty("root", out JsonElement root) && root.ValueKind == JsonValueKind.String)
  224. {
  225. //await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob() 容器:触发变更,{jsonMsg.ToJsonString()}",
  226. // GroupNames.成都开发測試群組);
  227. List<Dictionary<string, double?>> list = new List<Dictionary<string, double?>>();
  228. string[] uls = System.Web.HttpUtility.UrlDecode($"{root}", Encoding.UTF8).Split("/");
  229. string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
  230. string name = $"{_name}";
  231. string lockKey = $"Blob:Lock:{name}:{u}";
  232. bool exist = await _azureRedis.GetRedisClient(8).KeyExistsAsync(lockKey);
  233. if (!exist)
  234. { ///key不存在则正常进行计算
  235. bool condition = false;
  236. TimeSpan timeSpan = new TimeSpan(DateTimeOffset.UtcNow.AddMinutes(5).Ticks);
  237. timeSpan = timeSpan - new TimeSpan(DateTimeOffset.UtcNow.Ticks);
  238. //准备处理Blob刷新时间
  239. long action = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  240. await _azureRedis.GetRedisClient(8).StringSetAsync(lockKey, action, expiry: timeSpan);
  241. await RefreshBlob(name, u);
  242. //将action 与Redis最新的时间进行比较,如果
  243. var rds = await CheckLockKey(lockKey, action);
  244. condition = rds.condition;
  245. exist = rds.exist;
  246. if (condition || !exist)
  247. {
  248. await RefreshBlob(name, u);
  249. }
  250. //使用 CancellationToken
  251. //while (condition || !exist)
  252. //{
  253. //}
  254. }
  255. else
  256. {
  257. ///key存在则,则刷新key对应的值
  258. TimeSpan timeSpan = new TimeSpan(DateTimeOffset.UtcNow.AddMinutes(5).Ticks);
  259. timeSpan = timeSpan - new TimeSpan(DateTimeOffset.UtcNow.Ticks);
  260. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  261. await _azureRedis.GetRedisClient(8).StringSetAsync(lockKey, now, expiry: timeSpan);
  262. }
  263. //await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob() 容器:{name}使用:{u},文件分类:{list.ToJsonString()}",
  264. // GroupNames.成都开发測試群組);
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  270. }
  271. }
  272. private async Task<(bool condition, bool exist)> CheckLockKey(string lockKey, long nowTime)
  273. {
  274. //Redis的最新时间
  275. long newestTime = 0;
  276. RedisValue value = await _azureRedis.GetRedisClient(8).StringGetAsync(lockKey);
  277. if (value != default && !value.IsNullOrEmpty)
  278. {
  279. JsonElement record = value.ToString().ToObject<JsonElement>();
  280. if (record.TryGetInt64(out newestTime))
  281. {
  282. }
  283. }
  284. //说明key已经不存在
  285. if (newestTime == 0)
  286. {
  287. return (false, true);
  288. }
  289. //说明key存在
  290. else
  291. {
  292. //说明Redis记录了最新的时间戳
  293. if (nowTime != newestTime)
  294. {
  295. return (true, false);
  296. }
  297. //时间相同,没有被再次记录最新的时间戳
  298. else
  299. {
  300. await _azureRedis.GetRedisClient(8).KeyDeleteAsync(lockKey);
  301. return (false, true);
  302. }
  303. }
  304. }
  305. private async Task RefreshBlob(string name, string u)
  306. {
  307. long statr = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  308. var client = _azureStorage.GetBlobContainerClient(name);
  309. var size = await client.GetBlobsSize(u);
  310. await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", u);
  311. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", u, size.HasValue ? size.Value : 0);
  312. var scores = await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{name}");
  313. double blobsize = 0;
  314. if (scores != default && scores != null)
  315. {
  316. foreach (var score in scores)
  317. {
  318. blobsize = blobsize + score.Score;
  319. }
  320. }
  321. await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue(name), new RedisValue($"{blobsize}"));
  322. long end = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  323. long dis = (end - statr) / 1000;
  324. long timeout = 10;
  325. if (dis > timeout)
  326. {
  327. await _dingDing.SendBotMsg($"ServiceBus,RefreshBlob:空间计算已经超过{timeout}秒\n容器名:{name}\n文件夹:{u}\n计算时长:{dis}", GroupNames.醍摩豆服務運維群組);
  328. }
  329. }
  330. /// <summary>
  331. /// 完善课程变更,StuListChange, originCode是学校编码 则表示名单是学校自定义名单,如果是tmdid则表示醍摩豆的私有名单,scope=school,private。
  332. /// </summary>
  333. /// <data msg>
  334. /// CourseChange
  335. ///// </data>
  336. /// <param name="msg"></param>
  337. /// <returns></returns>
  338. [Function("TeacherTrainChange")]
  339. public async Task TeacherTrainChangeFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "teacher-train-change", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  340. {
  341. try
  342. {
  343. // await _dingDing.SendBotMsg($"teacher-train-change\n{msg}",GroupNames.成都开发測試群組);
  344. TeacherTrainChange change = msg.ToObject<TeacherTrainChange>();
  345. if (change.update == null || change.update.Count <= 0 || change.tmdids.IsEmpty())
  346. {
  347. return;
  348. }
  349. var client = _azureCosmos.GetCosmosClient();
  350. string insql = $"where c.id in ({string.Join(",", change.tmdids.Select(x => $"'{x}'"))})";
  351. string selsql = $"select value(c) from c {insql} ";
  352. List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
  353. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TeacherTrain>(queryText: selsql,
  354. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{change.school}") }))
  355. {
  356. teacherTrains.Add(item);
  357. }
  358. if (change.statistics != 1)
  359. {
  360. List<Task<ItemResponse<TeacherTrain>>> task = new List<Task<ItemResponse<TeacherTrain>>>();
  361. teacherTrains.ForEach(x =>
  362. {
  363. x.update.UnionWith(change.update);
  364. task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<TeacherTrain>(x, x.id, new PartitionKey($"TeacherTrain-{change.school}")));
  365. });
  366. await task.TaskPage(5);
  367. var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
  368. if (unchange != null)
  369. {
  370. task.Clear();
  371. unchange.ToList().ForEach(x =>
  372. {
  373. TeacherTrain teacherTrain = new TeacherTrain
  374. {
  375. pk = "TeacherTrain",
  376. id = x,
  377. code = $"TeacherTrain-{change.school}",
  378. tmdid = x,
  379. school = change.school,
  380. update = new HashSet<string> { StatisticsService.TeacherAbility,
  381. StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
  382. };
  383. teacherTrain.update.UnionWith(change.update);
  384. task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<TeacherTrain>(teacherTrain, new PartitionKey($"TeacherTrain-{change.school}")));
  385. });
  386. await task.TaskPage(1);
  387. }
  388. }
  389. else
  390. {
  391. Area area = null;
  392. string sql = $"select value(c) from c where c.standard='{change.standard}'";
  393. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: sql,
  394. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
  395. {
  396. area = item;
  397. }
  398. AreaSetting setting = null;
  399. if (area != null)
  400. {
  401. try
  402. {
  403. //优先找校级
  404. setting = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<AreaSetting>(change.school, new PartitionKey("AreaSetting"));
  405. }
  406. catch (CosmosException)
  407. {
  408. try
  409. {
  410. setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>(area.id, new PartitionKey("AreaSetting"));
  411. }
  412. catch (CosmosException)
  413. {
  414. setting = null;
  415. }
  416. }
  417. }
  418. if (setting == null)
  419. {
  420. setting = new AreaSetting
  421. {
  422. allTime = 50,
  423. classTime = 5,
  424. submitTime = 15,
  425. onlineTime = 20,
  426. offlineTime = 10,
  427. lessonMinutes = 45,
  428. };
  429. }
  430. List<Task<TeacherTrain>> task = new List<Task<TeacherTrain>>();
  431. teacherTrains.ForEach(x =>
  432. {
  433. x.update.UnionWith(change.update);
  434. task.Add(StatisticsService.StatisticsTeacher(x, setting, area, client, null));
  435. });
  436. await task.TaskPage(1);
  437. var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
  438. if (unchange != null)
  439. {
  440. task.Clear();
  441. unchange.ToList().ForEach(x =>
  442. {
  443. task.Add(StatisticsService.StatisticsTeacher(new TeacherTrain
  444. {
  445. pk = "TeacherTrain",
  446. id = x,
  447. code = $"TeacherTrain-{change.school}",
  448. tmdid = x,
  449. school = change.school,
  450. update = new HashSet<string> { StatisticsService.TeacherAbility,
  451. StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
  452. }, setting, area, client, null));
  453. });
  454. await task.TaskPage(1);
  455. }
  456. }
  457. }
  458. catch (CosmosException ex)
  459. {
  460. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}CosmosException{ex.Status}", GroupNames.成都开发測試群組);
  461. }
  462. catch (Exception ex)
  463. {
  464. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  465. }
  466. }
  467. /// <summary>
  468. /// 完善课程变更,StuListChange, originCode是学校编码 则表示名单是学校自定义名单,如果是tmdid则表示醍摩豆的私有名单,scope=school,private。
  469. /// </summary>
  470. /// <data msg>
  471. /// CourseChange
  472. ///// </data>
  473. /// <param name="msg"></param>
  474. /// <returns></returns>
  475. [Function("GroupChange")]
  476. public async Task GroupChangeFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "group-change", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  477. {
  478. var client = _azureCosmos.GetCosmosClient();
  479. try
  480. {
  481. //await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-名单成员变更-GroupChange\n{msg}", GroupNames.成都开发測試群組);
  482. var jsonMsg = JsonDocument.Parse(msg);
  483. GroupChange groupChange = msg.ToObject<GroupChange>();
  484. //名单变动修改学生课程关联信息
  485. //await StuListService.FixStuCourse(client, stuListChange);
  486. //Vote投票 Survey问卷 Exam评测 Learn学习活动 Homework作业活动
  487. //名单变动修改学生问卷关联信息
  488. await ActivityService.FixActivity(client, _dingDing, groupChange, "Survey");
  489. //名单变动修改学生投票关联信息
  490. await ActivityService.FixActivity(client, _dingDing, groupChange, "Vote");
  491. //名单变动修改学生评测关联信息
  492. await ActivityService.FixActivity(client, _dingDing, groupChange, "Exam");
  493. //名单变动修改学生研修关联信息
  494. await ActivityService.FixActivity(client, _dingDing, groupChange, "Study");
  495. //名单变动修改学生简易评测关联信息
  496. await ActivityService.FixActivity(client, _dingDing, groupChange, "ExamLite");
  497. //TODO学习活动
  498. //await FixActivity(client, stuListChange, "Learn");
  499. //名单变动修改学生作业活动信息
  500. await ActivityService.FixActivity(client, _dingDing, groupChange, "Homework");
  501. if (groupChange.type == null || !groupChange.type.Equals("research") || !groupChange.type.Equals("yxtrain") || !groupChange.type.Equals("activity"))
  502. {
  503. //课程名单变动修改学生课程关联信息
  504. await ActivityService.FixStuCourse(client, _dingDing, groupChange);
  505. }
  506. }
  507. catch (Exception ex)
  508. {
  509. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-GroupChange-GroupChange\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.成都开发測試群組);
  510. }
  511. }
  512. [Function("ItemCond")]
  513. public async Task ItemCondFunc([ServiceBusTrigger("%Azure:ServiceBus:ItemCondQueue%", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  514. {
  515. try
  516. {
  517. var client = _azureCosmos.GetCosmosClient();
  518. var jsonMsg = JsonDocument.Parse(msg);
  519. List<ItemCondDto> itemCondDtos = msg.ToObject<List<ItemCondDto>>();
  520. foreach (var itemCondDto in itemCondDtos)
  521. {
  522. if (itemCondDto.scope.Equals("school"))
  523. {
  524. ItemCond itemCond = null;
  525. List<ItemInfo> items = new List<ItemInfo>();
  526. var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where c.periodId='{itemCondDto.filed}' and c.pid= null ";
  527. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{itemCondDto.key}") }))
  528. {
  529. items.Add(item);
  530. }
  531. itemCond = new ItemCond()
  532. {
  533. id = $"{itemCondDto.filed}",
  534. code = $"ItemCond-{itemCondDto.key}",
  535. pk = "ItemCond",
  536. ttl = -1,
  537. count = items.Count,
  538. grades = new List<GradeCount>(),
  539. subjects = new List<SubjectCount>()
  540. };
  541. items.ForEach(z =>
  542. {
  543. if (!string.IsNullOrEmpty(z.type))
  544. {
  545. ItemService.CountItemCond(z, null, itemCond);
  546. }
  547. });
  548. await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:{itemCondDto.key}", $"{itemCondDto.filed}", itemCond.ToJsonString());
  549. }
  550. else
  551. {
  552. ItemCond itemCond = null;
  553. List<ItemInfo> items = new List<ItemInfo>();
  554. var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where c.pid= null ";
  555. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{itemCondDto.filed}") }))
  556. {
  557. items.Add(item);
  558. }
  559. itemCond = new ItemCond() { id = $"{itemCondDto.filed}", code = $"ItemCond", pk = "ItemCond", ttl = -1, count = items.Count };
  560. items.ForEach(z =>
  561. {
  562. if (!string.IsNullOrEmpty(z.type))
  563. {
  564. ItemService.CountItemCond(z, null, itemCond);
  565. }
  566. });
  567. await _azureRedis.GetRedisClient(8).HashSetAsync($"ItemCond:ItemCond", $"{itemCondDto.filed}", itemCond.ToJsonString());
  568. }
  569. }
  570. }
  571. catch (CosmosException ex)
  572. {
  573. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  574. }
  575. catch (Exception ex)
  576. {
  577. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  578. }
  579. }
  580. //更新產品一覽表
  581. [Function("Product")]
  582. public async Task ProductFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "product", Connection = "Azure:ServiceBus:ConnectionString")] string msg, ILogger log)
  583. {
  584. try
  585. {
  586. var jsonMsg = JsonDocument.Parse(msg);
  587. jsonMsg.RootElement.TryGetProperty("method", out JsonElement method);
  588. jsonMsg.RootElement.TryGetProperty("schoolId", out JsonElement schoolId);
  589. jsonMsg.RootElement.TryGetProperty("prodCode", out JsonElement prodCode);
  590. jsonMsg.RootElement.TryGetProperty("prodId", out JsonElement prodId);
  591. var client = _azureCosmos.GetCosmosClient();
  592. string strQuery = string.Empty;
  593. //取得所有學校產品
  594. ////序號
  595. List<SchoolProductSumData> serialsProductSumOrg = new List<SchoolProductSumData>();
  596. strQuery = $"SELECT * FROM c WHERE c.dataType = 'serial'";
  597. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: strQuery, requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Product-{schoolId}") }))
  598. {
  599. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  600. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  601. {
  602. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  603. {
  604. SchoolProductSerial serialInfo = obj.ToObject<SchoolProductSerial>();
  605. SchoolProductSumData serialProd = serialsProductSumOrg.Where(sp => sp.prodCode == serialInfo.prodCode).FirstOrDefault();
  606. if (serialProd == null)
  607. {
  608. SchoolProductSumData serialProdAdd = new SchoolProductSumData();
  609. serialProdAdd.prodCode = serialInfo.prodCode;
  610. serialProdAdd.ids.Add(serialInfo.id);
  611. serialProdAdd.avaliable = serialProdAdd.ids.Count;
  612. serialsProductSumOrg.Add(serialProdAdd);
  613. }
  614. else
  615. {
  616. if (!serialProd.ids.Contains(serialInfo.id))
  617. {
  618. serialProd.ids.Add(serialInfo.id);
  619. }
  620. serialProd.avaliable = serialProd.ids.Count;
  621. }
  622. }
  623. }
  624. }
  625. ////服務
  626. List<SchoolProductSumData> servicesProductSumOrg = new List<SchoolProductSumData>();
  627. long timestampToday = DateTimeOffset.UtcNow.AddSeconds(1).ToUnixTimeSeconds(); //比現實時間延遲1秒
  628. strQuery = $"SELECT * FROM c WHERE c.dataType = 'service' AND c.startDate <= {timestampToday} AND {timestampToday} <= c.endDate AND c.ttl < 0"; //在授權期間、ttl < 0 才取
  629. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: strQuery, requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Product-{schoolId}") }))
  630. {
  631. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  632. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  633. {
  634. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  635. {
  636. SchoolProductService serviceInfo = obj.ToObject<SchoolProductService>();
  637. SchoolProductSumData serviceProd = servicesProductSumOrg.Where(sp => sp.prodCode == serviceInfo.prodCode).FirstOrDefault();
  638. if (serviceProd == null)
  639. {
  640. SchoolProductSumData serviceProdAdd = new SchoolProductSumData();
  641. serviceProdAdd.prodCode = serviceInfo.prodCode;
  642. serviceProdAdd.avaliable = 0;
  643. serviceProdAdd.ids.Add(serviceInfo.id);
  644. serviceProdAdd.avaliable += serviceInfo.number;
  645. servicesProductSumOrg.Add(serviceProdAdd);
  646. }
  647. else
  648. {
  649. if (!serviceProd.ids.Contains(serviceInfo.id))
  650. {
  651. serviceProd.ids.Add(serviceInfo.id);
  652. serviceProd.avaliable += serviceInfo.number;
  653. }
  654. }
  655. }
  656. }
  657. }
  658. ////服務產品特別對應項
  659. if (servicesProductSumOrg.Count > 0)
  660. {
  661. foreach (SchoolProductSumData servicesProductSumOrgRow in servicesProductSumOrg)
  662. {
  663. //更新學校空間
  664. if (servicesProductSumOrgRow.prodCode.Equals("IPALJ6NY"))
  665. {
  666. School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{schoolId}", new PartitionKey("Base"));
  667. school.size = (servicesProductSumOrgRow.avaliable < 1) ? 1 : servicesProductSumOrgRow.avaliable;
  668. await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, $"{schoolId}", new PartitionKey("Base"));
  669. }
  670. }
  671. }
  672. ////硬體
  673. List<SchoolProductSumDataHard> hardsProductSumOrg = new List<SchoolProductSumDataHard>();
  674. strQuery = $"SELECT * FROM c WHERE c.dataType = 'hard'";
  675. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: strQuery, requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Product-{schoolId}") }))
  676. {
  677. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  678. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  679. {
  680. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  681. {
  682. SchoolProductHard hardInfo = obj.ToObject<SchoolProductHard>();
  683. SchoolProductSumData hardProd = hardsProductSumOrg.Where(sp => sp.prodCode == hardInfo.prodCode).FirstOrDefault();
  684. if (hardProd == null)
  685. {
  686. SchoolProductSumDataHard hardProdAdd = new SchoolProductSumDataHard();
  687. hardProdAdd.prodCode = hardInfo.prodCode;
  688. hardProdAdd.model = hardInfo.model;
  689. hardProdAdd.ids.Add(hardInfo.id);
  690. hardProdAdd.avaliable = hardProdAdd.ids.Count;
  691. hardsProductSumOrg.Add(hardProdAdd);
  692. }
  693. else
  694. {
  695. if (!hardProd.ids.Contains(hardInfo.id))
  696. {
  697. hardProd.ids.Add(hardInfo.id);
  698. }
  699. hardProd.avaliable = hardProd.ids.Count;
  700. }
  701. }
  702. }
  703. }
  704. //更新學校產品一覽表
  705. SchoolProductSum prodSum = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolProductSum>(schoolId.ToString(), new PartitionKey($"ProductSum"));
  706. prodSum.serial = serialsProductSumOrg;
  707. prodSum.service = servicesProductSumOrg;
  708. prodSum.hard = hardsProductSumOrg;
  709. await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolProductSum>(prodSum, prodSum.id, new PartitionKey($"{prodSum.code}"));
  710. }
  711. catch (CosmosException ex)
  712. {
  713. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Product()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  714. }
  715. catch (Exception ex)
  716. {
  717. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Product()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
  718. }
  719. }
  720. /// <summary>
  721. /// 批量复制文件
  722. /// </summary>
  723. /// <param name="msg"></param>
  724. /// <returns></returns>
  725. [Function("CopyStandardFile")]
  726. public async Task BatchCopyBlobFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "copy-standard-file", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  727. {
  728. try
  729. {
  730. //await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-Blob复制文件-CopyStandardFile\n{msg}", GroupNames.成都开发測試群組);
  731. var jsonMsg = JsonDocument.Parse(msg);
  732. BatchCopyFile bIBatchCopyFile = msg.ToObject<BatchCopyFile>();
  733. //批量复制文件
  734. var result = await BatchCopyFileService.CopyFile(_dingDing, _azureStorage, bIBatchCopyFile);
  735. if (result == 200)
  736. {
  737. //发送消息实体
  738. Notification notification = new Notification
  739. {
  740. hubName = "hita",
  741. type = "msg",
  742. from = $"BI:{_option.Location}:private",
  743. to = bIBatchCopyFile.tmdIds,
  744. label = $"{bIBatchCopyFile.codeKey}_finish",
  745. body = new { location = _option.Location, biz = $"{bIBatchCopyFile.codeKey}", tmdid = $"{bIBatchCopyFile.tmdid}", tmdname = $"{bIBatchCopyFile.tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
  746. expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
  747. };
  748. var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
  749. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  750. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  751. var location = _option.Location;
  752. await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
  753. }
  754. }
  755. catch (Exception ex)
  756. {
  757. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-Blob复制文件-CopyStandardFile\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.成都开发測試群組);
  758. }
  759. }
  760. /// <summary>
  761. /// 更新开课数据事件
  762. /// </summary>
  763. /// <param name="msg"></param>
  764. /// <returns></returns>
  765. [Function("LessonRecordEvent")]
  766. public async Task LessonRecordFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "lesson-record-event", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  767. {
  768. JsonElement data = msg.ToObject<JsonElement>();
  769. string scope = "";
  770. string tmdid = "";
  771. string lessonId;
  772. string school;
  773. string tbname;
  774. string code;
  775. string blobname;
  776. List<LessonUpdate> updates = new List<LessonUpdate>();
  777. //更新课堂记录
  778. if (data.TryGetProperty("lesson_id", out JsonElement _lessonId) && !string.IsNullOrEmpty($"{_lessonId}"))
  779. {
  780. if (!data.TryGetProperty("tmdid", out JsonElement _tmdid)) return;
  781. if (!data.TryGetProperty("scope", out JsonElement _scope)) return;
  782. if (!data.TryGetProperty("grant_types", out JsonElement _grant_types)) return;
  783. data.TryGetProperty("school", out JsonElement _school);
  784. school = $"{_school}";
  785. scope = $"{_scope}";
  786. tmdid = $"{_tmdid}";
  787. lessonId = $"{_lessonId}";
  788. updates = _grant_types.ToObject<List<LessonUpdate>>();
  789. }//创建课堂记录
  790. else if (data.TryGetProperty("id", out JsonElement _id) && !string.IsNullOrEmpty($"{_id}")
  791. && data.TryGetProperty("tmdid", out JsonElement _tmdid) && !string.IsNullOrEmpty($"{_tmdid}")
  792. && data.TryGetProperty("scope", out JsonElement _scope) && !string.IsNullOrEmpty($"{_scope}"))
  793. {
  794. data.TryGetProperty("school", out JsonElement _school);
  795. school = $"{_school}";
  796. scope = $"{_scope}";
  797. tmdid = $"{_tmdid}";
  798. lessonId = $"{_id}";
  799. updates.Add(new LessonUpdate { grant_type = "create" });
  800. }//删除课堂记录
  801. else if (data.TryGetProperty("delete_id", out JsonElement _delete_id) && !string.IsNullOrEmpty($"{_delete_id}")
  802. && data.TryGetProperty("tmdid", out JsonElement _dtmdid) && !string.IsNullOrEmpty($"{_dtmdid}")
  803. && data.TryGetProperty("scope", out JsonElement _dscope) && !string.IsNullOrEmpty($"{_dscope}")
  804. && data.TryGetProperty("opt", out JsonElement _opt) && !string.IsNullOrEmpty($"{_opt}"))
  805. {
  806. data.TryGetProperty("school", out JsonElement _dschool);
  807. school = $"{_dschool}";
  808. if ($"{_opt}".Equals("delete"))
  809. {
  810. scope = $"{_dscope}";
  811. tmdid = $"{_dtmdid}";
  812. lessonId = $"{_delete_id}";
  813. updates.Add(new LessonUpdate { grant_type = "delete" });
  814. }
  815. else { return; }
  816. }
  817. else
  818. {
  819. return;
  820. }
  821. var client = _azureCosmos.GetCosmosClient();
  822. if ($"{scope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
  823. {
  824. blobname = $"{school}";
  825. code = $"LessonRecord-{school}";
  826. tbname = "School";
  827. }
  828. else if ($"{scope}".Equals("private"))
  829. {
  830. blobname = $"{tmdid}";
  831. code = $"LessonRecord-{tmdid}";
  832. tbname = "Teacher";
  833. }
  834. else
  835. {
  836. return;
  837. }
  838. LessonDis lessonDis = new LessonDis();
  839. List<LessonUpdate> msgs = new List<LessonUpdate>();
  840. try
  841. {
  842. LessonRecord oldlessonRecord = null;
  843. LessonRecord lessonRecord = null;
  844. Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
  845. if (response.Status == 200)
  846. {
  847. var doc = JsonDocument.Parse(response.ContentStream);
  848. lessonRecord = doc.RootElement.ToObject<LessonRecord>();
  849. oldlessonRecord = doc.RootElement.ToObject<LessonRecord>();
  850. }
  851. else
  852. {
  853. lessonRecord = null;
  854. }
  855. if (updates.IsNotEmpty())
  856. {
  857. foreach (LessonUpdate update in updates)
  858. {
  859. switch (update.grant_type)
  860. {
  861. //更新课堂时长
  862. case "up-duration":
  863. var duration = double.Parse($"{update.data}");
  864. lessonRecord.duration = duration;
  865. msgs.Add(update);
  866. break;
  867. //更新T分
  868. case "up-tScore":
  869. var tScore = int.Parse($"{update.data}");
  870. lessonRecord.tScore = tScore;
  871. msgs.Add(update);
  872. break;
  873. //更新课P分
  874. case "up-pScore":
  875. var pScore = int.Parse($"{update.data}");
  876. lessonRecord.pScore = pScore;
  877. msgs.Add(update);
  878. break;
  879. //更新 学生人数
  880. case "up-mCount":
  881. var mCount = int.Parse($"{update.data}");
  882. lessonRecord.mCount = mCount;
  883. msgs.Add(update);
  884. break;
  885. //更新 议课次数
  886. case "up-techCount":
  887. var techCount = int.Parse($"{update.data}");
  888. lessonRecord.mCount = techCount;
  889. msgs.Add(update);
  890. break;
  891. //更新 时间线
  892. case "up-TimeLine":
  893. //BlobDownloadResult TimeLineblobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/{_lessonId}/IES/TimeLine.json").DownloadContentAsync();
  894. //var timeline = TimeLineblobDownload.Content.ToObjectFromJson<List<LessonTimeLine>>();
  895. msgs.Add(update);
  896. break;
  897. //更新 课堂总览信息
  898. case "up-ActivityInfo":
  899. //BlobDownloadResult ActivityInfoblobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/{_lessonId}/IES/ActivityInfo.json").DownloadContentAsync();
  900. //var activityInfos = ActivityInfoblobDownload.Content.ToObjectFromJson<List<LessonActivityInfo>>();
  901. msgs.Add(update);
  902. break;
  903. case "delete":
  904. try
  905. {
  906. await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemAsync<LessonRecord>(lessonId, new PartitionKey(code));
  907. msgs.Add(update);
  908. }
  909. catch (CosmosException ex)
  910. {
  911. msgs.Add(update);
  912. }
  913. lessonRecord = null;
  914. break;
  915. case "create":
  916. oldlessonRecord = null;
  917. //处理课堂选用的课程信息
  918. if (!string.IsNullOrEmpty(lessonRecord.courseId))
  919. {
  920. Course course = null;
  921. try
  922. {
  923. course = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Course>(lessonRecord.courseId, new PartitionKey($"Course-{lessonRecord.school}"));
  924. }
  925. catch (CosmosException ex) when (ex.Status != 404)
  926. {
  927. try
  928. {
  929. course = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Course>(lessonRecord.courseId, new PartitionKey($"Course-{lessonRecord.tmdid}"));
  930. }
  931. catch (CosmosException e) when (e.Status != 404)
  932. {
  933. course = null;
  934. }
  935. }
  936. if (course != null)
  937. {
  938. lessonRecord.periodId = course.period?.id;
  939. lessonRecord.subjectId = course.subject?.id;
  940. }
  941. }
  942. //处理课堂选用的名单
  943. if (lessonRecord.groupIds.IsNotEmpty())
  944. {
  945. HashSet<string> grades = new HashSet<string>();
  946. List<GroupListDto> groups = await GroupListService.GetGroupListListids(client, _dingDing, lessonRecord.groupIds, lessonRecord.school);
  947. List<GroupListDto> groupLists = groups.FindAll(x => !string.IsNullOrEmpty(x.periodId) && x.year > 0 && !string.IsNullOrEmpty(x.school));
  948. if (groupLists.IsNotEmpty() && !string.IsNullOrEmpty(lessonRecord.periodId))
  949. {
  950. School schoolObj = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(lessonRecord.school, new PartitionKey("Base"));
  951. //年级算法
  952. int? Count = schoolObj.period.Find(x => x.id.Equals(lessonRecord.periodId)).grades?.Count;
  953. if (Count.HasValue)
  954. {
  955. int Month = DateTimeOffset.UtcNow.Month;
  956. int Year = DateTimeOffset.UtcNow.Year;
  957. foreach (int year in groupLists.Select(x => x.year))
  958. {
  959. int grade;
  960. if (Month >= 1 && Month <= 6)
  961. {
  962. grade = (Year - year + 1) / Count.Value;
  963. }
  964. else
  965. {
  966. grade = (Year - year) / Count.Value;
  967. }
  968. grades.Add($"{grade}");
  969. }
  970. }
  971. }
  972. lessonRecord.grade.AddRange(grades);
  973. }
  974. msgs.Add(update);
  975. break;
  976. default:
  977. break;
  978. }
  979. }
  980. //
  981. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, lessonId, new PartitionKey(code));
  982. //计算课堂更新前后的差值
  983. lessonDis = LessonService.DisLessonCount(oldlessonRecord, lessonRecord, lessonDis);
  984. await LessonService.FixLessonCount(client, _dingDing, lessonRecord, oldlessonRecord, lessonDis);
  985. }
  986. }
  987. catch (CosmosException e)
  988. {
  989. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-更新课堂记录出错-CosmosDB异常{e.Message}\n{e.Status}", GroupNames.成都开发測試群組);
  990. }
  991. catch (Exception ex)
  992. {
  993. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-更新课堂记录出错\n{ex.Message}\n{ex.StackTrace}\n{data}\n{code}\n", GroupNames.成都开发測試群組);
  994. }
  995. }
  996. /// <summary>
  997. /// 完善课程变更
  998. /// </summary>
  999. /// <data msg>
  1000. /// CourseChange
  1001. ///// </data>
  1002. /// <param name="msg"></param>
  1003. /// <returns></returns>
  1004. [Function("Course")]
  1005. public async Task CourseFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "course", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
  1006. {
  1007. var client = _azureCosmos.GetCosmosClient();
  1008. try
  1009. {
  1010. //await _dingDing.SendBotMsg($"ServiceBus,CourseChange:{msg}", GroupNames.醍摩豆服務運維群組);
  1011. var jsonMsg = JsonDocument.Parse(msg);
  1012. CourseChange courseChange = msg.ToObject<CourseChange>();
  1013. if (courseChange == null)
  1014. {
  1015. return;
  1016. }
  1017. foreach (var cls in courseChange.addClass)
  1018. {
  1019. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, new List<string> { cls }, courseChange.school);
  1020. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  1021. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  1022. foreach (var stu in addStudentsCls)
  1023. {
  1024. try
  1025. {
  1026. ItemResponse<StuCourse> stuCourse = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
  1027. if (!stuCourse.Value.classId.Contains(cls))
  1028. {
  1029. stuCourse.Value.classId.Add(cls);
  1030. }
  1031. await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
  1032. }
  1033. catch (CosmosException ex)
  1034. {
  1035. if (ex.Response.Status == 404)
  1036. {
  1037. var course = new StuCourse
  1038. {
  1039. id = courseChange.id,
  1040. scode = courseChange.code,
  1041. name = courseChange.name,
  1042. code = $"StuCourse-{courseChange.school}-{stu.id}",
  1043. scope = courseChange.scope,
  1044. school = courseChange.school,
  1045. creatorId = courseChange.creatorId,
  1046. classId = new List<string> { cls },
  1047. pk = "StuCourse",
  1048. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1049. };
  1050. await client.GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(course, new PartitionKey(course.code));
  1051. }
  1052. else
  1053. {
  1054. await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  1055. }
  1056. }
  1057. }
  1058. foreach (var tmd in addTmdidsCls)
  1059. {
  1060. try
  1061. {
  1062. ItemResponse<StuCourse> stuCourse = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd.id}"));
  1063. if (!stuCourse.Value.classId.Contains(cls))
  1064. {
  1065. stuCourse.Value.classId.Add(cls);
  1066. }
  1067. await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd.id}"));
  1068. }
  1069. catch (CosmosException ex)
  1070. {
  1071. if (ex.Response.Status == 404)
  1072. {
  1073. var course = new StuCourse
  1074. {
  1075. id = courseChange.id,
  1076. scode = courseChange.code,
  1077. name = courseChange.name,
  1078. code = $"StuCourse-{tmd.id}",
  1079. scope = courseChange.scope,
  1080. school = courseChange.school,
  1081. creatorId = courseChange.creatorId,
  1082. classId = new List<string> { cls },
  1083. pk = "StuCourse",
  1084. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1085. };
  1086. await client.GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(course, new PartitionKey(course.code));
  1087. }
  1088. else
  1089. {
  1090. await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  1091. }
  1092. }
  1093. }
  1094. }
  1095. foreach (var list in courseChange.addList)
  1096. {
  1097. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, new List<string> { list }, courseChange.school);
  1098. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  1099. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  1100. foreach (var stu in addStudentsCls)
  1101. {
  1102. try
  1103. {
  1104. ItemResponse<StuCourse> stuCourse = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{stu.code}-{stu.id}"));
  1105. if (!stuCourse.Value.stulist.Contains(list))
  1106. {
  1107. stuCourse.Value.stulist.Add(list);
  1108. await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{stu.code}-{stu.id}"));
  1109. }
  1110. }
  1111. catch (CosmosException ex)
  1112. {
  1113. if (ex.Response.Status == 404)
  1114. {
  1115. var course = new StuCourse
  1116. {
  1117. id = courseChange.id,
  1118. scode = courseChange.code,
  1119. name = courseChange.name,
  1120. code = $"StuCourse-{courseChange.school}-{stu.id}",
  1121. scope = courseChange.scope,
  1122. school = courseChange.school,
  1123. creatorId = courseChange.creatorId,
  1124. stulist = new List<string> { list },
  1125. pk = "StuCourse",
  1126. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1127. };
  1128. await client.GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(course, new PartitionKey(course.code));
  1129. }
  1130. else
  1131. {
  1132. await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  1133. }
  1134. }
  1135. }
  1136. foreach (var tmd in addTmdidsCls)
  1137. {
  1138. try
  1139. {
  1140. ItemResponse<StuCourse> stuCourse = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd.id}"));
  1141. if (!stuCourse.Value.stulist.Contains(list))
  1142. {
  1143. stuCourse.Value.stulist.Add(list);
  1144. await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd.id}"));
  1145. }
  1146. }
  1147. catch (CosmosException ex)
  1148. {
  1149. if (ex.Response.Status == 404)
  1150. {
  1151. var course = new StuCourse
  1152. {
  1153. id = courseChange.id,
  1154. scode = courseChange.code,
  1155. name = courseChange.name,
  1156. code = $"StuCourse-{tmd.id}",
  1157. scope = courseChange.scope,
  1158. school = courseChange.school,
  1159. creatorId = courseChange.creatorId,
  1160. stulist = new List<string> { list },
  1161. pk = "StuCourse",
  1162. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1163. };
  1164. await client.GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(course, new PartitionKey(course.code));
  1165. }
  1166. else
  1167. {
  1168. await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  1169. }
  1170. }
  1171. }
  1172. }
  1173. foreach (var delCls in courseChange.delClass)
  1174. {
  1175. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, new List<string> { delCls }, courseChange.school);
  1176. var delStudentsCls = tchList.FindAll(x => x.type == 2);
  1177. var delTmdidsCls = tchList.FindAll(x => x.type == 1);
  1178. foreach (var stu in delStudentsCls)
  1179. {
  1180. try
  1181. {
  1182. ItemResponse<StuCourse> stuCourse = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
  1183. if (stuCourse.Value.classId.Contains(delCls))
  1184. {
  1185. stuCourse.Value.classId.Remove(delCls);
  1186. }
  1187. if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
  1188. {
  1189. //当两个列表都不存在时则直接删除
  1190. await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
  1191. }
  1192. else
  1193. {
  1194. await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
  1195. }
  1196. }
  1197. catch (CosmosException ex)
  1198. {
  1199. await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  1200. }
  1201. }
  1202. foreach (var tmd in delTmdidsCls)
  1203. {
  1204. try
  1205. {
  1206. ItemResponse<StuCourse> stuCourse = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd.id}"));
  1207. if (stuCourse.Value.classId.Contains(delCls))
  1208. {
  1209. stuCourse.Value.classId.Remove(delCls);
  1210. }
  1211. if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
  1212. {
  1213. //当两个列表都不存在时则直接删除
  1214. await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd.id}"));
  1215. }
  1216. else
  1217. {
  1218. await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd.id}"));
  1219. }
  1220. }
  1221. catch (CosmosException ex)
  1222. {
  1223. await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  1224. }
  1225. }
  1226. }
  1227. foreach (var delList in courseChange.delList)
  1228. {
  1229. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, new List<string> { delList }, courseChange.school);
  1230. var delStudentsCls = tchList.FindAll(x => x.type == 2);
  1231. var delTmdidsCls = tchList.FindAll(x => x.type == 1);
  1232. foreach (var stu in delStudentsCls)
  1233. {
  1234. try
  1235. {
  1236. ItemResponse<StuCourse> stuCourse = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
  1237. if (stuCourse.Value.stulist.Contains(delList))
  1238. {
  1239. stuCourse.Value.stulist.Remove(delList);
  1240. }
  1241. if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
  1242. {
  1243. //当两个列表都不存在时则直接删除
  1244. await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
  1245. }
  1246. else
  1247. {
  1248. await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
  1249. }
  1250. }
  1251. catch (CosmosException ex)
  1252. {
  1253. await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  1254. }
  1255. }
  1256. foreach (var tmd in delTmdidsCls)
  1257. {
  1258. try
  1259. {
  1260. ItemResponse<StuCourse> stuCourse = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd.id}"));
  1261. if (stuCourse.Value.stulist.Contains(delList))
  1262. {
  1263. stuCourse.Value.stulist.Remove(delList);
  1264. }
  1265. if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
  1266. {
  1267. //当两个列表都不存在时则直接删除
  1268. await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd.id}"));
  1269. }
  1270. else
  1271. {
  1272. await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd.id}"));
  1273. }
  1274. }
  1275. catch (CosmosException ex)
  1276. {
  1277. await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  1278. }
  1279. }
  1280. }
  1281. }
  1282. catch (Exception ex)
  1283. {
  1284. await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -Course\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  1285. }
  1286. }
  1287. }
  1288. }