소스 검색

Merge branch 'develop5.0-tmd' of http://106.12.23.251:10000/TEAMMODEL/TEAMModelOS into develop5.0-tmd

zhouj1203@hotmail.com 3 년 전
부모
커밋
07d461c767

+ 282 - 34
TEAMModelFunction/CourseServiceBus.cs

@@ -7,6 +7,7 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 
 namespace TEAMModelFunction
@@ -41,48 +42,295 @@ namespace TEAMModelFunction
                 if (courseChange == null) {
                     return;
                 }
-                //根据新增名单获取 新增的学生id 及timdid
-                (List<string> addTmdids, List<Students> addStudents) = await TriggerStuActivity.GetStuList(client, _dingDing, courseChange.addList, courseChange.school);
-                //根据删除名单获取 新增的学生id 及timdid
-                (List<string> delTmdids, List<Students> delStudents) = await TriggerStuActivity.GetStuList(client, _dingDing, courseChange.delList, courseChange.school);
-                foreach (var addStu in addStudents)
-                {
-                    var course = new StuCourse
+                foreach (var cls in courseChange.addClass) {
+                    (List<string> addTmdidsCls, List<Students> addStudentsCls) = await TriggerStuActivity.GetStuList(client, _dingDing,new List<string> { cls}, courseChange.school);
+                    foreach (var stu in addStudentsCls) {
+                        try
+                        {
+                            ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
+                            if (!stuCourse.Value.classId.Contains(cls)) {
+                                stuCourse.Value.classId.Add(cls);
+                            }
+                            await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
+                        }
+                        catch (CosmosException ex)
+                        {
+                            if (ex.Response.Status == 404)
+                            {
+                                var course = new StuCourse
+                                {
+                                    id = courseChange.id,
+                                    scode = courseChange.code,
+                                    name = courseChange.name,
+                                    code = $"StuCourse-{courseChange.school}-{stu.id}",
+                                    scope = courseChange.scope,
+                                    school = courseChange.school,
+                                    creatorId = courseChange.creatorId,
+                                    classId= new List<string> { cls},
+                                    pk = "StuCourse"
+                                };
+                                await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(course, new PartitionKey(course.code));
+                            }
+                        }
+                    }
+                    foreach (var tmd in addTmdidsCls)
                     {
-                        id = courseChange.id,
-                        scode = courseChange.code,
-                        name = courseChange.name,
-                        code = $"StuCourse-{courseChange.school}-{addStu.id}",
-                        scope = courseChange.scope,
-                        school = courseChange.school,
-                        creatorId = courseChange.creatorId,
-                        pk = "StuCourse"
-                    };
-                    await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(course, new PartitionKey(course.code));
+                        try
+                        {
+                            ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
+                            if (!stuCourse.Value.classId.Contains(cls))
+                            {
+                                stuCourse.Value.classId.Add(cls);
+                            }
+                            await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
+                        }
+                        catch (CosmosException ex)
+                        {
+                            if (ex.Response.Status == 404)
+                            {
+                                var course = new StuCourse
+                                {
+                                    id = courseChange.id,
+                                    scode = courseChange.code,
+                                    name = courseChange.name,
+                                    code = $"StuCourse-{tmd}",
+                                    scope = courseChange.scope,
+                                    school = courseChange.school,
+                                    creatorId = courseChange.creatorId,
+                                    classId = new List<string> { cls },
+                                    pk = "StuCourse"
+                                };
+                                await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(course, new PartitionKey(course.code));
+                            }
+                        }
+                    }
                 }
