CrazyIter_Bin 3 年之前
父节点
当前提交
61e6f768ba
共有 1 个文件被更改,包括 106 次插入0 次删除
  1. 106 0
      TEAMModelOS.SDK/Models/Service/GroupListService.cs

+ 106 - 0
TEAMModelOS.SDK/Models/Service/GroupListService.cs

@@ -21,6 +21,112 @@ namespace TEAMModelOS.SDK
 {
     public class GroupListService
     {
+
+        /// <summary>
+        /// 查询名单成员所在的名单列表,
+        /// </summary>
+        /// <param name="_coreAPIHttpService"></param>
+        /// <param name="client"></param>
+        /// <param name="_dingDing"></param>
+        /// <param name="memberId">成员id </param>
+        /// <param name="memberType">成员类型</param>
+        /// <param name="school">成员所在的学校 ,可为空</param>
+        /// <param name="groupTypes">过滤名单的类型集合,不传则是全部</param>
+        /// <returns></returns>
+        public static async Task<List<GroupListGrp>> GetMemberInGroupList(CoreAPIHttpService _coreAPIHttpService, CosmosClient client, DingDing _dingDing, string memberId, int memberType, string school,List<string> groupTypes) {
+
+            List<GroupListGrp> groupLists = new List<GroupListGrp>();
+
+            if (groupTypes.IsEmpty() || groupTypes.Contains("class")) {
+                if (string.IsNullOrWhiteSpace(school) && memberType == 2)
+                {
+                    Student student = null;
+                    try
+                    {
+                        student = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemAsync<Student>(memberId, new PartitionKey($"Base-{school}"));
+                    }
+                    catch (CosmosException ex) when (ex.Status == 404)
+                    {
+                        return null;
+                    }
+                    if (!string.IsNullOrWhiteSpace(student.classId))
+                    {
+                        try
+                        {
+                            Class clazz = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<Class>(memberId, new PartitionKey($"Class-{school}"));
+                            GroupListGrp groupList = new GroupListGrp
+                            {
+                                id = clazz.id,
+                                code = $"GroupList-{clazz.school}",
+                                name = clazz.name,
+                                periodId = clazz.periodId,
+                                pk = "GroupList",
+                                year = clazz.year,
+                                school = clazz.school,
+                                scope = "school",
+                                type = "class",
+                                no = clazz.no,
+                                leader = clazz.teacher?.id,
+                            };
+                            groupLists.Add(groupList);
+                        }
+                        catch (CosmosException ex) when (ex.Status == 404)
+                        {
+                        }
+                    }
+                }
+            }
+            if (groupTypes.IsEmpty() || groupTypes.Contains("teach")) {
+                //教学班
+                StringBuilder teachsql = new StringBuilder();
+                if (string.IsNullOrWhiteSpace(school) && memberType == 2) {
+                    teachsql.Append($"SELECT distinct value(c) FROM c join  m  in c.members   where c.type='teach' and  m.id={memberId} and m.school={school} and m.type=2 ");
+                }
+                if (memberType == 1)
+                {
+                    teachsql.Append($"SELECT distinct value(c) FROM c join  m  in c.members   where c.type='teach' and  m.id={memberId}and m.type=1 ");
+                }
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
+                    GetItemQueryIterator<GroupList>(queryText: teachsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
+                {
+                    HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
+                    groupLists.Add(new GroupListGrp(item, groupName));
+                }
+                //个人名单
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).
+                    GetItemQueryIterator<GroupList>(queryText: teachsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList") }))
+                {
+                    HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
+                    groupLists.Add(new GroupListGrp(item, groupName));
+                }
+            }
+            if (!string.IsNullOrWhiteSpace(school) && (groupTypes.IsEmpty() || groupTypes.Contains("research")))
+            {
+                //教研组
+                StringBuilder teachsql = new StringBuilder();
+                teachsql.Append($"SELECT distinct value(c) FROM c join  m  in c.members   where c.type='research' and  m.id={memberId}and m.type=1 ");
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
+                    GetItemQueryIterator<GroupList>(queryText: teachsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
+                {
+                    HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
+                    groupLists.Add(new GroupListGrp(item, groupName));
+                }
+            }
+            if (!string.IsNullOrWhiteSpace(school) && (groupTypes.IsEmpty() || groupTypes.Contains("yxtrain")))
+            {
+                //研修名单
+                StringBuilder teachsql = new StringBuilder();
+                teachsql.Append($"SELECT distinct value(c) FROM c join  m  in c.members   where c.type='yxtrain' and  m.id={memberId}and m.type=1 ");
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
+                    GetItemQueryIterator<GroupList>(queryText: teachsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
+                {
+                    HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
+                    groupLists.Add(new GroupListGrp(item, groupName));
+                }
+            }
+            return groupLists;      
+        }
+
         public static async Task<(int status, GroupList stuList)> CodeJoinList(CosmosClient client, string _stuListNo, string userid, int type, string school)
         {
             var queryNo = $"SELECT  value(c)  FROM c where  c.no ='{_stuListNo}'";