Ver código fonte

Merge branch 'develop6.0-tmd' of http://52.130.252.100:10000/TEAMMODEL/TEAMModelOS into develop6.0-tmd

XW 3 anos atrás
pai
commit
c8d7ce553d

+ 100 - 7
TEAMModelBI/Controllers/Census/ActivitySticsController.cs

@@ -258,7 +258,7 @@ namespace TEAMModelBI.Controllers.Census
                 ActivityCount tempCount = new ActivityCount() { id = school.id, name = school.name != null ? school.name : school.id };
                 foreach (var type in types)
                 {
-                    StringBuilder sqlTxt = new StringBuilder($"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.school='{school.id}' ");                
+                    StringBuilder sqlTxt = new($"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.school='{school.id}' ");                
                     long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "Common" });
 
                     switch (type)
@@ -299,7 +299,15 @@ namespace TEAMModelBI.Controllers.Census
 
             var cosmosClient = _azureCosmos.GetCosmosClient();
             List<RecSchool> schools = new();
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecSchool>(queryText: $"select c.id,c.name,c.picture,c.size,c.scale,c.type from c where c.areaId='{areaId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+
+
+            StringBuilder scSqlTxt = new("select c.id,c.name,c.picture,c.size,c.scale,c.type from c");
+            if (!string.IsNullOrEmpty($"{areaId}"))
+            {
+                scSqlTxt.Append($" where c.areaId='{areaId}'");
+            }
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecSchool>(queryText: scSqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
             {
                 schools.Add(item);
             }
@@ -331,7 +339,7 @@ namespace TEAMModelBI.Controllers.Census
                     heCount += 1;
                 else if (school.type == 1)
                     geCount += 1;
-                else oeCount += 0;
+                else oeCount += 1;
 
                 areaSize += school.size;
 
@@ -387,8 +395,7 @@ namespace TEAMModelBI.Controllers.Census
                 ActivityCount tempActivity = new ActivityCount() { id = school.id, name = school.name != null ? school.name : school.id };
                 foreach (var type in types)
                 {
-                    string sqlTxt = new string($"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.school='{school.id}' ");
-                    long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt, new List<string>() { "Common" });
+                    long totals = await CommonFind.FindTotals(cosmosClient, $"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.school='{school.id}' ", new List<string>() { "Common" });
 
                     string weekSql= $"select count(c.id) as totals from c where c.pk='{type}' and c.school='{school.id}' and c.createTime>={weekStart}   and c.createTime<={weekEnd}";
                     long weekCount = await CommonFind.FindTotals(cosmosClient, weekSql, new List<string>() { "Common" });
@@ -422,6 +429,76 @@ namespace TEAMModelBI.Controllers.Census
             return Ok(new { state = 200, schoolCount = schools.Count, countArea, weekActivity, termActivity, totalTime, appraiseArea, examAreaCount, surveyAreaCount, voteAreaCount, homeworkAreaCount, schools = schoolInfos, schoolLessons });
         }
 
+        /// <summary>
+        /// 所有区的统计接口
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("get-all")]
+        public async Task<IActionResult> GetAll() 
+        {
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+
+            List<AreaInfo> areaInfos = new();
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryIterator<AreaInfo>(queryText: $"select c.id,c.name,c.standard,c.standardName from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
+            {
+                areaInfos.Add(item);
+            }
+
+            var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
+            var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");
+            int heCount = 0;//高教
+            int geCount = 0;//普教
+            int oeCount = 0; //其他教育
+            int allSize = 0;//空间总量
+            Dictionary<string, long> activitys = new(); //活动类型集合
+            long allActivity = 0;  //活动累计
+            long weekActivity = 0;//本周活动
+            long tearActivity = 0;//本学期活动
+            long weekLess = 0;      //本周课例
+            long termLess = 0;     //本学期课例
+            long allLess = 0;     //所有课例
+
+            foreach (var area in areaInfos) 
+            {
+                List<RecSchool> recSchools = new();
+                await foreach (var school in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecSchool>(queryText: $"select c.id,c.name,c.picture,c.type,c.size,c.scale from c where c.areaId='{area.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") })) 
+                {
+                    recSchools.Add(school);
+                }
+
+                recSchools.ForEach(x => { if (x.type == 2) heCount += 1; else if (x.type == 1) geCount += 1; else oeCount += 1; });
+                allSize += recSchools.Select(s => s.size).Sum();
+                area.schoolCount = recSchools.Count;
+                //查教师
+                area.techCount = await CommonFind.GetPeopleNumber(cosmosClient,"School",recSchools?.Select(x=>x.id).ToList(), "Teacher");
+                //查询省
+                area.stuCount = await CommonFind.GetPeopleNumber(cosmosClient, "Student", recSchools?.Select(x => x.id).ToList(), "Base");
+            }
+
+            //统计活动
+            foreach (var type in types)
+            {
+                string sqlTxt = $"select COUNT(c.id) AS totals from c where c.pk='{type}'";
+                long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt, new List<string>() { "Common" });
+
+                string weekSql = $"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.createTime>={weekStart} and c.createTime<={weekStart} ";
+                weekActivity  += await CommonFind.FindTotals(cosmosClient, weekSql,new List<string> { "Common" });
+
+                string termSql = $"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.createTime>={termStart} and c.createTime<={termEnd} ";
+                tearActivity += await CommonFind.FindTotals(cosmosClient, termSql, new List<string> { "Common" });
+
+                allActivity += totals;
+                activitys.Add(type, totals);
+            }
+            
+            allLess = await CommonFind.FindTotals(cosmosClient, "select count(c.id) as totals from c where c.pk='LessonRecord'", new List<string>() { "School" });
+            weekLess = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='LessonRecord' and c.startTime>={weekStart} and c.startTime <={weekEnd}", new List<string>() { "School", "Teacher" });
+            termLess = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='LessonRecord' and c.startTime>={termStart} and c.startTime <={termEnd}", new List<string>() { "School","Teacher" });
+
+            return Ok(new { state = 200, areaCount = areaInfos.Count, allSize, heCount, geCount, oeCount, allLess, termLess, weekLess, allActivity, tearActivity,weekActivity, areaInfos });
+        }
+                
+
         /// <summary>
         /// 依据活动Id查询活动详情信息  数据管理工具——查询工具
         /// </summary>