-                foreach (var addTmd in addTmdids)
+
+                foreach (var list in courseChange.addList)
                 {
-                    var course = new StuCourse
+                    (List<string> addTmdidsCls, List<Students> addStudentsCls) = await TriggerStuActivity.GetStuList(client, _dingDing, new List<string> { list }, courseChange.school);
+                    foreach (var stu in addStudentsCls)
+                    {
+                        try
+                        {
+                            ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{stu.schoolId}-{stu.id}"));
+                            if (!stuCourse.Value.stulist.Contains(list))
+                            {
+                                stuCourse.Value.stulist.Add(list);
+                                await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{stu.schoolId}-{stu.id}"));
+                            }
+                        }
+                        catch (CosmosException ex)
+                        {
+                            if (ex.Response.Status == 404)
+                            {
+                                var course = new StuCourse
+                                {
+                                    id = courseChange.id,
+                                    scode = courseChange.code,
+                                    name = courseChange.name,
+                                    code = $"StuCourse-{courseChange.school}-{stu.id}",
+                                    scope = courseChange.scope,
+                                    school = courseChange.school,
+                                    creatorId = courseChange.creatorId,
+                                    stulist = new List<string> { list },
+                                    pk = "StuCourse"
+                                };
+                                await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(course, new PartitionKey(course.code));
+                            }
+                        }
+                    }
+                    foreach (var tmd in addTmdidsCls)
                     {
-                        id = courseChange.id,
-                        scode = courseChange.code,
-                        name = courseChange.name,
-                        code = $"StuCourse-{addTmd}",
-                        scope = courseChange.scope,
-                        //school = courseChange.school,
-                        creatorId = courseChange.creatorId,
-                        pk = "StuCourse"
-                    };
-                    await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(course, new PartitionKey(course.code));
+                        try
+                        {
+                            ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
+                            if (!stuCourse.Value.stulist.Contains(list))
+                            {
+                                stuCourse.Value.stulist.Add(list);
+                                await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
+                            }
+                            
+                        }
+                        catch (CosmosException ex)
+                        {
+                            if (ex.Response.Status == 404)
+                            {
+                                var course = new StuCourse
+                                {
+                                    id = courseChange.id,
+                                    scode = courseChange.code,
+                                    name = courseChange.name,
+                                    code = $"StuCourse-{tmd}",
+                                    scope = courseChange.scope,
+                                    school = courseChange.school,
+                                    creatorId = courseChange.creatorId,
+                                    stulist = new List<string> { list },
+                                    pk = "StuCourse"
+                                };
+                                await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(course, new PartitionKey(course.code));
+                            }
+                        }
+                    }
                 }
