CrazyIter_Bin 3 anni fa
parent
commit
e72540f27d

+ 0 - 48
TEAMModelOS.SDK/Models/Cosmos/Student/Parent.cs

@@ -1,48 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace TEAMModelOS.SDK.Models
-{
-    public class Parent : CosmosEntity
-    {
-        // id = tmdid
-        // code = "Base-Parent"
-
-        //绑定信息的key(手机号,邮箱,醍摩豆id)
-        
-        //姓名 姓名
-        public string name { get; set; }
-        //监护人:父亲,母亲,或者其他监护人
-        public string identity { get; set; }
-        /// <summary>
-        /// 头像
-        /// </summary>
-        public string picture { get; set; }
-        public string tmdid { get; set; }
-        public string mobile { get; set; }
-        public string mail { get; set; }
-    }
-    public class ParentChildren
-    {
-        /// <summary>
-        ///类型 1 tmdid,2 student
-        /// </summary>
-        public int type { get; set; }
-        public  string id { get; set; }
-        /// <summary>
-        /// 头像
-        /// </summary>
-        public string picture { get; set; }
-        /// <summary>
-        /// 名称
-        /// </summary>
-        public string name { get; set; }
-        /// <summary>
-        /// 学生所在的学校
-        /// </summary>
-        public string code { get; set; }
-    }
-}

+ 43 - 8
TEAMModelOS.SDK/Models/Cosmos/Student/Student.cs

@@ -41,16 +41,19 @@ namespace TEAMModelOS.SDK.Models
         /// 创建时间  十位 时间戳
         /// </summary>
         public long createTime { get; set; }
-        //public List<StudentParent> parents { get; set; }= new List<StudentParent>();
+        public List<StudentGuardian> guardians { get; set; }= new List<StudentGuardian>();
     }
-    public class Guardian
+    public class Guardian : CosmosEntity
     {
+        // id = tmdid
+        // code = "Base-Guardian"
+
         //绑定信息的key(手机号,邮箱,醍摩豆id)
-       // public List<BindKey> bindKey { get; set; } = new List<BindKey>();
+
         //姓名 姓名
         public string name { get; set; }
         //监护人:父亲,母亲,或者其他监护人
-        public string identity { get; set; }
+
         /// <summary>
         /// 头像
         /// </summary>
@@ -58,12 +61,44 @@ namespace TEAMModelOS.SDK.Models
         public string tmdid { get; set; }
         public string mobile { get; set; }
         public string mail { get; set; }
+        public List<GuardianStudent> students { get; set; } = new List<GuardianStudent>();
 
     }
-    public class BindKey
+    public class GuardianStudent
     {
-        // key(手机号,邮箱,醍摩豆id,Line,Google等信息)
-        public string key { get; set; }
-        public string type { get; set; }
+        public string relation { get; set; }
+        /// <summary>
+        ///类型 1 tmdid,2 student
+        /// </summary>
+        public int type { get; set; }
+        public string id { get; set; }
+        /// <summary>
+        /// 头像
+        /// </summary>
+        public string picture { get; set; }
+        /// <summary>
+        /// 名称
+        /// </summary>
+        public string name { get; set; }
+        /// <summary>
+        /// 学生所在的学校
+        /// </summary>
+        public string code { get; set; }
+    }
+    public class StudentGuardian
+    {
+        //绑定信息的key(手机号,邮箱,醍摩豆id)
+       // public List<BindKey> bindKey { get; set; } = new List<BindKey>();
+        //姓名 姓名
+        public string name { get; set; }
+        //监护人:父亲,母亲,或者其他监护人
+        public string relation { get; set; }
+        /// <summary>
+        /// 头像
+        /// </summary>
+        public string picture { get; set; }
+        public string tmdid { get; set; }
+        public string mobile { get; set; }
+        public string mail { get; set; }
     }
 }

+ 19 - 6
TEAMModelOS.SDK/Models/Service/StudentService.cs

@@ -478,7 +478,7 @@ namespace TEAMModelOS.SDK
         /// <param name="schoolId"></param>
         /// <param name="students"></param>
         /// <returns></returns>