@@ -467,7 +544,23 @@ namespace TEAMModelBI.Controllers.Census
             return Ok(new { state = 200, infos });
         }
 
+        /// <summary>
+        /// 区级信息
+        /// </summary>
+        public record AreaInfo
+        {
+            public string id { get; set; }
+            public string name { get; set; }
+            public string standard { get; set; }
+            public string standardName { get; set; }
+            public int schoolCount { get; set; }
+            public int techCount { get; set;}
+            public int stuCount { get; set; }
+        }
 
+        /// <summary>
+        /// 区级下学校信息显示
+        /// </summary>
         public record RecSchool
         {
             public string id { get; set; }
@@ -500,10 +593,10 @@ namespace TEAMModelBI.Controllers.Census
             public string id { get; set; }
             public string name { get; set; }
             public string picture { get; set; }
-            public int count{get;set;}
+            public int count { get; set; }
         }
 
-            public record ActivityCount 
+        public record ActivityCount
         {
             public string id { get; set; }
             public string name { get; set; }

+ 166 - 0
TEAMModelBI/Controllers/Census/BlobLogController.cs

@@ -0,0 +1,166 @@
+using Azure.Cosmos;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using StackExchange.Redis;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelBI.Tool;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+
+namespace TEAMModelBI.Controllers.Census
+{
+    [Route("bloblog")]
+    [ApiController]
+    public class BlobLogController : ControllerBase
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        private readonly AzureRedisFactory _azureRedis;
+
+        public BlobLogController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureFactory, DingDing dingDing, IOptionsSnapshot<Option> option, AzureRedisFactory azureRedis)
+        {
+            _azureCosmos = azureCosmos;
+            _azureStorage = azureFactory;
+            _dingDing = dingDing;
+            _option = option?.Value;
+            _azureRedis = azureRedis;
+        }
+
+        /// <summary>
+        /// 空间统计数量统计
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-area")]
+        public async Task<IActionResult> GetArea(JsonElement jsonElement) 
+        {
+            jsonElement.TryGetProperty("areaId", out JsonElement areaId);
+            var cosmosClient = _azureCosmos.GetCosmosClient();
+            StringBuilder sqlSize = new($"select sum(c.size) as totals from c ");
+            long useSize = 0;
+            List<RecBlobFile> blobFiles = new();
+
+            if (!string.IsNullOrEmpty($"{areaId}"))
+            {
+                string sqlTxt = $"select c.id from c where c.areaId='{areaId}'";
+                sqlSize.Append($" where c.areaId = '{areaId}'");
+
+                List<string> schools = await CommonFind.FindSchoolIds(cosmosClient, sqlTxt.ToString(), "Base");
+                foreach (var id in schools)
+                {
+                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecBlobFile>(queryText: "SELECT c.id,c.code,c.name,c.size,c.type FROM c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{id}") }))
+                    {
+                        blobFiles.Add(item);
+                    }
+
+                    List<string> tecId = await CommonFind.FindRolesId(cosmosClient, schools);
+                    List<RecBlobFile> tecBlob = await GetBlobTeache(cosmosClient, tecId);
+                    if (tecBlob.Count > 0) 
+                    {
+                        blobFiles.Concat(tecBlob);
+                    }
+
+                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecBlobFile>(queryText: $"SELECT c.id,c.code,c.name,c.size,c.type FROM c where c.pk='Bloblog'", requestOptions: new QueryRequestOptions() { }))
+                    {
+                        blobFiles.Add(item);
+                    }
+
+                    long blobsize = 0;
+                    RedisValue value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", $"{id}");
+                    if (!value.IsNullOrEmpty)
+                    {
+                        JsonElement record = value.ToString().ToObject<JsonElement>();
+                        if (record.TryGetInt64(out blobsize))
+                        {
+                            useSize += blobsize;
+                        }
+                    }
+                }
+            }
+            else
+            {
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecBlobFile>(queryText: "SELECT c.id,c.code,c.name,c.size,c.type FROM c where c.pk='Bloblog'", requestOptions: new QueryRequestOptions() { }))
+                {
+                    blobFiles.Add(item);
+                }
+
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecBlobFile>(queryText: "SELECT c.id,c.code,c.name,c.size,c.type FROM c where c.pk='Bloblog'", requestOptions: new QueryRequestOptions() { }))
+                {
+                    blobFiles.Add(item);
+                }
+
+                List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c", "Base");
+
+                foreach (var id in schoolIds) 
+                {
+                    long blobsize = 0;
+                    RedisValue value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", $"{id}");
+                    if (!value.IsNullOrEmpty)
+                    {
+                        JsonElement record = value.ToString().ToObject<JsonElement>();
+                        if (record.TryGetInt64(out blobsize))
+                        {
+                            useSize += blobsize;
+                        }
+                    }
+                }
+            }
+
+            var typeCount = blobFiles.GroupBy(m => new { m.type }).Select(y => new { key = y.Key.type, value = y.Count() }).ToList();
+            var areaSize = await CommonFind.FindTotals(cosmosClient, sqlSize.ToString(), "School", "Base");
+
+            return Ok(new { state = 200, areaSize, useSize, typeCount });
+
+        }
+
+        /// <summary>
+        /// 依据教师获取教师个人的记录
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="teacherIds"></param>
+        /// <returns></returns>
+        public async static Task<List<RecBlobFile>> GetBlobTeache(CosmosClient cosmosClient, List<string> teacherIds)
+        {
+            List<RecBlobFile> blobFiles = new();
+            if (teacherIds.Count > 0)
+            {
+                foreach (var teacherId in teacherIds)
+                {
+                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecBlobFile>(queryText: $"SELECT c.id,c.code,c.name,c.size,c.type FROM c where c.pk='Bloblog'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{teacherId}") }))
+                    {
+                        blobFiles.Add(item);
+                    }
+                }
+            }
+
+            return blobFiles;
+        }
+
+
+
+        /// <summary>
+        /// 空间内容信息
+        /// </summary>
+        public record RecBlobFile
+        {
+            public string id { get; set; }
+            public string code { get; set; }
+            public string name { get; set; }
+            public int size { get; set; }
+            public string type { get; set; }
+
+        }
+
+
+    }
+
+}

