TriggerStuActivity.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. using Azure;
  2. using Azure.Cosmos;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.Json;
  9. using System.Threading.Tasks;
  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.Common;
  15. using TEAMModelOS.SDK.Models.Service;
  16. using HTEXLib.COMM.Helpers;
  17. namespace TEAMModelOS.SDK
  18. {
  19. public class TriggerStuActivity
  20. {
  21. public static async Task RefreshStuActivity(CosmosClient client, DingDing _dingDing, string id, string code)
  22. {
  23. MQActivity activity = null;
  24. try
  25. {
  26. var aactivity = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id, new Azure.Cosmos.PartitionKey(code));
  27. using var da = await JsonDocument.ParseAsync(aactivity.ContentStream);
  28. activity = da.ToObject<MQActivity>();
  29. }
  30. catch (CosmosException ex)
  31. {
  32. }
  33. if (activity != null)
  34. {
  35. List<string> classes = ExamService.getClasses(activity.classes, activity.stuLists);
  36. (List<TmdInfo> tmdids, List<StuInfo> students,List<ClassListInfo> classLists) = await GetStuList(client, _dingDing, classes, activity.school);
  37. if (tmdids.IsNotEmpty())
  38. {
  39. foreach (TmdInfo tmdid in tmdids)
  40. {
  41. var stucourse = new StuActivity
  42. {
  43. id = activity.id,
  44. scode = activity.code,
  45. name = activity.name,
  46. code = $"Activity-{tmdid.id}",
  47. scope = activity.scope,
  48. school = activity.school,
  49. creatorId = activity.creatorId,
  50. pk = "Activity",
  51. type = activity.pk,
  52. subjects = activity.pk.ToLower().Equals("exam") && activity.subjects.IsNotEmpty() ? new List<string>() { activity.subjects[0].id } : new List<string>() { "" },
  53. startTime = activity.startTime,
  54. endTime = activity.endTime,
  55. blob = activity.blob,
  56. owner = activity.owner,
  57. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  58. taskStatus = -1,
  59. classIds = classes
  60. };
  61. await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
  62. }
  63. }
  64. if (students.IsNotEmpty())
  65. {
  66. foreach (StuInfo student in students)
  67. {
  68. var stucourse = new StuActivity
  69. {
  70. id = activity.id,
  71. scode = activity.code,
  72. name = activity.name,
  73. code = $"Activity-{activity.school}-{student.id}",
  74. scope = activity.scope,
  75. school = activity.school,
  76. creatorId = activity.creatorId,
  77. pk = "Activity",
  78. type = activity.pk,
  79. subjects = activity.pk.ToLower().Equals("exam") && activity.subjects.IsNotEmpty() ? new List<string>() { activity.subjects[0].id } : new List<string>() { "" },
  80. startTime = activity.startTime,
  81. endTime = activity.endTime,
  82. blob = activity.blob,
  83. owner = activity.owner,
  84. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  85. taskStatus = -1,
  86. classIds = classes
  87. };
  88. await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
  89. }
  90. }
  91. }
  92. }
  93. public static async Task<string> SaveStuActivity(CosmosClient client, DingDing _dingDing, List<StuActivity> stuActivities,List<StuActivity> tmdActivities) {
  94. try {
  95. if (stuActivities.IsNotEmpty())
  96. {
  97. foreach (var x in stuActivities)
  98. {
  99. await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(x, new PartitionKey(x.code));
  100. }
  101. }
  102. if (tmdActivities.IsNotEmpty())
  103. {
  104. foreach (var x in tmdActivities)
  105. {
  106. await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(x, new PartitionKey(x.code));
  107. }
  108. }
  109. } catch (Exception ex) {
  110. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-OS,TriggerStuActivity-SaveStuActivity\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  111. }
  112. return "";
  113. }
  114. /// <summary>
  115. /// 获取行政班接口
  116. /// </summary>
  117. /// <param name="client"></param>
  118. /// <param name="_dingDing"></param>
  119. /// <param name="classes"></param>
  120. /// <param name="school"></param>
  121. /// <returns></returns>
  122. public static async Task<List<ClassInfo>> GetClassInfo(CosmosClient client, DingDing _dingDing, List<string> classes, string school)
  123. {
  124. try {
  125. List<ClassInfo> classInfos = new List<ClassInfo>();
  126. if (classes.IsNotEmpty()) {
  127. List<string> sqlList = new List<string>();
  128. classes.ForEach(x => { sqlList.Add($" '{x}' "); });
  129. string sql = string.Join(" , ", sqlList);
  130. if (!string.IsNullOrEmpty(school))
  131. {
  132. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: $"select c.id,c.name ,c.periodId,c.year from c where c.id in ({sql})",
  133. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
  134. {
  135. classInfos.Add(item);
  136. }
  137. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: $"select c.id,c.name from c where c.id in ({sql})",
  138. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
  139. {
  140. //item.from = "SchStuList";
  141. classInfos.Add(item);
  142. }
  143. }
  144. List<StuList> tchLists = new List<StuList>();
  145. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<ClassInfo>(queryText: $"select c.id,c.name from c where c.id in ({sql})",
  146. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
  147. {
  148. // item.from = "TchStuList";
  149. classInfos.Add(item);
  150. }
  151. classInfos = classInfos.GroupBy(c => c.id).Select(s => s.First()).ToList();
  152. }
  153. return classInfos;
  154. } catch (Exception ex) {
  155. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-OS,TriggerStuActivity-GetClassInfo\n{ex.Message}\n{ex.StackTrace}\n class{classes.ToJsonString()},{school}", GroupNames.醍摩豆服務運維群組);
  156. throw new Exception(ex.Message, ex);
  157. }
  158. }
  159. public static async Task<(List<TmdInfo> tmdinfos, List<StuInfo> students, List<ClassListInfo> classInfo)> GetStuListInStu(CosmosClient client, DingDing _dingDing, List<string> claes, string school)
  160. {
  161. try
  162. {
  163. List<string> classes = new List<string>();
  164. foreach (string ss in claes)
  165. {
  166. classes.Add(ss);
  167. }
  168. List<TmdInfo> tmdinfos = new List<TmdInfo>();
  169. List<Students> studentss = new List<Students>();
  170. List<string> tmdids = new List<string>();
  171. List<StuInfo> stuInfos = new List<StuInfo>();
  172. if (!classes.IsNotEmpty()) { return (tmdinfos, new List<StuInfo>(), null); }
  173. List<string> sqlList = new List<string>();
  174. classes.ForEach(x => { sqlList.Add($" '{x}' "); });
  175. string sql = string.Join(" , ", sqlList);
  176. List<StuList> schList = new List<StuList>();
  177. List<Student> students = new List<Student>();
  178. if (!string.IsNullOrEmpty(school))
  179. {
  180. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
  181. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
  182. {
  183. schList.Add(item);
  184. }
  185. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
  186. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
  187. {
  188. students.Add(item);
  189. }
  190. }
  191. List<StuList> tchLists = new List<StuList>();
  192. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
  193. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
  194. {
  195. tchLists.Add(item);
  196. }
  197. foreach (var x in schList)
  198. {
  199. if (x.students.IsNotEmpty())
  200. {
  201. studentss.AddRange(x.students);
  202. }
  203. if (x.tmids.IsNotEmpty())
  204. {
  205. tmdids.AddRange(x.tmids);
  206. }
  207. if (x.teachers.IsNotEmpty())
  208. {
  209. tmdids.AddRange(x.teachers);
  210. }
  211. classes.Remove(x.id);
  212. }
  213. foreach (var x in tchLists)
  214. {
  215. if (x.students.IsNotEmpty())
  216. {
  217. studentss.AddRange(x.students);
  218. }
  219. if (x.tmids.IsNotEmpty())
  220. {
  221. tmdids.AddRange(x.tmids);
  222. }
  223. classes.Remove(x.id);
  224. }
  225. if (tmdids.IsNotEmpty())
  226. {
  227. List<TmdInfo> infos = new List<TmdInfo>();
  228. List<string> inids = new List<string>();
  229. tmdids.ForEach(x => { inids.Add($"'{x}'"); });
  230. var insql = string.Join(",", inids);
  231. var queryslt = $"SELECT value(c) FROM c where c.id in ({insql})";
  232. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  233. {
  234. infos.Add(item);
  235. tmdids.Remove(item.id);
  236. }
  237. if (tmdids.IsNotEmpty()) {
  238. inids = new List<string>();
  239. tmdids.ForEach(x => { inids.Add($"'{x}'"); });
  240. insql = string.Join(",", inids);
  241. queryslt = $"SELECT value(c) FROM c where c.id in ({insql})";
  242. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  243. {
  244. infos.Add(item);
  245. }
  246. }
  247. tmdinfos.AddRange(infos);
  248. }
  249. if (studentss.IsNotEmpty())
  250. {
  251. var stuGroups = studentss.GroupBy(x => x.code).ToList().Select(x => new { key = x.Key, list = x.ToList() }) ;
  252. foreach (var gp in stuGroups) {
  253. List<string> inidstus = new List<string>();
  254. gp.list.Select(x => x.id).ToList().ForEach(x => { inidstus.Add($"'{x}'"); });
  255. PartitionKey partitionKey = new PartitionKey($"Base-{gp.key.Replace("Base-", "")}");
  256. var insqlstu = string.Join(",", inidstus);
  257. var querystu = $"SELECT c.id,c.code,c.name,c.picture,c.classId,c.groupId,c.groupName,c.year,c.schoolId FROM c where c.id in ({insqlstu})";
  258. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey= partitionKey }))
  259. {
  260. stuInfos.Add(item);
  261. }
  262. }
  263. }
  264. students.ForEach(x =>
  265. {
  266. if (!stuInfos.Select(y => y.classId).ToList().Contains(x.id))
  267. {
  268. stuInfos.Add(new StuInfo { id = x.id, code = x.code, schoolId = x.schoolId, classId = x.classId, name = x.name, picture = x.picture, year = x.year,groupId = x.groupId,groupName=x.groupName,no=x.no });
  269. }
  270. });
  271. List<ClassListInfo> classInfo = new List<ClassListInfo>();
  272. schList.ForEach(x => {
  273. ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
  274. if (x.students.IsNotEmpty())
  275. {
  276. x.students.ForEach(y => {
  277. var stuinfo = stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
  278. if (stuinfo != null)
  279. {
  280. classListInfo.stuInfos.Add(stuinfo);
  281. }
  282. });
  283. }
  284. if (x.tmids.IsNotEmpty())
  285. {
  286. x.tmids.ForEach(y => {
  287. var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
  288. if (tmdinfo != null)
  289. {
  290. classListInfo.tmdInfos.Add(tmdinfo);
  291. }
  292. });
  293. }
  294. if (x.teachers.IsNotEmpty())
  295. {
  296. x.teachers.ForEach(y => {
  297. var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
  298. if (tmdinfo != null)
  299. {
  300. classListInfo.tmdInfos.Add(tmdinfo);
  301. }
  302. });
  303. }
  304. classInfo.Add(classListInfo);
  305. });
  306. tchLists.ForEach(x => {
  307. ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
  308. if (x.students.IsNotEmpty())
  309. {
  310. x.students.ForEach(y => {
  311. var stuinfo = stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
  312. if (stuinfo != null)
  313. {
  314. classListInfo.stuInfos.Add(stuinfo);
  315. }
  316. });
  317. }
  318. if (x.tmids.IsNotEmpty())
  319. {
  320. x.tmids.ForEach(y => {
  321. var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
  322. if (tmdinfo != null)
  323. {
  324. classListInfo.tmdInfos.Add(tmdinfo);
  325. }
  326. });
  327. }
  328. classInfo.Add(classListInfo);
  329. });
  330. //var classeids= students.GroupBy(x => x.classId).Select(x => x.Key).ToList();
  331. List<ClassInfo> classInfos = await GetClassInfo(client, _dingDing, classes, school);
  332. classInfos.ForEach(x =>
  333. {
  334. ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
  335. var list = students.Where(y => y.classId .Equals(x.id)).ToList();
  336. list.ForEach(z => { classListInfo.stuInfos.Add(new StuInfo { id = z.id, code = z.code, schoolId = z.schoolId, classId = z.classId, name = z.name, picture = z.picture, year = z.year,groupId=z.groupId,groupName=z.groupName,no=z.no }); });
  337. classInfo.Add(classListInfo);
  338. });
  339. return (tmdinfos, stuInfos, classInfo);
  340. }
  341. catch (Exception ex)
  342. {
  343. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-OS,TriggerStuActivity-GetStuList\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  344. }
  345. return (null, null, null);
  346. }
  347. public static async Task<(List<TmdInfo> tmdinfos, List<StuInfo> students,List<ClassListInfo>classInfo)> GetStuList(CosmosClient client, DingDing _dingDing, List<string> claes, string school)
  348. {
  349. try {
  350. List<string> classes = new List<string>();
  351. foreach (string ss in claes)
  352. {
  353. classes.Add(ss);
  354. }
  355. List<TmdInfo> tmdinfos = new List<TmdInfo>();
  356. List<Students> studentss = new List<Students>();
  357. List<string> tmdids = new List<string>();
  358. List<StuInfo> stuInfos = new List<StuInfo>();
  359. if (!classes.IsNotEmpty()) { return (tmdinfos, new List<StuInfo>(),null); }
  360. List<string> sqlList = new List<string>();
  361. classes.ForEach(x => { sqlList.Add($" '{x}' "); });
  362. string sql = string.Join(" , ", sqlList);
  363. List<StuList> schList = new List<StuList>();
  364. List<Student> students = new List<Student>();
  365. if (!string.IsNullOrEmpty(school)) {
  366. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
  367. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
  368. {
  369. schList.Add(item);
  370. }
  371. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
  372. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
  373. {
  374. students.Add(item);
  375. }
  376. }
  377. List<StuList> tchLists = new List<StuList>();
  378. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
  379. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
  380. {
  381. tchLists.Add(item);
  382. }
  383. foreach (var x in schList) {
  384. if (x.students.IsNotEmpty())
  385. {
  386. studentss.AddRange(x.students);
  387. }
  388. if (x.tmids.IsNotEmpty())
  389. {
  390. tmdids.AddRange(x.tmids);
  391. }
  392. classes.Remove(x.id);
  393. }
  394. foreach (var x in tchLists)
  395. {
  396. if (x.students.IsNotEmpty()) {
  397. studentss.AddRange(x.students);
  398. }
  399. if (x.tmids.IsNotEmpty())
  400. {
  401. tmdids.AddRange(x.tmids);
  402. }
  403. classes.Remove(x.id);
  404. }
  405. if (tmdids.IsNotEmpty()) {
  406. List<TmdInfo> infos = new List<TmdInfo>();
  407. List<string> inids = new List<string>();
  408. tmdids.ForEach(x => { inids.Add($"'{x}'"); });
  409. var insql = string.Join(",", inids);
  410. var queryslt = $"SELECT value(c) FROM c where c.id in ({insql})";
  411. //合并代码/
  412. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  413. {
  414. infos.Add(item);
  415. }
  416. tmdinfos.AddRange(infos);
  417. }
  418. if (studentss.IsNotEmpty()) {
  419. List<string> inidstus = new List<string>();
  420. foreach (Students stu in studentss) {
  421. var querystu = $"SELECT c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id = '{stu.id}'";
  422. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{stu.code}") }))
  423. {
  424. stuInfos.Add(item);
  425. }
  426. }
  427. /*studentss.Select(x => x.id).ToList().ForEach(x => { inidstus.Add($"'{x}'"); });
  428. var insqlstu = string.Join(",", inidstus);
  429. var querystu = $"SELECT c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id in ({insqlstu})";
  430. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school}") }))
  431. {
  432. stuInfos.Add(item);
  433. }*/
  434. }
  435. students.ForEach(x =>
  436. {
  437. if (!stuInfos.Select(y => y.classId).ToList().Contains(x.id)) {
  438. stuInfos.Add(new StuInfo { id = x.id, code = x.code, schoolId = x.schoolId, classId = x.classId, name = x.name, picture = x.picture, year = x.year,groupId=x.groupId,groupName=x.groupName,no=x.no });
  439. }
  440. });
  441. List<ClassListInfo> classInfo = new List<ClassListInfo>();
  442. schList.ForEach(x => {
  443. ClassListInfo classListInfo = new ClassListInfo {id=x.id,name=x.name };
  444. if (x.students.IsNotEmpty()) {
  445. x.students.ForEach(y => {
  446. var stuinfo= stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
  447. if (stuinfo != null) {
  448. classListInfo.stuInfos.Add(stuinfo);
  449. }
  450. });
  451. }
  452. if (x.tmids.IsNotEmpty())
  453. {
  454. x.tmids.ForEach(y => {
  455. var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
  456. if (tmdinfo != null)
  457. {
  458. classListInfo.tmdInfos.Add(tmdinfo);
  459. }
  460. });
  461. }
  462. classInfo.Add(classListInfo);
  463. });
  464. tchLists.ForEach(x => {
  465. ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
  466. if (x.students.IsNotEmpty())
  467. {
  468. x.students.ForEach(y => {
  469. var stuinfo = stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
  470. if (stuinfo != null)
  471. {
  472. classListInfo.stuInfos.Add(stuinfo);
  473. }
  474. });
  475. }
  476. if (x.tmids.IsNotEmpty())
  477. {
  478. x.tmids.ForEach(y => {
  479. var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
  480. if (tmdinfo != null)
  481. {
  482. classListInfo.tmdInfos.Add(tmdinfo);
  483. }
  484. });
  485. }
  486. classInfo.Add(classListInfo);
  487. });
  488. //var classeids= students.GroupBy(x => x.classId).Select(x => x.Key).ToList();
  489. List<ClassInfo> classInfos= await GetClassInfo(client, _dingDing, classes, school);
  490. classInfos.ForEach(x =>
  491. {
  492. ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
  493. var list= students.Where(y => y.classId .Equals(x.id)).ToList();
  494. list.ForEach(z => { classListInfo.stuInfos.Add(new StuInfo { id = z.id, code = z.code, schoolId = z.schoolId, classId = z.classId, name = z.name, picture = z.picture, year = z.year ,groupId=z.groupId,groupName=z.groupName,no=z.no}); });
  495. classInfo.Add(classListInfo);
  496. });
  497. return (tmdinfos, stuInfos, classInfo) ;
  498. }
  499. catch (Exception ex)
  500. {
  501. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-OS,TriggerStuActivity-GetStuList\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  502. }
  503. return (null, null,null);
  504. }
  505. }
  506. public class ClassListInfo
  507. {
  508. public string id { get; set; }
  509. public string name { get; set; }
  510. // public string from { get; set; }
  511. public List<StuInfo> stuInfos { get; set; } = new List<StuInfo>();
  512. public List<TmdInfo> tmdInfos { get; set; } = new List<TmdInfo>();
  513. }
  514. }