瀏覽代碼

名单数据结构

CrazyIter_Bin 3 年之前
父節點
當前提交
f2ad7227cd
共有 2 個文件被更改,包括 79 次插入25 次删除
  1. 78 24
      TEAMModelOS.SDK/Models/Service/TriggerStuActivity.cs
  2. 1 1
      TEAMModelOS/Controllers/Common/VoteController.cs

+ 78 - 24
TEAMModelOS.SDK/Models/Service/TriggerStuActivity.cs

@@ -455,9 +455,10 @@ namespace TEAMModelOS.SDK
             }
             return (null,  null);
         }
-        public static async Task<(List<TmdInfo> tmdinfos, List<StuInfo> students,List<ClassListInfo>classInfo)> GetStuList(CosmosClient client, DingDing _dingDing, List<string> claes, string school)
+        public static async Task<(List<TmdInfo> tmdinfos, List<StuInfo> students, List<ClassListInfo> classInfo)> GetStuList(CosmosClient client, DingDing _dingDing, List<string> claes, string school)
         {
-            try {
+            try
+            {
                 List<string> classes = new List<string>();
                 foreach (string ss in claes)
                 {
@@ -467,23 +468,46 @@ namespace TEAMModelOS.SDK
                 List<Students> studentss = new List<Students>();
                 List<string> tmdids = new List<string>();
                 List<StuInfo> stuInfos = new List<StuInfo>();
-                if (!classes.IsNotEmpty()) { return (tmdinfos, new List<StuInfo>(),null); }
+                if (!classes.IsNotEmpty()) { return (tmdinfos, new List<StuInfo>(), null); }
                 List<string> sqlList = new List<string>();
                 classes.ForEach(x => { sqlList.Add($" '{x}' "); });
                 string sql = string.Join(" , ", sqlList);
                 List<StuList> schList = new List<StuList>();
                 List<Student> students = new List<Student>();
-                if (!string.IsNullOrEmpty(school)) {
+                if (!string.IsNullOrEmpty(school))
+                {
                     await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
                     requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
                     {
                         schList.Add(item);
                     }
-                   
+                    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}") }))
+                    {
+                        students.Add(item);
+                    }
                 }
-               
-                
-                foreach (var x  in schList) {
+                List<StuList> tchLists = new List<StuList>();
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
+                {
+                    tchLists.Add(item);
+                }
+
+                foreach (var x in schList)
+                {
+                    if (x.students.IsNotEmpty())
+                    {
+                        studentss.AddRange(x.students);
+                    }
+                    if (x.tmids.IsNotEmpty())
+                    {
+                        tmdids.AddRange(x.tmids);
+                    }
+                    classes.Remove(x.id);
+                }
+                foreach (var x in tchLists)
+                {
                     if (x.students.IsNotEmpty())
                     {
                         studentss.AddRange(x.students);
@@ -494,9 +518,9 @@ namespace TEAMModelOS.SDK
                     }
                     classes.Remove(x.id);
                 }
-             
 
-                if (tmdids.IsNotEmpty()) {
+                if (tmdids.IsNotEmpty())
+                {
                     List<TmdInfo> infos = new List<TmdInfo>();
                     List<string> inids = new List<string>();
                     tmdids.ForEach(x => { inids.Add($"'{x}'"); });
@@ -509,9 +533,11 @@ namespace TEAMModelOS.SDK
                     }
                     tmdinfos.AddRange(infos);
                 }
-                if (studentss.IsNotEmpty()) {
+                if (studentss.IsNotEmpty())
+                {
                     List<string> inidstus = new List<string>();
-                    foreach (Students stu in studentss) {
+                    foreach (Students stu in studentss)
+                    {
                         var querystu = $"SELECT  c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id = '{stu.id}'";
                         await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{stu.code}") }))
                         {
@@ -528,17 +554,44 @@ namespace TEAMModelOS.SDK
                 }
                 students.ForEach(x =>
                 {
-                    if (!stuInfos.Select(y => y.classId).ToList().Contains(x.id)) {
-                        stuInfos.Add(new StuInfo { id = x.id, code = x.code, schoolId = x.schoolId, classId = x.classId, name = x.name, picture = x.picture, year = x.year,groupId=x.groupId,groupName=x.groupName,no=x.no });
+                    if (!stuInfos.Select(y => y.classId).ToList().Contains(x.id))
+                    {
+                        stuInfos.Add(new StuInfo { id = x.id, code = x.code, schoolId = x.schoolId, classId = x.classId, name = x.name, picture = x.picture, year = x.year, groupId = x.groupId, groupName = x.groupName, no = x.no });
                     }
                 });
                 List<ClassListInfo> classInfo = new List<ClassListInfo>();
                 schList.ForEach(x => {
-                    ClassListInfo classListInfo = new ClassListInfo {id=x.id,name=x.name };
-                    if (x.students.IsNotEmpty()) {
+                    ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
+                    if (x.students.IsNotEmpty())
+                    {
                         x.students.ForEach(y => {
-                            var stuinfo= stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
-                            if (stuinfo != null) {
+                            var stuinfo = stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
+                            if (stuinfo != null)
+                            {
+                                classListInfo.stuInfos.Add(stuinfo);
+                            }
+                        });
+                    }
+                    if (x.tmids.IsNotEmpty())
+                    {
+                        x.tmids.ForEach(y => {
+                            var tmdinfo = tmdinfos.Where(z => z.id.Equals(y)).FirstOrDefault();
+                            if (tmdinfo != null)
+                            {
+                                classListInfo.tmdInfos.Add(tmdinfo);
+                            }
+                        });
+                    }
+                    classInfo.Add(classListInfo);
+                });
+                tchLists.ForEach(x => {
+                    ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
+                    if (x.students.IsNotEmpty())
+                    {
+                        x.students.ForEach(y => {
+                            var stuinfo = stuInfos.Where(z => z.id.Equals(y.id)).FirstOrDefault();
+                            if (stuinfo != null)
+                            {
                                 classListInfo.stuInfos.Add(stuinfo);
                             }
                         });
@@ -556,23 +609,24 @@ namespace TEAMModelOS.SDK
                     classInfo.Add(classListInfo);
                 });
 
+
                 //var classeids= students.GroupBy(x => x.classId).Select(x => x.Key).ToList();
-                List<ClassInfo> classInfos= await  GetClassInfo(client, _dingDing, classes, school);
+                List<ClassInfo> classInfos = await GetClassInfo(client, _dingDing, classes, school);
                 classInfos.ForEach(x =>
                 {
                     ClassListInfo classListInfo = new ClassListInfo { id = x.id, name = x.name };
-                    var list= students.Where(y => y.classId .Equals(x.id)).ToList();
-                    list.ForEach(z => { classListInfo.stuInfos.Add(new StuInfo { id = z.id, code = z.code, schoolId = z.schoolId, classId = z.classId, name = z.name, picture = z.picture, year = z.year ,groupId=z.groupId,groupName=z.groupName,no=z.no}); });
+                    var list = students.Where(y => y.classId.Equals(x.id)).ToList();
+                    list.ForEach(z => { classListInfo.stuInfos.Add(new StuInfo { id = z.id, code = z.code, schoolId = z.schoolId, classId = z.classId, name = z.name, picture = z.picture, year = z.year, groupId = z.groupId, groupName = z.groupName, no = z.no }); });
                     classInfo.Add(classListInfo);
                 });
-                
-                return (tmdinfos, stuInfos, classInfo) ;
+
+                return (tmdinfos, stuInfos, classInfo);
             }
             catch (Exception ex)
             {
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-OS,TriggerStuActivity-GetStuList\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
             }
-                return (null, null,null);
+            return (null, null, null);
         }
     }
     public class ClassListInfo

+ 1 - 1
TEAMModelOS/Controllers/Common/VoteController.cs

@@ -312,7 +312,7 @@ namespace TEAMModelOS.Controllers.Learn
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/find-id()\n{ex.Message}\n{id}\n{code}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/find-id()\n{ex.Message}\n{requert.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
                 return Ok(new { vote,status=404 });
             }