Forráskód Böngészése

名单代码提交

CrazyIter_Bin 3 éve
szülő
commit
3cb9877147

+ 2 - 3
TEAMModelOS.SDK/Models/Cosmos/Common/StuList.cs

@@ -2,7 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 
-namespace TEAMModelOS.SDK.Models.Cosmos.Common
+namespace TEAMModelOS.SDK.Models
 {
     public class StuList : CosmosEntity
     {
@@ -12,7 +12,6 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         }
         public List<Students> students { get; set; } = new List<Students>();
         public List<string> tmids { get; set; }
-        public List<string> teachers { get; set; }
         public string name { get; set; }
         //标记该名单唯一code
         public string no { get; set; }
@@ -21,7 +20,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         public string school { get; set; }
         public string creatorId { get; set; }
         /// <summary>
-        /// student 学生名单类型  teacher 教师分组名单 , research 教研组名单
+        /// student 学生名单类型
         /// </summary>
         public string type { get; set; } = "student";
     }

+ 5 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/TchList.cs

@@ -2,10 +2,14 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 
-namespace TEAMModelOS.SDK.Models.Cosmos.Common
+namespace TEAMModelOS.SDK.Models
 {
    public class TchList : CosmosEntity
     {
+        public TchList()
+        {
+            pk = "TchList";
+        }
         public List<string> teachers { get; set; }
         public string name { get; set; }
         //标记该名单唯一code

+ 147 - 31
TEAMModelOS.SDK/Models/Service/TriggerStuActivity.cs

@@ -215,10 +215,7 @@ namespace TEAMModelOS.SDK
                     {
                         tmdids.AddRange(x.tmids);
                     }
-                    if (x.teachers.IsNotEmpty())
-                    {
-                        tmdids.AddRange(x.teachers);
-                    }
+                   
                     classes.Remove(x.id);
                 }
                 foreach (var x in tchLists)
@@ -304,16 +301,6 @@ namespace TEAMModelOS.SDK
                             }
                         });
                     }
-                    if (x.teachers.IsNotEmpty())
-                    {
-                        x.teachers.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 => {
@@ -360,9 +347,10 @@ namespace TEAMModelOS.SDK
             }
             return (null, 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)> GetTchList(CosmosClient client, DingDing _dingDing, List<string> claes, string school)
         {
-            try {
+            try
+            {
                 List<string> classes = new List<string>();
                 foreach (string ss in claes)
                 {
@@ -372,13 +360,14 @@ 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}") }))
                     {
@@ -396,8 +385,9 @@ namespace TEAMModelOS.SDK
                 {
                     tchLists.Add(item);
                 }
-                
-                foreach (var x  in schList) {
+
+                foreach (var x in schList)
+                {
                     if (x.students.IsNotEmpty())
                     {
                         studentss.AddRange(x.students);
@@ -408,9 +398,10 @@ namespace TEAMModelOS.SDK
                     }
                     classes.Remove(x.id);
                 }
-                foreach (var x in tchLists) 
+                foreach (var x in tchLists)
                 {
-                    if (x.students.IsNotEmpty()) {
+                    if (x.students.IsNotEmpty())
+                    {
                         studentss.AddRange(x.students);
                     }
                     if (x.tmids.IsNotEmpty())
@@ -420,7 +411,8 @@ 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}'"); });
@@ -433,9 +425,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}") }))
                         {
@@ -452,17 +446,20 @@ 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);
                             }
                         });
@@ -505,6 +502,125 @@ namespace TEAMModelOS.SDK
                 });
 
 
+                //var classeids= students.GroupBy(x => x.classId).Select(x => x.Key).ToList();
+                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 }); });
+                    classInfo.Add(classListInfo);
+                });
+
+                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);
+        }
+        public static async Task<(List<TmdInfo> tmdinfos, List<StuInfo> students,List<ClassListInfo>classInfo)> GetStuList(CosmosClient client, DingDing _dingDing, List<string> claes, string school)
+        {
+            try {
+                List<string> classes = new List<string>();
+                foreach (string ss in claes)
+                {
+                    classes.Add(ss);
+                }
+                List<TmdInfo> tmdinfos = new List<TmdInfo>();
+                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); }
+                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)) {
+                    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);
+                    }
+                   
+                }
+               
+                
+                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);
+                }
+             
+
+                if (tmdids.IsNotEmpty()) {
+                    List<TmdInfo> infos = new List<TmdInfo>();
+                    List<string> inids = new List<string>();
+                    tmdids.ForEach(x => { inids.Add($"'{x}'"); });
+                    var insql = string.Join(",", inids);
+                    var queryslt = $"SELECT  value(c) FROM c where c.id in ({insql})";
+                    //合并代码/
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<TmdInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                    {
+                        infos.Add(item);
+                    }
+                    tmdinfos.AddRange(infos);
+                }
+                if (studentss.IsNotEmpty()) {
+                    List<string> inidstus = new List<string>();
+                    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}") }))
+                        {
+                            stuInfos.Add(item);
+                        }
+                    }
+                    /*studentss.Select(x => x.id).ToList().ForEach(x => { inidstus.Add($"'{x}'"); });
+                    var insqlstu = string.Join(",", inidstus);
+                    var querystu = $"SELECT  c.id,c.code,c.name,c.picture,c.classId,c.year,c.schoolId FROM c where c.id in ({insqlstu})";
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuInfo>(queryText: querystu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school}") }))
+                    {
+                        stuInfos.Add(item);
+                    }*/
+                }
+                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 });
+                    }
+                });
+                List<ClassListInfo> classInfo = new List<ClassListInfo>();
+                schList.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);
+                            }
+                        });
+                    }
+                    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);
+                });
+
                 //var classeids= students.GroupBy(x => x.classId).Select(x => x.Key).ToList();
                 List<ClassInfo> classInfos= await  GetClassInfo(client, _dingDing, classes, school);
                 classInfos.ForEach(x =>

+ 0 - 4
TEAMModelOS/Controllers/Item/ItemController.cs

@@ -4,16 +4,12 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using TEAMModelOS.Models;
-using TEAMModelOS.SDK;
-using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using System.Text.Json;
-using TEAMModelOS.SDK.Helper.Common.StringHelper;
 using TEAMModelOS.SDK.Models;
 using Microsoft.AspNetCore.Http;
 using TEAMModelOS.SDK.Extension;
 using Azure.Cosmos;
-using Microsoft.AspNetCore.Authentication;
 using System.Text;
 using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
 using Microsoft.Extensions.Options;

+ 21 - 36
TEAMModelOS/Controllers/School/StuListController.cs

@@ -5,27 +5,19 @@ using Microsoft.Extensions.Options;
 using System;
 using System.Collections.Generic;
 using System.IdentityModel.Tokens.Jwt;
-using System.IO;
 using System.Linq;
-using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.Models;
-using TEAMModelOS.Models.Dto;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
-using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
 using TEAMModelOS.SDK.Extension;
-using TEAMModelOS.SDK;
-using TEAMModelOS.SDK.Helper.Common.StringHelper;
-using System.Dynamic;
 using Azure;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 using TEAMModelOS.Filter;
-using Azure.Storage.Blobs.Models;
 using HTEXLib.COMM.Helpers;
 
 namespace TEAMModelOS.Controllers
@@ -52,7 +44,26 @@ namespace TEAMModelOS.Controllers
             _configuration = configuration;
             _azureStorage = azureStorage;
         }