-                foreach (var delStu in delStudents)
-                {
-                    await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(courseChange.id, new PartitionKey($"Course-{courseChange.school}-{delStu.id}"));
+
+                foreach (var delCls in courseChange.delClass) {
+                    (List<string> delTmdidsCls, List<Students> delStudentsCls) = await TriggerStuActivity.GetStuList(client, _dingDing, new List<string> { delCls }, courseChange.school);
+                    foreach (var stu in delStudentsCls)
+                    {
+                        try
+                        {
+                            ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
+                           
+                            if (stuCourse.Value.classId.Contains(delCls))
+                            {
+                                stuCourse.Value.classId.Remove(delCls);
+                            }
+
+                            if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
+                            {
+                                //当两个列表都不存在时则直接删除
+                                await client.GetContainer("TEAMModelOS", "Student").DeleteItemAsync<StuCourse>( courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
+                            }
+                            else {
+                                await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
+                            }
+                           
+                        }
+                        catch (CosmosException ex)
+                        {
+                            
+                        }
+                    }
+                    foreach (var tmd in delTmdidsCls)
+                    {
+                        try
+                        {
+                            ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
+
+                            if (stuCourse.Value.classId.Contains(delCls))
+                            {
+                                stuCourse.Value.classId.Remove(delCls);
+                            }
+
+                            if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
+                            {
+                                //当两个列表都不存在时则直接删除
+                                await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
+                            }
+                            else
+                            {
+                                await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
+                            }
+
+                        }
+                        catch (CosmosException ex)
+                        {
+
+                        }
+                    }
                 }
-                foreach (var delTmd in delTmdids)
+                foreach (var delList in courseChange.delList)
                 {
-                    await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(courseChange.id, new PartitionKey($"Course-{delTmd}"));
+                    (List<string> delTmdidsCls, List<Students> delStudentsCls) = await TriggerStuActivity.GetStuList(client, _dingDing, new List<string> { delList }, courseChange.school);
+                    foreach (var stu in delStudentsCls)
+                    {
+                        try
+                        {
+                            ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
+
+                            if (stuCourse.Value.stulist.Contains(delList))
+                            {
+                                stuCourse.Value.stulist.Remove(delList);
+                            }
+
+                            if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
+                            {
+                                //当两个列表都不存在时则直接删除
+                                await client.GetContainer("TEAMModelOS", "Student").DeleteItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
+                            }
+                            else
+                            {
+                                await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
+                            }
+
+                        }
+                        catch (CosmosException ex)
+                        {
+
+                        }
+                    }
+                    foreach (var tmd in delTmdidsCls)
+                    {
+                        try
+                        {
+                            ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
+
+                            if (stuCourse.Value.stulist.Contains(delList))
+                            {
+                                stuCourse.Value.stulist.Remove(delList);
+                            }
+
+                            if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
+                            {
+                                //当两个列表都不存在时则直接删除
+                                await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
+                            }
+                            else
+                            {
+                                await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
+                            }
+
+                        }
+                        catch (CosmosException ex)
+                        {
+
+                        }
+                    }
                 }
+
+                ////根据新增名单获取 新增的学生id 及timdid
+                //(List<string> addTmdids, List<Students> addStudents) = await TriggerStuActivity.GetStuList(client, _dingDing, courseChange.addList, courseChange.school);
+                ////根据删除名单获取 新增的学生id 及timdid
+                //(List<string> delTmdids, List<Students> delStudents) = await TriggerStuActivity.GetStuList(client, _dingDing, courseChange.delList, courseChange.school);
+                //foreach (var addStu in addStudents)
+                //{
+                //    var course = new StuCourse
+                //    {
+                //        id = courseChange.id,
+                //        scode = courseChange.code,
+                //        name = courseChange.name,
+                //        code = $"StuCourse-{courseChange.school}-{addStu.id}",
+                //        scope = courseChange.scope,
+                //        school = courseChange.school,
+                //        creatorId = courseChange.creatorId,
+                //        pk = "StuCourse"
+                //    };
+                //    await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(course, new PartitionKey(course.code));
+                //}
+                //foreach (var addTmd in addTmdids)
+                //{
+                //    var course = new StuCourse
+                //    {
+                //        id = courseChange.id,
+                //        scode = courseChange.code,
+                //        name = courseChange.name,
+                //        code = $"StuCourse-{addTmd}",
+                //        scope = courseChange.scope,
+                //        //school = courseChange.school,
+                //        creatorId = courseChange.creatorId,
+                //        pk = "StuCourse"
+                //    };
+                //    await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(course, new PartitionKey(course.code));
+                //}
+                //foreach (var delStu in delStudents)
+                //{
+                //    await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(courseChange.id, new PartitionKey($"Course-{courseChange.school}-{delStu.id}"));
+                //}
+                //foreach (var delTmd in delTmdids)
+                //{
+                //    await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(courseChange.id, new PartitionKey($"Course-{delTmd}"));
+                //}
             }
             catch (Exception ex)
             {

+ 10 - 2
TEAMModelOS.SDK/Models/Cosmos/Common/Inner/CourseChange.cs

@@ -9,11 +9,19 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// <summary>
         /// 新增的名单
         /// </summary>
-        public List<string> addList { get; set; }
+        public List<string> addList { get; set; } = new List<string>();
+        /// <summary>
+        /// 新增的行政班
+        /// </summary>
+        public List<string> addClass { get; set; } = new List<string>();
         /// <summary>
         /// 移除的名单
         /// </summary>
-        public List<string> delList { get; set; }
+        public List<string> delList { get; set; } = new List<string>();
+        /// <summary>
+        /// 移除的行政班
+        /// </summary>
+        public List<string> delClass { get; set; } = new List<string>();
         public string id { get; set; }
         public string code { get; set; }
         public string name { get; set; }

+ 18 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/StuCourse.cs

@@ -15,9 +15,27 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// 课程的分区键课程Code
         /// </summary>
         public string scode { get; set; } 
+        /// <summary>
+        ///课程名称
+        /// </summary>
         public string name { get; set; }
         public  string scope { get; set; }
+        /// <summary>
+        /// 学校
+        /// </summary>
         public string school { get; set; }
+        /// <summary>
+        /// 创建者
+        /// </summary>
         public string creatorId { get; set; }
+
+        /// <summary>
+        /// 行政班  数组方式 是为了解决 同一个课程,多个编辑或者名单中有重复的学生。
+        /// </summary>
+        public List<string> classId { get; set; } = new List<string>();
+        /// <summary>
+        /// 自定义名单
+        /// </summary>
+        public List<string> stulist { get; set; } = new List<string>();
     }
 }

