GroupListService.cs 109 KB

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