CrazyIter_Bin 1 年之前
父節點
當前提交
3fa5813fa6

+ 1 - 3
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -534,9 +534,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                     var data = await  GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, new List<string> { groupChange.listid }, groupChange.school);
                     if (data.groups.IsNotEmpty()) {
                         School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(groupChange.school, new PartitionKey("Base"));
-                        
-                        //
-                       var period = school.period.Find(z => z.id.Equals(data.groups.First().periodId));
+                        var period = school.period.Find(z => z.id.Equals(data.groups.First().periodId));
                         if (period != null)
                         {
                             var dataSemester =  SchoolService.GetSemester(period,DateTimeOffset.Now.ToUnixTimeMilliseconds());

+ 426 - 223
TEAMModelOS.SDK/Models/Service/GroupListService.cs

@@ -4,7 +4,6 @@ using System.Collections.Generic;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
-using TEAMModelOS.SDK.Models.Cosmos.Common;
 using HTEXLib.COMM.Helpers;
 using System.Linq;
 using System.Text;
@@ -12,13 +11,12 @@ using System.Text.Json;
 using TEAMModelOS.Models;
 using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
-using TEAMModelOS.SDK.Models.Service;
 using System.Text.RegularExpressions;
 using TEAMModelOS.SDK.Models;
 using System.Net.Http;
-using DocumentFormat.OpenXml.Wordprocessing;
-using static TEAMModelOS.SDK.GroupListService;
 using DocumentFormat.OpenXml.Drawing.Charts;
+using System.Reflection;
+
 
 namespace TEAMModelOS.SDK
 {
@@ -76,8 +74,8 @@ namespace TEAMModelOS.SDK
         /// <param name="groupTypes">过滤名单的类型集合,不传则是全部</param>
         /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</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,int graduate =-1) {
-
+        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) 
+        {
             List<GroupListGrp> groupLists = new List<GroupListGrp>();
             if (groupTypes.IsEmpty() || groupTypes.Contains("class")) {
                 if (!string.IsNullOrWhiteSpace(school) && memberType == 2)
@@ -93,6 +91,8 @@ namespace TEAMModelOS.SDK
                     }
                     if (!string.IsNullOrWhiteSpace(student.classId))
                     {
+                       
+
                         try
                         {
                             Class clazz = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<Class>(student.classId, new PartitionKey($"Class-{school}"));
@@ -180,6 +180,53 @@ namespace TEAMModelOS.SDK
                     groupLists.Add(new GroupListGrp(item, groupName));
                 }
             }
+            List<GroupListSemester> groupListSemesters = new List<GroupListSemester>();
+            List<RMember> rmembers = new List<RMember>();
+            List<RGroupList> rgroupList = new List<RGroupList>();
+            List<GroupListDto> groupListDtos = new List<GroupListDto>();
+            if (!string.IsNullOrWhiteSpace(school)  && time>0  && groupLists.IsNotEmpty())
+            {
+                School schoolBase = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
+                foreach (var period in schoolBase.period)
+                {
+                    var dataSemester = SchoolService.GetSemester(period,time);
+                    //string id = $"{dataSemester.studyYear}-{dataSemester.currSemester.id}-{student.classId}";
+                    string code = $"GroupListSemester-{school}";
+                    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}'"))}) ";
+                    var result = await client.GetContainer(Constant.TEAMModelOS, Constant.School).GetList<GroupListSemester>(sql, code);
+                    if (result.list.IsNotEmpty())
+                    {
+                        foreach (var x in result.list) {
+                            HashSet<string> groupName = x.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
+                            groupLists.Add(new GroupListGrp {
+                                id = x.id,
+                                code = x.code,
+                                periodId = x.periodId,
+                                pk = x.pk,
+                                name = x.name,
+                                school = x.school,
+                                creatorId = x.creatorId,
+                                no = x.no,
+                                scope = x.scope,
+                                type = x.type,
+                                scount = x.scount,
+                                tcount = x.tcount,
+                                leader = x.leader,
+                                year = x.year,
+                                expire = x.expire,
+                                groupName = groupName,
+                                froms = x.froms,
+                                joinLock = x.joinLock,
+                                qrcodeExpire = x.qrcodeExpire,
+                                qrcodeDays = x.qrcodeDays,
+                                review=x.review,
+                                limitCount = x.limitCount,
+                                grades = x.grades,
+                            });
+                        }
+                    }
+                }
+            }
             return groupLists;      
         }
 
@@ -242,7 +289,6 @@ namespace TEAMModelOS.SDK
                             groupName= item.name,
                             applyTime=now
                         };
-                        string sql = "select value c from c join b in c.schedules where b.groupId='60f92012-72cf-4d5c-a66a-552678303fad'"; 
                         string key = $"GroupList:GroupWaitingList:{item.scope}:{item.id}";
                         string filed = !string.IsNullOrWhiteSpace(school) ? $"{school}_{userid}" : userid;
                         await _azureRedis.GetRedisClient(8).HashSetAsync(key, filed, waitingList.ToJsonString());