+ 2 - 2
TEAMModelOS.SDK/Models/Cosmos/School/Course.cs

@@ -78,7 +78,7 @@ namespace TEAMModelOS.SDK.Models
         /// 自定义名单
         /// </summary>
         public string stulist { get; set; }
-        public List<timeInfo> time { get; set; } = new List<timeInfo>();
+        public List<TimeInfo> time { get; set; } = new List<TimeInfo>();
         public string notice { get; set; }
 
     }
@@ -92,7 +92,7 @@ namespace TEAMModelOS.SDK.Models
         public string code { get; set; }
 
     }
-    public class timeInfo
+    public class TimeInfo
     {
         public string id { get; set; }
         public string week { get; set; }

+ 8 - 248
TEAMModelOS/Controllers/School/CourseController.cs

@@ -61,10 +61,10 @@ namespace TEAMModelOS.Controllers
             try
             {
                 Course course = new Course();
-                if (!requert.TryGetProperty("course", out JsonElement room)) return BadRequest();
+                if (!requert.TryGetProperty("course", out JsonElement _course)) return BadRequest();
                 if (!requert.TryGetProperty("option", out JsonElement option)) return BadRequest();
                 if (!requert.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
-                course = room.ToObject<Course>();
+                course = _course.ToObject<Course>();
                 var client = _azureCosmos.GetCosmosClient();
                 course.pk = typeof(Course).Name;
                 string code = course.code;
@@ -741,36 +741,6 @@ namespace TEAMModelOS.Controllers
                 var client = _azureCosmos.GetCosmosClient();
                 if (scope.ToString().Equals("school"))
                 {
-                    /*List<CourseManagement> managements = new List<CourseManagement>();
-                    await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select value(c) from c join A0 in c.courses where A0.course.id = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CourseManagement-{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())
-                            {
-                                managements.Add(obj.ToObject<CourseManagement>());
-                            }
-                        }
-                    }
-
-                    for (int i = 0; i < managements.Count; i++)
-                    {
-                        bool flag = false;
-                        for (int j = 0; j < managements[i].courses.Count; j++)
-                        {
-                            if (!managements[i].courses[j].course.id.Equals(id.ToString()))
-                            {
-                                flag = true;
-                                managements[i].courses.Remove(managements[i].courses[j]);
-                                break;
-                            }
-                        }
-                        if (flag)
-                        {
-                            await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(managements[i], managements[i].id, new PartitionKey($"{managements[i].code}"));
-                        }
-                    }*/
                     await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Course-{code}"));
                 }
                 else
@@ -802,28 +772,9 @@ namespace TEAMModelOS.Controllers
                                 if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();*/
                 var client = _azureCosmos.GetCosmosClient();
                 if (request == null) return BadRequest();
-                /*                StringBuilder sql = new StringBuilder();
-                                sql.Append("select value(c) from c ");*/
-                /*Dictionary<string, object> dict = new Dictionary<string, object>();
-                //处理id
-                if (request.ids.IsNotEmpty())
-                {
-                    dict.Add("id", request.ids.ToArray());
-                }*/
+               
                 string school_code = request.code;
-                /*AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
-                List<Course> courses = new List<Course>();
-                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school_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())
-                        {
-                            courses.Add(obj.ToObject<Course>());
-                        }
-                    }
-                }*/
+               
                 if (request.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
                 {
                     List<Response> res = await client.GetContainer("TEAMModelOS", "School").DeleteItemsStreamAsync(request.ids, $"Course-{school_code}");
@@ -833,54 +784,6 @@ namespace TEAMModelOS.Controllers
                     List<Response> res = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemsStreamAsync(request.ids, $"Course-{school_code}");
                 }
 
-                // TODO JJ调整批量删除
-                //await _azureCosmos.DeleteAll(courses);
-                //List<IdPk> idPk = await _azureCosmos.DeleteAll<Course>(request);
-                //await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Class-{code}"));
-                //[Jeff] CourseManagement表廢除 刪除預定:以下CourseManagement更新程序
-                /*StringBuilder sqlM = new StringBuilder();
-                sqlM.Append("select value(c) from c ");
-                Dictionary<string, object> dict_management = new Dictionary<string, object>();
-                //处理ID
-                if (request.ids.IsNotEmpty())
-                {
-                    dict_management.Add("courses[*].course.id", request.ids.ToArray());
-                }
-                List<CourseManagement> managements = new List<CourseManagement>();
-                AzureCosmosQuery cosmosDbQuery_1 = SQLHelper.GetSQL(dict_management, sqlM);
-                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery_1.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CourseManagement-{school_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())
-                        {
-                            managements.Add(obj.ToObject<CourseManagement>());
-                        }
-                    }
-                }
-
-                for (int i = 0; i < managements.Count; i++)
-                {
-                    bool flag = false;
-                    for (int k = 0; k < request.ids.Count; k++)
-                    {
-                        for (int j = 0; j < managements[i].courses.Count; j++)
-                        {
-                            if (managements[i].courses[j].course.id.Equals(request.ids[k].ToString()))
-                            {
-                                managements[i].courses.Remove(managements[i].courses[j]);
-                                flag = true;
-                            }
-                        }
-                    }
-                    if (flag)
-                    {
-                        await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(managements[i], managements[i].id, new PartitionKey($"{managements[i].code}"));
-                    }
-                }*/
-                ////[Jeff] CourseManagement表廢除 刪除預定:以下CourseManagement更新程序
-                //IdPk idPk=  await _azureCosmos.DeleteAsync<Course>(request);
                 return Ok(new { ids = request.ids });
             }
             catch (Exception ex)
@@ -888,12 +791,6 @@ namespace TEAMModelOS.Controllers
                 await _dingDing.SendBotMsg($"CN,{_option.Location},course/delete()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
-
-
-
-            //ResponseBuilder builder = ResponseBuilder.custom();
-            //return builder.Data(idPk).build();
-            //return Ok(new { idPk });
         }
 
         /// <summary>
@@ -919,20 +816,12 @@ namespace TEAMModelOS.Controllers
                 var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(requert.id, new PartitionKey($"CourseManagement-{code}"));
                 if (response.Status == 200)
                 {
-                    /*                    using var json = await JsonDocument.ParseAsync(response.ContentStream);
-                                        CourseManagement courseManagement = json.ToObject<CourseManagement>();
-                                        courseManagement.courses = requert.courses;*/
-                    //return Ok(new { error = ResponseCode.DATA_EXIST, V = "课程编码已经存在!" });
                     course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync(requert, requert.id, new PartitionKey($"CourseManagement-{code}"));
-
                 }
                 else
                 {
                     course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(requert, new PartitionKey($"CourseManagement-{code}"));
-
                 }
-
-
                 return Ok(new { course });
             }
             catch (Exception ex)
@@ -982,43 +871,7 @@ namespace TEAMModelOS.Controllers
                     }
                 }
             }