-
+        //处理通用名单
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "teacher,admin")]
+        [HttpPost("upsert-list")]
+        public async Task<IActionResult> upsertList(StuList stuList)
+        {
+            try
+            {
+                var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
+                stuList.creatorId = userid;
+                stuList.school = school;
+                stuList = await upsertList(stuList, stuList.scope);
+                return Ok(new { stuList });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},course/upsert-list()\n{ex.Message}{ex.StackTrace}\n{stuList}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
         /*
         {
             "stuListNo": "1124582",
@@ -73,9 +84,7 @@ namespace TEAMModelOS.Controllers
         {
             try
             {
-
                 if (!json.TryGetProperty("stuListNo", out JsonElement _stuListNo)) return BadRequest();
-
                 json.TryGetProperty("school", out JsonElement _school);
                 string school = $"{_school}";
                 var client = _azureCosmos.GetCosmosClient();
@@ -83,7 +92,6 @@ namespace TEAMModelOS.Controllers
                 StuList stuList = null;
                 json.TryGetProperty("studentId", out JsonElement _studentId);
                 json.TryGetProperty("tmdId", out JsonElement _tmdId);
-
                 if (!string.IsNullOrEmpty(school) && !string.IsNullOrEmpty($"{_studentId}"))
                 {
                     await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: queryNo,
@@ -315,30 +323,7 @@ namespace TEAMModelOS.Controllers
             }
             return (status, stuList);
         }
-        //处理通用名单
-        [ProducesDefaultResponseType]
-        [AuthToken(Roles = "teacher,admin")]
-        [HttpPost("upsert-list")]
-        public async Task<IActionResult> upsertList(JsonElement json)
-        {
-            try
-            {
-                var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
-                StuList stuList = new StuList();
-                if (!json.TryGetProperty("stuList", out JsonElement student)) return BadRequest();
-                if (!json.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
-                stuList = student.ToObject<StuList>();
-                stuList.creatorId = userid;
-                stuList.school = school;
-                stuList = await upsertList(stuList, $"{scope}");
-                return Ok(new { stuList });
-            }
-            catch (Exception ex)
-            {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},course/upsert-list()\n{ex.Message}{ex.StackTrace}\n{json}", GroupNames.醍摩豆服務運維群組);
-                return BadRequest();
-            }
-        }
+        
         private async Task<StuList> upsertList(StuList stuList, string scope)
         {
             try

+ 0 - 7
TEAMModelOS/Controllers/Teacher/CommentController.cs

@@ -3,20 +3,13 @@ using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
-using System.IdentityModel.Tokens.Jwt;
 using System.Text.Json;
 using System.Threading.Tasks;
-using TEAMModelOS.Models.Dto;
 using TEAMModelOS.SDK.Models;
-using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
-using TEAMModelOS.SDK;
-using TEAMModelOS.SDK.Helper.Common.StringHelper;
 using TEAMModelOS.Models;
 using Microsoft.Extensions.Options;
-using System.Text;
-using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 using System.Linq;
 using TEAMModelOS.Filter;