@@ -623,9 +669,9 @@ namespace TEAMModelOS.SDK
         /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
         /// <returns></returns>
         public static async Task<List<GroupListDto>> GetGroupListByListids(CosmosClient client, DingDing _dingDing, List<string> classes, string school,
-            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.expire ,c.qrcodeExpire,c.qrcodeDays  ,c.grades ", int graduate = -1)
+            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.expire ,c.qrcodeExpire,c.qrcodeDays  ,c.grades ", int graduate = -1,long time=-1)
         {
-            List<GroupListDto> groupLists = null;
+            List<GroupListDto> groupLists = new List<GroupListDto>();
             try
             {
                 classes.RemoveAll(x => x == null);
@@ -652,74 +698,81 @@ namespace TEAMModelOS.SDK
                 else
                 {
                     Dictionary<string, List<GroupListDto>> groups = new Dictionary<string, List<GroupListDto>>();
-                    //List<Student> students = new List<Student>();
-                    string sql = string.Join(",", classes.Select(x => $"'{x}'"));
-                    if (!string.IsNullOrEmpty(school))
+                    var semesterGroupList = await GetGroupListSemester(client, classes, school, type: null, periodId: null, no: null, time);
+                    groupLists.AddRange(semesterGroupList.groupListDtos);
+                    classes = classes.Except(semesterGroupList.rgroupList.Select(y => y.id)).ToList();
+                    if (classes.IsNotEmpty())
                     {
-                        List<GroupListDto> schoolList = new List<GroupListDto>();
-
-                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupListDto>(queryText: $"select {SummarySql} from c where c.id in ({sql})",
-                                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
-                        {
-                            schoolList.Add(item);
-                        }
-                        if (schoolList.IsNotEmpty())
-                        {
-                            groups.Add("School", schoolList);
-                        }
-                        //取差集,减少二次搜寻
-                        classes = classes.Except(schoolList.Select(y => y.id)).ToList();
-                        if (classes.IsNotEmpty())
+                      
+                        //List<Student> students = new List<Student>();
+                        string sql = string.Join(",", classes.Select(x => $"'{x}'"));
+                        if (!string.IsNullOrEmpty(school))
                         {
-                            if (!groupLists.IsNotEmpty())
+                            List<GroupListDto> schoolList = new List<GroupListDto>();
+
+                            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupListDto>(queryText: $"select {SummarySql} from c where c.id in ({sql})",
+                                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
                             {
-                                groupLists = new List<GroupListDto>();
+                                schoolList.Add(item);
                             }
-                            string insql = string.Join(",", classes.Select(x => $"'{x}'"));
-                            //搜寻没有关联学生的行政班
-                            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupListDto>(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})",
-                                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
+                            if (schoolList.IsNotEmpty())
                             {
-                                ///行政班(学生搜寻classId动态返回)class
-                                GroupListDto group = new GroupListDto
-                                {
-                                    id = item.id,
-                                    code = $"GroupList-{school}",
-                                    name = item.name,
-                                    periodId = item.periodId,
-                                    scope = "school",
-                                    school = school,
-                                    type = "class",
-                                    year = item.year,
-                                    expire = item.expire,
-                                    leader = item.leader,
-                                    no = item.no,
-                                    pk = "GroupList",
-                                    graduate = item.graduate,
-                                    grades= new HashSet<int> { item.year }
-                                };
-                                //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
-                                if (graduate >= 0)
+                                groups.Add("School", schoolList);
+                            }
+                            //取差集,减少二次搜寻
+                            classes = classes.Except(schoolList.Select(y => y.id)).ToList();
+                            if (classes.IsNotEmpty())
+                            {
+                                string insql = string.Join(",", classes.Select(x => $"'{x}'"));
+                                //搜寻没有关联学生的行政班
+                                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupListDto>(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})",
+                                        requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
                                 {
-                                    if (group.graduate == graduate)
+                                    ///行政班(学生搜寻classId动态返回)class
+                                    GroupListDto group = new GroupListDto
+                                    {
+                                        id = item.id,
+                                        code = $"GroupList-{school}",
+                                        name = item.name,
+                                        periodId = item.periodId,
+                                        scope = "school",
+                                        school = school,
+                                        type = "class",
+                                        year = item.year,
+                                        expire = item.expire,
+                                        leader = item.leader,
+                                        no = item.no,
+                                        pk = "GroupList",
+                                        graduate = item.graduate,
+                                        grades= new HashSet<int> { item.year }
+                                    };
+                                    //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
+                                    if (graduate >= 0)
+                                    {
+                                        if (group.graduate == graduate)
+                                        {
+                                            groupLists.Add(group);
+                                        }
+                                    }
+                                    //全部。
+                                    else
                                     {
                                         groupLists.Add(group);
                                     }
+                                    //  groupLists.Add(group);
                                 }
-                                //全部。
-                                else
-                                {
-                                    groupLists.Add(group);
-                                }
-                                //  groupLists.Add(group);
+                                //取差集,减少二次搜寻
+                                classes = classes.Except(groupLists.Select(y => y.id)).ToList();
                             }
-                            //取差集,减少二次搜寻
-                            classes = classes.Except(groupLists.Select(y => y.id)).ToList();
                         }
                     }
+
+
+                    
                     if (classes.IsNotEmpty())
                     {
+                        string sql = string.Join(",", classes.Select(x => $"'{x}'"));
                         List<GroupListDto> privateList = new List<GroupListDto>();
                         sql = string.Join(",", classes.Select(x => $"'{x}'"));
                         await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<GroupListDto>(queryText: $"select {SummarySql} from c where c.id in ({sql})",
@@ -762,13 +815,106 @@ namespace TEAMModelOS.SDK
                             groupLists = groups.SelectMany(x => x.Value).ToList();
                         }
                     }
-
                 }
             } catch (Exception ex ) {
                 await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
             }
             return groupLists;
         }
+        public static async Task<(List<GroupListSemester> groupListSemesters, List<RMember> rmembers, List<RGroupList> rgroupList, List<GroupListDto> groupListDtos)> 
+            GetGroupListSemester(CosmosClient client, List<string> classes, string school,string type,string periodId,string  no , long time =-1) {
+            List<GroupListSemester> groupListSemesters = new List<GroupListSemester>();
+            List<RMember> rmembers = new List<RMember>();
+            List<RGroupList> rgroupList = new List<RGroupList>();
+            List<GroupListDto> groupListDtos = new List<GroupListDto>();
+            if (!string.IsNullOrWhiteSpace(school) && classes.IsNotEmpty() && time>0) {
+                School schoolBase = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
+                foreach (var period in schoolBase.period) {
+                    var dataSemester = SchoolService.GetSemester(period, time);
+                    //string id = $"{dataSemester.studyYear}-{dataSemester.currSemester.id}-{student.classId}";
+                    string code = $"GroupListSemester-{school}";
+                    StringBuilder sql =new StringBuilder($"select value c from c  where c.studyYear={dataSemester.studyYear} and c.semesterId='{dataSemester.currSemester.id}' ");
+                    if (classes.IsNotEmpty())
+                    {
+                        sql.Append($" and c.groupListId  in({string.Join(",", classes.Select(c => $"'{c}'"))})");
+                    }
+                    if (!string.IsNullOrWhiteSpace(type)) {
+                        sql.Append($" and c.type ='{type}'");
+                    }
+                    if (!string.IsNullOrWhiteSpace(periodId))
+                    {
+                        sql.Append($" and c.periodId ='{periodId}'");
+                    }
+                    if (!string.IsNullOrWhiteSpace(no))
+                    {
+                        sql.Append($" and c.no ='{no}'");
+                    }
+                    var result = await client.GetContainer(Constant.TEAMModelOS, Constant.School).GetList<GroupListSemester>(sql.ToString(), code);
+                    if (result.list.IsNotEmpty()) {
+                        groupListSemesters.AddRange(result.list);
+                    }
+                }
+                if (groupListSemesters.IsNotEmpty()) {
+                    rmembers.AddRange(groupListSemesters.SelectMany(x => x.members));
+                    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();
+                    rgroupList.AddRange(groupListSemesters.Select(z => new RGroupList
+                    {
+                        id = z.groupListId,
+                        code= $"GroupList-{school}",
+                        pk="GroupList",
+                        name=z.name,
+                        no=z.no,
+                        periodId=z.periodId,
+                        school=z.school,
+                        scope=z.scope,
+                        creatorId=z.creatorId,
+                        type=z.type,
+                        year=z.year,
+                        expire=z.expire,
+                        tcount=z.tcount,
+                        scount=z.scount,
+                        members=z.members,
+                        leader=z.leader,
+                        froms=z.froms,
+                        joinLock=z.joinLock,
+                        graduate=z.graduate,
+                        review=z.review,
+                        limitCount=z.limitCount,
+                        qrcodeDays=z.qrcodeDays,
+                        qrcodeExpire=z.qrcodeExpire,
+                        grades  =z.grades,
+                    }));
+                    groupListDtos.AddRange(groupListSemesters.Select(z => new GroupListDto
+                    {
+                        id = z.groupListId,
+                        code= $"GroupList-{school}",
+                        pk="GroupList",
+                        name=z.name,
+                        no=z.no,
+                        periodId=z.periodId,
+                        school=z.school,
+                        scope=z.scope,
+                        creatorId=z.creatorId,
+                        type=z.type,
+                        year=z.year,
+                        expire=z.expire,
+                        tcount=z.tcount,
+                        scount=z.scount,
+                        leader=z.leader,
+                        froms=z.froms,
+                        joinLock=z.joinLock,
+                        graduate=z.graduate,
+                        review=z.review,
+                        limitCount=z.limitCount,
+                        qrcodeDays=z.qrcodeDays,
+                        qrcodeExpire=z.qrcodeExpire,
+                        grades  =z.grades, 
+                    }));
+                }
+            }
+            return (groupListSemesters,rmembers, rgroupList,groupListDtos);
+        }
+
         /// <summary>
         ///  根据任意名单id获取成员信息。rmembers是去重的信息,groups是名单及人员信息,同一个人可能在不同的名单内。
         /// </summary>
@@ -781,7 +927,7 @@ namespace TEAMModelOS.SDK
         /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
         /// <returns></returns>
         public static async Task<(List<RMember>rmembers, List<RGroupList> groups)> GetMemberByListids(CoreAPIHttpService _coreAPIHttpService, CosmosClient client, DingDing _dingDing, 
-            List<string> classes, string school, List<(string, List<string>)> groupids = null,  int graduate = -1)
+            List<string> classes, string school, List<(string, List<string>)> groupids = null,  int graduate = -1,long  time =-1)
         {
             List<RMember> members = new List<RMember>();
             List<RGroupList> groupLists = new List<RGroupList>();
@@ -793,11 +939,14 @@ namespace TEAMModelOS.SDK
             {
                 return (members, groupLists);
             }
+
+
+
             string periodId = string.Empty;
             if (classes.Count == 1 && classes.First().Equals("TeacherAll") && !string.IsNullOrEmpty(school))
             {
                 //默认的教研组
-                members = new List<RMember>();
+               // members = new List<RMember>();
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
                     GetItemQueryIterator<TmdInfo>(queryText: $"SELECT  c.id,c.name,c.picture  FROM c ", 
                     requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school}") }))
@@ -827,58 +976,177 @@ namespace TEAMModelOS.SDK
             }
             else
             {
-                Dictionary<string, List<RGroupList>> groups = new Dictionary<string, List<RGroupList>>();
-                List<Student> students = new List<Student>();
-                string sql = string.Join(",", classes.Select(x => $"'{x}'"));
-                if (!string.IsNullOrEmpty(school))
-                {
-                    List<RGroupList> schoolList = new List<RGroupList>();
-                    string queryText = $"select value(c) from c where c.id in ({sql})";
-                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<RGroupList>(queryText: queryText,
-                            requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
-                    {
-                        schoolList.Add(item);
-                    }
-                    if (schoolList.IsNotEmpty())
-                    {
-                        groups.Add("School", schoolList);
-                    }
-                    //取差集,减少二次搜寻
-                    classes = classes.Except(schoolList.Select(y => y.id)).ToList();
-                    if (classes.IsNotEmpty())
+                var semesterGroupList = await GetGroupListSemester(client, classes, school,type:null,periodId:null ,no:null, time);
+                classes = classes.Except(semesterGroupList.rgroupList.Select(y => y.id)).ToList();
+                if (classes.IsNotEmpty()) {
+                    Dictionary<string, List<RGroupList>> groups = new Dictionary<string, List<RGroupList>>();
+                    List<Student> students = new List<Student>();
+                    string sql = string.Join(",", classes.Select(x => $"'{x}'"));
+                    if (!string.IsNullOrEmpty(school))
                     {
-                        sql = string.Join(",", classes.Select(x => $"'{x}'"));
-                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
-                            requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
+
+
+                        List<RGroupList> schoolList = new List<RGroupList>();
+                        string queryText = $"select value(c) from c where c.id in ({sql})";
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<RGroupList>(queryText: queryText,
+                                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
                         {
-                            //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
-                            if (graduate >= 0)
+                            schoolList.Add(item);
+                        }
+                        if (schoolList.IsNotEmpty())
+                        {
+                            groups.Add("School", schoolList);
+                        }
+                        //取差集,减少二次搜寻
+                        classes = classes.Except(schoolList.Select(y => y.id)).ToList();
+                        if (classes.IsNotEmpty())
+                        {
+                            sql = string.Join(",", classes.Select(x => $"'{x}'"));
+                            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
+                                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
                             {
-                                if (item.graduate == graduate)
+                                //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
+                                if (graduate >= 0)
+                                {
+                                    if (item.graduate == graduate)
+                                    {
+                                        students.Add(item);
+                                    }
+                                }
+                                //全部。
+                                else
                                 {
                                     students.Add(item);
                                 }
+                                //  students.Add(item);
                             }
-                            //全部。
-                            else  
+                            //取差集,减少二次搜寻
+                            classes = classes.Except(students.Select(y => y.classId)).ToList();
+                        }
+                        if (classes.IsNotEmpty())
+                        {
+                            string insql = string.Join(",", classes.Select(x => $"'{x}'"));
+                            //搜寻没有关联学生的行政班
+                            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School")
+                                .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})",
+                                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
                             {
-                                students.Add(item);
+                                ///行政班(学生搜寻classId动态返回)class
+                                List<RMember> smembers = new List<RMember>();
+                                RGroupList group = new RGroupList
+                                {
+                                    id = item.id,
+                                    code = $"GroupList-{school}",
+                                    name = item.name,
+                                    periodId = item.periodId,
+                                    scope = "school",
+                                    school = school,
+                                    type = "class",
+                                    year = item.year,
+                                    expire = item.expire,
+                                    members = smembers,
+                                    scount = smembers.Count,
+                                    pk = "GroupList",
+                                    leader = item.leader,
+                                    no = item.no,
+                                    graduate = item.graduate,
+                                    grades= new HashSet<int>() { item.year }
+                                };
+
+                                //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
+                                if (graduate >= 0)
+                                {
+                                    if (group.graduate == graduate)
+                                    {
+                                        groupLists.Add(group);
+                                    }
+                                }
+                                //全部。
+                                else
+                                {
+                                    groupLists.Add(group);
+                                }
+
+                                //groupLists.Add(group);
                             }
-                            //  students.Add(item);
+                            //取差集,减少二次搜寻
+                            classes = classes.Except(groupLists.Select(y => y.id)).ToList();
                         }
-                        //取差集,减少二次搜寻
-                        classes = classes.Except(students.Select(y => y.classId)).ToList();
+
                     }
                     if (classes.IsNotEmpty())
                     {
-                        string insql = string.Join(",", classes.Select(x => $"'{x}'"));
-                        //搜寻没有关联学生的行政班
-                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School")
-                            .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})",
-                                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
+                        List<RGroupList> privateList = new List<RGroupList>();
+                        sql = string.Join(",", classes.Select(x => $"'{x}'"));
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<RGroupList>(queryText: $"select value(c) from c where c.id in ({sql})",
+                               requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList") }))
+                        {
+                            privateList.Add(item);
+                            //if (string.IsNullOrWhiteSpace(school))
+                            //{
+                            //    privateList.Add(item);
+                            //}
+                            //else
+                            //{
+                            //    if (!string.IsNullOrWhiteSpace(item.school))
+                            //    {
+                            //        if (item.school.Equals(school))
+                            //        {
+                            //            privateList.Add(item);
+                            //        }
+                            //    }
+                            //    else
+                            //    {
+                            //        privateList.Add(item);
+                            //    }
+                            //}
+                        }
+                        if (privateList.IsNotEmpty())
+                        {
+                            groups.Add("Teacher", privateList);
+                        }
+                    }
+                    foreach (var item in groups)
+                    {
+                        var list = item.Value.GroupBy(x => x.type).Select(y => new { key = y.Key, list = y.ToList() });
+                        foreach (var group in list)
+                        {
+                            (List<RGroupList> rgroups, List<RMember> rmembers) = await GetGroupListMemberInfo(_coreAPIHttpService, client, group.key, group.list, item.Key, _dingDing, school, graduate);
+                            members.AddRange(rmembers);
+                        }
+                    }
+                    groupLists.AddRange(groups.SelectMany(x => x.Value).ToList());
+
+                    if (students.IsNotEmpty())
+                    {
+                        List<string> sqlList = students.Select(x => x.classId).ToList();
+                        string insql = string.Join(",", sqlList.Select(x => $"'{x}'"));
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
+                            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})",
+                                  requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
                         {
                             ///行政班(学生搜寻classId动态返回)class
-                            List<RMember> smembers = new List<RMember>();
+                            List<RMember> smembers = students.Where(x => x.classId.Equals(item.id))
+                                .Select(y => new RMember
+                                {
+                                    id = y.id,
+                                    code = school,
+                                    name = y.name,
+                                    //nickname = y.name,
+                                    type = 2,
+                                    picture = y.picture,
+                                    no = y.no,
+                                    classId = y.classId,
+                                    groupId = y.groupId,
+                                    groupName = y.groupName,
+                                    irs = y.irs,
+                                    year= y.year,
+                                    graduate = y.graduate,
+                                    gender= y.gender,
+                                    periodId=y.periodId,
+                                }).ToList();
+                            members.AddRange(smembers);
+
                             RGroupList group = new RGroupList
                             {
                                 id = item.id,
@@ -888,17 +1156,16 @@ namespace TEAMModelOS.SDK
                                 scope = "school",
                                 school = school,
                                 type = "class",
+                                expire= item.expire,
                                 year = item.year,
-                                expire = item.expire,
                                 members = smembers,
                                 scount = smembers.Count,
-                                pk = "GroupList",
-                                leader = item.leader,
                                 no = item.no,
+                                leader = item.leader,
+                                pk = "GroupList",
                                 graduate = item.graduate,
-                                grades= new HashSet<int>() { item.year }
+                                grades= new HashSet<int> { item.year }
                             };
-
                             //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
                             if (graduate >= 0)
                             {
@@ -908,128 +1175,17 @@ namespace TEAMModelOS.SDK
                                 }
                             }
                             //全部。
-                            else  
+                            else
                             {
                                 groupLists.Add(group);
                             }
-
-                            //groupLists.Add(group);
+                            // groupLists.Add(group);
                         }
-                        //取差集,减少二次搜寻
-                        classes = classes.Except(groupLists.Select(y => y.id)).ToList();
+                        //去重。
+                        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();
                     }
 
                 }
