Pārlūkot izejas kodu

处理通过手机号和醍摩豆账户信息查询相关信息

Li 3 gadi atpakaļ
vecāks
revīzija
c6ddc4c870

+ 50 - 3
TEAMModelBI/Controllers/BISchool/BatchAreaController.cs

@@ -25,6 +25,10 @@ using TEAMModelBI.DI.BIAzureStorage;
 using Azure.Storage.Blobs.Models;
 using Azure.Storage.Blobs.Models;
 using Azure;
 using Azure;
 using Azure.Storage.Blobs.Specialized;
 using Azure.Storage.Blobs.Specialized;
+using System.Net.Http;
+using System.Net.Http.Json;
+using System.Net;
+using TEAMModelOS.SDK;
 
 
 namespace TEAMModelBI.Controllers.BISchool
 namespace TEAMModelBI.Controllers.BISchool
 {
 {
@@ -39,8 +43,10 @@ namespace TEAMModelBI.Controllers.BISchool
         private readonly IConfiguration _configuration;
         private readonly IConfiguration _configuration;
         private readonly NotificationService _notificationService;
         private readonly NotificationService _notificationService;
         private readonly AzureServiceBusFactory _serviceBus;
         private readonly AzureServiceBusFactory _serviceBus;
+        private readonly IHttpClientFactory _http;
+        private readonly CoreAPIHttpService _coreAPIHttpService;
 
 
-        public BatchAreaController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService, AzureServiceBusFactory serviceBus)
+        public BatchAreaController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService, AzureServiceBusFactory serviceBus, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService) 
         {
         {
             _azureCosmos = azureCosmos;
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
             _dingDing = dingDing;
@@ -49,6 +55,8 @@ namespace TEAMModelBI.Controllers.BISchool
             _configuration = configuration;
             _configuration = configuration;
             _notificationService = notificationService;
             _notificationService = notificationService;
             _serviceBus = serviceBus;
             _serviceBus = serviceBus;
+            _http = http;
+            _coreAPIHttpService = coreAPIHttpService;
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -116,6 +124,7 @@ namespace TEAMModelBI.Controllers.BISchool
                 jsonElement.TryGetProperty("provName", out JsonElement provName);
                 jsonElement.TryGetProperty("provName", out JsonElement provName);
                 jsonElement.TryGetProperty("cityCode", out JsonElement cityCode);
                 jsonElement.TryGetProperty("cityCode", out JsonElement cityCode);
                 jsonElement.TryGetProperty("cityName", out JsonElement cityName);
                 jsonElement.TryGetProperty("cityName", out JsonElement cityName);
+                jsonElement.TryGetProperty("areaAdmin", out JsonElement areadAdmin);
                 if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
                 if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
                 if (!jsonElement.TryGetProperty("standardName", out JsonElement standardName)) return BadRequest();
                 if (!jsonElement.TryGetProperty("standardName", out JsonElement standardName)) return BadRequest();
                 jsonElement.TryGetProperty("institution", out JsonElement institution);
                 jsonElement.TryGetProperty("institution", out JsonElement institution);
@@ -162,6 +171,7 @@ namespace TEAMModelBI.Controllers.BISchool
                         return Ok(new { state = 1, message = "新创区的standard已存在请检查" });
                         return Ok(new { state = 1, message = "新创区的standard已存在请检查" });
                 }
                 }
 
 
+
                 //区级的ID
                 //区级的ID
                 string areaId = Guid.NewGuid().ToString();
                 string areaId = Guid.NewGuid().ToString();
                 Area addArea = new Area()
                 Area addArea = new Area()
@@ -178,6 +188,43 @@ namespace TEAMModelBI.Controllers.BISchool
                     institution = $"{institution}"
                     institution = $"{institution}"
                 };
                 };
 
 
+                #region  区级管理员
+
+                var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{areadAdmin}" } }, _option.Location, _configuration);
+                if (coreUser.id == null)
+                    return Ok(new { state = 404, msg = "未找到改账户的管理员" });
+
+                //string tmdId = !string.IsNullOrEmpty(tempTmdId) ? tempTmdId : $"{areadAdmin}";
+                Teacher teacher = null;
+                try
+                {
+                    //查询该教师是否存在
+                    teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{coreUser.id}", new PartitionKey("Base"));
+                }
+                catch
+                {
+                }
+
+                if (teacher != null)
+                {
+                    //教师存在,在该教师信息中添加要管理的学校信息
+                    teacher.areas.Add(new Teacher.TeacherArea { areaId = addArea.id, status = "join", name = addArea.name });
+                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
+                }
+                else
+                {
+                    teacher.name = coreUser.name;
+                    teacher.pk = "Base";
+                    teacher.code = "Base";
+                    teacher.size = 1;
+                    teacher.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    //教师存在,在该教师信息中添加要管理的学校信息
+                    teacher.areas.Add(new Teacher.TeacherArea { areaId = addArea.id, status = "join", name = addArea.name });
+                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
+                }
+
+                #endregion
+
                 //创建区域
                 //创建区域
                 await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync<Area>(addArea, new PartitionKey("Base-Area"));
                 await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").CreateItemAsync<Area>(addArea, new PartitionKey("Base-Area"));
 
 
