GroupListService.cs 108 KB

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