Bläddra i källkod

學生帳號 回收AClassOne API
#290

jeff 4 år sedan
förälder
incheckning
8f43f4b32a

+ 28 - 1
TEAMModelOS.SDK/Models/Cosmos/School/Class.cs

@@ -17,6 +17,7 @@ namespace TEAMModelOS.SDK.Models
             pk = "Class";
             teacher = new Teachers();
             students = new List<StudentSimple>();
+            courses = new List<coursesInClass>();
         }
         /// <summary>
         /// 教室编号
@@ -32,6 +33,7 @@ namespace TEAMModelOS.SDK.Models
         public string sn { get; set; }
 
         public List<StudentSimple> students { get; set; }
+        public List<coursesInClass> courses { get; set; }
         /// <summary>
         /// TBL IRS 类型区分
         /// </summary>
@@ -63,4 +65,29 @@ public class StudentSimple
 
     public string groupId { get; set; }
     public string groupName { get; set; }
-}
+}
+
+//[JEFF] 指定某班級某課程由某位老師授課時用欄位
+/// <summary>
+/// 該班級排定的課程
+/// </summary>
+public class coursesInClass
+{
+    public courseAtcoursesInClass course { get; set; } //課程資訊
+    public List<Teachers> teachers { get; set; } //老師資訊(複數)
+}
+
+public class courseAtcoursesInClass
+{
+    public string id { get; set; } //課程ID
+    public string name { get; set; } //課程名稱
+    public string notice { get; set; } //公告
+}
+
+public class Teachers
+{
+    public string id { get; set; }
+    public string name { get; set; }
+}
+////[JEFF] 指定某班級某課程由某位老師授課時用欄位
+

+ 11 - 0
TEAMModelOS.SDK/Models/Cosmos/School/Course.cs

@@ -17,6 +17,7 @@ namespace TEAMModelOS.SDK.Models
             subject = new SubjectSimple();
             period = new PeriodSimple();
             teachers = new List<Teachers>();
+            classes = new List<classesInCourse>();
         }        
         /// <summary>
         /// 课程名称
@@ -44,6 +45,7 @@ namespace TEAMModelOS.SDK.Models
         /// 任课教师范围
         /// </summary>
         public List<Teachers> teachers { get; set; }
+        public List<classesInCourse> classes { get; set; }
         public string scope { get; set; }
         public string notice { get; set; }
 
@@ -65,4 +67,13 @@ namespace TEAMModelOS.SDK.Models
         public string id { get; set; }
         public string name { get; set; }
     }
+
+    //[JEFF] 指定某班級某課程由某位老師授課時用欄位
+    public class classesInCourse
+    {
+        public string id { get; set; } //班級ID
+        public string name { get; set; } //班級名稱
+        public List<Teachers> teachers { get; set; } //老師資訊(複數)
+    }
+    ////[JEFF] 指定某班級某課程由某位老師授課時用欄位
 }

+ 5 - 0
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -252,6 +252,11 @@ namespace TEAMModelOS.Controllers.Client
                 }
 
                 List<object> courses = new List<object>(); //老師被安排的課程列表
+
+
+
+
+                
                 var query = $"SELECT c.id, c.name, c.teacher, cc.course, c.scope FROM c JOIN cc IN c.courses JOIN cct IN cc.teachers WHERE cct.id = '{id}'";
                 await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CourseManagement-{school_code}") }))
                 {

+ 7 - 2
TEAMModelOS/Controllers/School/ClassRoomController.cs

@@ -151,10 +151,15 @@ namespace TEAMModelOS.Controllers
                             if (flag)
                             {
                                 await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(course[i], course[i].id, new PartitionKey($"{course[i].code}"));
+                            
                             }
                         }
                         //string code = classroom.code.Substring(classroom.pk.Length + 1);
-                        //[Jeff] CourseManagement表廢除 刪除預定:以下CourseManagement更新程序
+
+                        //[Jeff] 若Course中的classes.id相同,且name或teachers不同 => 更新
+
+
+                        //[Jeff] CourseManagement表廢除
                         var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(classroom.id, new PartitionKey($"CourseManagement-{school_code}"));
                         if (sresponse.Status == 200)
                         {
@@ -172,7 +177,7 @@ namespace TEAMModelOS.Controllers
                                 await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(classroom1, classroom1.id, new PartitionKey($"{classroom1.code}"));
                             }
                         }
