GroupListService.cs 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590
  1. using Azure.Cosmos;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Threading.Tasks;
  5. using TEAMModelOS.SDK.DI;
  6. using TEAMModelOS.SDK.Extension;
  7. using TEAMModelOS.SDK.Models.Cosmos.Common;
  8. using HTEXLib.COMM.Helpers;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Text.Json;
  12. using TEAMModelOS.Models;
  13. using Azure.Messaging.ServiceBus;
  14. using Microsoft.Extensions.Configuration;
  15. using TEAMModelOS.SDK.Models.Service;
  16. using System.Text.RegularExpressions;
  17. using TEAMModelOS.SDK.Models;
  18. using System.Net.Http;
  19. using DocumentFormat.OpenXml.Wordprocessing;
  20. using static TEAMModelOS.SDK.GroupListService;
  21. using DocumentFormat.OpenXml.Drawing.Charts;
  22. namespace TEAMModelOS.SDK
  23. {
  24. public class GroupListService
  25. {
  26. public static async Task DeleteGrouplistEvent(string id , string code,string tbname ,CosmosClient client, IConfiguration _configuration, AzureServiceBusFactory _serviceBus)
  27. {
  28. GroupChange change = new GroupChange();
  29. GroupList groupList = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<GroupList>(id.ToString(), new PartitionKey(code));
  30. var tleave = groupList.members.FindAll(x => x.type == 1);
  31. if (tleave.IsNotEmpty())
  32. {
  33. if (groupList.type.Equals("research") || groupList.type.Equals("yxtrain"))
  34. {
  35. change.tchleave.AddRange(tleave);
  36. }
  37. else
  38. {
  39. change.tmdleave.AddRange(tleave);
  40. }
  41. }
  42. var sleave = groupList.members.FindAll(x => x.type == 2);
  43. if (sleave.IsNotEmpty())
  44. {
  45. change.stuleave.AddRange(sleave);
  46. }
  47. change.listid = groupList.id;
  48. change.scope = groupList.scope;
  49. change.originCode = $"{code}";
  50. change.school = groupList.school;
  51. change.creatorId = groupList.creatorId;
  52. change.type = groupList.type;
  53. change.status = "delete";
  54. if (change.tmdleave.IsNotEmpty() || change.tchleave.IsNotEmpty() || change.stuleave.IsNotEmpty())
  55. {
  56. var messageChange = new ServiceBusMessage(change.ToJsonString());
  57. messageChange.ApplicationProperties.Add("name", "GroupChange");
  58. var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  59. await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
  60. }
  61. await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemStreamAsync(id.ToString(), new PartitionKey(code));
  62. }
  63. /// <summary>
  64. /// 查询名单成员所在的名单列表,
  65. /// </summary>
  66. /// <param name="_coreAPIHttpService"></param>
  67. /// <param name="client"></param>
  68. /// <param name="_dingDing"></param>
  69. /// <param name="memberId">成员id </param>
  70. /// <param name="memberType">成员类型</param>
  71. /// <param name="school">成员所在的学校 ,可为空</param>
  72. /// <param name="groupTypes">过滤名单的类型集合,不传则是全部</param>
  73. /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
  74. /// <returns></returns>
  75. public static async Task<List<GroupListGrp>> GetMemberInGroupList(CoreAPIHttpService _coreAPIHttpService, CosmosClient client, DingDing _dingDing, string memberId, int memberType, string school,List<string> groupTypes,int graduate =-1) {
  76. List<GroupListGrp> groupLists = new List<GroupListGrp>();
  77. if (groupTypes.IsEmpty() || groupTypes.Contains("class")) {
  78. if (!string.IsNullOrWhiteSpace(school) && memberType == 2)
  79. {
  80. Student student = null;
  81. try
  82. {
  83. student = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemAsync<Student>(memberId, new PartitionKey($"Base-{school}"));
  84. }
  85. catch (CosmosException ex) when (ex.Status == 404)
  86. {
  87. return null;
  88. }
  89. if (!string.IsNullOrWhiteSpace(student.classId))
  90. {
  91. try
  92. {
  93. Class clazz = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<Class>(student.classId, new PartitionKey($"Class-{school}"));
  94. GroupListGrp groupList = new GroupListGrp
  95. {
  96. id = clazz.id,
  97. code = $"GroupList-{clazz.school}",
  98. name = clazz.name,
  99. periodId = clazz.periodId,
  100. pk = "GroupList",
  101. expire=0,
  102. year = clazz.year,
  103. school = clazz.school,
  104. scope = "school",
  105. type = "class",
  106. no = clazz.no,
  107. leader = clazz.teacher?.id,
  108. graduate=clazz.graduate,
  109. grades= new HashSet<int>() { clazz.year}
  110. };
  111. //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
  112. if (graduate >= 0 )
  113. {
  114. if (groupList.graduate == graduate) {
  115. groupLists.Add(groupList);
  116. }
  117. }
  118. //全部。
  119. else if(graduate == -1)
  120. {
  121. groupLists.Add(groupList);
  122. }
  123. }
  124. catch (CosmosException ex) when (ex.Status == 404)
  125. {
  126. }
  127. }
  128. }
  129. }
  130. string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.leader ,c.froms ,c.joinLock ,c.review,c.limitCount ,c.expire,c.qrcodeExpire ,c.qrcodeDays ,c.grades ";
  131. if (groupTypes.IsEmpty() || groupTypes.Contains("teach")) {
  132. //教学班
  133. string teachsql="";
  134. if (!string.IsNullOrWhiteSpace(school) && memberType == 2) {
  135. teachsql= $"SELECT distinct {SummarySql} FROM c join m in c.members where c.type='teach' and m.id='{memberId}' and m.code='{school}' and m.type=2 ";
  136. }
  137. if (memberType == 1)
  138. {
  139. teachsql=$"SELECT distinct {SummarySql} FROM c join m in c.members where c.type='teach' and m.id='{memberId}' and m.type=1 ";
  140. }
  141. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
  142. GetItemQueryIterator<GroupList>(queryText: teachsql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
  143. {
  144. HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
  145. groupLists.Add(new GroupListGrp(item, groupName));
  146. }
  147. //个人名单
  148. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).
  149. GetItemQueryIterator<GroupList>(queryText: teachsql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList") }))
  150. {
  151. HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
  152. groupLists.Add(new GroupListGrp(item, groupName));
  153. }
  154. }
  155. if (!string.IsNullOrWhiteSpace(school) && (groupTypes.IsEmpty() || groupTypes.Contains("research")))
  156. {
  157. //教研组
  158. string teachsql = $"SELECT distinct {SummarySql} FROM c join m in c.members where c.type='research' and m.id='{memberId}' and m.type=1 ";
  159. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
  160. GetItemQueryIterator<GroupList>(queryText: teachsql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
  161. {
  162. HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
  163. groupLists.Add(new GroupListGrp(item, groupName));
  164. }
  165. }
  166. if (!string.IsNullOrWhiteSpace(school) && (groupTypes.IsEmpty() || groupTypes.Contains("yxtrain")))
  167. {
  168. //研修名单
  169. string teachsql = $"SELECT distinct {SummarySql} FROM c join m in c.members where c.type='yxtrain' and m.id='{memberId}' and m.type=1 ";
  170. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
  171. GetItemQueryIterator<GroupList>(queryText: teachsql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
  172. {
  173. HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
  174. groupLists.Add(new GroupListGrp(item, groupName));
  175. }
  176. }
  177. return groupLists;
  178. }
  179. /// <summary>
  180. ///-1状态异常,0加入成功, 1加入学生或醍摩豆ID为空,2重复加入 ,3不允许跨校加入名单, 4表示个人名单未开放加入,状态=5 ,人数已满。状态=6 ,需要审核通过再加入。状态7 二维码设置已经过期
  181. /// </summary>
  182. /// <param name="client"></param>
  183. /// <param name="_stuListNo"></param>
  184. /// <param name="userid"></param>
  185. /// <param name="type"></param>
  186. /// <param name="school"></param>
  187. /// <returns></returns>
  188. public static async Task<(int status, GroupList stuList,Member member)> CodeJoinList(CosmosClient client,AzureRedisFactory _azureRedis, string _stuListNo, string userid, int type, string school,int year,string name ,string picture,string lang,string courseId= null)
  189. {
  190. var queryNo = $"SELECT value(c) FROM c where c.no ='{_stuListNo}'";
  191. (int status, GroupList stuList,Member member) data = (-1, null,null);
  192. if (!string.IsNullOrEmpty(school))
  193. {
  194. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: queryNo,
  195. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
  196. {
  197. data = JoinList(item, userid, type, school,year);
  198. break;
  199. }
  200. }
  201. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<GroupList>(queryText: queryNo,
  202. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList") }))
  203. {
  204. if (item.joinLock == 0) {
  205. //状态=4 表示未开放加入。
  206. return (4, item, null) ;
  207. }
  208. if (item.review ==1)
  209. {
  210. //状态=6 ,人数已满,需要审核通过再加入。
  211. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  212. if (now>item.qrcodeExpire)
  213. {
  214. //二维码设置已经过期,只有需要审核的时候才检查二维码过期问题,目的是为了未正式加入人员的缓存
  215. return (7, item, null);
  216. }
  217. else
  218. {
  219. GroupWaitingList waitingList = new GroupWaitingList
  220. {
  221. stuListNo=_stuListNo,
  222. userid=userid,
  223. type=type,
  224. school= school,
  225. year = year,
  226. groupId = item.id,
  227. groupScope=item.scope,
  228. name = name,
  229. picture = picture,
  230. lang = lang,
  231. qrcodeExpire=item.qrcodeExpire,
  232. groupName= item.name,
  233. applyTime=now
  234. };
  235. string sql = "select value c from c join b in c.schedules where b.groupId='60f92012-72cf-4d5c-a66a-552678303fad'";
  236. string key = $"GroupList:GroupWaitingList:{item.scope}:{item.id}";
  237. string filed = !string.IsNullOrWhiteSpace(school) ? $"{school}_{userid}" : userid;
  238. await _azureRedis.GetRedisClient(8).HashSetAsync(key, filed, waitingList.ToJsonString());
  239. await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, expiry: DateTimeOffset.FromUnixTimeMilliseconds(item.qrcodeExpire).UtcDateTime);
  240. string stuKey = !string.IsNullOrWhiteSpace(school) ? $"GroupList:StudentWaitinglist:{school}_{userid}" :$"GroupList:StudentWaitinglist:{userid}" ;
  241. string sutFiled = $"{item.scope}:{item.id}";
  242. await _azureRedis.GetRedisClient(8).HashSetAsync(stuKey, sutFiled, waitingList.ToJsonString());
  243. //三十天都不登录,则不需要查看申请清单,30*24=720
  244. await _azureRedis.GetRedisClient(8).KeyExpireAsync(stuKey, new TimeSpan(720 , 0, 0));
  245. return (6, item, null);
  246. }
  247. }
  248. if (item.members!=null &&item.limitCount>0 && item.members.Count>=item.limitCount) {
  249. //状态=5 ,人数已满
  250. return (5, item, null);
  251. }
  252. data = JoinList(item, userid, type, school,year);
  253. //TODO 需要考虑已经通过别的途径加入名单,但是缓存数据仍记录数据的问题。 还要考虑手动加入过的。或者在获取名未加入名单成员的临时缓存数据的时候过滤已经加入的。
  254. break;
  255. }
  256. return data;
  257. }
  258. /// <summary>
  259. /// 加入名单等候列表
  260. /// </summary>
  261. public class GroupWaitingList
  262. {
  263. /// <summary>
  264. ///
  265. /// </summary>
  266. public string stuListNo { get; set; }
  267. public string userid { get; set; }
  268. //学生类型,1醍摩豆id,2 校内账号
  269. public int type { get; set; }
  270. public string school { get; set; }
  271. public int year { get; set; }
  272. public string groupId { get; set; }
  273. public string groupScope { get; set; }
  274. public string name { get; set; }
  275. public string picture { get; set; }
  276. public string lang { get; set; }
  277. public long qrcodeExpire { get; set; }
  278. public string groupName { get; set; }
  279. public long applyTime{ get; set; }
  280. /// <summary>
  281. /// 申请状态,-1 申请中,0 通过,1 拒绝,2 已过期。
  282. /// </summary>
  283. public int status { get; set; } = -1;
  284. public List<IdName> courses { get; set; }= new List<IdName>();
  285. }
  286. public static (int status, GroupList stuList, Member member) JoinList(GroupList stuList, string userid, int type, string school,int year)
  287. {
  288. int status = -1;
  289. if (!string.IsNullOrWhiteSpace(stuList.school) && !string.IsNullOrWhiteSpace(school))
  290. {
  291. if (!stuList.school.Equals(school))
  292. {
  293. status = 3;//不允许跨校加入名单
  294. return (status, stuList,null);
  295. }
  296. }
  297. string irs = string.Empty;
  298. List<string> irsOrder = stuList.members.Select(x => x.irs)?.Where(y => !string.IsNullOrEmpty(y) && Regex.IsMatch(y, @"^\d*$")).OrderBy(x => int.Parse(x)).ToList();
  299. if (!irsOrder.Contains("0"))
  300. {
  301. irsOrder.Insert(0, "0");
  302. }
  303. if (irsOrder != null)
  304. {
  305. if (!irsOrder.Contains("0"))
  306. {
  307. irsOrder.Insert(0, "0");
  308. }
  309. }
  310. else { irsOrder = new List<string>() { "0" }; }
  311. for (int i = 0; i < irsOrder.Count; i++)
  312. {
  313. irs = $"{int.Parse(irsOrder[i]) + 1}";
  314. int index = i + 1;
  315. if (index <= irsOrder.Count - 1)
  316. {
  317. if (!irs.Equals(irsOrder[index]))
  318. {
  319. break;
  320. }
  321. }
  322. }
  323. Member member = null;
  324. if (string.IsNullOrEmpty($"{userid}"))
  325. {
  326. //加入学生或醍摩豆ID为空
  327. status = 1;
  328. }
  329. else
  330. {
  331. if (type == 1)
  332. {
  333. member = stuList.members.Find(x => x.type == 1 && x.id.Equals(userid));
  334. if (member != null)
  335. {
  336. //重复加入
  337. status = 2;
  338. }
  339. else
  340. {
  341. //加入成功
  342. status = 0;
  343. member = new Member { id = userid, type = type, irs = irs, no = irs,year=year };
  344. stuList.members.Add(member);
  345. }
  346. }
  347. else if (type == 2)
  348. {
  349. member = stuList.members.Find(x => x.type == 2 && x.id.Equals(userid) && x.code.Equals(school));
  350. if (member != null)
  351. {
  352. //重复加入
  353. status = 2;
  354. }
  355. else
  356. {
  357. status = 0;
  358. member = new Member { id = userid, code = school, type = type, irs = irs, no = irs, year = year };
  359. stuList.members.Add(member);
  360. }
  361. }
  362. }
  363. return (status, stuList, member);
  364. }
  365. public static async Task<GroupList> UpsertList(GroupList list, AzureCosmosFactory _azureCosmos, IConfiguration _configuration, AzureServiceBusFactory _serviceBus)
  366. {
  367. bool isnew = false;
  368. var client = _azureCosmos.GetCosmosClient();
  369. if (string.IsNullOrEmpty(list.id))
  370. {
  371. list.id = Guid.NewGuid().ToString();
  372. isnew = true;
  373. }
  374. string tbname = list.scope.Equals("private") ? "Teacher" : "School";
  375. var tmembers = list.members.Where(x => x.type == 1);
  376. var smembers = list.members.Where(x => x.type == 2);
  377. //处理年级
  378. HashSet<int> grades = new HashSet<int>();
  379. if (smembers.Any()) {
  380. grades = smembers.Where(z => z.year > 2000).Select(z=>z.year).ToHashSet();
  381. }
  382. list.grades = grades;
  383. list.scount = smembers.Count();
  384. list.tcount = tmembers.Count();
  385. //if (smembers.Count() > 0 && smembers.Select(x => x.code).ToHashSet().Count()>=2) {
  386. // //处理移除多个学校的名单,只保留一个学校的。
  387. // if (string.IsNullOrWhiteSpace(list.school))
  388. // {
  389. // HashSet<string> codes = smembers.Select(x => x.code).ToHashSet();
  390. // list.school = codes.First();
  391. // codes.Remove(codes.First());
  392. // list.members.RemoveAll(x => codes.Contains(x.code));
  393. // }
  394. // else {
  395. // list.members.RemoveAll(x => !x.code.Equals(list.school));
  396. // }
  397. //}
  398. if (string.IsNullOrWhiteSpace(list.school) && smembers.Count() >= 1)
  399. {
  400. list.school = smembers.First().code;
  401. }
  402. if (!string.IsNullOrWhiteSpace(list.school) && smembers.Count() == 0 && list.scope.Equals("private"))
  403. {
  404. list.school = null;
  405. }
  406. //学生名单,教研组会触发活动中间表刷新
  407. if (list.type.Equals("teach") || list.type.Equals("research") || list.type.Equals("yxtrain") || list.type.Equals("activity"))
  408. {
  409. GroupChange change = new GroupChange()
  410. {
  411. type = list.type,
  412. listid = list.id,
  413. scope = list.scope,
  414. originCode = list.school,
  415. school = list.school,
  416. creatorId = list.creatorId
  417. };
  418. GroupList oldList = null;
  419. if (!isnew)
  420. {
  421. try
  422. {
  423. oldList = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<GroupList>(list.id, new PartitionKey(list.code));
  424. }
  425. catch (CosmosException)
  426. {
  427. oldList = null;
  428. }
  429. }
  430. if (list.members.IsNotEmpty() && (oldList == null || !oldList.members.IsNotEmpty()))
  431. {
  432. //加入的
  433. var tmdids = list.members.FindAll(x => x.type == 1);
  434. if (tmdids.IsNotEmpty())
  435. {
  436. if (list.type.Equals("research") || list.type.Equals("yxtrain"))
  437. {
  438. change.tchjoin.AddRange(tmdids);
  439. }
  440. else
  441. {
  442. change.tmdjoin.AddRange(tmdids);
  443. }
  444. }
  445. var stuids = list.members.FindAll(x => x.type == 2);
  446. if (stuids.IsNotEmpty())
  447. {
  448. change.stujoin.AddRange(stuids);
  449. }
  450. }
  451. else
  452. {
  453. if (list.members.IsNotEmpty())
  454. {
  455. var tmdids = list.members.FindAll(x => x.type == 1);
  456. var oldtmdids = oldList.members.FindAll(x => x.type == 1);
  457. //取各自的差集
  458. //新=》旧差集,表示新增
  459. var jointmdid = tmdids.Select(x => x.id).Except(oldtmdids.Select(y => y.id)).ToList();
  460. //旧=》新差集,表示离开
  461. var leavetmdid = oldtmdids.Select(x => x.id).Except(tmdids.Select(y => y.id)).ToList();
  462. if (list.type.Equals("research") || list.type.Equals("yxtrain"))
  463. {
  464. if (tmdids!=null && jointmdid!=null)
  465. {
  466. change.tchjoin.AddRange(tmdids.Where(x => jointmdid.Exists(y => y.Equals(x.id))));
  467. }
  468. if (oldtmdids!= null &&leavetmdid != null) {
  469. change.tchleave.AddRange(oldtmdids.Where(x => leavetmdid.Exists(y => y.Equals(x.id))));
  470. }
  471. }
  472. else
  473. {
  474. if (tmdids!=null && jointmdid!=null)
  475. {
  476. change.tmdjoin.AddRange(tmdids.Where(x => jointmdid.Exists(y => y.Equals(x.id))));
  477. }
  478. if (oldtmdids!= null &&leavetmdid != null)
  479. {
  480. change.tmdleave.AddRange(oldtmdids.Where(x => leavetmdid.Exists(y => y.Equals(x.id))));
  481. }
  482. }
  483. var stuids = list.members.FindAll(x => x.type == 2);
  484. var oldstuids = oldList.members.FindAll(x => x.type == 2);
  485. var joinstudent = stuids.Select(x => (x.id, x.code)).Except(oldstuids.Select(y => (y.id, y.code)), new CompareIdCode()).ToList();
  486. var leavestudent = oldstuids.Select(x => (x.id, x.code)).Except(stuids.Select(y => (y.id, y.code)), new CompareIdCode()).ToList();
  487. change.stujoin.AddRange(stuids.Where(x => joinstudent.Exists(y => y.id.Equals(x.id) && y.code.Equals(x.code))));
  488. change.stuleave.AddRange(oldstuids.Where(x => leavestudent.Exists(y => y.id.Equals(x.id) && y.code.Equals(x.code))));
  489. }
  490. else
  491. {
  492. //离开的
  493. if (oldList != null)
  494. {
  495. var tmdids = oldList.members.FindAll(x => x.type == 1);
  496. if (tmdids.IsNotEmpty())
  497. {
  498. if (list.type.Equals("research") || list.type.Equals("yxtrain"))
  499. {
  500. change.tchleave.AddRange(tmdids);
  501. }
  502. else
  503. {
  504. change.tmdleave.AddRange(tmdids);
  505. }
  506. }
  507. var stuids = oldList.members.FindAll(x => x.type == 2);
  508. if (stuids.IsNotEmpty())
  509. {
  510. change.stuleave.AddRange(stuids);
  511. }
  512. }
  513. }
  514. }
  515. if (change.tmdjoin.Count != 0 || change.tmdleave.Count != 0 || change.stujoin.Count != 0 || change.stuleave.Count != 0
  516. || change.tchjoin.Count != 0 || change.tchleave.Count != 0)
  517. {
  518. var messageChange = new ServiceBusMessage(change.ToJsonString());
  519. messageChange.ApplicationProperties.Add("name", "GroupChange");
  520. var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  521. await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
  522. }
  523. }
  524. await client.GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(list, new PartitionKey(list.code));
  525. return list;
  526. }
  527. public static async Task<GroupList> CheckListNo(GroupList list, AzureCosmosFactory _azureCosmos, DingDing _dingDing, Option _option)
  528. {
  529. try
  530. {
  531. var client = _azureCosmos.GetCosmosClient();
  532. if (string.IsNullOrEmpty(list.no))
  533. {
  534. list.no = $"{Utils.CreatSaltString(6, "123456789")}";
  535. for (int i = 0; i < 10; i++)
  536. {
  537. List<string> noStus = new List<string>();
  538. var queryNo = $"SELECT c.no FROM c where c.no ='{list.no}'";
  539. if (list.scope.Equals("school"))
  540. {
  541. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: queryNo,
  542. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{list.code}") }))
  543. {
  544. using var jsonNo = await JsonDocument.ParseAsync(item.ContentStream);
  545. if (jsonNo.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  546. {
  547. var accounts = jsonNo.RootElement.GetProperty("Documents").EnumerateArray();
  548. while (accounts.MoveNext())
  549. {
  550. JsonElement account = accounts.Current;
  551. noStus.Add(account.GetProperty("no").GetString());
  552. }
  553. }
  554. }
  555. }
  556. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: queryNo,
  557. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey("GroupList") }))
  558. {
  559. using var jsonNo = await JsonDocument.ParseAsync(item.ContentStream);
  560. if (jsonNo.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  561. {
  562. var accounts = jsonNo.RootElement.GetProperty("Documents").EnumerateArray();
  563. while (accounts.MoveNext())
  564. {
  565. JsonElement account = accounts.Current;
  566. noStus.Add(account.GetProperty("no").GetString());
  567. }
  568. }
  569. }
  570. if (noStus.Count == 0)
  571. {
  572. break;
  573. }
  574. else
  575. {
  576. if (i == 9)
  577. {
  578. string msg = $"OS,{_option.Location},school/course/upsert-list()\n 编号生成异常,重复生成次数超过10次";
  579. await _dingDing.SendBotMsg(msg, GroupNames.醍摩豆服務運維群組);
  580. throw new Exception(msg);
  581. }
  582. else
  583. {
  584. list.no = $"{Utils.CreatSaltString(6, "123456789")}";
  585. }
  586. }
  587. }
  588. }
  589. }
  590. catch (Exception ex)
  591. {
  592. }
  593. return list;
  594. }
  595. /// <summary>
  596. ///根据任意名单id获取名单摘要信息。
  597. /// </summary>
  598. /// <param name="client"></param>
  599. /// <param name="_dingDing"></param>
  600. /// <param name="classes"></param>
  601. /// <param name="school"></param>
  602. /// <param name="SummarySql"></param>
  603. /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
  604. /// <returns></returns>
  605. public static async Task<List<GroupListDto>> GetGroupListByListids(CosmosClient client, DingDing _dingDing, List<string> classes, string school,
  606. string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.leader ,c.froms ,c.joinLock ,c.review,c.limitCount ,c.expire ,c.qrcodeExpire,c.qrcodeDays ,c.grades ", int graduate = -1)
  607. {
  608. List<GroupListDto> groupLists = null;
  609. try
  610. {
  611. classes.RemoveAll(x => x == null);
  612. if (!classes.IsNotEmpty())
  613. {
  614. return null;
  615. }
  616. if (classes.Count == 1 && classes.First().Equals("TeacherAll") && !string.IsNullOrEmpty(school))
  617. {
  618. //默认的教研组
  619. GroupListDto groupList = new GroupListDto
  620. {
  621. id = "TeacherAll",
  622. name = "TeacherAll",
  623. code = $"GroupList-{school}",
  624. school = school,
  625. scope = "school",
  626. type = "yxtrain",
  627. };
  628. groupLists = new List<GroupListDto> { groupList };
  629. }
  630. else
  631. {
  632. Dictionary<string, List<GroupListDto>> groups = new Dictionary<string, List<GroupListDto>>();
  633. //List<Student> students = new List<Student>();
  634. string sql = string.Join(",", classes.Select(x => $"'{x}'"));
  635. if (!string.IsNullOrEmpty(school))
  636. {
  637. List<GroupListDto> schoolList = new List<GroupListDto>();
  638. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupListDto>(queryText: $"select {SummarySql} from c where c.id in ({sql})",
  639. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
  640. {
  641. schoolList.Add(item);
  642. }
  643. if (schoolList.IsNotEmpty())
  644. {
  645. groups.Add("School", schoolList);
  646. }
  647. //取差集,减少二次搜寻
  648. classes = classes.Except(schoolList.Select(y => y.id)).ToList();
  649. if (classes.IsNotEmpty())
  650. {
  651. if (!groupLists.IsNotEmpty())
  652. {
  653. groupLists = new List<GroupListDto>();
  654. }
  655. string insql = string.Join(",", classes.Select(x => $"'{x}'"));
  656. //搜寻没有关联学生的行政班
  657. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupListDto>(queryText:
  658. $"select c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.teacher.id as leader ,c.graduate from c where c.id in ({insql})",
  659. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
  660. {
  661. ///行政班(学生搜寻classId动态返回)class
  662. GroupListDto group = new GroupListDto
  663. {
  664. id = item.id,
  665. code = $"GroupList-{school}",
  666. name = item.name,
  667. periodId = item.periodId,
  668. scope = "school",
  669. school = school,
  670. type = "class",
  671. year = item.year,
  672. expire = item.expire,
  673. leader = item.leader,
  674. no = item.no,
  675. pk = "GroupList",
  676. graduate = item.graduate,
  677. grades= new HashSet<int> { item.year }
  678. };
  679. //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
  680. if (graduate >= 0)
  681. {
  682. if (group.graduate == graduate)
  683. {
  684. groupLists.Add(group);
  685. }
  686. }
  687. //全部。
  688. else
  689. {
  690. groupLists.Add(group);
  691. }
  692. // groupLists.Add(group);
  693. }
  694. //取差集,减少二次搜寻
  695. classes = classes.Except(groupLists.Select(y => y.id)).ToList();
  696. }
  697. }
  698. if (classes.IsNotEmpty())
  699. {
  700. List<GroupListDto> privateList = new List<GroupListDto>();
  701. sql = string.Join(",", classes.Select(x => $"'{x}'"));
  702. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<GroupListDto>(queryText: $"select {SummarySql} from c where c.id in ({sql})",
  703. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList") }))
  704. {
  705. privateList.Add(item);
  706. //if (string.IsNullOrWhiteSpace(school))
  707. //{
  708. // privateList.Add(item);
  709. //}
  710. //else
  711. //{
  712. // if (!string.IsNullOrWhiteSpace(item.school))
  713. // {
  714. // if (item.school.Equals(school))
  715. // {
  716. // privateList.Add(item);
  717. // }
  718. // }
  719. // else
  720. // {
  721. // privateList.Add(item);
  722. // }
  723. //}
  724. }
  725. if (privateList.IsNotEmpty())
  726. {
  727. groups.Add("Teacher", privateList);
  728. }
  729. }
  730. if (groups.Count != 0)
  731. {
  732. if (groupLists.IsNotEmpty())
  733. {
  734. groupLists.AddRange(groups.SelectMany(x => x.Value).ToList());
  735. }
  736. else
  737. {
  738. groupLists = groups.SelectMany(x => x.Value).ToList();
  739. }
  740. }
  741. }
  742. } catch (Exception ex ) {
  743. await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  744. }
  745. return groupLists;
  746. }
  747. /// <summary>
  748. /// 根据任意名单id获取成员信息。rmembers是去重的信息,groups是名单及人员信息,同一个人可能在不同的名单内。
  749. /// </summary>
  750. /// <param name="_coreAPIHttpService"></param>
  751. /// <param name="client"></param>
  752. /// <param name="_dingDing"></param>
  753. /// <param name="classes"></param>
  754. /// <param name="school"></param>
  755. /// <param name="groupids"></param>
  756. /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
  757. /// <returns></returns>
  758. public static async Task<(List<RMember>rmembers, List<RGroupList> groups)> GetMemberByListids(CoreAPIHttpService _coreAPIHttpService, CosmosClient client, DingDing _dingDing,
  759. List<string> classes, string school, List<(string, List<string>)> groupids = null, int graduate = -1)
  760. {
  761. List<RMember> members = new List<RMember>();
  762. List<RGroupList> groupLists = new List<RGroupList>();
  763. if (classes != null)
  764. {
  765. classes.RemoveAll(x => x == null);
  766. }
  767. if (classes == null || classes.Count <= 0)
  768. {
  769. return (members, groupLists);
  770. }
  771. string periodId = string.Empty;
  772. if (classes.Count == 1 && classes.First().Equals("TeacherAll") && !string.IsNullOrEmpty(school))
  773. {
  774. //默认的教研组
  775. members = new List<RMember>();
  776. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
  777. GetItemQueryIterator<TmdInfo>(queryText: $"SELECT c.id,c.name,c.picture FROM c ",
  778. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school}") }))
  779. {
  780. RMember member = new RMember
  781. {
  782. id = item.id,
  783. name = item.name,
  784. picture = item.picture,
  785. type = 1,
  786. // nickname=item.name,
  787. };
  788. members.Add(member);
  789. }
  790. RGroupList groupList = new RGroupList
  791. {
  792. id = "TeacherAll",
  793. name = "TeacherAll",
  794. code = $"GroupList-{school}",
  795. school = school,
  796. scope = "school",
  797. type = "TeacherAll",
  798. members = members
  799. };
  800. groupLists = new List<RGroupList> { groupList };
  801. }
  802. else
  803. {
  804. Dictionary<string, List<RGroupList>> groups = new Dictionary<string, List<RGroupList>>();
  805. List<Student> students = new List<Student>();
  806. string sql = string.Join(",", classes.Select(x => $"'{x}'"));
  807. if (!string.IsNullOrEmpty(school))
  808. {
  809. List<RGroupList> schoolList = new List<RGroupList>();
  810. string queryText = $"select value(c) from c where c.id in ({sql})";
  811. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<RGroupList>(queryText: queryText,
  812. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
  813. {
  814. schoolList.Add(item);
  815. }
  816. if (schoolList.IsNotEmpty())
  817. {
  818. groups.Add("School", schoolList);
  819. }
  820. //取差集,减少二次搜寻
  821. classes = classes.Except(schoolList.Select(y => y.id)).ToList();
  822. if (classes.IsNotEmpty())
  823. {
  824. sql = string.Join(",", classes.Select(x => $"'{x}'"));
  825. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
  826. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
  827. {
  828. //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
  829. if (graduate >= 0)
  830. {
  831. if (item.graduate == graduate)
  832. {
  833. students.Add(item);
  834. }
  835. }
  836. //全部。
  837. else
  838. {
  839. students.Add(item);
  840. }
  841. // students.Add(item);
  842. }
  843. //取差集,减少二次搜寻
  844. classes = classes.Except(students.Select(y => y.classId)).ToList();
  845. }
  846. if (classes.IsNotEmpty())
  847. {
  848. string insql = string.Join(",", classes.Select(x => $"'{x}'"));
  849. //搜寻没有关联学生的行政班
  850. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School")
  851. .GetItemQueryIterator<RGroupList>(queryText: $"select c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.teacher.id as leader ,c.graduate from c where c.id in ({insql})",
  852. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
  853. {
  854. ///行政班(学生搜寻classId动态返回)class
  855. List<RMember> smembers = new List<RMember>();
  856. RGroupList group = new RGroupList
  857. {
  858. id = item.id,
  859. code = $"GroupList-{school}",
  860. name = item.name,
  861. periodId = item.periodId,
  862. scope = "school",
  863. school = school,
  864. type = "class",
  865. year = item.year,
  866. expire = item.expire,
  867. members = smembers,
  868. scount = smembers.Count,
  869. pk = "GroupList",
  870. leader = item.leader,
  871. no = item.no,
  872. graduate = item.graduate,
  873. grades= new HashSet<int>() { item.year }
  874. };
  875. //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
  876. if (graduate >= 0)
  877. {
  878. if (group.graduate == graduate)
  879. {
  880. groupLists.Add(group);
  881. }
  882. }
  883. //全部。
  884. else
  885. {
  886. groupLists.Add(group);
  887. }
  888. //groupLists.Add(group);
  889. }
  890. //取差集,减少二次搜寻
  891. classes = classes.Except(groupLists.Select(y => y.id)).ToList();
  892. }
  893. }
  894. if (classes.IsNotEmpty())
  895. {
  896. List<RGroupList> privateList = new List<RGroupList>();
  897. sql = string.Join(",", classes.Select(x => $"'{x}'"));
  898. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<RGroupList>(queryText: $"select value(c) from c where c.id in ({sql})",
  899. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList") }))
  900. {
  901. privateList.Add(item);
  902. //if (string.IsNullOrWhiteSpace(school))
  903. //{
  904. // privateList.Add(item);
  905. //}
  906. //else
  907. //{
  908. // if (!string.IsNullOrWhiteSpace(item.school))
  909. // {
  910. // if (item.school.Equals(school))
  911. // {
  912. // privateList.Add(item);
  913. // }
  914. // }
  915. // else
  916. // {
  917. // privateList.Add(item);
  918. // }
  919. //}
  920. }
  921. if (privateList.IsNotEmpty())
  922. {
  923. groups.Add("Teacher", privateList);
  924. }
  925. }
  926. foreach (var item in groups)
  927. {
  928. var list = item.Value.GroupBy(x => x.type).Select(y => new { key = y.Key, list = y.ToList() });
  929. foreach (var group in list)
  930. {
  931. (List<RGroupList> rgroups, List<RMember> rmembers) = await GetGroupListMemberInfo(_coreAPIHttpService, client, group.key, group.list, item.Key, _dingDing, school,graduate);
  932. members.AddRange(rmembers);
  933. }
  934. }
  935. groupLists.AddRange(groups.SelectMany(x => x.Value).ToList());
  936. if (students.IsNotEmpty())
  937. {
  938. List<string> sqlList = students.Select(x => x.classId).ToList();
  939. string insql = string.Join(",", sqlList.Select(x => $"'{x}'"));
  940. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
  941. GetItemQueryIterator<RGroupList>(queryText: $"select c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.teacher.id as leader ,c.graduate from c where c.id in ({insql})",
  942. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
  943. {
  944. ///行政班(学生搜寻classId动态返回)class
  945. List<RMember> smembers = students.Where(x => x.classId.Equals(item.id))
  946. .Select(y => new RMember
  947. {
  948. id = y.id,
  949. code = school,
  950. name = y.name,
  951. //nickname = y.name,
  952. type = 2,
  953. picture = y.picture,
  954. no = y.no,
  955. classId = y.classId,
  956. groupId = y.groupId,
  957. groupName = y.groupName,
  958. irs = y.irs,
  959. year= y.year,
  960. graduate = y.graduate,
  961. gender= y.gender,
  962. periodId=y.periodId,
  963. }).ToList();
  964. members.AddRange(smembers);
  965. RGroupList group = new RGroupList
  966. {
  967. id = item.id,
  968. code = $"GroupList-{school}",
  969. name = item.name,
  970. periodId = item.periodId,
  971. scope = "school",
  972. school = school,
  973. type = "class",
  974. expire= item.expire,
  975. year = item.year,
  976. members = smembers,
  977. scount = smembers.Count,
  978. no = item.no,
  979. leader = item.leader,
  980. pk = "GroupList",
  981. graduate = item.graduate,
  982. grades= new HashSet<int> { item.year}
  983. };
  984. //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
  985. if (graduate >= 0)
  986. {
  987. if (group.graduate == graduate)
  988. {
  989. groupLists.Add(group);
  990. }
  991. }
  992. //全部。
  993. else
  994. {
  995. groupLists.Add(group);
  996. }
  997. // groupLists.Add(group);
  998. }
  999. //去重。
  1000. members = members.FindAll(x => x.type == 2).Where((x, i) => members.FindAll(x => x.type == 2).FindIndex(n => n.id.Equals(x.id) && n.code.Equals(x.code)) == i).ToList();
  1001. }
  1002. }
  1003. if (groupids.IsNotEmpty())
  1004. {
  1005. List<RMember> rmembers = new List<RMember>();
  1006. groupLists.ForEach(y => {
  1007. (string id, List<string> grpids) = groupids.Find(x => x.Item1.Equals(y.id));
  1008. var gpmember = y.members.FindAll(x => !string.IsNullOrEmpty(x.groupName) && grpids.Contains(x.groupName));
  1009. if (grpids.Contains("default"))
  1010. {
  1011. var gpmemberdft = y.members.FindAll(x => string.IsNullOrWhiteSpace(x.groupName));
  1012. if (gpmember.IsNotEmpty())
  1013. {
  1014. gpmember.AddRange(gpmemberdft);
  1015. }
  1016. else
  1017. {
  1018. gpmember = gpmemberdft;
  1019. }
  1020. }
  1021. y.members = gpmember;
  1022. });
  1023. var gpgpmembers = groupLists.SelectMany(x => x.members).ToList();
  1024. List<RMember> tmdids = gpgpmembers.FindAll(x => x.type == 1).Where((x, i) => gpgpmembers.FindAll(x => x.type == 1).FindIndex(n => n.id.Equals(x.id)) == i).ToList();
  1025. List<RMember> students = gpgpmembers.FindAll(x => x.type == 2).Where((x, i) => gpgpmembers.FindAll(x => x.type == 2).FindIndex(n => n.id.Equals(x.id) && n.code.Equals(x.code)) == i).ToList();
  1026. if (tmdids.IsNotEmpty())
  1027. {
  1028. rmembers.AddRange(tmdids);
  1029. }
  1030. if (students.IsNotEmpty())
  1031. {
  1032. rmembers.AddRange(students);
  1033. }
  1034. groupLists.ForEach(x => {
  1035. if (string.IsNullOrWhiteSpace(x.periodId)) {
  1036. var meb = x.members.Where(z => !string.IsNullOrWhiteSpace(z.periodId)).FirstOrDefault();
  1037. if (meb!= null)
  1038. {
  1039. x.periodId=meb?.periodId;
  1040. }
  1041. }
  1042. });
  1043. return (rmembers, groupLists);
  1044. }
  1045. else
  1046. {
  1047. groupLists.ForEach(x => {
  1048. if (string.IsNullOrWhiteSpace(x.periodId))
  1049. {
  1050. var meb = x.members.Where(z => !string.IsNullOrWhiteSpace(z.periodId)).FirstOrDefault();
  1051. if (meb!= null)
  1052. {
  1053. x.periodId=meb?.periodId;
  1054. }
  1055. }
  1056. });
  1057. return (members, groupLists);
  1058. }
  1059. }
  1060. /// <summary>
  1061. /// 根据名单类型获取名单及成员信息。
  1062. /// </summary>
  1063. /// <param name="_coreAPIHttpService"></param>
  1064. /// <param name="client"></param>
  1065. /// <param name="type"></param>
  1066. /// <param name="scopes"></param>
  1067. /// <param name="school"></param>
  1068. /// <param name="_dingDing"></param>
  1069. /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
  1070. /// <returns></returns>
  1071. public static async Task<List<GroupListDto>> GetGroupListByType(CosmosClient client, string type, School school, Models.Period period, int graduate = -1)
  1072. {
  1073. List<GroupListDto> classes = new List<GroupListDto>();
  1074. List<int> grd = new List<int> ();
  1075. int index = 0;
  1076. period.grades.ForEach(z => { grd.Add(index); index+=1; });
  1077. var yearsdata = SchoolService.GetYears(school, period.id, grd);
  1078. List<int> years = yearsdata.years.ToList();
  1079. if (years.IsNotEmpty()) {
  1080. StringBuilder sql = new StringBuilder($"select c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.teacher.id as leader ,c.graduate from c where c.year in ({string.Join(",", years)}) and c.periodId='{period.id}' ");
  1081. if (graduate!=-1) {
  1082. sql.Append($" and c.graduate={graduate} ");
  1083. }
  1084. var result = await client.GetContainer(Constant.TEAMModelOS, Constant.School).GetList<RGroupList>(sql.ToString(), $"Class-{school.id}");
  1085. foreach (var item in result.list)
  1086. {
  1087. GroupListDto group = new GroupListDto
  1088. {
  1089. id = item.id,
  1090. code = $"GroupList-{school.id}",
  1091. name = item.name,
  1092. periodId = item.periodId,
  1093. scope = "school",
  1094. school = school.id,
  1095. type = "class",
  1096. expire= item.expire,
  1097. year = item.year,
  1098. no = item.no,
  1099. leader = item.leader,
  1100. pk = "GroupList",
  1101. graduate = item.graduate,
  1102. grades= new HashSet<int> { item.year }
  1103. };
  1104. classes.Add(group);
  1105. }
  1106. }
  1107. return classes;
  1108. }
  1109. /// <summary>
  1110. /// 根据名单类型获取名单及成员信息。
  1111. /// </summary>
  1112. /// <param name="_coreAPIHttpService"></param>
  1113. /// <param name="client"></param>
  1114. /// <param name="type"></param>
  1115. /// <param name="scopes"></param>
  1116. /// <param name="school"></param>
  1117. /// <param name="_dingDing"></param>
  1118. /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
  1119. /// <returns></returns>
  1120. public static async Task<List<RGroupList>> GetGroupListMemberByType(CoreAPIHttpService _coreAPIHttpService, CosmosClient client, string type, List<string> scopes, string school, DingDing _dingDing, int graduate = -1)
  1121. {
  1122. StringBuilder sql = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='{type}'");
  1123. Dictionary<string, List<RGroupList>> groups = new Dictionary<string, List<RGroupList>>();
  1124. if (scopes.Contains("school"))
  1125. {
  1126. if (!string.IsNullOrEmpty(school))
  1127. {
  1128. List<RGroupList> groupLists = new List<RGroupList>();
  1129. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<RGroupList>(queryText: sql.ToString(),
  1130. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
  1131. {
  1132. groupLists.Add(item);
  1133. }
  1134. groups.Add("School", groupLists);
  1135. }
  1136. }
  1137. else if (scopes.Contains("private"))
  1138. {
  1139. List<RGroupList> groupLists = new List<RGroupList>();
  1140. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<RGroupList>(queryText: sql.ToString(),
  1141. requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList") }))
  1142. {
  1143. groupLists.Add(item);
  1144. //if (string.IsNullOrWhiteSpace(school))
  1145. //{
  1146. // groupLists.Add(item);
  1147. //}
  1148. //else
  1149. //{
  1150. // if (!string.IsNullOrWhiteSpace(item.school))
  1151. // {
  1152. // if (item.school.Equals(school))
  1153. // {
  1154. // groupLists.Add(item);
  1155. // }
  1156. // }
  1157. // else {
  1158. // groupLists.Add(item);
  1159. // }
  1160. //}
  1161. }
  1162. groups.Add("Teacher", groupLists);
  1163. }
  1164. foreach (var item in groups)
  1165. {
  1166. var list = item.Value.GroupBy(x => x.type).Select(y => new { key = y.Key, list = y.ToList() });
  1167. foreach (var group in list)
  1168. {
  1169. (List<RGroupList> rgroups, List<RMember> rmembers) = await GetGroupListMemberInfo(_coreAPIHttpService, client, group.key, group.list, item.Key, _dingDing, school,graduate);
  1170. }
  1171. }
  1172. var lists = groups.SelectMany(x => x.Value).ToList();
  1173. return lists;
  1174. }
  1175. /// <summary>
  1176. /// 根据名单类型,名单分组信息获取成员信息, rmembers是去重的信息,groups是名单及人员信息,同一个人可能在不同的名单内。
  1177. /// </summary>
  1178. /// <param name="_coreAPIHttpService"></param>
  1179. /// <param name="client"></param>
  1180. /// <param name="type"></param>
  1181. /// <param name="groups"></param>
  1182. /// <param name="groupTbname"></param>
  1183. /// <param name="_dingDing"></param>
  1184. /// <param name="school"></param>
  1185. /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
  1186. /// <returns></returns>
  1187. public static async Task<(List<RGroupList> groups, List<RMember> members)> GetGroupListMemberInfo(CoreAPIHttpService _coreAPIHttpService, CosmosClient client,
  1188. string type, List<RGroupList> groups, string groupTbname, DingDing _dingDing, string school, int graduate = -1)
  1189. {
  1190. try
  1191. {
  1192. HashSet<RGroupList> changes = new HashSet<RGroupList>();
  1193. var members = groups.SelectMany(y => y.members).ToList();
  1194. //去重
  1195. List<RMember> tmdids = members.FindAll(x => x.type == 1).Where((x, i) => members.FindAll(x => x.type == 1).FindIndex(n => n.id.Equals(x.id)) == i).ToList();
  1196. List<RMember> students = members.FindAll(x => x.type == 2).Where((x, i) => members.FindAll(x => x.type == 2).FindIndex(n => n.id.Equals(x.id) && n.code.Equals(x.code)) == i).ToList();
  1197. var stu = students.GroupBy(x => x.code).Select(y => new { key = y.Key, list = y.ToList() });
  1198. List<Student> studentsData = new List<Student>();
  1199. string periodId = "";
  1200. if (stu != null)
  1201. {
  1202. foreach (var item in stu)
  1203. {
  1204. var ids = item.list.Select(x => x.id).ToList();
  1205. if (ids.IsNotEmpty())
  1206. {
  1207. StringBuilder stuSql = new StringBuilder($"SELECT distinct c.name,c.id,c.code,c.picture,c.no,c.irs,c.classId ,c.graduate,c.year ,c.periodId FROM c ");
  1208. string insql = string.Join(",", ids.Select(x => $"'{x}'"));
  1209. stuSql.Append($"where c.id in ({insql})");
  1210. await foreach (var student in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: stuSql.ToString(),
  1211. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{item.key}") }))
  1212. {
  1213. periodId=student.periodId;
  1214. student.schoolId = item.key;
  1215. studentsData.Add(student);
  1216. }
  1217. }
  1218. }
  1219. var unexist_student = students.Select(x => (x.id, x.code)).Except(studentsData.Select(y => (y.id, y.schoolId)), new CompareIdCode()).ToList();
  1220. groups.ForEach(x =>
  1221. {
  1222. int item = x.members.RemoveAll(y => y.type == 2 && unexist_student.Exists(x => x.id.Equals(y.id) && x.Item2.Equals(y.code)));
  1223. if (item > 0)
  1224. {
  1225. changes.Add(x);
  1226. }
  1227. });
  1228. }
  1229. List<TmdUser> tmdsData = new List<TmdUser>();
  1230. if (tmdids.IsNotEmpty())
  1231. {
  1232. string memberTbname = "";
  1233. if ($"{type}".Equals("activity"))
  1234. {
  1235. var mbers = groups.SelectMany(x => x.members).Where(z => !string.IsNullOrEmpty(z.code));
  1236. var schoolTeachers = mbers.GroupBy(y => y.code).Select(m => new { key = m.Key, list = m.ToList() });
  1237. foreach (var schoolTeacher in schoolTeachers)
  1238. {
  1239. StringBuilder tmdidSql = new StringBuilder($"SELECT distinct c.name,c.id,c.picture FROM c ");
  1240. string insql = string.Join(",", schoolTeacher.list.Select(x => $"'{x.id}'"));
  1241. tmdidSql.Append($" where c.id in ({insql})");
  1242. await foreach (var tmd in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<TmdUser>(queryText: tmdidSql.ToString(),
  1243. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{schoolTeacher.key}") }))
  1244. {
  1245. tmdsData.Add(tmd);
  1246. }
  1247. }
  1248. var unexist_teachers = mbers.Select(x => (x.id, x.code)).Except(tmdsData.Select(y => (y.id, y.code)), new CompareIdCode()).ToList();
  1249. groups.ForEach(x =>
  1250. {
  1251. int item = x.members.RemoveAll(y => y.type == 2 && unexist_teachers.Exists(x => x.id.Equals(y.id) && x.Item2.Equals(y.code)));
  1252. if (item > 0)
  1253. {
  1254. changes.Add(x);
  1255. }
  1256. });
  1257. }
  1258. else
  1259. {
  1260. //处理研修名单,如果是学校老师的,则需要检查SchoolTeacher
  1261. //处理 学校教研组,学校管理人员,学校任课教师,学校研修名单。
  1262. if (!string.IsNullOrEmpty(school) && ($"{type}".Equals("yxtrain") || $"{type}".Equals("research") || $"{type}".Equals("manage") || $"{type}".Equals("subject")))
  1263. {
  1264. StringBuilder tmdidSql = new StringBuilder($"SELECT distinct c.name,c.id,c.picture FROM c ");
  1265. string insql = string.Join(",", tmdids.Select(x => $"'{x.id}'"));
  1266. tmdidSql.Append($" where c.id in ({insql})");
  1267. await foreach (var tmd in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<TmdUser>(queryText: tmdidSql.ToString(),
  1268. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school}") }))
  1269. {
  1270. tmdsData.Add(tmd);
  1271. }
  1272. }
  1273. else
  1274. {
  1275. {
  1276. StringBuilder tmdidSql = new StringBuilder($"SELECT distinct c.name,c.id,c.picture FROM c ");
  1277. string insql = string.Join(",", tmdids.Select(x => $"'{x.id}'"));
  1278. tmdidSql.Append($" where c.id in ({insql})");
  1279. memberTbname = "Teacher";
  1280. await foreach (var tmd in client.GetContainer(Constant.TEAMModelOS, memberTbname).GetItemQueryIterator<TmdUser>(queryText: tmdidSql.ToString(),
  1281. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  1282. {
  1283. tmdsData.Add(tmd);
  1284. }
  1285. }
  1286. {
  1287. //取差集,减少二次搜寻
  1288. var tmdidexp = tmdids.Select(x => x.id).Except(tmdsData.Select(y => y.id)).ToList();
  1289. if (tmdidexp.IsNotEmpty())
  1290. {
  1291. StringBuilder tmdidSql = new StringBuilder($"SELECT distinct c.name,c.id,c.picture FROM c ");
  1292. string insql = string.Join(",", tmdidexp.Select(x => $"'{x}'"));
  1293. tmdidSql.Append($" where c.id in ({insql})");
  1294. memberTbname = "Student";
  1295. await foreach (var tmd in client.GetContainer(Constant.TEAMModelOS, memberTbname).GetItemQueryIterator<TmdUser>(queryText: tmdidSql.ToString(),
  1296. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  1297. {
  1298. tmdsData.Add(tmd);
  1299. }
  1300. }
  1301. }
  1302. }
  1303. tmdsData = tmdsData.Where((x, i) => tmdsData.FindIndex(n => n.id.Equals(x.id)) == i).ToList();
  1304. var unexist_tmdid = tmdids.Select(x => x.id).Except(tmdsData.Select(y => y.id)).ToList();
  1305. groups.ForEach(x =>
  1306. {
  1307. int item = x.members.RemoveAll(y => unexist_tmdid.Contains(y.id) && y.type == 1);
  1308. if (item > 0)
  1309. {
  1310. changes.Add(x);
  1311. }
  1312. });
  1313. }
  1314. }
  1315. if (tmdids.IsNotEmpty() && _coreAPIHttpService.check) {
  1316. ///获取真实的名称 ,大于50则不处理
  1317. if (tmdids.Count < 60)
  1318. {
  1319. var content = new StringContent(tmdids.Select(x => x.id).ToHashSet().ToJsonString(), Encoding.UTF8, "application/json");
  1320. string json = null;
  1321. try
  1322. {
  1323. json = await _coreAPIHttpService.GetUserInfos(content);
  1324. if (!string.IsNullOrWhiteSpace(json))
  1325. {
  1326. List<TmdInfo> tmdInfos = json.ToObject<List<TmdInfo>>();
  1327. if (tmdInfos.IsNotEmpty())
  1328. {
  1329. tmdsData.ForEach(y =>
  1330. {
  1331. var tmd = tmdInfos.Find(x => x.id.Equals(y.id));
  1332. if (tmd != null)
  1333. {
  1334. y.name = tmd?.name;
  1335. y.picture = tmd?.picture;
  1336. }
  1337. else
  1338. {
  1339. groups.ForEach(x =>
  1340. {
  1341. int item = x.members.RemoveAll(z => z.id.Equals(y.id) && z.type == 1);
  1342. if (item > 0)
  1343. {
  1344. changes.Add(x);
  1345. }
  1346. });
  1347. }
  1348. });
  1349. }
  1350. }
  1351. }
  1352. catch (Exception ex)
  1353. {
  1354. await _dingDing.SendBotMsg($"{_coreAPIHttpService.options.location}用户转换失败:{_coreAPIHttpService.options.coreUrl}{json}\n {ex.Message}\n{ex.StackTrace}{tmdids.Select(x => x.id).ToJsonString()}", GroupNames.醍摩豆服務運維群組);
  1355. }
  1356. }
  1357. }
  1358. tmdids.ForEach(x =>
  1359. {
  1360. var user = tmdsData.Find(y => y.id.Equals(x.id));
  1361. x.name = user?.name;
  1362. // x.nickname = string.IsNullOrWhiteSpace(x.nickname) ? user?.name : x.nickname;
  1363. x.picture = user?.picture;
  1364. });
  1365. students.ForEach(x =>
  1366. {
  1367. var student = studentsData.Find(y => y.id.Equals(x.id) && y.schoolId.Equals(x.code));
  1368. if (student != null)
  1369. {
  1370. x.name = student?.name;
  1371. // x.nickname = string.IsNullOrWhiteSpace(x.nickname) ? student?.name:x.nickname;
  1372. x.picture = student?.picture;
  1373. x.classId = student?.classId;
  1374. x.graduate = student.graduate;
  1375. x.year = student.year;
  1376. x.gender= student.gender;
  1377. x.periodId = student.periodId;
  1378. }
  1379. });
  1380. var mbs = tmdids;
  1381. mbs.AddRange(students);
  1382. if (changes.Count > 0 && !string.IsNullOrEmpty(groupTbname))
  1383. {
  1384. foreach (var change in changes)
  1385. {
  1386. change.tcount = change.members.Where(x => x.type == 1).Count();
  1387. change.scount = change.members.Where(x => x.type == 2).Count();
  1388. GroupList group = change.ToJsonString().ToObject<GroupList>();
  1389. await client.GetContainer(Constant.TEAMModelOS, groupTbname).ReplaceItemAsync(group, group.id, new PartitionKey(group.code));
  1390. }
  1391. }
  1392. groups.ForEach(x =>
  1393. {
  1394. x.members.ForEach(y =>
  1395. {
  1396. if (y.type == 1)
  1397. {
  1398. var tmd = tmdids.Find(t => t.id.Equals(y.id));
  1399. y.name = tmd?.name;
  1400. //y.nickname = string.IsNullOrWhiteSpace(y.nickname) ? tmd?.nickname : y.nickname;
  1401. y.picture = tmd?.picture;
  1402. }
  1403. if (y.type == 2)
  1404. {
  1405. var student = students.Find(t => t.id.Equals(y.id) && t.code.Equals(y.code));
  1406. if (student != null)
  1407. {
  1408. y.name = student?.name;
  1409. // y.nickname = string.IsNullOrWhiteSpace(y.nickname) ? student?.nickname : y.nickname;
  1410. y.picture = student?.picture;
  1411. y.classId = student?.classId;
  1412. y.graduate = student.graduate;
  1413. y.gender = student.gender;
  1414. y.year = student.year;
  1415. x.periodId = student.periodId;
  1416. x.grades.Add(student.year);
  1417. }
  1418. }
  1419. });
  1420. if (!x.type.Equals("class")) {
  1421. var yearc = x.members.Where(z => z.type == 2).GroupBy(g => g.year).Select(k => new { key = k.Key, count = k.Count() }).OrderByDescending(z => z.count);
  1422. if (yearc.Any())
  1423. {
  1424. //有一半的人是同一个班的,则以
  1425. if (yearc.First().count * 1.0 / x.members.Count > 0.51)
  1426. {
  1427. x.year = yearc.First().key;
  1428. }
  1429. }
  1430. }
  1431. if (!x.scope.Equals("private")) {
  1432. x.periodId=periodId;
  1433. }
  1434. });
  1435. HashSet<string> schoolCodes = groups.SelectMany(x => x.members).Where(y => !string.IsNullOrEmpty(y.code)).Select(z => z.code).ToHashSet();
  1436. if (schoolCodes != null && schoolCodes.Count > 0)
  1437. {
  1438. List<School> schools = new List<School>();
  1439. string insql = $"select c.name,c.id from c where c.id in ({string.Join(",", schoolCodes.Select(x => $"'{x}'"))})";
  1440. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: insql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  1441. {
  1442. schools.Add(item);
  1443. }
  1444. if (schools.IsNotEmpty())
  1445. {
  1446. groups.SelectMany(x => x.members).Where(y => !string.IsNullOrEmpty(y.code)).ToList().ForEach(z => {
  1447. var school = schools.Find(j => j.id.Equals(z.code));
  1448. z.schoolName = school?.name;
  1449. });
  1450. }
  1451. }
  1452. if (graduate >= 0)
  1453. {
  1454. groups= groups.FindAll(x => x.graduate == graduate);
  1455. if (groups != null) {
  1456. groups.ForEach(x =>
  1457. {
  1458. x.members.RemoveAll(y => y.graduate != graduate);
  1459. });
  1460. }
  1461. mbs.RemoveAll(z => z.graduate != graduate);
  1462. return (groups, mbs);
  1463. }
  1464. //直接返回
  1465. else {
  1466. return (groups, mbs);
  1467. }
  1468. }
  1469. catch (Exception ex)
  1470. {
  1471. await _dingDing.SendBotMsg($"{_coreAPIHttpService.options.location},GetGroupListMemberInfo()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1472. }
  1473. return (null, null);
  1474. }
  1475. /// <summary>
  1476. /// 处理活动结束的
  1477. /// </summary>
  1478. /// <param name="_coreAPIHttpService"></param>
  1479. /// <param name="cosmosClient">数据库</param>
  1480. /// <param name="_dingDing">钉钉消息</param>
  1481. /// <param name="school">学校编码</param>
  1482. /// <param name="classes">行政班</param>
  1483. /// <param name="stuLists">学生</param>
  1484. /// <param name="tchLists">教师</param>
  1485. /// <param name="_groupLists">分组</param>
  1486. /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
  1487. /// <returns></returns>
  1488. public static async Task<List<FMember>> GetFinishMemberInfo(CoreAPIHttpService _coreAPIHttpService, CosmosClient cosmosClient, DingDing _dingDing, string school, List<string> classes, List<string> stuLists, List<string> tchLists, List<(string, List<string>)> _groupLists = null, int graduate = -1)
  1489. {
  1490. List<FMember> fMembers = new();
  1491. if (classes != null && classes.Count > 0)
  1492. {
  1493. (List<RMember> staffList, List<RGroupList> classInfos) = await GetMemberByListids(_coreAPIHttpService, cosmosClient, _dingDing, classes, school);
  1494. staffList.ForEach(x => fMembers.Add(new FMember() { id = x.id, code = school, type = 1, }));
  1495. }
  1496. if (stuLists != null && stuLists.Count > 0)
  1497. {
  1498. (List<RMember> staffList, List<RGroupList> classInfos) = await GetMemberByListids(_coreAPIHttpService, cosmosClient, _dingDing, stuLists, school);
  1499. staffList.ForEach(x => fMembers.Add(new FMember() { id = x.id, code = school, type = 2 }));
  1500. }
  1501. /* if (tchLists != null && tchLists.Count > 0)
  1502. {
  1503. (List<RMember> staffList, List<RGroupList> classInfos) = await GetMemberByListids(_coreAPIHttpService, cosmosClient, _dingDing, tchLists, school);
  1504. staffList.ForEach(x => fMembers.Add(new FMember() { id = x.id, code = school, type = 2 }));
  1505. }*/
  1506. if (tchLists != null && tchLists.Count > 0)
  1507. {
  1508. (List<RMember> staffList, List<RGroupList> groupLists1) = await GetMemberByListids(_coreAPIHttpService, cosmosClient, _dingDing, tchLists, school, _groupLists);
  1509. staffList.ForEach(x => fMembers.Add(new FMember() { id = x.id, code = school, type = 2 }));
  1510. }
  1511. return fMembers;
  1512. }
  1513. }
  1514. public class CompareIdCode : IEqualityComparer<(string id, string code)>
  1515. {
  1516. public bool Equals((string id, string code) x, (string id, string code) y)
  1517. {
  1518. return x.id.Equals(y.id) && x.code.Equals(y.code);
  1519. }
  1520. public int GetHashCode((string id, string code) obj)
  1521. {
  1522. if (obj.id != null && obj.code != null)
  1523. {
  1524. return 1;
  1525. }
  1526. else
  1527. {
  1528. return 0;
  1529. }
  1530. }
  1531. }
  1532. }