-                if (classes.IsNotEmpty())
-                {
-                    List<RGroupList> privateList = new List<RGroupList>();
-                    sql = string.Join(",", classes.Select(x => $"'{x}'"));
-                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<RGroupList>(queryText: $"select value(c) from c where c.id in ({sql})",
-                           requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList") }))
-                    {
-                        privateList.Add(item);
-                        //if (string.IsNullOrWhiteSpace(school))
-                        //{
-                        //    privateList.Add(item);
-                        //}
-                        //else
-                        //{
-                        //    if (!string.IsNullOrWhiteSpace(item.school))
-                        //    {
-                        //        if (item.school.Equals(school))
-                        //        {
-                        //            privateList.Add(item);
-                        //        }
-                        //    }
-                        //    else
-                        //    {
-                        //        privateList.Add(item);
-                        //    }
-                        //}
-                    }
-                    if (privateList.IsNotEmpty())
-                    {
-                        groups.Add("Teacher", privateList);
-                    }
-                }
-                foreach (var item in groups)
-                {
-                    var list = item.Value.GroupBy(x => x.type).Select(y => new { key = y.Key, list = y.ToList() });
-                    foreach (var group in list)
-                    {
-                        (List<RGroupList> rgroups, List<RMember> rmembers) = await GetGroupListMemberInfo(_coreAPIHttpService, client, group.key, group.list, item.Key, _dingDing, school,graduate);
-                        members.AddRange(rmembers);
-                    }
-                }
-                groupLists.AddRange(groups.SelectMany(x => x.Value).ToList());
-              
-                if (students.IsNotEmpty())
-                {
-                    List<string> sqlList = students.Select(x => x.classId).ToList();
-                    string insql = string.Join(",", sqlList.Select(x => $"'{x}'"));
-                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
-                        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})",
-                              requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
-                    {
-                        ///行政班(学生搜寻classId动态返回)class
-                        List<RMember> smembers = students.Where(x => x.classId.Equals(item.id))
-                            .Select(y => new RMember
-                            {
-                                id = y.id,
-                                code = school,
-                                name = y.name,
-                                //nickname = y.name,
-                                type = 2,
-                                picture = y.picture,
-                                no = y.no,
-                                classId = y.classId,
-                                groupId = y.groupId,
-                                groupName = y.groupName,
-                                irs = y.irs,
-                                year= y.year,
-                                graduate = y.graduate,
-                                gender= y.gender,
-                                periodId=y.periodId,
-                            }).ToList();
-                        members.AddRange(smembers);
-
-                        RGroupList group = new RGroupList
-                        {
-                            id = item.id,
-                            code = $"GroupList-{school}",
-                            name = item.name,
-                            periodId = item.periodId,
-                            scope = "school",
-                            school = school,
-                            type = "class",
-                            expire= item.expire,
-                            year = item.year,
-                            members = smembers,
-                            scount = smembers.Count,
-                            no = item.no,
-                            leader = item.leader,
-                            pk = "GroupList",
-                            graduate = item.graduate,
-                            grades= new HashSet<int> { item.year}
-                        };
-                        //graduate传入的状态>=0 表示指定状态查询,且传入的状态与数据库的状态一致。
-                        if (graduate >= 0)
-                        {
-                            if (group.graduate == graduate)
-                            {
-                                groupLists.Add(group);
-                            }
-                        }
-                        //全部。
-                        else  
-                        {
-                            groupLists.Add(group);
-                        }
-                       // groupLists.Add(group);
-                    }
-                    //去重。
-                    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();
-                }
             }
             if (groupids.IsNotEmpty())
             {
@@ -1152,7 +1308,7 @@ namespace TEAMModelOS.SDK
         /// <param name="_dingDing"></param>
         /// <param name="graduate">毕业类型0在校,1毕业 , -1查全部。</param>
         /// <returns></returns>
-        public static async Task<List<RGroupList>> GetGroupListMemberByType(CoreAPIHttpService _coreAPIHttpService, CosmosClient client, string type, List<string> scopes, string school, DingDing _dingDing, int graduate = -1)
+        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)
         {
             StringBuilder sql = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='{type}'");
 
@@ -1168,6 +1324,53 @@ namespace TEAMModelOS.SDK
                         groupLists.Add(item);
                     }
                     groups.Add("School", groupLists);