-            /* List<object> courses = new List<object>();
-             var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(id.ToString(), new PartitionKey($"CourseManagement-{code}"));
-             if (response.Status == 200)
-             {
-                 using var json = await JsonDocument.ParseAsync(response.ContentStream);
-                 foreach (var obj in json.RootElement.GetProperty("courseSimples").EnumerateArray())
-                 {
-                     courses.Add(obj.ToObject<object>());
-                 }
-                 *//*if (json.RootElement.TryGetProperty("courseSimples", out JsonElement value))
-                 {
-                     courses = (List<object>)value.ToObject<object>();
-                 }*//*
-             }
-             else {
-                 return Ok(new { error = ResponseCode.UNDEFINED, V = "数据未找到!" });
-             }*/
             return Ok(new { courses });
-            /* var query = $"select c.code,c.id,c.name,c.period,c.subject,c.teachers from c";
-             await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school_code.GetString()}") }))
-             {
-                 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())
-                     {
-                         courses.Add(obj.ToObject<object>());
-                     }
-                 }
-             }*/
-            //return Ok(new { courses, courses.Count });
-
-            /* List<Course> data = new List<Course>();
-             if (StringHelper.getKeyCount(request) > 0) {
-                 data = await _azureCosmos.FindByDict<Course>(request);
-             }
-             return builder.Data(data).Extend(new Dictionary<string, object> { { "count", data.Count } }).build();*/
         }
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "Teacher")]
@@ -1140,20 +993,7 @@ namespace TEAMModelOS.Controllers
             Teachers teachers = teacherInfo.ToObject<Teachers>();
             var client = _azureCosmos.GetCosmosClient();
             List<CourseManagement> courseManagements = new List<CourseManagement>();