+ 5 - 0
TEAMModelBI/Models/MonthStartEnd.cs

@@ -10,9 +10,14 @@
 
     }
 
+    /// <summary>
+    /// 教师列表
+    /// </summary>
     public class SchoolTeacherRoles
     {
         public string tmdId { get; set; }
         public string tmdName { get; set; }
     }
+
+
 }

+ 1 - 0
TEAMModelBI/TEAMModelBI.csproj

@@ -27,6 +27,7 @@
 	</ItemGroup>
 
 	<ItemGroup>
+		<Folder Include="Tool\Cosmos\StudentBank\" />
 		<Folder Include="wwwroot\" />
 	</ItemGroup>
 	<PropertyGroup>

+ 41 - 2
TEAMModelBI/Tool/CommonFind.cs

@@ -1,6 +1,7 @@
 using Azure.Cosmos;
 using System;
 using System.Collections.Generic;
+using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelBI.Models;
@@ -182,12 +183,12 @@ namespace TEAMModelBI.Tool
             return assistSchools;
         }
 
-
         /// <summary>
         /// 依据学校查询教师列表
         /// </summary>
         /// <param name="cosmosClient"></param>
-        /// <param name="schools"></param>
+        /// <param name="schools">学校列表</param>
+        /// <param name="roles">不传默认教师角色</param>
         /// <returns></returns>
         public static async Task<List<string>> FindRolesId(CosmosClient cosmosClient, List<string> schools, string roles = null)
         {
@@ -213,5 +214,43 @@ namespace TEAMModelBI.Tool
             return teachers;
         }
 