+
+                    if (!string.IsNullOrWhiteSpace(school)  && time>0  && groupLists.IsNotEmpty())
+                    {
+                        School schoolBase = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
+                        foreach (var period in schoolBase.period)
+                        {
+                            var dataSemester = SchoolService.GetSemester(period, time);
+                            //string id = $"{dataSemester.studyYear}-{dataSemester.currSemester.id}-{student.classId}";
+                            string code = $"GroupListSemester-{school}";
+                            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}'"))}) ";
+                            var result = await client.GetContainer(Constant.TEAMModelOS, Constant.School).GetList<GroupListSemester>(sqlSem, code);
+                            if (result.list.IsNotEmpty())
+                            {
+                                foreach (var x in result.list)
+                                {
+                                    HashSet<string> groupName = x.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
+                                    groupLists.Add(new RGroupList
+                                    {
+                                        id = x.groupListId,
+                                        code = $"GroupList-{school}",
+                                        periodId = x.periodId,
+                                        pk = x.pk,
+                                        name = x.name,
+                                        school = x.school,
+                                        creatorId = x.creatorId,
+                                        no = x.no,
+                                        scope = x.scope,
+                                        type = x.type,
+                                        scount = x.scount,
+                                        tcount = x.tcount,
+                                        leader = x.leader,
+                                        year = x.year,
+                                        expire = x.expire,
+                                        graduate = x.graduate,
+                                        members = x.members,
+                                        froms = x.froms,
+                                        joinLock = x.joinLock,
+                                        qrcodeExpire = x.qrcodeExpire,
+                                        qrcodeDays = x.qrcodeDays,
+                                        review=x.review,
+                                        limitCount = x.limitCount,
+                                        grades = x.grades,
+                                    });
+                                }
+                            }
+                        }
+                    }
                 }
             }
             else if (scopes.Contains("private"))

