CrazyIter_Bin 3 lat temu
rodzic
commit
18fca5ffa9

+ 9 - 0
TEAMModelOS.SDK/Models/Cosmos/Student/Student.cs

@@ -6,6 +6,15 @@ using static TEAMModelOS.SDK.Models.Teacher;
 
 namespace TEAMModelOS.SDK.Models
 {
+    public class Imei : CosmosEntity
+    {
+        ///id: 电子学生证id,
+        ///code:"Imei",
+        /// stuid :"学生id"
+        public string stuid { get; set; }
+        /// school :"学校编码"
+        public string school { get; set; }
+    }
     public class Student : CosmosEntity
     {
         public string mail { get; set; }

+ 9 - 12
TEAMModelOS.SDK/Models/Service/GroupListService.cs

@@ -75,7 +75,6 @@ namespace TEAMModelOS.SDK
         public static async Task<List<GroupListGrp>> GetMemberInGroupList(CoreAPIHttpService _coreAPIHttpService, CosmosClient client, DingDing _dingDing, string memberId, int memberType, string school,List<string> groupTypes) {
 
             List<GroupListGrp> groupLists = new List<GroupListGrp>();
-
             if (groupTypes.IsEmpty() || groupTypes.Contains("class")) {
                 if (!string.IsNullOrWhiteSpace(school) && memberType == 2)
                 {
@@ -118,23 +117,23 @@ namespace TEAMModelOS.SDK
             string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount,c.leader ";
             if (groupTypes.IsEmpty() || groupTypes.Contains("teach")) {
                 //教学班
-                StringBuilder teachsql = new StringBuilder();
+                string teachsql="";
                 if (!string.IsNullOrWhiteSpace(school) && memberType == 2) {
-                    teachsql.Append($"SELECT distinct {SummarySql} FROM c join  m  in c.members   where c.type='teach' and  m.id='{memberId}' and m.code='{school}' and m.type=2 ");
+                    teachsql= $"SELECT distinct {SummarySql} FROM c join  m  in c.members   where c.type='teach' and  m.id='{memberId}' and m.code='{school}' and m.type=2 ";
                 }
                 if (memberType == 1)
                 {
-                    teachsql.Append($"SELECT distinct {SummarySql} FROM c join  m  in c.members   where c.type='teach' and  m.id='{memberId}' and m.type=1 ");
+                    teachsql=$"SELECT distinct {SummarySql} FROM c join  m  in c.members   where c.type='teach' and  m.id='{memberId}' and m.type=1 ";
                 }
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
-                    GetItemQueryIterator<GroupList>(queryText: teachsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
+                    GetItemQueryIterator<GroupList>(queryText: teachsql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
                 {
                     HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
                     groupLists.Add(new GroupListGrp(item, groupName));
                 }
                 //个人名单
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).
-                    GetItemQueryIterator<GroupList>(queryText: teachsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList") }))
+                    GetItemQueryIterator<GroupList>(queryText: teachsql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList") }))
                 {
                     HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
                     groupLists.Add(new GroupListGrp(item, groupName));
@@ -144,10 +143,9 @@ namespace TEAMModelOS.SDK
             if (!string.IsNullOrWhiteSpace(school) && (groupTypes.IsEmpty() || groupTypes.Contains("research")))
             {
                 //教研组
-                StringBuilder teachsql = new StringBuilder();
-                teachsql.Append($"SELECT distinct {SummarySql} FROM c join  m  in c.members   where c.type='research' and  m.id='{memberId}' and m.type=1 ");
+                string teachsql = $"SELECT distinct {SummarySql} FROM c join  m  in c.members   where c.type='research' and  m.id='{memberId}' and m.type=1 ";
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
-                    GetItemQueryIterator<GroupList>(queryText: teachsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
+                    GetItemQueryIterator<GroupList>(queryText: teachsql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
                 {
                     HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
                     groupLists.Add(new GroupListGrp(item, groupName));
@@ -156,10 +154,9 @@ namespace TEAMModelOS.SDK
             if (!string.IsNullOrWhiteSpace(school) && (groupTypes.IsEmpty() || groupTypes.Contains("yxtrain")))
             {
                 //研修名单
-                StringBuilder teachsql = new StringBuilder();
-                teachsql.Append($"SELECT distinct {SummarySql} FROM c join  m  in c.members   where c.type='yxtrain' and  m.id='{memberId}' and m.type=1 ");
+                string teachsql = $"SELECT distinct {SummarySql} FROM c join  m  in c.members   where c.type='yxtrain' and  m.id='{memberId}' and m.type=1 ";
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
-                    GetItemQueryIterator<GroupList>(queryText: teachsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
+                    GetItemQueryIterator<GroupList>(queryText: teachsql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
                 {
                     HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
                     groupLists.Add(new GroupListGrp(item, groupName));

+ 35 - 22
TEAMModelOS.SDK/Models/Service/StudentService.cs

@@ -786,14 +786,9 @@ namespace TEAMModelOS.SDK
                         tmpStudInfo.gradeId = classNoId[stud.Value.classNo + "_" + stud.Value.classYear].gradeId;
                         tmpStudInfo.periodId = classNoId[stud.Value.classNo + "_" + stud.Value.classYear].periodId;
                     }
-
-                    if (!string.IsNullOrWhiteSpace(stud.Value.imei))
-                    {
-                        writerNew.WriteString("imei", stud.Value.imei);
-                    }
-                    else {
-                        writerNew.WriteNull("imei");
-                    }
+                    
+                  
+                     
                     if (string.IsNullOrWhiteSpace(stud.Value.no))
                     {
                         writerNew.WriteNull("no");
@@ -819,7 +814,11 @@ namespace TEAMModelOS.SDK
                     
                     writerNew.WriteEndObject();
                     writerNew.Flush();
-
+                    if (!string.IsNullOrWhiteSpace(stud.Value.imei))
+                    {
+                        Imei imei = new Imei { id = stud.Value.imei, code = "Imei", stuid = stud.Key, school = schoolId };
+                        await cosmosContainer.UpsertItemAsync(imei, new PartitionKey($"Imei"));
+                    }
                     var response = await cosmosContainer.CreateItemStreamAsync(memoryStream, new PartitionKey($"Base-{schoolId}"));
 
                     if (response.Status == (int)HttpStatusCode.Created)
@@ -856,10 +855,6 @@ namespace TEAMModelOS.SDK
                             {
                                 student.periodId = stud.Value.periodId;
                             }
-                            if (!string.IsNullOrWhiteSpace(stud.Value.imei))
-                            {
-                                student.imei = stud.Value.imei;
-                            }
                             if (!isUpPwDone)
                             {
                                 student.pw = stud.Value.pw;
@@ -953,8 +948,6 @@ namespace TEAMModelOS.SDK
                 writer.WriteNull("mail");
                 writer.WriteNull("mobile");
                 writer.WriteNull("country");
-                if (string.IsNullOrWhiteSpace(studCreateInfo.imei)) writer.WriteNull("imei");
-                else writer.WriteString("periodId", studCreateInfo.imei);
                 //Password,若沒給則使用學號當密碼
                 string salt = Utils.CreatSaltString(8);
                 string hashPw = string.IsNullOrWhiteSpace(studCreateInfo.pw)
@@ -1000,7 +993,13 @@ namespace TEAMModelOS.SDK
                 }
                 writer.WriteEndObject();
                 writer.Flush();
-
+                if (!string.IsNullOrWhiteSpace(studCreateInfo.imei))
+                {
+                    Imei imei = new Imei { id = studCreateInfo.imei, code = "Imei", stuid = studCreateInfo.id, school = schoolId };
+                    await _azureCosmos
+                                .GetCosmosClient()
+                                .GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(imei, new PartitionKey($"Imei"));
+                }
                 var response = await _azureCosmos
                                 .GetCosmosClient()
                                 .GetContainer(Constant.TEAMModelOS, "Student")
@@ -1255,6 +1254,13 @@ namespace TEAMModelOS.SDK
                 List<(string id, string name, string picture, int year, string no, string periodId, string irs, string imei, List<StudentGuardian> guardians)> notJoinClassStuds = 
                     new List<(string id, string name, string picture, int year, string no, string periodId, string irs, string imei, List<StudentGuardian> guardians)>();
 
+
+                List<Imei> imeis= new List<Imei>();
+                string imeiQueryText = $"SELECT  *  FROM c WHERE c.code = '{schoolId}'";
+                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
+                   .GetItemQueryIterator<Imei>(queryText:imeiQueryText,requestOptions:new QueryRequestOptions { PartitionKey= new PartitionKey("Imei")})){
+                    imeis.Add(item);
+                }
                 string queryText = $"SELECT  *  FROM c WHERE c.code = 'Base-{schoolId}'";
 
                 //回傳用ContinuationToken
@@ -1290,6 +1296,8 @@ namespace TEAMModelOS.SDK
                                     guardians= guardians.FindAll(x => !string.IsNullOrWhiteSpace(x.mobile)) ;
                                 }
                             }
+
+                            var imeiObj= imeis.Find(x => x.stuid.Equals(acc.GetProperty("id").GetString()));
                             if (string.IsNullOrWhiteSpace(classId))
                             {
                                 notJoinClassStuds.Add(
@@ -1301,7 +1309,7 @@ namespace TEAMModelOS.SDK
                                             acc.GetProperty("no").GetString(),
                                             acc.TryGetProperty("periodId", out JsonElement _periodId) && _periodId.ValueKind.Equals(JsonValueKind.String) ? _periodId.GetString() : null,
                                             $"{irs}",
-                                             acc.TryGetProperty("imei", out JsonElement _imei) && _imei.ValueKind.Equals(JsonValueKind.String) ? _imei.GetString() : null,
+                                            imeiObj?.id,//imei
                                             guardians
                                         )
                                     );
@@ -1318,7 +1326,7 @@ namespace TEAMModelOS.SDK
                                                 acc.GetProperty("year").GetInt32(),
                                                 acc.GetProperty("no").GetString(), acc.TryGetProperty("periodId", out JsonElement _periodId) && _periodId.ValueKind.Equals(JsonValueKind.String) ? _periodId.GetString() : null,
                                                 $"{irs}",
-                                                acc.TryGetProperty("imei", out JsonElement _imei) && _imei.ValueKind.Equals(JsonValueKind.String) ? _imei.GetString() : null,
+                                                imeiObj?.id,//imei
                                                 guardians
                                             )
                                         );
@@ -1334,9 +1342,8 @@ namespace TEAMModelOS.SDK
                                                 acc.GetProperty("picture").GetString(),
                                                 acc.GetProperty("year").GetInt32(),
                                                 acc.GetProperty("no").GetString(),  acc.TryGetProperty("periodId",out JsonElement _periodId)&&  _periodId.ValueKind.Equals(JsonValueKind.String) ? _periodId.GetString() : null,
-                                                $"{irs}"
-                                                ,
-                                                acc.TryGetProperty("imei", out JsonElement _imei) && _imei.ValueKind.Equals(JsonValueKind.String) ? _imei.GetString() : null,
+                                                $"{irs}"  ,
+                                                imeiObj?.id,//imei
                                                 guardians
                                             )
                                             }
@@ -2151,7 +2158,13 @@ namespace TEAMModelOS.SDK
                                     
                                     writer.WriteEndObject();
                                     writer.Flush();
-
+                                    if (!string.IsNullOrWhiteSpace(studentInfos[id].imei))
+                                    {
+                                        Imei imei = new Imei { id = studentInfos[id].imei, code = "Imei", stuid = id, school = schoolId };
+                                        await _azureCosmos
+                                                    .GetCosmosClient()
+                                                    .GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(imei, new PartitionKey($"Imei"));
+                                    }
                                     try
                                     {
                                         var ret = await cosmosContainer.ReplaceItemStreamAsync(memoryStream, id, new PartitionKey($"Base-{schoolId}"));