GroupListService.cs 110 KB

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