+ 149 - 84
TEAMModelOS/Controllers/Both/GroupListController.cs

@@ -94,7 +94,15 @@ namespace TEAMModelOS.Controllers
             {
                 memberType = 1;
             }
-            List<GroupListGrp> groups = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, userid, memberType, school, new List<string> { "class", "teach" });
+            List<GroupListGrp> groups = null;
+            if (json.TryGetProperty("time", out JsonElement _time)  && long.TryParse($"{_time}", out long time)  && time>0)
+            {
+                groups = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, userid, memberType, school, new List<string> { "class", "teach" },time:time);
+            }
+            else {
+               groups = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, userid, memberType, school, new List<string> { "class", "teach" });
+            }
+           
             return Ok(new { groups = groups });
         }
 
@@ -307,7 +315,7 @@ namespace TEAMModelOS.Controllers
             return Ok(new { groupLists });
         }
         /// <summary>
-        /// 获取发布活动的名单
+        /// 获取发布活动的名单(弃用)
         /// </summary>
         /// <param name="json"></param>
         /// <returns></returns>
@@ -422,6 +430,7 @@ namespace TEAMModelOS.Controllers
                         }
                     }
                     return Ok(new { groupLists });
+                    //弃用 
                 case bool when $"{opt}".Equals("teach", StringComparison.OrdinalIgnoreCase):
                     //我执教的
                     //从学校的课程和个人课程搜寻与我相关的课程对应的名单。
