소스 검색

教研组名单

CrazyIter_Bin 3 년 전
부모
커밋
e72c51d8f0

+ 11 - 2
TEAMModelOS.SDK/Models/Cosmos/Common/Inner/StuListChange.cs

@@ -7,11 +7,11 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
     public class StuListChange
     {
         /// <summary>
-        /// 教师名单加入的成员
+        /// 醍摩豆学生名单加入的成员
         /// </summary>
         public List<string> tmdjoin { get; set; } = new List<string>();
         /// <summary>
-        /// 教师名单离开的成员
+        /// 醍摩豆学生名单离开的成员
         /// </summary>
         public List<string> tmdhleave { get; set; } = new List<string>();
         /// <summary>
@@ -22,6 +22,15 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// 学校学生名单离开的成员
         /// </summary>
         public List<Students> stuleave { get; set; } = new List<Students>();
+
+        /// <summary>
+        /// 学校教师名单加入的成员
+        /// </summary>
+        public List<string> tchjoin { get; set; } = new List<string>();
+        /// <summary>
+        /// 学校教师名单离开的成员
+        /// </summary>
+        public List<string> tchleave { get; set; } = new List<string>();
         public string listid { get; set; }
         /// <summary>
         /// 分区

+ 4 - 6
TEAMModelOS.SDK/Models/Cosmos/Common/StuList.cs

@@ -13,7 +13,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 CourseInfo course { get; set; } = new CourseInfo();
         public string name { get; set; }
         //标记该名单唯一code
         public string no { get; set; }
@@ -21,6 +20,10 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         public string scope { get; set; }
         public string school { get; set; }
         public string creatorId { get; set; }
+        /// <summary>
+        /// student 学生名单类型  teacher 教师分组名单 , research 教研组名单
+        /// </summary>
+        public string type { get; set; } = "student";
     }
     public class Students
     {
@@ -28,9 +31,4 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         public string code { get; set; }
         public string schoolId { get; set; }
     }
-    //public class CourseInfo
-    //{
-    //    public string id { get; set; }
-    //    public string code { get; set; }
-    //}
 }

+ 1 - 1
TEAMModelOS.SDK/Models/Service/StuListService.cs

@@ -23,7 +23,7 @@ namespace TEAMModelFunction
             try
             {
                 var query = $"SELECT distinct c.owner, c.id,c.code, c.classes,c.stuLists,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime   FROM c  where  c.pk='{type}' " +
-                    $" and (( array_contains(c.classes,'{stuListChange.listid}')) or ( array_contains(c.stuLists,'{stuListChange.listid}')))";
+                    $" and (( array_contains(c.classes,'{stuListChange.listid}')) or ( array_contains(c.stuLists,'{stuListChange.listid}'))or ( array_contains(c.tchLists,'{stuListChange.listid}')))";
                     //$"and A1 in('{stuListChange.listid}') ";
                 List<MQActivity> datas = new List<MQActivity>();
                 if (stuListChange.scope.Equals("school", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(stuListChange.school)) {

+ 86 - 55
TEAMModelOS/Controllers/School/StuListController.cs

@@ -502,7 +502,45 @@ namespace TEAMModelOS.Controllers
                                 }
                             }
                         }
-                        if (change.tmdjoin.Count != 0 || change.tmdhleave.Count != 0 || change.stujoin.Count != 0 || change.stuleave.Count != 0)
+                        if (stuList.teachers != null) {
+                            if (odlStus[0].teachers != null)
+                            {
+                                StuList oldStu = odlStus[0];
+                                foreach (var teacher in stuList.teachers)
+                                {
+                                    bool flag = false;
+                                    //判断新增名单成员不在已经存在的名单
+                                    foreach (var old in oldStu.teachers)
+                                    {
+                                        if (old.Equals(teacher))
+                                        {
+                                            flag = true;
+                                        }
+                                    }
+                                    if (flag == false)
+                                    {
+                                        change.tchjoin.Add(teacher);
+                                    }
+                                }
+                                foreach (var old in oldStu.teachers)
+                                {
+                                    bool flag = false;
+                                    //判断已存在名单成员不在变更后的名单里
+                                    foreach (var teacher in stuList.teachers)
+                                    {
+                                        if (old.Equals(teacher))
+                                        {
+                                            flag = true;
+                                        }
+                                    }
+                                    if (flag == false)
+                                    {
+                                        change.tchleave.Add(old);
+                                    }
+                                }
+                            }
+                        }
+                        if (change.tmdjoin.Count != 0 || change.tmdhleave.Count != 0 || change.stujoin.Count != 0 || change.stuleave.Count != 0 || change.tchjoin.Count != 0 || change.tchleave.Count != 0)
                         {
                             var messageChange = new ServiceBusMessage(change.ToJsonString());
                             messageChange.ApplicationProperties.Add("name", "StuList");
@@ -528,7 +566,7 @@ namespace TEAMModelOS.Controllers
                         creatorId = stuList.creatorId
                     };
 
-                    var query = $"SELECT distinct value(c)  FROM c    where  c.id='{stuList.id}'";
+                    var query = $"SELECT distinct value(c)  FROM c  where  c.id='{stuList.id}'";
                     List<StuList> odlStus = new List<StuList>();
                     await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<StuList>(queryText: query,
                             requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
@@ -699,7 +737,7 @@ namespace TEAMModelOS.Controllers
 
         //查询名单
         [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "Teacher")]