-        private static (Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear)> studs,
+        private static (Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear, string guardian, string gName, string gPhone)> studs,
             Dictionary<string, (string className, string periodId, int year, string no)> classInfo,
             Dictionary<string, List<(string id, string no)>> classStudNo,
             List<string> errorYear,
@@ -487,8 +487,8 @@ namespace TEAMModelOS.SDK
             //批量匯入 檢查輸入數據 確認座號 確認教室(創建教室) 確認學生存不存在或是要不要更新
 
             //存放輸入的學生資訊 key:stud id value:學生詳細資料
-            Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear)> dicStuds =
-                new Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear)>();
+            Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear,   string guardian, string gName, string gPhone) > dicStuds =
+                new Dictionary<string, (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear, string guardian, string gName, string gPhone)>();
 
             //存放教室資訊用 key:classNo value:className
             Dictionary<string, (string className, string periodId, int year, string classNo)> dicClassInfo = new Dictionary<string, (string className, string periodId, int year, string classNo)>();
@@ -524,7 +524,7 @@ namespace TEAMModelOS.SDK
                         dicStuds.Remove(id);
                     }
 
-                    (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear) studentInfo = (null, null, 0, null, null, null, null, null, 0);
+                    (string name, string no, int year, string salt, string pw, string classNo, string className, string periodId, int classYear,string guardian,string gName,string gPhone) studentInfo = (null, null, 0, null, null, null, null, null, 0,null,null, null);
 
                     if (student.TryGetProperty("name", out var tmpName) && !string.IsNullOrWhiteSpace(tmpName.GetString())) studentInfo.name = tmpName.GetString();
 
@@ -577,8 +577,13 @@ namespace TEAMModelOS.SDK
                         }
                     }
 
-
-
+                    if (student.TryGetProperty("guardian", out var guardian) && !string.IsNullOrWhiteSpace($"{guardian}")) {
+                        studentInfo.guardian =$"{guardian}";
+                        student.TryGetProperty("gName", out var gName);
+                        student.TryGetProperty("gPhone", out var gPhone);
+                        studentInfo.gName = $"{gName}";
+                        studentInfo.gPhone = $"{gPhone}";
+                    }
                     //將最後結果加到字典內
                     dicStuds.Add(id, studentInfo);
                 }
@@ -787,6 +792,14 @@ namespace TEAMModelOS.SDK
                     };
                     writerNew.WriteNull("groupId");
                     writerNew.WriteNull("groupName");
+                    ///写入监护人
+                    writerNew.WriteStartArray("guardians");
+                    writerNew.WriteStartObject();
+                    writerNew.WriteString("relation", stud.Value.guardian);
+                    writerNew.WriteString("name", stud.Value.gName);
+                    writerNew.WriteString("mobile", stud.Value.gPhone);
+                    writerNew.WriteEndObject();
+                    writerNew.WriteEndArray();
 
                     writerNew.WriteEndObject();
                     writerNew.Flush();

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

@@ -894,10 +894,11 @@ namespace TEAMModelOS.Controllers
         [Authorize(Roles = "IES")]
         public async Task<IActionResult> RmvSchoolTeacher(JsonElement request)
         {
+            if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
             try
             {
                 var (tid, tname, _, tschool) = HttpContext.GetAuthTokenInfo();
-                if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
+             
                 request.TryGetProperty("id", out JsonElement id);
                 request.TryGetProperty("name", out JsonElement name);
                 var client = _azureCosmos.GetCosmosClient();
@@ -995,6 +996,22 @@ namespace TEAMModelOS.Controllers
             {
                 return BadRequest();
             }
+            finally {
+                Azure.Response   schoolRes = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{school_code}", new PartitionKey("Base"));
+                if (schoolRes.Status==200)
+                {
+                    School school = JsonDocument.Parse(schoolRes.Content).RootElement.Deserialize<School>();
+                    string sql = "select  sum(c.size ) from c  ";
+                    int teachSize = 0;
+                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<int>(queryText: sql,
+                        requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school_code}") }))
+                    {
+                        teachSize += item;
+                    }
+                    school.tsize = teachSize;
+                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey("Base"));
+                }
+            }
         }
 
         /// <summary>