GroupListService.cs 110 KB

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