+        [AuthToken(Roles = "admin,teacher")]
         [HttpPost("get-summary-list")]
         public async Task<IActionResult> getSummary(JsonElement requert)
         {
@@ -707,45 +745,41 @@ namespace TEAMModelOS.Controllers
             {
                 if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 if (!requert.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
-                if (!requert.TryGetProperty("ids", out JsonElement classId)) return BadRequest();
+                requert.TryGetProperty("ids", out JsonElement _stuids);
                 var client = _azureCosmos.GetCosmosClient();
                 List<object> stuList = new();
-                //List<int> stuCount = new List<int>();
                 List<string> ids = new();
-                ids = classId.ToObject<List<string>>();
-                if (!(ids.Count > 0)) return BadRequest();
-                //List<Students> stu = new();
-                var query = $"select c.id,c.name,c.students,c.tmids,c.no,c.code,c.scope,c.school,c.creatorId from c where c.id in ({string.Join(",", ids.Select(o => $"'{o}'"))})";
+                ids = _stuids.ToObject<List<string>>();
+                // var query = $"select c.id,c.name,c.students,c.tmids,c.periodId from c";
+                StringBuilder query = new StringBuilder($"select c.id,c.name,c.students,c.tmids,c.no,c.code,c.scope,c.school,c.creatorId,c.periodId from c ");
+                if (ids.IsNotEmpty()) { 
+                    string sql= $" where c.id in ({string.Join(",", ids.Select(o => $"'{o}'"))})";
+                    query.Append(sql);
+                }
                 if (scope.ToString().Equals("school", StringComparison.OrdinalIgnoreCase))
                 {
-                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList-{code}") }))
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: query.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList-{code}") }))
                     {
                         using var json = await JsonDocument.ParseAsync(item.ContentStream);
                         if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                         {
                             foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
                             {
-                                //stu = obj.GetProperty("students").ToObject<List<Students>>();
                                 stuList.Add(obj.ToObject<object>());
-                                //stuList.Add(stu.Count);
-                                //stuCount.Add(stu.Count);
                             }
                         }
                     }
                 }
                 else
                 {
-                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList") }))
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: query.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList") }))
                     {
                         using var json = await JsonDocument.ParseAsync(item.ContentStream);
                         if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                         {
                             foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
                             {
-                                //stu = obj.GetProperty("students").ToObject<List<Students>>();
                                 stuList.Add(obj.ToObject<object>());
-                                //stuList.Add(stu.Count);
-                                //stuCount.Add(stu.Count);
                             }
                         }
                     }
@@ -759,10 +793,43 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
             }
         }
-
         //查询名单
         [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "Teacher")]
+        [AuthToken(Roles = "admin,teacher")]
+        [HttpPost("get-research-list")]
+        public async Task<IActionResult> getResearch(JsonElement requert)
+        {
+            try
+            {
+                if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                if (!requert.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
+                requert.TryGetProperty("ids", out JsonElement _stuids);
+                var client = _azureCosmos.GetCosmosClient();
+                List<StuList> stuList = new();
+                List<string> ids = new();
+                ids = _stuids.ToObject<List<string>>();
+                // var query = $"select c.id,c.name,c.students,c.tmids,c.periodId from c";
+                StringBuilder query = new StringBuilder($"select vaule(c) from c where c.type='research' ");
+                if (ids.IsNotEmpty())
+                {
+                    string sql = $" and c.id in ({string.Join(",", ids.Select(o => $"'{o}'"))})";
+                    query.Append(sql);
+                }
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StuList>(queryText: query.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList-{code}") }))
+                {
+                    stuList.Add(item);
+                }
+                return Ok(new { stuList });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},course/get-summary-list()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+        //查询名单
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "admin,teacher")]
         [HttpPost("delete-list")]
         public async Task<IActionResult> deleteList(JsonElement requert)
         {
@@ -772,50 +839,14 @@ namespace TEAMModelOS.Controllers
                 if (!requert.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
-                //var query = $"select c.id,c.name,c.students,c.tmids from c where c.id in ({string.Join(",", ids.Select(o => $"'{o}'"))})";
                 if (scope.ToString().Equals("school", StringComparison.OrdinalIgnoreCase))
                 {
-                    /*List<string> classIds = new List<string>();
-                    var query = $"select c.id from c join A0 in c.schedule where A0.teacherId = '{id}'";
-                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{id}") }))
-                    {
-                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                        {
-                            var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
-                            while (accounts.MoveNext())
-                            {
-                                JsonElement account = accounts.Current;
-                                if (string.IsNullOrEmpty(account.GetProperty("id").GetString()))
-                                {
-                                    continue;
-                                }
-                                classIds.Add(account.GetProperty("id").GetString());
-                                listClassInfo.Add((account.GetProperty("id").GetString(), account.GetProperty("scope").GetString()));
-                            }
-                        }
-                    }*/
                     await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"StuList-{code}"));
                 }
                 else
                 {
                     await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"StuLis"));
-                    /*await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StuList") }))
-                    {
-                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                        {
-                            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
-                            {
-                                List<Students> stu = obj.GetProperty("students").ToObject<List<Students>>();
-                                stuList.Add(obj.ToObject<object>());
-                                //stuList.Add(stu.Count);
-                                //stuCount.Add(stu.Count);
-                            }
-                        }
-                    }*/
                 }
-
                 return Ok(new { id });
             }
             catch (Exception ex)