+
+        /// <summary>
+        /// 依据学校Id集合查询 学校人数统计
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="container"></param>
+        /// <param name="schoolId"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<int> GetPeopleNumber(CosmosClient cosmosClient, string container, List<string> schoolId, string code,string sqlWhere = null) 
+        {
+            int totals = 0;
+            StringBuilder sqlTxt = new("select count(c.id) as totals from c ");
+            if (!string.IsNullOrEmpty(sqlWhere)) 
+            {
+                sqlTxt.Append(sqlWhere);
+            }
+
+            if (schoolId.Count > 0)
+            {
+                foreach (var id in schoolId)
+                {
+                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}-{id}") }))
+                    {
+                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt32() > 0)
+                        {
+                            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                            {
+                                totals += obj.GetProperty("totals").GetInt32();
+                            }
+                        }
+                    }
+                }
+            }
+
+            return totals;
+        }
     }
 }

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/ExamClassResult.cs

@@ -35,7 +35,7 @@ namespace TEAMModelOS.SDK.Models
         public List<List<double>> studentScores { get; set; }
         //记录学生原始学校ID
         //public List<string> scIds { get; set; } = new List<string>();
-        //继续学生作答状态
+        //记录学生作答状态
         //0 未完成 1缺考 2补考 3补考完成
         public List<int> status { get; set; } = new List<int>();
         //批注

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

@@ -164,7 +164,7 @@ namespace TEAMModelOS.SDK.Models
         public string name { get; set; }
         public string desc { get; set; }
         public string no { get; set; }
-        [Required(ErrorMessage = "{0} 课程的科目id必须填写"), RegularExpression(@"[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}",ErrorMessage ="科目的uuid格式错误!")]
+        [Required(ErrorMessage = "{0} 课程的科目id必须填写"), RegularExpression(@"[0-9a-zA-Z]{8}(-[0-9a-zA-Z]{4}){3}-[0-9a-zA-Z]{12}",ErrorMessage ="科目的uuid格式错误!")]
         public string subjectId { get; set; }
    
         public string subjectName { get; set; }

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/School/Room.cs

