瀏覽代碼

处理必修和根据任意名单id获取信息。

CrazyIter_Bin 3 年之前
父節點
當前提交
0d5314ee58

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

@@ -276,6 +276,97 @@ namespace TEAMModelOS.SDK.Models
             }
             return list;
         }
+        public static async Task<List<GroupListDto> > GetGroupListListids(CosmosClient client, DingDing _dingDing, List<string> classes, string school,string SummarySql) {
+            List<GroupListDto> groupLists = null;
+            if (classes.Count == 1 && classes.First().Equals("default") && !string.IsNullOrEmpty(school))
+            {
+                //默认的教研组
+
+                GroupListDto groupList = new GroupListDto
+                {
+                    id = "default",
+                    name = "default",
+                    code = $"GroupList-{school}",
+                    school = school,
+                    scope = "school",
+                    type = "research",
+                };
+                groupLists = new List<GroupListDto> { groupList };
+            }
+            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))
+                {
+                    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())
+                    {
+                        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}") }))
+                        {
+                            students.Add(item);
+                        }
+                        //取差集,减少二次搜寻
+                        classes = classes.Except(students.Select(y => y.classId)).ToList();
+                    }
+                }
+                if (classes.IsNotEmpty())
+                {
+                    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})",
+                           requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList") }))
+                    {
+                        privateList.Add(item);
+                    }
+                    if (privateList.IsNotEmpty())
+                    {
+                        groups.Add("Teacher", privateList);
+                    }
+                }
+                groupLists = 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<ClassInfo>(queryText: $"select c.id,c.name ,c.periodId  ,c.year from c where c.id in ({insql})",
+                              requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
+                    {
+                        ///行政班(学生搜寻classId动态返回)class
+                        List<string> smembers = students.Where(x => x.classId.Equals(item.id)).Select(y => y.id).ToList();
+                        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,
+                            scount = smembers.Count
+                        };
+                        groupLists.Add(group);
+                    }
+                }
+            }
+            return groupLists;
+        }
         public static async Task<(List<RMember>, List<RGroupList> groups)> GetStutmdidListids(CosmosClient client, DingDing _dingDing, List<string> classes, string school)
         {
             List<RMember> members = new List<RMember>();

+ 20 - 17
TEAMModelOS/Controllers/Research/AbilityStatisticsController.cs

@@ -1620,27 +1620,30 @@ namespace TEAMModelOS.Controllers.Research
                         await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(abilitySub, new PartitionKey(abilitySub.code));
                     }
                 }
-                //必修
-                foreach (var item in currencyAb1)
-                {
-                    var had = hadSubs.Where(x => x.id.Equals(item.id)).FirstOrDefault();
-                    if (had == null)
+                if (currencyAb1 != null) {
+                    //必修
+                    foreach (var item in currencyAb1)
                     {
-                        hadSubs.Add(item);
-                        AbilitySub abilitySub = new AbilitySub
+                        var had = hadSubs.Where(x => x.id.Equals(item.id)).FirstOrDefault();
+                        if (had == null)
                         {
-                            id = item.id,
-                            code = $"AbilitySub-{school}-{id}",
-                            school = $"{school}",
-                            creatorId = $"{id}",
-                            done = false,
-                            hour = 0,
-                            comid = Guid.NewGuid().ToString(),
-                            pk = "AbilitySub"
-                        };
-                        await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(abilitySub, new PartitionKey(abilitySub.code));
+                            hadSubs.Add(item);
+                            AbilitySub abilitySub = new AbilitySub
+                            {
+                                id = item.id,
+                                code = $"AbilitySub-{school}-{id}",
+                                school = $"{school}",
+                                creatorId = $"{id}",
+                                done = false,
+                                hour = 0,
+                                comid = Guid.NewGuid().ToString(),
+                                pk = "AbilitySub"
+                            };
+                            await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(abilitySub, new PartitionKey(abilitySub.code));
+                        }
                     }
                 }
+                
                 return Ok(new { rcdSubs, hadSubs });
             }
             catch (Exception ex)

+ 18 - 1
TEAMModelOS/Controllers/School/GroupListController.cs

@@ -344,7 +344,7 @@ namespace TEAMModelOS.Controllers
         [ProducesDefaultResponseType]
         [AuthToken(Roles = "teacher,admin,student")]
         [HttpPost("get-members-listids")]
-        public async Task<IActionResult> GetStutmdidListids(JsonElement json)
+        public async Task<IActionResult> GetMembersListids(JsonElement json)
         {
             var client = _azureCosmos.GetCosmosClient();
             if (!json.TryGetProperty("ids", out JsonElement ids)) return BadRequest();
@@ -354,6 +354,23 @@ namespace TEAMModelOS.Controllers
             return Ok(new { groups, members });
         }
         /// <summary>
+        /// 根据任意名单id获取名单摘要信息。
+        /// </summary>
+        /// <param name="json"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "teacher,admin,student")]
+        [HttpPost("get-grouplist-listids")]
+        public async Task<IActionResult> GetGroupListListids(JsonElement json)
+        {
+            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.GetGroupListListids(client, _dingDing, listids, $"{schoolId}", SummarySql);
+            return Ok(new { groups });
+        }
+        /// <summary>
         /// 获取名单和成员信息。
         /// </summary>
         /// <param name="json"></param>

文件差異過大導致無法顯示
+ 31 - 0
TEAMModelOS/Controllers/XTest/FixDataController.cs