@@ -561,6 +570,7 @@ namespace TEAMModelOS.Controllers
             if (!json.TryGetProperty("opt", out JsonElement opt)) { return BadRequest(); }
             json.TryGetProperty("periodId", out JsonElement periodId);
             long nowtime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+            json.TryGetProperty("time", out JsonElement _time);
            
             switch (true)
             {
@@ -660,7 +670,7 @@ namespace TEAMModelOS.Controllers
                                 groupLists.Add(new GroupListGrp(item, groupName));
                             }
                         }
-                        long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        //long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                         return Ok(new { groupLists });
                     }
                 case bool when $"{opt}".Equals("teach", StringComparison.OrdinalIgnoreCase):
@@ -882,6 +892,7 @@ namespace TEAMModelOS.Controllers
             if (!json.TryGetProperty("ids", out JsonElement ids)) return BadRequest();
             json.TryGetProperty("schoolId", out JsonElement schoolId);
             json.TryGetProperty("groupNames", out JsonElement groupNames);
+
             List<Dictionary<string, List<string>>> groupLists = new List<Dictionary<string, List<string>>>();
             if (groupNames.ValueKind.Equals(JsonValueKind.Array))
             {
@@ -899,8 +910,17 @@ namespace TEAMModelOS.Controllers
                 }
             }
             List<string> listids = ids.ToObject<List<string>>();
-            (List<RMember> members, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, listids, $"{schoolId}", ps);
-            return Ok(new { groups, members });
+            if (json.TryGetProperty("time", out JsonElement _time) &&  long.TryParse($"{_time}", out long time)  && time>0)
+            {
+                (List<RMember> members, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, listids, $"{schoolId}", ps,time:time);
+                return Ok(new { groups, members });
+            }
+            else
+            {
+                (List<RMember> members, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, listids, $"{schoolId}", ps);
+                return Ok(new { groups, members });
+            }
+           
         }
         /// <summary>
         /// 根据任意名单id获取名单摘要信息。
@@ -918,8 +938,17 @@ namespace TEAMModelOS.Controllers
             var client = _azureCosmos.GetCosmosClient();
             if (!json.TryGetProperty("ids", out JsonElement ids)) return BadRequest();
             json.TryGetProperty("schoolId", out JsonElement schoolId);