-            /*var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
-            if (sresponse.Status == 200)
-            {
-                using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
-                CourseManagement course = json.ToObject<CourseManagement>();
-                for (int i =0; i < course.courses.Count;i++) {
-                    if (course.courses[i].course.id.Equals(courseId.ToString())) {
-                        course.courses[i].course.notice = notice.ToString();
-                        await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(course, course.id, new PartitionKey($"{course.code}"));
-                        break;
-                    }                  
-                }                
-
-            }*/
+            
             StringBuilder sql = new StringBuilder();
             sql.Append("select value(c) from c");
             Dictionary<string, object> dict = new Dictionary<string, object>();
@@ -1187,54 +1027,9 @@ namespace TEAMModelOS.Controllers
             }
             return Ok(new { id });
         }
-        internal class valitime
-        {
-            public string code { get; set; }
-            public string courseId { get; set; }
-            public string classroomCode { get; set; }
-            public string time { get; set; }
-            public string day { get; set; }
-            public string notice { get; set; }
-            public CourseTime courseTime { get; set; }
-            /// <summary>
-            /// 学生分组
-            /// </summary>
-            public List<GroupStudent> groups { get; set; }
-            /// <summary>
-            /// 助教
-            /// </summary>
-            public List<Assistant> assistant { get; set; }
-            /// <summary>
-            /// 学期代码
-            /// </summary>
-            public string semesterCode { get; set; }
-        }
-
-        // TODO 前端没在用
+         
 