-                        ////[Jeff] CourseManagement表廢除 刪除預定:以下CourseManagement更新程序
+                        ////[Jeff] CourseManagement表廢除 
                         classroom = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync(classroom, classroom.id, new PartitionKey($"Class-{school_code}"));
                     }
 

+ 88 - 0
TEAMModelOS/Controllers/School/SchoolController.cs

@@ -901,5 +901,93 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
             }
         }
+
+        /// <summary>
+        /// 回收某學校AClassOne固定分配、動態分配授權學生
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("recall-school-aclasson")]
+        public async Task<IActionResult> RecallSchoolAclassone(JsonElement request)
+        {
+            if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
+            string action = "all"; //預設回收:固定及動態均回收  sta:回收固定 dync:回收動態
+            if (request.TryGetProperty("mode", out JsonElement mode))
+            {
+                if(mode.GetString() == "sta" || mode.GetString() == "dync")
+                {
+                    action = mode.GetString();
+                }
+            }
+            int status = 0;
+            string err = "";
+            var redisClient = _azureRedis.GetRedisClient(8);
+            string keys = school_code.GetString() + ":" + "AclassOne" + ":" + "dynamic";
+            string keyd = school_code.GetString() + ":" + "AclassOne" + ":" + "dynamicIds";
+            var clientContainer = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School");
+            var response = await clientContainer.ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Product"));
+            if (response.Status == 200)
+            {
+                int total = 0; //(回傳值)可分配總數
+                int staNum = 0; //(回傳值)固定分配數
+                int dyncNum = 0; //(回傳值)動態分配數
+                List<string> staIds = new List<string>(); //(回傳值)固定學生ID列
+                List<string> dyncIds = new List<string>(); //(回傳值)動態學生ID列
+                using (Stream stream = response.ContentStream)
+                {
+                    using (StreamReader streamReader = new StreamReader(stream))
+                    {
+                        string content = streamReader.ReadToEnd();
+                        SchoolProduct schoolProduct = System.Text.Json.JsonSerializer.Deserialize<SchoolProduct>(content);
+                        if (schoolProduct.aclassone != null) //有AClassOne產品授權,schoolProduct.aclassone不會為null
+                        {
+                            total = schoolProduct.aclassone.total;
+                            staNum = schoolProduct.aclassone.used;
+                            staIds = schoolProduct.aclassone.ids;
+                            dyncNum = (int)GetSchoolDynamicAclassOneIDCount(school_code.GetString());
+                            dyncIds = GetSchoolDynamicAclassOneIDList(school_code.GetString());
+                            switch (action)
+                            {
+                                case "sta":
+                                    staIds = schoolProduct.aclassone.ids = new List<string>();
+                                    staNum = schoolProduct.aclassone.used = 0;
+                                    await clientContainer.ReplaceItemAsync<SchoolProduct>(schoolProduct, schoolProduct.id, new PartitionKey("Product"));
+                                    int updDynAclassCount = (total - dyncNum > 0) ? total - dyncNum : 0;
+                                    redisClient.StringSet(keys, updDynAclassCount);
+                                    break;
+                                case "dync": //動態回收
+                                    dyncNum = total - staNum;
+                                    dyncIds = new List<string>();
+                                    redisClient.StringSet(keys, dyncNum);
+                                    redisClient.KeyDelete(keyd);
+                                    break;
+                                case "all": //全回收
+                                    staIds = schoolProduct.aclassone.ids = new List<string>();
+                                    staNum = schoolProduct.aclassone.used = 0;
+                                    await clientContainer.ReplaceItemAsync<SchoolProduct>(schoolProduct, schoolProduct.id, new PartitionKey("Product"));
+                                    dyncNum = total;
+                                    dyncIds = new List<string>();
+                                    redisClient.StringSet(keys, dyncNum);
+                                    redisClient.KeyDelete(keyd);
+                                    break;
+                            }
+                            return Ok(new { status, err, total, staNum, dyncNum, staIds, dyncIds });
+                        }
+                        else
+                        {
+                            status = 1;
+                            err = "AClassOne has no authorization.";
+                            return Ok(new { status, err });
+                        }
+                    }
+                }
+            }
+            else
+            {
+                return BadRequest();
+            }
+
+        }
     }
 }