-            List<string> listids = ids.ToObject<List<string>>();
-            List<GroupListDto> groups = await GroupListService.GetGroupListByListids(client, _dingDing, listids, $"{schoolId}", SummarySql);
+            List<string> listids = ids.ToObject<HashSet<string>>().ToList() ;
+            List<GroupListDto> groups = null;
+            if (json.TryGetProperty("time", out JsonElement _time) &&  long.TryParse($"{_time}", out long time)  && time>0)
+            {
+                groups = await GroupListService.GetGroupListByListids(client, _dingDing, listids, $"{schoolId}", SummarySql, time: time);
+            }
+            else
+            {
+                groups = await GroupListService.GetGroupListByListids(client, _dingDing, listids, $"{schoolId}", SummarySql);
+            }
+              
             return Ok(new { groups });
         }
         /// <summary>
@@ -942,8 +971,21 @@ namespace TEAMModelOS.Controllers
                 if (!json.TryGetProperty("type", out JsonElement type)) return BadRequest();
                 json.TryGetProperty("periodId", out JsonElement periodId);
                 json.TryGetProperty("no", out JsonElement no);
-                StringBuilder sql = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='{type}'");
+               
                 List<RGroupList> groups = new List<RGroupList>();
+
+                string sqlSemester = "";
+                if (json.TryGetProperty("time", out JsonElement _time) &&  long.TryParse($"{_time}", out long time)  && time>0)
+                {
+                    var groupListSemester = await GetGroupListSemester(client, null, $"{_schoolId}", $"{type}", $"{periodId}", $"{no}", time);
+                    if (groupListSemester.groupListDtos.IsNotEmpty())
+                    {
+                        groups.AddRange(groupListSemester.rgroupList);
+                        //排除掉已有的数据
+                        sqlSemester =$" and c.id not in ({string.Join(",", groupListSemester.groupListDtos.Select(z => $"'{z.id}'"))})";
+                    }
+                }
+                StringBuilder sql = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='{type}'");
                 string tbname = "Teacher";
                 string code = $"GroupList";
                 if ($"{scope}".Equals("school", StringComparison.OrdinalIgnoreCase))
@@ -1001,9 +1043,18 @@ namespace TEAMModelOS.Controllers
                 if (!json.TryGetProperty("type", out JsonElement type)) return BadRequest();
                 json.TryGetProperty("periodId", out JsonElement periodId);
                 json.TryGetProperty("no", out JsonElement no);
-                StringBuilder sql = new StringBuilder($"SELECT distinct {SummarySql} FROM c where c.type='{type}'");
-
                 List<GroupListDto> groups = new List<GroupListDto>();
+                string sqlSemester = "";
+                if (json.TryGetProperty("time", out JsonElement _time) &&  long.TryParse($"{_time}", out long time)  && time>0) {
+                   var groupListSemester = await GetGroupListSemester(client, null, $"{_schoolId}", $"{type}", $"{periodId}", $"{no}", time);
+                    if (groupListSemester.groupListDtos.IsNotEmpty()) {
+                        groups.AddRange(groupListSemester.groupListDtos);
+                        //排除掉已有的数据
+                        sqlSemester =$" and c.id not in ({string.Join(",",groupListSemester.groupListDtos.Select(z=>$"'{z.id}'"))})";
+                    }
+                }
+                StringBuilder sql = new StringBuilder($"SELECT distinct {SummarySql} FROM c where c.type='{type}'  {sqlSemester}");
+               
                 string tbname = "Teacher";
                 string code = $"GroupList";
                 if ($"{scope}".Equals("school", StringComparison.OrdinalIgnoreCase))
