TriggerStuActivity.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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, List<StuActivity> tchActivities) {
  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. if (tchActivities.IsNotEmpty())
  110. {
  111. foreach (var x in tmdActivities)
  112. {
  113. await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync(x, new PartitionKey(x.code));
  114. }
  115. }
  116. } catch (Exception ex) {
  117. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-OS,TriggerStuActivity-SaveStuActivity\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  118. }
  119. return "";
  120. }
  121. /// <summary>
  122. /// 获取行政班接口
  123. /// </summary>
  124. /// <param name="client"></param>
  125. /// <param name="_dingDing"></param>
  126. /// <param name="classes"></param>
  127. /// <param name="school"></param>
  128. /// <returns></returns>
  129. public static async Task<List<ClassInfo>> GetClassInfo(CosmosClient client, DingDing _dingDing, List<string> classes, string school)
  130. {
  131. try {
  132. List<ClassInfo> classInfos = new List<ClassInfo>();
  133. if (classes.IsNotEmpty()) {
  134. List<string> sqlList = new List<string>();
  135. classes.ForEach(x => { sqlList.Add($" '{x}' "); });
  136. string sql = string.Join(" , ", sqlList);
  137. if (!string.IsNullOrEmpty(school))
  138. {
  139. 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})",
  140. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
  141. {
  142. classInfos.Add(item);
  143. }
  144. 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})",
  145. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
  146. {
  147. //item.from = "SchStuList";
  148. classInfos.Add(item);
  149. }
  150. }
  151. List<StuList> tchLists = new List<StuList>();
  152. 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})",
  153. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
  154. {
  155. // item.from = "TchStuList";
  156. classInfos.Add(item);
  157. }
  158. classInfos = classInfos.GroupBy(c => c.id).Select(s => s.First()).ToList();
  159. }
  160. return classInfos;
  161. } catch (Exception ex) {
  162. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-OS,TriggerStuActivity-GetClassInfo\n{ex.Message}\n{ex.StackTrace}\n class{classes.ToJsonString()},{school}", GroupNames.醍摩豆服務運維群組);
  163. throw new Exception(ex.Message, ex);
  164. }
  165. }
  166. public static async Task<(List<TmdInfo> tmdinfos, List<StuInfo> students, List<ClassListInfo> classInfo)> GetStuListInStu(CosmosClient client, DingDing _dingDing, List<string> claes, string school)
  167. {
  168. try
  169. {
  170. List<string> classes = new List<string>();
  171. foreach (string ss in claes)
  172. {
  173. classes.Add(ss);
  174. }
  175. List<TmdInfo> tmdinfos = new List<TmdInfo>();
  176. List<Students> studentss = new List<Students>();
  177. List<string> tmdids = new List<string>();
  178. List<StuInfo> stuInfos = new List<StuInfo>();
  179. if (!classes.IsNotEmpty()) { return (tmdinfos, new List<StuInfo>(), null); }
  180. List<string> sqlList = new List<string>();
  181. classes.ForEach(x => { sqlList.Add($" '{x}' "); });
  182. string sql = string.Join(" , ", sqlList);
  183. List<StuList> schList = new List<StuList>();
  184. List<Student> students = new List<Student>();
  185. if (!string.IsNullOrEmpty(school))
  186. {
  187. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
  188. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
  189. {
  190. schList.Add(item);
  191. }
  192. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
  193. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
  194. {
  195. students.Add(item);
  196. }
  197. }
  198. List<StuList> tchLists = new List<StuList>();
  199. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
  200. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
  201. {
  202. tchLists.Add(item);
  203. }
  204. foreach (var x in schList)
  205. {
  206. if (x.students.IsNotEmpty())
  207. {
  208. studentss.AddRange(x.students);
  209. }
  210. if (x.tmids.IsNotEmpty())
  211. {
  212. tmdids.AddRange(x.tmids);
  213. }
  214. if (x.teachers.IsNotEmpty())
  215. {
  216. tmdids.AddRange(x.teachers);
  217. }
  218. classes.Remove(x.id);
  219. }
  220. foreach (var x in tchLists)
  221. {
  222. if (x.students.IsNotEmpty())
  223. {
  224. studentss.AddRange(x.students);
  225. }
  226. if (x.tmids.IsNotEmpty())
  227. {
  228. tmdids.AddRange(x.tmids);
  229. }
  230. classes.Remove(x.id);
  231. }
  232. if (tmdids.IsNotEmpty())
  233. {
  234. List<TmdInfo> infos = new List<TmdInfo>();
  235. List<string> inids = new List<string>();
  236. tmdids.ForEach(x => { inids.Add($"'{x}'"); });
  237. var insql = string.Join(",", inids);
  238. var queryslt = $"SELECT value(c) FROM c where c.id in ({insql})";
  239. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  240. {
  241. infos.Add(item);
  242. tmdids.Remove(item.id);
  243. }
  244. if (tmdids.IsNotEmpty()) {
  245. inids = new List<string>();
  246. tmdids.ForEach(x => { inids.Add($"'{x}'"); });
  247. insql = string.Join(",", inids);
  248. queryslt = $"SELECT value(c) FROM c where c.id in ({insql})";
  249. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  250. {
  251. infos.Add(item);
  252. }
  253. }
  254. tmdinfos.AddRange(infos);
  255. }
  256. if (studentss.IsNotEmpty())
  257. {
  258. var stuGroups = studentss.GroupBy(x => x.code).ToList().Select(x => new { key = x.Key, list = x.ToList() }) ;
  259. foreach (var gp in stuGroups) {
  260. List<string> inidstus = new List<string>();
  261. gp.list.Select(x => x.id).ToList().ForEach(x => { inidstus.Add($"'{x}'"); });
  262. PartitionKey partitionKey = new PartitionKey($"Base-{gp.key.Replace("Base-", "")}");
  263. var insqlstu = string.Join(",", inidstus);
  264. 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})";
  265. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey= partitionKey }))
  266. {
  267. stuInfos.Add(item);
  268. }
  269. }
  270. }
  271. students.ForEach(x =>
  272. {
  273. if (!stuInfos.Select(y => y.classId).ToList().Contains(x.id))
  274. {
  275. 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 });
  276. }
  277. });
  278. List<ClassListInfo> classInfo = new List<ClassListInfo>();
  279. schList.ForEach(x => {
  280. ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
  281. if (x.students.IsNotEmpty())
  282. {
  283. x.students.ForEach(y => {
  284. var stuinfo = stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
  285. if (stuinfo != null)
  286. {
  287. classListInfo.stuInfos.Add(stuinfo);
  288. }
  289. });
  290. }
  291. if (x.tmids.IsNotEmpty())
  292. {
  293. x.tmids.ForEach(y => {
  294. var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
  295. if (tmdinfo != null)
  296. {
  297. classListInfo.tmdInfos.Add(tmdinfo);
  298. }
  299. });
  300. }
  301. if (x.teachers.IsNotEmpty())
  302. {
  303. x.teachers.ForEach(y => {
  304. var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
  305. if (tmdinfo != null)
  306. {
  307. classListInfo.tmdInfos.Add(tmdinfo);
  308. }
  309. });
  310. }
  311. classInfo.Add(classListInfo);
  312. });
  313. tchLists.ForEach(x => {
  314. ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
  315. if (x.students.IsNotEmpty())
  316. {
  317. x.students.ForEach(y => {
  318. var stuinfo = stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
  319. if (stuinfo != null)
  320. {
  321. classListInfo.stuInfos.Add(stuinfo);
  322. }
  323. });
  324. }
  325. if (x.tmids.IsNotEmpty())
  326. {
  327. x.tmids.ForEach(y => {
  328. var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
  329. if (tmdinfo != null)
  330. {
  331. classListInfo.tmdInfos.Add(tmdinfo);
  332. }
  333. });
  334. }
  335. classInfo.Add(classListInfo);
  336. });
  337. //var classeids= students.GroupBy(x => x.classId).Select(x => x.Key).ToList();
  338. List<ClassInfo> classInfos = await GetClassInfo(client, _dingDing, classes, school);
  339. classInfos.ForEach(x =>
  340. {
  341. ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
  342. var list = students.Where(y => y.classId .Equals(x.id)).ToList();
  343. 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 }); });
  344. classInfo.Add(classListInfo);
  345. });
  346. return (tmdinfos, stuInfos, classInfo);
  347. }
  348. catch (Exception ex)
  349. {
  350. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-OS,TriggerStuActivity-GetStuList\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  351. }
  352. return (null, null, null);
  353. }
  354. public static async Task<(List<TmdInfo> tmdinfos, List<StuInfo> students,List<ClassListInfo>classInfo)> GetStuList(CosmosClient client, DingDing _dingDing, List<string> claes, string school)
  355. {
  356. try {
  357. List<string> classes = new List<string>();
  358. foreach (string ss in claes)
  359. {
  360. classes.Add(ss);
  361. }
  362. List<TmdInfo> tmdinfos = new List<TmdInfo>();
  363. List<Students> studentss = new List<Students>();
  364. List<string> tmdids = new List<string>();
  365. List<StuInfo> stuInfos = new List<StuInfo>();
  366. if (!classes.IsNotEmpty()) { return (tmdinfos, new List<StuInfo>(),null); }
  367. List<string> sqlList = new List<string>();
  368. classes.ForEach(x => { sqlList.Add($" '{x}' "); });
  369. string sql = string.Join(" , ", sqlList);
  370. List<StuList> schList = new List<StuList>();
  371. List<Student> students = new List<Student>();
  372. if (!string.IsNullOrEmpty(school)) {
  373. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
  374. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
  375. {
  376. schList.Add(item);
  377. }
  378. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
  379. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
  380. {
  381. students.Add(item);
  382. }
  383. }
  384. List<StuList> tchLists = new List<StuList>();
  385. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
  386. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
  387. {
  388. tchLists.Add(item);
  389. }
  390. foreach (var x in schList) {
  391. if (x.students.IsNotEmpty())
  392. {
  393. studentss.AddRange(x.students);
  394. }
  395. if (x.tmids.IsNotEmpty())
  396. {
  397. tmdids.AddRange(x.tmids);
  398. }
  399. classes.Remove(x.id);
  400. }
  401. foreach (var x in tchLists)
  402. {
  403. if (x.students.IsNotEmpty()) {
  404. studentss.AddRange(x.students);
  405. }
  406. if (x.tmids.IsNotEmpty())
  407. {
  408. tmdids.AddRange(x.tmids);
  409. }
  410. classes.Remove(x.id);
  411. }
  412. if (tmdids.IsNotEmpty()) {
  413. List<TmdInfo> infos = new List<TmdInfo>();
  414. List<string> inids = new List<string>();
  415. tmdids.ForEach(x => { inids.Add($"'{x}'"); });
  416. var insql = string.Join(",", inids);
  417. var queryslt = $"SELECT value(c) FROM c where c.id in ({insql})";
  418. //合并代码/
  419. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  420. {
  421. infos.Add(item);
  422. }
  423. tmdinfos.AddRange(infos);
  424. }
  425. if (studentss.IsNotEmpty()) {
  426. List<string> inidstus = new List<string>();
  427. foreach (Students stu in studentss) {
  428. var querystu = $"SELECT c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id = '{stu.id}'";
  429. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{stu.code}") }))
  430. {
  431. stuInfos.Add(item);
  432. }
  433. }
  434. /*studentss.Select(x => x.id).ToList().ForEach(x => { inidstus.Add($"'{x}'"); });
  435. var insqlstu = string.Join(",", inidstus);
  436. var querystu = $"SELECT c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id in ({insqlstu})";
  437. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school}") }))
  438. {
  439. stuInfos.Add(item);
  440. }*/
  441. }
  442. students.ForEach(x =>
  443. {
  444. if (!stuInfos.Select(y => y.classId).ToList().Contains(x.id)) {
  445. 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 });
  446. }
  447. });
  448. List<ClassListInfo> classInfo = new List<ClassListInfo>();
  449. schList.ForEach(x => {
  450. ClassListInfo classListInfo = new ClassListInfo {id=x.id,name=x.name };
  451. if (x.students.IsNotEmpty()) {
  452. x.students.ForEach(y => {
  453. var stuinfo= stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
  454. if (stuinfo != null) {
  455. classListInfo.stuInfos.Add(stuinfo);
  456. }
  457. });
  458. }
  459. if (x.tmids.IsNotEmpty())
  460. {
  461. x.tmids.ForEach(y => {
  462. var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
  463. if (tmdinfo != null)
  464. {
  465. classListInfo.tmdInfos.Add(tmdinfo);
  466. }
  467. });
  468. }
  469. classInfo.Add(classListInfo);
  470. });
  471. tchLists.ForEach(x => {
  472. ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
  473. if (x.students.IsNotEmpty())
  474. {
  475. x.students.ForEach(y => {
  476. var stuinfo = stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
  477. if (stuinfo != null)
  478. {
  479. classListInfo.stuInfos.Add(stuinfo);
  480. }
  481. });
  482. }
  483. if (x.tmids.IsNotEmpty())
  484. {
  485. x.tmids.ForEach(y => {
  486. var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
  487. if (tmdinfo != null)
  488. {
  489. classListInfo.tmdInfos.Add(tmdinfo);
  490. }
  491. });
  492. }
  493. classInfo.Add(classListInfo);
  494. });
  495. //var classeids= students.GroupBy(x => x.classId).Select(x => x.Key).ToList();
  496. List<ClassInfo> classInfos= await GetClassInfo(client, _dingDing, classes, school);
  497. classInfos.ForEach(x =>
  498. {
  499. ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
  500. var list= students.Where(y => y.classId .Equals(x.id)).ToList();
  501. 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}); });
  502. classInfo.Add(classListInfo);
  503. });
  504. return (tmdinfos, stuInfos, classInfo) ;
  505. }
  506. catch (Exception ex)
  507. {
  508. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-OS,TriggerStuActivity-GetStuList\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  509. }
  510. return (null, null,null);
  511. }
  512. }
  513. public class ClassListInfo
  514. {
  515. public string id { get; set; }
  516. public string name { get; set; }
  517. // public string from { get; set; }
  518. public List<StuInfo> stuInfos { get; set; } = new List<StuInfo>();
  519. public List<TmdInfo> tmdInfos { get; set; } = new List<TmdInfo>();
  520. }
  521. }