@@ -477,11 +524,11 @@ namespace TEAMModelBI.Controllers.BISchool
                     expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
                     expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
                 };
                 };
 
 
-                var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
+                var notiUrl = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
                 var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
                 var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
                 var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
                 var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
                 var location = _option.Location;
                 var location = _option.Location;
-                await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
+                await _notificationService.SendNotification(clientID, clientSecret, location, notiUrl, notification); //站内发送消息
 
 
                 //保存操作记录
                 //保存操作记录
                 //await _azureStorage.SaveBILog("area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);
                 //await _azureStorage.SaveBILog("area-add", $"{_tmdName}【{_tmdId}】已操作创区功能模块:{name},当前标准【{standard}】,复制的微能力点:{tempStandard}", _dingDing, httpContext: HttpContext);

+ 13 - 24
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -28,6 +28,7 @@ using TEAMModelBI.Tool;
 using TEAMModelBI.Models;
 using TEAMModelBI.Models;
 using TEAMModelBI.Tool.Context;
 using TEAMModelBI.Tool.Context;
 using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.DI.BIAzureStorage;
+using TEAMModelOS.SDK;
 
 
 namespace TEAMModelBI.Controllers.BISchool
 namespace TEAMModelBI.Controllers.BISchool
 {
 {
@@ -43,8 +44,9 @@ namespace TEAMModelBI.Controllers.BISchool
         private readonly IHttpClientFactory _http;
         private readonly IHttpClientFactory _http;
         //读取配置信息
         //读取配置信息
         private readonly IConfiguration _configuration;
         private readonly IConfiguration _configuration;
+        private readonly CoreAPIHttpService _coreAPIHttpService;
 
 
-        public BatchSchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, IHttpClientFactory http)
+        public BatchSchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService)
         {
         {
             _azureCosmos = azureCosmos;
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
             _dingDing = dingDing;
@@ -53,6 +55,7 @@ namespace TEAMModelBI.Controllers.BISchool
             _environment = hostingEnvironment;
             _environment = hostingEnvironment;
             _configuration = configuration;
             _configuration = configuration;
             _http = http;
             _http = http;
+            _coreAPIHttpService = coreAPIHttpService;
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -164,23 +167,9 @@ namespace TEAMModelBI.Controllers.BISchool
                         }
                         }
                         if (scName.Count <= 0)
                         if (scName.Count <= 0)
                         {
                         {
-                            string tempTmdId = null;
-                            HttpClient httpClient = _http.CreateClient();
-                            string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
-                            List<string> mobile = new List<string>() { bischool.admin };
-                            HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobile);
-                            if (responseMessage.StatusCode == HttpStatusCode.OK)
-                            {
-                                string temp = responseMessage.Content.ReadAsStringAsync().Result;
-                                List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
-                                foreach (var item in json_id)
-                                {
-                                    tempTmdId = item.GetProperty("id").ToString();
-                                }
-                            }
+                            var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{bischool.admin}" } }, _option.Location, _configuration);
 
 
-                            string tmdId = !string.IsNullOrEmpty(tempTmdId) ? tempTmdId : bischool.admin;
-                            if (!string.IsNullOrEmpty(tmdId))
+                            if (coreUser.id != null)
                             {
                             {
                                 CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
                                 CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
                                 {
                                 {
@@ -237,7 +226,7 @@ namespace TEAMModelBI.Controllers.BISchool
                                     try
                                     try
                                     {
                                     {
                                         //查询该教师是否存在
                                         //查询该教师是否存在
-                                        teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{tmdId}", new PartitionKey("Base"));
+                                        teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{coreUser.id}", new PartitionKey("Base"));
                                     }
                                     }
                                     catch
                                     catch
                                     {
                                     {
@@ -246,10 +235,10 @@ namespace TEAMModelBI.Controllers.BISchool
                                     {
                                     {
                                         //教师存在,在该教师信息中添加要管理的学校信息
                                         //教师存在,在该教师信息中添加要管理的学校信息
                                         teacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId, schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
                                         teacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId, schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
-                                        //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, tmdId, new PartitionKey("Base"));
+                                        //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, coreUser.id, new PartitionKey("Base"));
                                         SchoolTeacher schoolTeacher = new SchoolTeacher
                                         SchoolTeacher schoolTeacher = new SchoolTeacher
                                         {
                                         {
-                                            id = tmdId,
+                                            id = coreUser.id,
                                             code = $"Teacher-{createSchoolInfo.id}",
                                             code = $"Teacher-{createSchoolInfo.id}",
                                             roles = new List<string> { "admin", "teacher" },
                                             roles = new List<string> { "admin", "teacher" },
                                             job = "管理员",
                                             job = "管理员",
@@ -269,10 +258,10 @@ namespace TEAMModelBI.Controllers.BISchool
                                         //不存在 新建教师和新建要管理的学校信息
                                         //不存在 新建教师和新建要管理的学校信息
                                         Teacher addteacher = new Teacher
                                         Teacher addteacher = new Teacher
                                         {
                                         {
-                                            id = tmdId,
+                                            id = coreUser.id,
                                             pk = "Base",
                                             pk = "Base",
                                             code = "Base",
                                             code = "Base",
-                                            name = $"{bischool.name}-管理员"?.ToString(),
+                                            name = $"{coreUser.name}",
                                             picture = "",
                                             picture = "",
                                             //创建账号并第一次登录IES5则默认赠送1G
                                             //创建账号并第一次登录IES5则默认赠送1G
                                             size = 1,
                                             size = 1,
@@ -290,11 +279,11 @@ namespace TEAMModelBI.Controllers.BISchool
 
 
                                         SchoolTeacher schoolTeacher = new SchoolTeacher
                                         SchoolTeacher schoolTeacher = new SchoolTeacher
                                         {
                                         {
-                                            id = tmdId,
+                                            id = coreUser.id,
                                             code = $"Teacher-{createSchoolInfo.id}",
                                             code = $"Teacher-{createSchoolInfo.id}",
                                             roles = new List<string> { "admin", "teacher" },
                                             roles = new List<string> { "admin", "teacher" },
                                             job = "管理员",
                                             job = "管理员",
-                                            name = $"{tmdId}-管理员",
+                                            name = $"{coreUser.name}",
                                             picture = "",
                                             picture = "",
                                             status = "join",
                                             status = "join",
                                             createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                                             createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),

+ 24 - 14
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -705,23 +705,33 @@ namespace TEAMModelBI.Controllers.BISchool
                         {
                         {
                             if (string.IsNullOrEmpty(ddInfo.tmdId))
                             if (string.IsNullOrEmpty(ddInfo.tmdId))
                             {
                             {
-                                List<string> moblie = new() { $"{ddInfo.mobile}" };
-
-                                var content = new StringContent(moblie.ToJsonString(), Encoding.UTF8, "application/json");
-                                string json = await _coreAPIHttpService.GetUserInfos(content);
-                                if (!string.IsNullOrEmpty(json))
+                                var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{ddInfo.mobile}" } }, _option.Location, _configuration);
+                                if (coreUser.id != null)
                                 {
                                 {
-                                    List<JsonElement> json_id = json.ToObject<List<JsonElement>>();
-                                    foreach (var tmd in json_id)
-                                    {
-                                        ddInfo.tmdId = tmd.GetProperty("id").ToString();
-                                        ddInfo.tmdName = tmd.GetProperty("name").ToString();
-                                        ddInfo.tmdMobile = tmd.GetProperty("mobile").ToString();
-                                        ddInfo.picture = tmd.GetProperty("picture").ToString();
-                                        ddInfo.mail = tmd.GetProperty("mail").ToString();
-                                    }
+                                    ddInfo.tmdId = coreUser.id;
+                                    ddInfo.tmdName = coreUser.name;
+                                    ddInfo.tmdMobile = coreUser.mobile;
+                                    ddInfo.picture = coreUser.picture;
+                                    ddInfo.mail = coreUser.mail;
                                 }
                                 }
                                 else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
                                 else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
+
+                                //List<string> moblie = new() { $"{ddInfo.mobile}" };
+                                //var content = new StringContent(moblie.ToJsonString(), Encoding.UTF8, "application/json");
+                                //string json = await _coreAPIHttpService.GetUserInfos(content);
+                                //if (!string.IsNullOrEmpty(json))
+                                //{
+                                //    List<JsonElement> json_id = json.ToObject<List<JsonElement>>();
+                                //    foreach (var tmd in json_id)
+                                //    {
+                                //        ddInfo.tmdId = tmd.GetProperty("id").ToString();
+                                //        ddInfo.tmdName = tmd.GetProperty("name").ToString();
+                                //        ddInfo.tmdMobile = tmd.GetProperty("mobile").ToString();
+                                //        ddInfo.picture = tmd.GetProperty("picture").ToString();
+                                //        ddInfo.mail = tmd.GetProperty("mail").ToString();
+                                //    }
+                                //}
+                                //else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
                             }
                             }
                             List<string> noSchool = await SchoolWay.SchoolAdviser(cosmosClient, ddInfo, schoolIds, $"{busy}");
                             List<string> noSchool = await SchoolWay.SchoolAdviser(cosmosClient, ddInfo, schoolIds, $"{busy}");
                             if (noSchool.Count > 0)
                             if (noSchool.Count > 0)

+ 27 - 21
TEAMModelBI/Controllers/BIServer/BiServersController.cs

@@ -75,31 +75,37 @@ namespace TEAMModelBI.Controllers.BIServer
         /// <param name="jsonElment"></param>
         /// <param name="jsonElment"></param>
         /// <returns></returns>
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
-        [HttpPost("get-mobileuserinfo")]
+        [HttpPost("get-userinfo")]
         public async Task<IActionResult> SendMobileGetUserIfo(JsonElement jsonElment) 
         public async Task<IActionResult> SendMobileGetUserIfo(JsonElement jsonElment) 
         {
         {
             try
             try
             {
             {
-                HttpClient httpClient = _http.CreateClient();
-                string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
-                HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, jsonElment);
-                List<userInfo> userInfos = new List<userInfo>();
-                if (responseMessage.StatusCode == HttpStatusCode.OK)
-                {
-                    string temp = responseMessage.Content.ReadAsStringAsync().Result;
-                    List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
-                    foreach (var item in json_id)
-                    {
-                        userInfo userInfo = new userInfo();
-                        userInfo.tmdid = item.GetProperty("id").ToString();
-                        userInfo.tmdname = item.GetProperty("name").ToString();
-                        userInfo.mobile = item.GetProperty("mobile").ToString();
-                        userInfos.Add(userInfo);
-                    }
-
-                    return Ok(new { state = 200, userInfos });
-                }
-                else return Ok(new { responseMessage.StatusCode });
+                if (!jsonElment.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
+                var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{mobile}" } }, _option.Location, _configuration);
+                if (coreUser.id != null)
+                    return Ok(new { state = 200, coreUser });
+                else return Ok(new { state = 404, msg = "未找到改账户" });
+
+                //HttpClient httpClient = _http.CreateClient();
+                //string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
+                //HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, jsonElment);
+                //List<userInfo> userInfos = new List<userInfo>();
+                //if (responseMessage.StatusCode == HttpStatusCode.OK)
+                //{
+                //    string temp = responseMessage.Content.ReadAsStringAsync().Result;
+                //    List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
+                //    foreach (var item in json_id)
+                //    {
+                //        userInfo userInfo = new userInfo();
+                //        userInfo.tmdid = item.GetProperty("id").ToString();
+                //        userInfo.tmdname = item.GetProperty("name").ToString();
+                //        userInfo.mobile = item.GetProperty("mobile").ToString();
+                //        userInfos.Add(userInfo);
+                //    }
+
+                //    return Ok(new { state = 200, userInfos });
+                //}
+                //else return Ok(new { responseMessage.StatusCode });
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {

+ 37 - 23
TEAMModelBI/Controllers/DingDingStruc/TableDingDingInfoController.cs

@@ -27,6 +27,7 @@ using TEAMModelBI.Models;
 using TEAMModelBI.Tool.CosmosBank;
 using TEAMModelBI.Tool.CosmosBank;
 using TEAMModelBI.Tool.Context;
 using TEAMModelBI.Tool.Context;
 using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.DI.BIAzureStorage;
+using TEAMModelOS.SDK;
 
 
 namespace TEAMModelBI.Controllers.DingDingStruc
 namespace TEAMModelBI.Controllers.DingDingStruc
 {
 {
@@ -44,8 +45,9 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         private readonly DingDing _dingDing;
         private readonly DingDing _dingDing;
         private readonly Option _option;
         private readonly Option _option;
         private readonly IHttpClientFactory _http;
         private readonly IHttpClientFactory _http;
+        private readonly CoreAPIHttpService _coreAPIHttpService;
 
 
-        public TableDingDingInfoController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, IHttpClientFactory http)
+        public TableDingDingInfoController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService)
         {
         {
             _azureCosmos = azureCosmos;
             _azureCosmos = azureCosmos;
             _dingDing = dingDing;
             _dingDing = dingDing;
@@ -53,6 +55,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
             _option = option?.Value;
             _option = option?.Value;
             _http = http;
             _http = http;
             _configuration = configuration;
             _configuration = configuration;
+            _coreAPIHttpService = coreAPIHttpService;
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -83,8 +86,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
 
 
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
 
 
-                HttpClient httpClient = _http.CreateClient();
-                string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
+                //HttpClient httpClient = _http.CreateClient();
+                //string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
 
 
                 //获取access_token
                 //获取access_token
                 IDingTalkClient tokenClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
                 IDingTalkClient tokenClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
@@ -758,27 +761,38 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 string mail = null;
                 string mail = null;
                 string picture = null;
                 string picture = null;
 
 
-                HttpClient httpClient = _http.CreateClient();
-                string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
-                List<string> mobiles = new List<string>() { $"{mobile}" };
-                HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobiles);
-                if (responseMessage.StatusCode == HttpStatusCode.OK)
+                var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{mobile}" } }, _option.Location, _configuration);
+                if (coreUser.id != null) 
                 {
                 {
-                    string temp = responseMessage.Content.ReadAsStringAsync().Result;
-                    List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
-                    if (json_id.Count > 0)
-                    {
-                        foreach (var item in json_id)
-                        {
-                            tmdId = item.GetProperty("id").ToString();
-                            tmdName = item.GetProperty("name").ToString();
-                            tmdMobile = item.GetProperty("mobile").ToString();
-                            mail = item.GetProperty("mail").ToString();
-                            picture = item.GetProperty("picture").ToString();
-                        }
-                    }
-                    else return Ok(new { state = 1, message = "该手机号未找到醍摩豆账户" });
-                }
+
+                    tmdId = coreUser.id;
+                    tmdName = coreUser.name;
+                    tmdMobile = coreUser.mobile;
+                    mail = coreUser.mail;
+                    picture = coreUser.picture;
+                }else return Ok(new { state = 1, message = "该手机号未找到醍摩豆账户" });
+
+                //HttpClient httpClient = _http.CreateClient();
+                //string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
+                //List<string> mobiles = new List<string>() { $"{mobile}" };
+                //HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobiles);
+                //if (responseMessage.StatusCode == HttpStatusCode.OK)
+                //{
+                //    string temp = responseMessage.Content.ReadAsStringAsync().Result;
+                //    List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
+                //    if (json_id.Count > 0)
+                //    {
+                //        foreach (var item in json_id)
+                //        {
+                //            tmdId = item.GetProperty("id").ToString();
+                //            tmdName = item.GetProperty("name").ToString();
+                //            tmdMobile = item.GetProperty("mobile").ToString();
+                //            mail = item.GetProperty("mail").ToString();
+                //            picture = item.GetProperty("picture").ToString();
+                //        }
+                //    }
+                //    else return Ok(new { state = 1, message = "该手机号未找到醍摩豆账户" });
+                //}
 
 
                 tempddUsers = await table.QueryWhereString<DingDingUserInfo>(tableSql.ToString());
                 tempddUsers = await table.QueryWhereString<DingDingUserInfo>(tableSql.ToString());
 
 

+ 133 - 101
TEAMModelBI/Controllers/LoginController.cs

@@ -166,44 +166,33 @@ namespace TEAMModelBI.Controllers
                     {
                     {
                         if (string.IsNullOrEmpty(item.tmdId))
                         if (string.IsNullOrEmpty(item.tmdId))
                         {
                         {
-                            List<string> mobiles = new() { $"{ item.mobile}" };
-                            var content = new StringContent(mobiles.ToJsonString(), Encoding.UTF8, "application/json");
-                            string json = await _coreAPIHttpService.GetUserInfos(content);
-                            if (!string.IsNullOrEmpty(json))
+                            var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{item.mobile}" } }, _option.Location, _configuration);
+                            if (coreUser.id != null)
                             {
                             {
-                                List<JsonElement> json_id = json.ToObject<List<JsonElement>>();
-                                foreach (var tmd in json_id)
-                                {
-                                    item.tmdId = tmd.GetProperty("id").ToString();
-                                    item.tmdName = tmd.GetProperty("name").ToString();
-                                    item.tmdMobile = tmd.GetProperty("mobile").ToString();
-                                    item.picture = tmd.GetProperty("picture").ToString();
-                                    item.mail = tmd.GetProperty("mail").ToString();
-                                }
+                                item.tmdId = coreUser.id;
+                                item.tmdName = coreUser.name;
+                                item.tmdMobile = coreUser.mobile;
+                                item.picture = coreUser.picture;
+                                item.mail = coreUser.mail;
                             }
                             }
                             else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
                             else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
 
 
-                            //HttpClient httpClient = _http.CreateClient();
-                            //string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
                             //List<string> mobiles = new() { $"{ item.mobile}" };
                             //List<string> mobiles = new() { $"{ item.mobile}" };
-                            //HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobiles);
-                            //if (responseMessage.StatusCode == HttpStatusCode.OK)
+                            //var content = new StringContent(mobiles.ToJsonString(), Encoding.UTF8, "application/json");
+                            //string json = await _coreAPIHttpService.GetUserInfos(content);
+                            //if (!string.IsNullOrEmpty(json))
                             //{
                             //{
-                            //    string temp = responseMessage.Content.ReadAsStringAsync().Result;
-                            //    List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
-                            //    if (json_id.Count > 0)
+                            //    List<JsonElement> json_id = json.ToObject<List<JsonElement>>();
+                            //    foreach (var tmd in json_id)
                             //    {
                             //    {
-                            //        foreach (var tmd in json_id)
-                            //        {
-                            //            item.tmdId = tmd.GetProperty("id").ToString();
-                            //            item.tmdName = tmd.GetProperty("name").ToString();
-                            //            item.tmdMobile = tmd.GetProperty("mobile").ToString();
-                            //            item.picture = tmd.GetProperty("picture").ToString();
-                            //            item.mail = tmd.GetProperty("mail").ToString();
-                            //        }
+                            //        item.tmdId = tmd.GetProperty("id").ToString();
+                            //        item.tmdName = tmd.GetProperty("name").ToString();
+                            //        item.tmdMobile = tmd.GetProperty("mobile").ToString();
+                            //        item.picture = tmd.GetProperty("picture").ToString();
+                            //        item.mail = tmd.GetProperty("mail").ToString();
                             //    }
                             //    }
-                            //    else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
                             //}
                             //}
+                            //else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
 
 
                             strMsg.Append($"{item.tmdName}【{item.tmdId}】醍摩豆账号和{item.name}【{item.userId}】钉钉账户绑定成功");
                             strMsg.Append($"{item.tmdName}【{item.tmdId}】醍摩豆账号和{item.name}【{item.userId}】钉钉账户绑定成功");
 
 
@@ -259,28 +248,39 @@ namespace TEAMModelBI.Controllers
 
 
                     if (!string.IsNullOrEmpty($"{ddUserInfo.mobile}"))
                     if (!string.IsNullOrEmpty($"{ddUserInfo.mobile}"))
                     {
                     {
-                        HttpClient httpClient = _http.CreateClient();
-                        string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
-
-                        List<string> mobiles = new() { $"{ ddUserInfo.mobile}" };
-                        HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobiles);
-                        if (responseMessage.StatusCode == HttpStatusCode.OK)
-                        {
-                            string temp = responseMessage.Content.ReadAsStringAsync().Result;
-                            List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
-                            if (json_id.Count > 0)
-                            {
-                                foreach (var tmd in json_id)
-                                {
-                                    ddUserInfo.tmdId = tmd.GetProperty("id").ToString();
-                                    ddUserInfo.tmdName = tmd.GetProperty("name").ToString();
-                                    ddUserInfo.tmdMobile = tmd.GetProperty("mobile").ToString();
-                                    ddUserInfo.picture = tmd.GetProperty("picture").ToString();
-                                    ddUserInfo.mail = tmd.GetProperty("mail").ToString();
-                                }
-                            }
-                            else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
+                        var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{ddUserInfo.mobile}" } }, _option.Location, _configuration);
+                        if (coreUser.id != null) {
+
+                            ddUserInfo.tmdId = coreUser.id;
+                            ddUserInfo.tmdName = coreUser.name;
+                            ddUserInfo.tmdMobile = coreUser.mobile;
+                            ddUserInfo.picture = coreUser.mobile;
+                            ddUserInfo.mail = coreUser.mail;
                         }
                         }
+                        else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
+
+                        //HttpClient httpClient = _http.CreateClient();
+                        //string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
+
+                        //List<string> mobiles = new() { $"{ ddUserInfo.mobile}" };
+                        //HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobiles);
+                        //if (responseMessage.StatusCode == HttpStatusCode.OK)
+                        //{
+                        //    string temp = responseMessage.Content.ReadAsStringAsync().Result;
+                        //    List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
+                        //    if (json_id.Count > 0)
+                        //    {
+                        //        foreach (var tmd in json_id)
+                        //        {
+                        //            ddUserInfo.tmdId = tmd.GetProperty("id").ToString();
+                        //            ddUserInfo.tmdName = tmd.GetProperty("name").ToString();
+                        //            ddUserInfo.tmdMobile = tmd.GetProperty("mobile").ToString();
+                        //            ddUserInfo.picture = tmd.GetProperty("picture").ToString();
+                        //            ddUserInfo.mail = tmd.GetProperty("mail").ToString();
+                        //        }
+                        //    }
+                        //    else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
+                        //}
                     }
                     }
                     else return Ok(new { state = 404, msg = "钉钉手机号为空" });
                     else return Ok(new { state = 404, msg = "钉钉手机号为空" });
 
 
@@ -352,7 +352,6 @@ namespace TEAMModelBI.Controllers
                 }
                 }
 
 
                 HttpClient httpClient = _http.CreateClient();
                 HttpClient httpClient = _http.CreateClient();
-                string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
                 var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
                 var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
                 var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "userId", $"{userId}" } });
                 var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "userId", $"{userId}" } });
 
 
@@ -379,25 +378,38 @@ namespace TEAMModelBI.Controllers
 
 
                     if (!string.IsNullOrEmpty($"{mobile}"))
                     if (!string.IsNullOrEmpty($"{mobile}"))
                     {
                     {
-                        List<string> mobiles = new() { $"{mobile}" };
-                        HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobiles);
-                        if (responseMessage.StatusCode == HttpStatusCode.OK)
+
+                        var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{mobile}" } }, _option.Location, _configuration);
+                        if (coreUser.id != null)
                         {
                         {
-                            var temp = await responseMessage.Content.ReadAsStringAsync();
-                            if (temp.Length > 0)
-                            {
-                                List<JsonElement> itemjson = temp.ToObject<List<JsonElement>>();
-                                foreach (var item in itemjson)
-                                {
-                                    itemUser.tmdId = item.GetProperty("id").ToString();
-                                    itemUser.tmdName = item.GetProperty("name").ToString();
-                                    itemUser.tmdMobile = item.GetProperty("mobile").ToString();
-                                    itemUser.picture = item.GetProperty("picture").ToString();
-                                    itemUser.mail = item.GetProperty("mail").ToString();
-                                }
-                            }
+                            itemUser.tmdId = coreUser.id;
+                            itemUser.tmdName = coreUser.name;
+                            itemUser.tmdMobile = coreUser.mobile;
+                            itemUser.picture = coreUser.mobile;
+                            itemUser.mail = coreUser.mail;
                         }
                         }
                         else return Ok(new { state = 404, msg = "手机号未找到醍摩豆账户" });
                         else return Ok(new { state = 404, msg = "手机号未找到醍摩豆账户" });
+
+                        //string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
+                        //List<string> mobiles = new() { $"{mobile}" };
+                        //HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobiles);
+                        //if (responseMessage.StatusCode == HttpStatusCode.OK)
+                        //{
+                        //    var temp = await responseMessage.Content.ReadAsStringAsync();
+                        //    if (temp.Length > 0)
+                        //    {
+                        //        List<JsonElement> itemjson = temp.ToObject<List<JsonElement>>();
+                        //        foreach (var item in itemjson)
+                        //        {
+                        //            itemUser.tmdId = item.GetProperty("id").ToString();
+                        //            itemUser.tmdName = item.GetProperty("name").ToString();
+                        //            itemUser.tmdMobile = item.GetProperty("mobile").ToString();
+                        //            itemUser.picture = item.GetProperty("picture").ToString();
+                        //            itemUser.mail = item.GetProperty("mail").ToString();
+                        //        }
+                        //    }
+                        //}
+                        //else return Ok(new { state = 404, msg = "手机号未找到醍摩豆账户" });
                     }
                     }
 
 
                     if (string.IsNullOrEmpty($"{mobile}") && string.IsNullOrEmpty($"{idtoken}"))
                     if (string.IsNullOrEmpty($"{mobile}") && string.IsNullOrEmpty($"{idtoken}"))
@@ -483,46 +495,66 @@ namespace TEAMModelBI.Controllers
                     }
                     }
                     else
                     else
                     {
                     {
-                        HttpClient httpClient = _http.CreateClient();
-                        string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
-                        HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, moile);
-
-                        if (responseMessage.StatusCode == HttpStatusCode.OK)
+                        var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{moile}" } }, _option.Location, _configuration);
+                        if (coreUser.id != null)
                         {
                         {
-                            var temp = await responseMessage.Content.ReadAsStringAsync();
-                            if (temp.Length > 0)
-                            {
-                                List<JsonElement> itemjson = temp.ToObject<List<JsonElement>>();
-                                string tmdId = null;
-                                string tmdName = null;
-                                foreach (var item in itemjson)
-                                {
-                                    tmdId = item.GetProperty("id").ToString();
-                                    tmdName = item.GetProperty("name").ToString();
-                                    itemUser.tmdId = tmdId?.ToString();
-                                    itemUser.tmdName = tmdName?.ToString();
-                                    itemUser.tmdMobile = item.GetProperty("mobile").ToString();
-                                    itemUser.picture = item.GetProperty("picture").ToString();
-                                    itemUser.mail = item.GetProperty("mail").ToString();
-                                    roles = !string.IsNullOrEmpty($"{itemUser.roles}") ? new List<string>(itemUser.roles.Split(",")) : new List<string>();
-                                    permissions = !string.IsNullOrEmpty($"{itemUser.permissions}") ? new List<string>(itemUser.permissions.Split(",")) : new List<string>();
-
-                                    ddUserInfos.Add(itemUser);
-                                }
-
-                                ddUserInfos = await table.UpdateAll<DingDingUserInfo>(ddUserInfos);
-
-                                //保存操作记录
-                                //await _azureStorage.SaveBILog("tabledd-update", $"{tmdName}【{tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
-                                await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{tmdName}【{tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
-                            }
-                            else return Ok(new { state = 400, message = "该手机没有注册醍摩豆账号信息" });
+                            itemUser.tmdId = coreUser.id;
+                            itemUser.tmdName = coreUser.name;
+                            itemUser.tmdMobile = coreUser.mobile;
+                            itemUser.picture = coreUser.mobile;
+                            itemUser.mail = coreUser.mail;
+
+                            roles = !string.IsNullOrEmpty($"{itemUser.roles}") ? new List<string>(itemUser.roles.Split(",")) : new List<string>();
+                            permissions = !string.IsNullOrEmpty($"{itemUser.permissions}") ? new List<string>(itemUser.permissions.Split(",")) : new List<string>();
+
+                            ddUserInfos.Add(itemUser);
+
+                            await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{coreUser.name}【{coreUser.id}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
                         }
                         }
-                        else return Ok(new { state = responseMessage.StatusCode });
+                        else return Ok(new { state = 400, message = "该手机没有注册醍摩豆账号信息" });
+
+                        //HttpClient httpClient = _http.CreateClient();
+                        //string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
+                        //HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, moile);
+
+                        //if (responseMessage.StatusCode == HttpStatusCode.OK)
+                        //{
+                        //    var temp = await responseMessage.Content.ReadAsStringAsync();
+                        //    if (temp.Length > 0)
+                        //    {
+                        //        List<JsonElement> itemjson = temp.ToObject<List<JsonElement>>();
+                        //        string tmdId = null;
+                        //        string tmdName = null;
+                        //        foreach (var item in itemjson)
+                        //        {
+                        //            tmdId = item.GetProperty("id").ToString();
+                        //            tmdName = item.GetProperty("name").ToString();
+                        //            itemUser.tmdId = tmdId?.ToString();
+                        //            itemUser.tmdName = tmdName?.ToString();
+                        //            itemUser.tmdMobile = item.GetProperty("mobile").ToString();
+                        //            itemUser.picture = item.GetProperty("picture").ToString();
+                        //            itemUser.mail = item.GetProperty("mail").ToString();
+                        //            roles = !string.IsNullOrEmpty($"{itemUser.roles}") ? new List<string>(itemUser.roles.Split(",")) : new List<string>();
+                        //            permissions = !string.IsNullOrEmpty($"{itemUser.permissions}") ? new List<string>(itemUser.permissions.Split(",")) : new List<string>();
+
+                        //            ddUserInfos.Add(itemUser);
+                        //        }
+
+                        //        ddUserInfos = await table.UpdateAll<DingDingUserInfo>(ddUserInfos);
+
+                        //        //保存操作记录
+                        //        //await _azureStorage.SaveBILog("tabledd-update", $"{tmdName}【{tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
+                        //        await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{tmdName}【{tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.userId}】钉钉账户绑定成功", _dingDing, tid: itemUser.tmdId, tname: itemUser.name, twebsite: Website, httpContext: HttpContext);
+                        //    }
+                        //    else return Ok(new { state = 400, message = "该手机没有注册醍摩豆账号信息" });
+                        //}
+                        //else return Ok(new { state = responseMessage.StatusCode });
                     }
                     }
                     //自己写的
                     //自己写的
                     id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, itemUser.tmdId?.ToString(), itemUser.tmdName?.ToString(), itemUser.picture?.ToString(), _option.JwtSecretKey, scope: "assist", webSite: Website, isex: false, itemUser.userId?.ToString(), itemUser.name?.ToString(), itemUser.avatar?.ToString(), roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire: 3);
                     id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, itemUser.tmdId?.ToString(), itemUser.tmdName?.ToString(), itemUser.picture?.ToString(), _option.JwtSecretKey, scope: "assist", webSite: Website, isex: false, itemUser.userId?.ToString(), itemUser.name?.ToString(), itemUser.avatar?.ToString(), roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire: 3);
                 }
                 }
+                
+                await table.SaveOrUpdateAll<DingDingUserInfo>(ddUserInfos);
 
 
                 string osblob_uri = null, osblob_sas = null;
                 string osblob_uri = null, osblob_sas = null;