@@ -1051,26 +1102,45 @@ namespace TEAMModelOS.Controllers
         [Authorize(Roles = "IES")]
         public async Task<IActionResult> GetClassStudentsIdcode(JsonElement json)
         {
+            var client = _azureCosmos.GetCosmosClient();
             if (!json.TryGetProperty("id", out JsonElement id)) return BadRequest();
             if (!json.TryGetProperty("code", out JsonElement _code)) return BadRequest();
-            try
+            List<Student> students = new List<Student>();
+            Class clazz = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Class>($"{id}", new PartitionKey($"Class-{_code}"));
+            if (json.TryGetProperty("time", out JsonElement _time) &&  long.TryParse($"{_time}", out long time)  && time>0)
             {
-                var client = _azureCosmos.GetCosmosClient();
-                Class clazz = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Class>($"{id}", new PartitionKey($"Class-{_code}"));
-                List<Student> students = new List<Student>();
-                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId = '{clazz.id}'",
-                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{_code}") }))
+                var groupListSemester = await GetGroupListSemester(client, new List<string> { id.GetString()}, $"{_code}",type:null, periodId:null,no:null, time);
+                if (groupListSemester.rmembers.IsNotEmpty())
                 {
-                    item.salt = null;
-                    item.pw = null;
-                    students.Add(item);
+                    
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.id in ({string.Join(",",groupListSemester.rmembers.Select(z=>$"'{z.id}'"))}) ",
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{_code}") }))
+                    {
+                        item.salt = null;
+                        item.pw = null;
+                        item.classId=clazz.id;
+                        students.Add(item);
+                    }
                 }
-                return Ok(new { classInfo = clazz, students = students });
             }
-            catch (Exception ex)
-            {
-                return Ok(new { error = 404, msg = "班级不存在!" });
+            if (!students.IsNotEmpty()) {
+                try
+                {
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId = '{clazz.id}'",
+                        requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{_code}") }))
+                    {
+                        item.salt = null;
+                        item.pw = null;
+                        students.Add(item);
+                    }
+                   
+                }
+                catch (Exception ex)
+                {
+                    return Ok(new { error = 404, msg = "班级不存在!" });
+                }
             }
+            return Ok(new { classInfo = clazz, students = students });
 
         }
         //处理通用名单
@@ -1088,61 +1158,71 @@ namespace TEAMModelOS.Controllers
                 json.TryGetProperty("code", out JsonElement _code);
                 if (!json.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 if (!json.TryGetProperty("id", out JsonElement id)) return BadRequest();
+              
                 string tbname = $"{scope}".Equals("private") ? "Teacher" : "School";
                 string code = "";
-                if (string.IsNullOrEmpty($"{_type}") || !$"{_type}".Equals("class"))
-                {
-                    if ($"{scope}".Equals("private"))
-                    {
-                        //私人名单
-                        code = "GroupList";
+                //根据时间获取历史名单
+                if (json.TryGetProperty("time", out JsonElement _time)  && long.TryParse($"{_time}",out long time)  && time>0  && !string.IsNullOrWhiteSpace($"{_code}")){
+                    var semesterGroupList = await GetGroupListSemester(client, new List<string> { id.GetString()}, _code.GetString(),type:null,periodId:null,no:null, time);
+                    if (semesterGroupList.rgroupList.IsNotEmpty()) {
+                        groupList=semesterGroupList.rgroupList.First();
                     }
-                    else
+                }
+                if (groupList==null) {
+                    if (string.IsNullOrEmpty($"{_type}") || !$"{_type}".Equals("class"))
                     {
-                        //学校自定义名单
-                        code = !code.StartsWith("GroupList-") ? $"GroupList-{_code}" : code;
+                        if ($"{scope}".Equals("private"))
+                        {
+                            //私人名单
+                            code = "GroupList";
+                        }
+                        else
+                        {
+                            //学校自定义名单
+                            code = !code.StartsWith("GroupList-") ? $"GroupList-{_code}" : code;
+                        }
+                        groupList = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<RGroupList>($"{id}", new PartitionKey($"{code}"));
                     }
-                    groupList = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<RGroupList>($"{id}", new PartitionKey($"{code}"));
-                }
-                else if ($"{_type}".Equals("class"))
-                {
-                    try
+                    else if ($"{_type}".Equals("class"))
                     {
-                        code = $"Class-{_code}";
-                        Class clazz = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Class>($"{id}", new PartitionKey($"{code}"));
-                        if (clazz != null)
+                        try
                         {
-                            List<Student> students = new List<Student>();
-                            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId = '{clazz.id}'",
-                                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{_code}") }))
+                            code = $"Class-{_code}";
+                            Class clazz = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Class>($"{id}", new PartitionKey($"{code}"));
+                            if (clazz != null)
                             {
-                                students.Add(item);
+                                List<Student> students = new List<Student>();
+                                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId = '{clazz.id}'",
+                                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{_code}") }))
+                                {
+                                    students.Add(item);
+                                }
+                                ///行政班(学生搜寻classId动态返回)class
+                                List<RMember> smembers = students.Where(x => x.classId.Equals(clazz.id)).Select(y => new RMember { id = y.id, code = $"{_code}", name = y.name, type = 2, picture = y.picture, no = y.no, classId = y.classId, groupId = y.groupId, groupName = y.groupName }).ToList();
+                                groupList = new RGroupList
+                                {
+                                    id = clazz.id,
+                                    code = $"GroupList-{clazz.school}",
+                                    name = clazz.name,
+                                    periodId = clazz.periodId,
+                                    pk = "GroupList",
+                                    year = clazz.year,
+                                    expire = 0,
+                                    school = clazz.school,
+                                    scope = "school",
+                                    type = "class",
+                                    scount = smembers.Count,
+                                    no = clazz.no,
+                                    leader = clazz.teacher?.id,
+                                    members = smembers,
+                                };
                             }
-                            ///行政班(学生搜寻classId动态返回)class
-                            List<RMember> smembers = students.Where(x => x.classId.Equals(clazz.id)).Select(y => new RMember { id = y.id, code = $"{_code}", name = y.name, type = 2, picture = y.picture, no = y.no, classId = y.classId, groupId = y.groupId, groupName = y.groupName }).ToList();
-                            groupList = new RGroupList
-                            {
-                                id = clazz.id,
-                                code = $"GroupList-{clazz.school}",
-                                name = clazz.name,
-                                periodId = clazz.periodId,
-                                pk = "GroupList",
-                                year = clazz.year,
-                                expire = 0,
-                                school = clazz.school,
-                                scope = "school",
-                                type = "class",
-                                scount = smembers.Count,
-                                no = clazz.no,
-                                leader = clazz.teacher?.id,
-                                members = smembers,
-                            };
                         }
-                    }
-                    catch (CosmosException ex)
-                    {
-                        await _dingDing.SendBotMsg($"OS,{_option.Location},grouplist/get-grouplist-idcode()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
-                        return Ok(new { groupList });
+                        catch (CosmosException ex)
+                        {
+                            await _dingDing.SendBotMsg($"OS,{_option.Location},grouplist/get-grouplist-idcode()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                            return Ok(new { groupList });
+                        }
                     }
                 }
                 (List<RGroupList> groupsData, List<RMember> members) = await GroupListService.GetGroupListMemberInfo(_coreAPIHttpService, client, $"{groupList.type}", new List<RGroupList> { groupList }, tbname, _dingDing, $"{_code}");
@@ -1633,22 +1713,7 @@ namespace TEAMModelOS.Controllers
         }
 
 
-        /// <
-        /// summary>
-        /// 名单备份
-        /// </summary>
-        /// <param name="json"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-
-        [HttpPost("backups-opt")]
-#if !DEBUG
-[AuthToken(Roles = "teacher,admin")]
-        [Authorize(Roles = "IES")]
-#endif
-        public async Task<IActionResult> BackupsOpt(JsonElement json) {
-            return Ok();
-        }
+     
 
         /// <
         /// summary>