-        /// <summary>
-        /// 教师更新副属信息,助教,分组等。
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        //[ProducesDefaultResponseType]
-        ////[AuthToken(Roles = "Teacher")]
-        //[HttpPost("upsert-plan")]
-        //public async Task<BaseResponse> UpsertPlan(CoursePlan request) {
-        //    ResponseBuilder builder = ResponseBuilder.custom();
-        //    CoursePlan datas = await _azureCosmos.FindByIdPk<CoursePlan>(request.id,request.code);
-        //    if (datas!=null) {
-        //        request.semesterCode = datas.semesterCode;
-        //        request.classes.ForEach(x => {
-        //            datas.classes.ForEach(m => { 
-        //            if (m.classroomCode == x.classroomCode) {
-        //                x.courseTimes = m.courseTimes;
-        //            } }); 
-        //        });
-        //        await _azureCosmos.Update(request);
-        //    }
-        //    return builder.Data(request).build();
-        //}
+        
 
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "Teacher")]
@@ -1517,42 +1312,7 @@ namespace TEAMModelOS.Controllers
             //courses = courses.Distinct().ToList();
             return Ok(new { courses});          
         }
-
-        // TODO 前端没在用
-
-        /// <summary>
-        /// 删除课程安排
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        //[ProducesDefaultResponseType]
-        ////[AuthToken(Roles = "Teacher")]
-        //[HttpPost("delete-time")]
-        //public async Task<BaseResponse> DeletePlan(JsonElement request)
-        //{
-        //    ResponseBuilder builder = ResponseBuilder.custom();
-        //    if (request.TryGetProperty("id",out JsonElement id) && request.TryGetProperty("code",out JsonElement code) && request.TryGetProperty("classroomCode",out JsonElement classroomCode) 
-        //        && request.TryGetProperty("time",out JsonElement time) && request.TryGetProperty("day",out JsonElement day)) {
-        //        CoursePlan coursePlan = await _azureCosmos.FindByIdPk<CoursePlan>(id.ToString(), code.ToString());
-        //        List<CourseTime> courseTimes = new List<CourseTime>();
-        //        coursePlan.classes.ForEach(x=> {
-        //            if (x.classroomCode == classroomCode.ToString()) {
-        //                x.courseTimes.ForEach(y => {
-        //                    if (y.time == time.ToString() && y.day == day.ToString())
-        //                    {
-        //                        courseTimes.Add(y);
-        //                    }
-        //                });
-        //            }
-        //        });
-        //       coursePlan.classes.ForEach(x => { if (x.classroomCode == classroomCode.ToString()) {
-        //               courseTimes.ForEach(y => { x.courseTimes.Remove(y); });
-        //           } });
-        //       await _azureCosmos.Update(coursePlan);
-        //        return builder.Data(coursePlan).build();
-        //    }
-        //    return builder.Data(null).build();
-        //}
+         
 
         public class Student
         {

+ 33 - 3
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -72,7 +72,38 @@ namespace TEAMModelOS.Controllers.XTest
             
         }
 
-
+        /// <summary>
+        /// 测试redis通配符
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpGet("test-delete-read")]
+        public async Task<IActionResult> TestDelete() {
+            var client = _azureCosmos.GetCosmosClient();
+            string aaa = "0";
+            try { 
+                ItemResponse<Student> a = await client.GetContainer("TEAMModelOS", "Student").DeleteItemAsync<Student>("1111111", new PartitionKey($"Course-111111"));
+                Ok(a.GetRawResponse().Status);
+            } catch (CosmosException ex) {
+                if (ex.Response.Status == 404) {
+                    aaa = "404";
+                }
+            }
+            try
+            {
+                ItemResponse<Student> a = await client.GetContainer("TEAMModelOS", "Student").ReadItemAsync<Student>("1111111", new PartitionKey($"Course-111111"));
+                Ok(a.GetRawResponse().Status);
+            }
+            catch (CosmosException ex)
+            {
+                if (ex.Response.Status == 404)
+                {
+                    aaa = aaa+ " 404";
+                }
+            }
+            return Ok(new { aaa });
+        }
         /// <summary>
         /// 测试redis通配符
         /// </summary>
@@ -81,8 +112,7 @@ namespace TEAMModelOS.Controllers.XTest
         [ProducesDefaultResponseType]
         [HttpGet("test-redis")]
         public async Task<IActionResult> TestRedis( ) {
-
-
+            
             try
             {
                 var client = _azureCosmos.GetCosmosClient();