@@ -47,7 +47,7 @@ namespace TEAMModelOS.SDK.Models
 
     public class RoomDto
     {
-        [Required(ErrorMessage = "物理教室的id必须填写"), RegularExpression(@"[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}", ErrorMessage = "物理教室的uuid格式错误!")]
+        [Required(ErrorMessage = "物理教室的id必须填写"), RegularExpression(@"[0-9a-zA-Z]{8}(-[0-9a-zA-Z]{4}){3}-[0-9a-zA-Z]{12}", ErrorMessage = "物理教室的uuid格式错误!")]
         public string id { get; set; }
         [Required(ErrorMessage = "{0} 教室的名称必须填写")]
         public string name { get; set; }

+ 36 - 2
TEAMModelOS/Controllers/School/SchoolTeacherController.cs

@@ -532,6 +532,8 @@ namespace TEAMModelOS.Controllers
                 {
                     bizcode = "request-join";
                 }
+
+               
                 Notification notification = new Notification
                 {
                     hubName = "hita",
@@ -572,7 +574,7 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("grant_type", out JsonElement grant_type)) return BadRequest();
                 if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
                 if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
-
+                request.TryGetProperty("importName", out JsonElement _importName);
                 var client = _azureCosmos.GetCosmosClient();
                 //取得學校資訊
                 var schresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Base"));
@@ -663,6 +665,38 @@ namespace TEAMModelOS.Controllers
                 if (grant_type.GetString() .Equals("join"))
                 {
                     bizcode = "request-join";
+                    if (!string.IsNullOrWhiteSpace($"{_importName}")) {
+                        Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync($"{school_code}", new PartitionKey("TeacherImport"));
+                        TeacherImport teacherImport = null;
+                        if (response.Status == 200)
+                        {
+                            teacherImport = JsonDocument.Parse(response.Content).RootElement.Deserialize<TeacherImport>();
+                            var tchs = teacherImport.teachers.FindAll(x => x.name.Equals($"{_importName}") && string.IsNullOrWhiteSpace(x.id));
+                            if (tchs.IsNotEmpty())
+                            {
+                                var tch = tchs[0];
+                                string ujson = null;
+                                var content = new StringContent(new List<string> { $"{id}" }.ToJsonString(), Encoding.UTF8, "application/json");
+                                ujson = await _coreAPIHttpService.GetUserInfos(content);
+                                List<CoreUser> coreUsers = new List<CoreUser>();
+                                if (!string.IsNullOrWhiteSpace(ujson))
+                                {
+                                    coreUsers = ujson.ToObject<List<CoreUser>>();
+                                }
+                                if (coreUsers.IsNotEmpty())
+                                {
+                                    tch.phone = coreUsers[0].mobile;
+                                    tch.email = coreUsers[0].mail;
+                                }
+                                tch.id = $"{teacher.id}";
+                                tch.picture = $"{teacher.picture}";
+                                tch.status = $"{grant_type}";
+                                tch.time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                                tch.tmdid = teacher.id;
+                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(teacherImport, $"{school_code}", new PartitionKey("TeacherImport"));
+                            }
+                        }
+                    }
                 }
                 Notification notification = new Notification
                 {
@@ -714,7 +748,7 @@ namespace TEAMModelOS.Controllers
                 }
                 if (!string.IsNullOrWhiteSpace($"{name}")  && teacherImport!= null) {
                     //移除同名的、其中一个
-                    var ts=  teacherImport.teachers.FindAll(x => !string.IsNullOrWhiteSpace(x.name ) &&  x.name.Equals($"{name}"));
+                    var ts=  teacherImport.teachers.FindAll(x => string.IsNullOrWhiteSpace(x.id)  &&  !string.IsNullOrWhiteSpace(x.name ) &&  x.name.Equals($"{name}"));
                     if (ts.IsNotEmpty()) {
                         teacherImport.teachers.Remove(ts.First());
                         await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(teacherImport, $"{school_code}", new PartitionKey("TeacherImport"));

+ 35 - 0
TEAMModelOS/Controllers/Teacher/InitController.cs

@@ -28,6 +28,7 @@ using TEAMModelOS.Services;
 using Microsoft.AspNetCore.Authorization;
 using System.Diagnostics;
 using Microsoft.Extensions.Logging;
+using System.Text;
 
 namespace TEAMModelOS.Controllers
 {
@@ -819,6 +820,40 @@ namespace TEAMModelOS.Controllers
                         };
                         var response = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(st, new PartitionKey($"Teacher-{school_code}"));
                     }
+                    if ($"{grant_type}".Equals("request")) {
+                        Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync($"{school_code}", new PartitionKey("TeacherImport"));
+                        TeacherImport teacherImport = null;
+                        if (response.Status == 200)
+                        {
+                            teacherImport = JsonDocument.Parse(response.Content).RootElement.Deserialize<TeacherImport>();
+                            var tchs = teacherImport.teachers.FindAll(x => x.name.Equals($"{name}") && string.IsNullOrWhiteSpace(x.id));
+                            if (tchs.IsNotEmpty())
+                            {
+                                var tch  = tchs[0];
+                                string ujson = null;
+                                
+                                 
+                                var content = new StringContent(new List<string> { $"{id}"}.ToJsonString(), Encoding.UTF8, "application/json");
+                                ujson = await _coreAPIHttpService.GetUserInfos(content);
+                                List<CoreUser> coreUsers = new List<CoreUser>();
+                                if (!string.IsNullOrWhiteSpace(ujson))
+                                {
+                                    coreUsers = ujson.ToObject<List<CoreUser>>();
+                                }
+                                if (coreUsers.IsNotEmpty())
+                                {
+                                    tch.phone = coreUsers[0].mobile;
+                                    tch.email = coreUsers[0].mail;
+                                }
+                                tch.id = $"{id}";
+                                tch.picture = $"{picture}";
+                                tch.status = $"{grant_type}";
+                                tch.time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                                tch.tmdid = id;
+                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(teacherImport, $"{school_code}", new PartitionKey("TeacherImport"));
+                            }
+                        }
+                    }
                     if (grant_type.ToString().Equals("join"))
                     {
                         await TmdUserService.JoinSchool(client, teacher.id, teacher.picture, teacher.name, school.schoolId, school.name);