浏览代码

添加得第三方接口

Li 3 年之前
父节点
当前提交
ea2296bbf9

+ 1 - 1
TEAMModelBI/Controllers/BINormal/BIOpenApiController.cs

@@ -16,7 +16,7 @@ using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 
-namespace TEAMModelBI.Controllers.BINormal
+namespace TEAMModelBI.Controllers.BITable
 {
     [Route("openapi")]
     [ApiController]

+ 34 - 25
TEAMModelBI/Controllers/BINormal/CompanyController.cs

@@ -21,7 +21,7 @@ using TEAMModelOS.SDK.Models.Cosmos.BI;
 using TEAMModelOS.SDK.Models.Service;
 using TEAMModelOS.SDK.Models.Table;
 
-namespace TEAMModelBI.Controllers.BINormal
+namespace TEAMModelBI.Controllers.BITable
 {
     [Route("business")]
     [ApiController]
@@ -120,8 +120,10 @@ namespace TEAMModelBI.Controllers.BINormal
                     blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
                 }
                 List<BusinessConfig> companys = new();
+                BusinessUser businessUser = new();
+                BizRelUser bizRelUser = new();
 
-                var table = tableClient.GetTableReference("IESOpenApi");
+                 var table = tableClient.GetTableReference("IESOpenApi");
 
                 string salt = Utils.CreatSaltString(8);
                 string type = "";
@@ -135,33 +137,33 @@ namespace TEAMModelBI.Controllers.BINormal
                     company.jti = auth_token.jti;
                     company.token = auth_token.jwt;
                     company = await table.SaveOrUpdate<BusinessConfig>(company);
+                    
+                    businessUser = new() { RowKey = Guid.NewGuid().ToString(), name = $"{company.mobile}", mobile = company.mobile, salt = salt, pwd = Utils.HashedPassword($"{company.mobile}", salt) };
+                    businessUser = await table.SaveOrUpdate<BusinessUser>(businessUser);
+
+                    bizRelUser = new() { RowKey = $"{businessUser.RowKey}-{company.RowKey}",userId= $"{company.RowKey}", bizId = $"{company.RowKey}",bizName = company.name ,roles = "admin" };
+                    bizRelUser = await table.SaveOrUpdate<BizRelUser>(bizRelUser);
+
                     companys.Add(company);
-                    strMsg.Append($"{company.name}【{company.RowKey}】新增企业基础信息。");
+                    strMsg.Append($"{company.name}【{company.RowKey}】新增企业基础信息。新增该企业管理员信息{businessUser.name}【{businessUser.RowKey}】。");
                     type = "business-add";
                 }
                 else 
                 {
-                    List<BusinessConfig> companyTables = table.FindListByDictSync<BusinessConfig>(new Dictionary<string, object> { { "PartitionKey", "BusinessConfig" }, { "RowKey", $"{company.RowKey}" } });
-                    if (companyTables.Count > 0)
+                    //List<BusinessConfig> companyTables = table.FindListByDictSync<BusinessConfig>(new Dictionary<string, object> { { "PartitionKey", "BusinessConfig" }, { "RowKey", $"{company.RowKey}" } });
+                    BusinessConfig businessConfig = table.Get<BusinessConfig>("BusinessConfig", $"{company.RowKey}");
+
+                    if (businessConfig != null)
                     {
-                        foreach (var item in companyTables)
-                        {
-                            item.name = company.name;
-                            item.credit = company.credit;
-                            item.picture = company.picture;
-                            //item.jti = company.jti;
-                            //item.secretKey = company.secretKey;
-                            item.email = company.email;
-                            item.mobile = company.mobile;
-                            //item.salt = company.salt;
-                            //item.password = company.password;
-                            item.domain = company.domain;
-                            item.webhook = company.webhook;
-                            strMsg.Append($"{item.name}【{item.RowKey}】修改企业基础信息:{item}。");
-                            companys.Add(item);
-                        }
-
-                        companyTables = await table.SaveOrUpdateAll<BusinessConfig>(companyTables);
+                        company.PartitionKey = businessConfig.PartitionKey;
+                        company.RowKey = businessConfig.RowKey;
+                        company.credit = businessConfig.credit;
+                        company.jti = businessConfig.jti;
+                        company.token = businessConfig.token;
+
+                        businessConfig = await table.SaveOrUpdate<BusinessConfig>(company);
+                        companys.Add(businessConfig);
+                        strMsg.Append($"{company.name}【{company.RowKey}】修改企业基础信息:{company}。");
                         type = "business-add";
                     }
                     else
@@ -173,8 +175,15 @@ namespace TEAMModelBI.Controllers.BINormal
                         company.jti = auth_token.jti;
                         company.token = auth_token.jwt;
                         company = await table.SaveOrUpdate<BusinessConfig>(company);
+
+                        businessUser = new() { RowKey = Guid.NewGuid().ToString(), name = $"{company.mobile}", mobile = company.mobile, salt = salt, pwd = Utils.HashedPassword($"{company.mobile}", salt) };
+                        businessUser = await table.SaveOrUpdate<BusinessUser>(businessUser);
+
+                        bizRelUser = new() { RowKey = $"{businessUser.RowKey}-{company.RowKey}", userId = $"{company.RowKey}", bizId = $"{company.RowKey}", bizName = company.name, roles = "admin" };
+                        bizRelUser = await table.SaveOrUpdate<BizRelUser>(bizRelUser);
+
                         companys.Add(company);
-                        strMsg.Append($"{company.name}【{company.RowKey}】新增企业基础信息:{company}。");
+                        strMsg.Append($"{company.name}【{company.RowKey}】新增企业基础信息:{company}。新增该企业管理员信息{businessUser.name}【{businessUser.RowKey}】。");
                         type = "business-add";
                     }
                 }
@@ -182,7 +191,7 @@ namespace TEAMModelBI.Controllers.BINormal
                 //保存操作记录
                 //await _azureStorage.SaveBILog(type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
                 await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, type, strMsg.ToString(), _dingDing, httpContext: HttpContext);
-                return Ok(new { state = 200, companys });
+                return Ok(new { state = 200, companys, businessUser });
             }
             catch (Exception e)
             {

+ 68 - 8
TEAMModelBI/Controllers/BINormal/CompanyUserController.cs

@@ -7,11 +7,12 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelBI.Tool.Context;
 using TEAMModelOS.Models;
+using TEAMModelOS.SDK.Context.Constant;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models.Table;
 
-namespace TEAMModelBI.Controllers.BINormal
+namespace TEAMModelBI.Controllers.BITable
 {
     [Route("bizuser")]
     [ApiController]
@@ -36,14 +37,13 @@ namespace TEAMModelBI.Controllers.BINormal
         /// <param name="bizUser"></param>
         /// <param name="site"></param>
         /// <returns></returns>
+        [ProducesDefaultResponseType]
         [HttpPost("set-bizuser")]
         public async Task<IActionResult> SetBizUser([FromBody] BusinessUser bizUser, [FromHeader] string site)
         {
-            var cosmosClient = _azureCosmos.GetCosmosClient();
             var tableClient = _azureStorage.GetCloudTableClient();
             if ($"{site}".Equals(BIConst.Global))
             {
-                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
                 tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
             }
 
@@ -78,12 +78,13 @@ namespace TEAMModelBI.Controllers.BINormal
 
             return Ok(new { state = 200, bizUser });
         }
-        
+
         /// <summary>
         /// 重置密码
         /// </summary>
         /// <param name="jsonElement"></param>
         /// <returns></returns>
+        [ProducesDefaultResponseType]
         [HttpPost("res-pwd")]
         public async Task<IActionResult> ResetPwd(JsonElement jsonElement) 
         {
@@ -93,11 +94,9 @@ namespace TEAMModelBI.Controllers.BINormal
                 jsonElement.TryGetProperty("pwd", out JsonElement pwd);
                 jsonElement.TryGetProperty("site", out JsonElement site);
 
-                var cosmosClient = _azureCosmos.GetCosmosClient();
                 var tableClient = _azureStorage.GetCloudTableClient();
                 if ($"{site}".Equals(BIConst.Global))
                 {
-                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
                     tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
                 }
                 var table = tableClient.GetTableReference("IESOpenApi");
@@ -133,17 +132,16 @@ namespace TEAMModelBI.Controllers.BINormal
         /// </summary>
         /// <param name="jsonElement"></param>
         /// <returns></returns>
+        [ProducesDefaultResponseType]
         [HttpPost("get-infos")]
         public async Task<IActionResult> GetInfos(JsonElement jsonElement) 
         {
             if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
             jsonElement.TryGetProperty("site", out JsonElement site);
 
-            var cosmosClient = _azureCosmos.GetCosmosClient();
             var tableClient = _azureStorage.GetCloudTableClient();
             if ($"{site}".Equals(BIConst.Global))
             {
-                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
                 tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
             }
             var table = tableClient.GetTableReference("IESOpenApi");
@@ -152,6 +150,68 @@ namespace TEAMModelBI.Controllers.BINormal
             return Ok(new { state = 200 , bizUsers });
         }
 
+        /// <summary>
+        /// 关联用户和企业
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("set-userrebiz")]
+        public async Task<IActionResult> SetUserReBiz(JsonElement jsonElement) 
+        {
+            if(!jsonElement.TryGetProperty("userRowKey", out JsonElement userRowKey)) return BadRequest();
+            if (!jsonElement.TryGetProperty("bizRowKey", out JsonElement bizRowKey)) return BadRequest();
+            if (!jsonElement.TryGetProperty("bizName", out JsonElement bizName)) return BadRequest();
+            jsonElement.TryGetProperty("roles", out JsonElement roles);
+            jsonElement.TryGetProperty("site", out JsonElement site);
+
+            var tableClient = _azureStorage.GetCloudTableClient();
+            if ($"{site}".Equals(BIConst.Global))
+            {
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
+            }
+            var table = tableClient.GetTableReference("IESOpenApi");
+            BizRelUser findBizRelUser = table.Get<BizRelUser>("BizRelUser", $"{userRowKey}|{bizRowKey}");
+
+            if (findBizRelUser == null)
+            {
+                BizRelUser bizRelUser = new() { PartitionKey = "BizRelUser", RowKey = $"{userRowKey}|{bizRowKey}", userId = $"{userRowKey}", bizId = $"{bizRowKey}", bizName = $"{bizName}", roles = string.IsNullOrEmpty($"{roles}") ? "develo" : $"{roles}" };
+                await table.SaveOrUpdate<BizRelUser>(bizRelUser);
+                return Ok(new { state = RespondCode.Ok, bizRelUser });
+            }
+            else return Ok(new { state = RespondCode.NotFound,msg="该账户已经是该企业的用户" });
+        }
+
+        /// <summary>
+        /// 获取账户关联的企业信息
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-userrebizs")]
+        public async Task<IActionResult> GetUserReBizs(JsonElement jsonElement)
+        {
+            jsonElement.TryGetProperty("userId", out JsonElement userId);
+            jsonElement.TryGetProperty("site", out JsonElement site);
+
+            var tableClient = _azureStorage.GetCloudTableClient();
+            if ($"{site}".Equals(BIConst.Global))
+            {
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
+            }
+            var table = tableClient.GetTableReference("IESOpenApi");
+
+            List<BizRelUser> bizRelUsers = new();
+
+            if (!string.IsNullOrEmpty($"{userId}"))
+                bizRelUsers = await table.QueryWhereString<BizRelUser>($"PartitionKey eq 'BizRelUser' and userId eq '{userId}'");
+            else
+                //bizRelUsers = await table.FindListByDict<BizRelUser>(new Dictionary<string, object>() { { "PartitionKey ", "BizRelUser" } });
+                bizRelUsers = await table.QueryWhereString<BizRelUser>($"PartitionKey eq 'BizRelUser'");
+
+            return Ok(new { state = RespondCode.Ok, bizRelUsers });
+        }
+
 
     }
 }

+ 75 - 69
TEAMModelBI/Controllers/LoginController.cs

@@ -36,6 +36,8 @@ using Microsoft.AspNetCore.Hosting;
 using TEAMModelBI.Tool;
 using TEAMModelBI.DI.BIAzureStorage;
 using TEAMModelBI.Tool.Context;
+using TEAMModelOS.SDK.Models.Table;
+using TEAMModelOS.SDK.Context.Constant;
 //using static DingTalk.Api.Response.OapiV2UserGetResponse;
 
 namespace TEAMModelBI.Controllers
@@ -583,11 +585,13 @@ namespace TEAMModelBI.Controllers
         /// <param name="jsonElement"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [HttpPost("get-commpany")]
+        [HttpPost("get-bizuserlogin")]
         public async Task<IActionResult> GetCommpanyLogin(JsonElement jsonElement)
         {
-            if (!jsonElement.TryGetProperty("account", out JsonElement accout)) return BadRequest();
-            if (!jsonElement.TryGetProperty("password", out JsonElement password)) return BadRequest();
+            jsonElement.TryGetProperty("mobile", out JsonElement mobile);
+            jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
+            jsonElement.TryGetProperty("mail", out JsonElement mail);
+            if (!jsonElement.TryGetProperty("pwd", out JsonElement password)) return BadRequest();
             jsonElement.TryGetProperty("site", out JsonElement site);
 
             string Website = "China";
@@ -601,54 +605,77 @@ namespace TEAMModelBI.Controllers
                 blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
                 Website = BIConst.Global;
             }
-
-            StringBuilder sqlTxt = new($"select value(c) from c");
-            var temps = $"{accout}".Contains($"@");
-            if (temps)
-                sqlTxt.Append($" where c.emall='{accout}'");
-            else
-                sqlTxt.Append($" where c.mobile='{accout}'");
-
-            Company company = new();
-            List<Company> companies = new();
-            string id_token = "";
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryIterator<Company>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Company") }))
+            Dictionary<string, object> tableDic = new();
+            string tableSql = null;
+            if (!string.IsNullOrEmpty($"{mail}")) 
+            {
+                tableSql = $" PartitionKey eq 'BusinessUser' and mail eq '{mail}'";
+                tableDic = new Dictionary<string, object>() { { "PartitionKey", "BizRelUser" }, { "mail", $"{mail}" } };
+            }
+            if (!string.IsNullOrEmpty($"{tmdId}"))
             {
-                companies.Add(item);
+                tableSql = $" PartitionKey eq 'BusinessUser' and tmdId eq '{tmdId}'";
+                tableDic = new Dictionary<string, object>() { { "PartitionKey", "BizRelUser" }, { "tmdId", $"{tmdId}" } };
             }
-            if (companies.Count > 0)
+            if (!string.IsNullOrEmpty($"{mobile}"))
+            {
+                tableSql = $" PartitionKey eq 'BusinessUser' and mobile eq '{mobile}'";
+                tableDic = new Dictionary<string, object>() { { "PartitionKey", "BizRelUser" }, { "mobile", $"{mobile}" } };
+            }
+
+            if (!string.IsNullOrEmpty(tableSql))
             {
-                foreach (var item in companies)
+                var table = tableClient.GetTableReference("IESOpenApi");
+                List<BusinessUser> findBizUsers = await table.QueryWhereString<BusinessUser>(tableSql);
+                //List<BusinessUser> findBizUsers = await table.FindListByDict<BusinessUser>(tableDic);
+                if (findBizUsers.Count > 0)
                 {
-                    var hashedPw = Utils.HashedPassword(password.ToString(), item.salt.ToString());
-                    if (hashedPw.Equals(item.password))
+                    BusinessUser bizUser = new();
+                    foreach (var item in findBizUsers)
                     {
-                        company = item;
-                        id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, item.id?.ToString(), item.name?.ToString(), company.picture?.ToString(), _option.JwtSecretKey, scope: "company", webSite: Website, expire: 3);
+                        bizUser.PartitionKey = item.PartitionKey;
+                        bizUser.RowKey = item.RowKey;
+                        bizUser.name = item.name;
+                        bizUser.picture = item.picture;
+                        bizUser.tmdId = item.tmdId;
+                        bizUser.mobile = item.mobile;
+                        bizUser.mail = item.mail;
+                        bizUser.salt = item.salt;
+                        bizUser.pwd = item.pwd;
                     }
+                    List<BizRelUser> bizRelUsers = new();
+                    if (bizUser != null) 
+                    {
+                        bizRelUsers = await table.FindListByDict<BizRelUser>(new Dictionary<string, object>() { { "PartitionKey", "BizRelUser" }, { "bizUser", $"{bizUser.RowKey}" } });
+                    }
+                    var hashedPw = Utils.HashedPassword(password.ToString(), bizUser.salt.ToString());
+                    if (hashedPw.Equals(bizUser.pwd))
+                    {
+                        string id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, bizUser.RowKey?.ToString(), bizUser.name?.ToString(), bizUser.picture?.ToString(), _option.JwtSecretKey, scope: "company", webSite: Website, expire: 3);
+                        await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{bizUser.name}【{bizUser.RowKey}】登录商务智能开放平台", _dingDing, tid: bizUser.RowKey, tname: bizUser.name, twebsite: Website?.ToString(), httpContext: HttpContext);
+                        return Ok(new { state = RespondCode.Ok, id_token, bizUser, bizRelUsers });
+                    }
+                    else return Ok(new { state = RespondCode.ForbiddenPwd, msg = "密码错误!" });
                 }
+                else return Ok(new { state = RespondCode.NotFound, msg = "该账户不存在" });                
             }
-            else return Ok(new { state = 404 });
-
-            //保存操作记录
-            //await _azureStorage.SaveBILog("tabledd-update", $"{company.name}【{company.id}】登录商务智能开放平台", _dingDing, tid: company.id, tname: company.name, twebsite: "BI", httpContext: HttpContext);
-            await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{company.name}【{company.id}】登录商务智能开放平台", _dingDing, tid: company.id, tname: company.name, twebsite: Website?.ToString(), httpContext: HttpContext);
-
-            return Ok(new { error = 200, id_token, company });
+            else return Ok(new { state = RespondCode.ParamsError, msg = "参数错误" });
         }
 
         /// <summary>
-        /// 企业注册信息
+        /// 用户信息注册
         /// </summary>
         /// <param name="jsonElement"></param>
         /// <returns></returns>
-        [HttpPost("set-registered")]
+        [HttpPost("set-ropen")]
         public async Task<IActionResult> SetRegistered(JsonElement jsonElement)
         {
             if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
-            if (!jsonElement.TryGetProperty("credit", out JsonElement credit)) return BadRequest();
             if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
-            if (!jsonElement.TryGetProperty("password", out JsonElement password)) return BadRequest();
+            jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
+            jsonElement.TryGetProperty("mail", out JsonElement mail);
+            jsonElement.TryGetProperty("pwd", out JsonElement pwd);
+
             jsonElement.TryGetProperty("site", out JsonElement site);
 
             string Website = "China";
@@ -663,48 +690,27 @@ namespace TEAMModelBI.Controllers
                 Website = BIConst.Global;
             }
 
-            string salt = Utils.CreatSaltString(8);
+            var table = tableClient.GetTableReference("IESOpenApi");
 
-            string sqltxt = $"select value(c) from c where c.mobile='{mobile}'";
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryStreamIterator(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Company") }))
-            {
-                using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                {
-                    return Ok(new { state = 201, msg = "手机号已存在," });
-                }
-            }
+            string salt = Utils.CreatSaltString(8);
 
-            CreateSchoolInfo createCompanyCode = new CreateSchoolInfo()
-            {
-                province = "",
-                id = "",
-                name = $"{name}",
-                city = "",
-                aname = "",
-                createCount = 0,
-            };
-
-            //生成企业ID
-            bool tempStaus = true;
-            do
+            BusinessUser bizUser = null;
+            List<BusinessUser> findBizUsers = await table.QueryWhereString<BusinessUser>($" PartitionKey eq 'BusinessUser' and mobile eq '{mobile}'");
+            if (findBizUsers.Count <= 0)
             {
-                createCompanyCode = await SchoolCode.GenerateSchoolCode(createCompanyCode, _dingDing, _environment);
-                var companyState = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync($"{createCompanyCode.id}", new PartitionKey("Company"));
-                if (companyState.Status != 200) tempStaus = false;
-                else createCompanyCode.createCount = createCompanyCode.createCount >= 3 ? createCompanyCode.createCount = 3 : createCompanyCode.createCount += 1;
-            } while (tempStaus);
-
-            Company company = new() { name = $"{name}", credit = $"{credit}", mobile = $"{mobile}", salt = salt, password = Utils.HashedPassword($"{password}", salt), pk = "Company", code = "Company", createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() };
+                var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{mobile}" } }, _option.Location, _configuration);
 
-            company = await cosmosClient.GetContainer("TEAMModelOS", "Normal").CreateItemAsync<Company>(company, new PartitionKey("Company"));
-
-            //保存操作记录
-            //await _azureStorage.SaveBILog("tabledd-update", $"{company.name}【{company.id}】注册商务智能开放平台", _dingDing, tid: company.id, tname: company.name, twebsite: "BI", httpContext: HttpContext);
-            await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{company.name}【{company.id}】注册商务智能开放平台", _dingDing, tid: company.id, tname: company.name, twebsite: Website?.ToString(), httpContext: HttpContext);
+                if (coreUser != null)
+                    bizUser = new() { RowKey = Guid.NewGuid().ToString(), name = coreUser.name, tmdId = coreUser.id, mobile = coreUser.mobile, mail = coreUser.mail, salt = salt, pwd = string.IsNullOrEmpty($"{pwd}") ? Utils.HashedPassword($"{mobile}", salt) : Utils.HashedPassword($"{pwd}", salt) };
+                else
+                    bizUser = new() { RowKey = Guid.NewGuid().ToString(), name = $"{name}", mobile = $"{mobile}", salt = salt, pwd = string.IsNullOrEmpty($"{pwd}") ? Utils.HashedPassword($"{mobile}", salt) : Utils.HashedPassword($"{pwd}", salt) };
 
+                bizUser = await table.Save<BusinessUser>(bizUser);
 
-            return Ok(new { state = 200, company });
+                await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "bizUser-update", $"{bizUser.name}【{bizUser.RowKey}】注册开放平台用户", _dingDing, tid: bizUser.RowKey, tname: bizUser.name, twebsite: Website?.ToString(), httpContext: HttpContext);
+                return Ok(new { state = RespondCode.Ok, bizUser });
+            }
+            else return Ok(new { state = RespondCode.Conflict, msg = "该手机号已注册开放平台,请直接登录" });
         }
 
         public record DingDingbinds

+ 112 - 26
TEAMModelBI/Tool/CommonFind.cs

@@ -111,15 +111,20 @@ namespace TEAMModelBI.Tool
         public static async Task<List<string>> FindSchoolIds(CosmosClient cosmosClient, string tmdId)
         {
             List<string> schoolIds = new();
-            string schoolSql = $"SELECT DISTINCT REPLACE(c.code,'Teacher-','') AS schoolId,c.code,c.roles,c.id,c.name From c where ARRAY_CONTAINS(c.roles,'assist',true) AND c.status = 'join' AND c.id='{tmdId}'";
+            //string schoolSql = $"SELECT DISTINCT REPLACE(c.code,'Teacher-','') AS schoolId,c.code,c.roles,c.id,c.name From c where ARRAY_CONTAINS(c.roles,'assist',true) AND c.status = 'join' AND c.id='{tmdId}'";
+            //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: schoolSql, requestOptions: new QueryRequestOptions() { }))
+            //{
+            //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+            //    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+            //    {
+            //        schoolIds.Add(obj.GetProperty("schoolId").GetString());
+            //    }
+            //}
 
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: schoolSql, requestOptions: new QueryRequestOptions() { }))
+            string schoolSql = $"SELECT value(REPLACE(c.code, 'Teacher-', '')) FROM c where array_contains(c.roles,'assist',true) and c.pk='Teacher' and c.id='{tmdId}'";
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: schoolSql, requestOptions: new QueryRequestOptions() { }))
             {
-                using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
-                {
-                    schoolIds.Add(obj.GetProperty("schoolId").GetString());
-                }
+                schoolIds.Add(item);
             }
 
             return schoolIds;
@@ -166,15 +171,20 @@ namespace TEAMModelBI.Tool
             List<string> teachers = new();
             foreach (var school in schools) 
             {
-                string sqlTxt = $"select c.id from c where ARRAY_CONTAINS(c.roles,'{rolesName}',true) and c.status = 'join'";
-                await foreach (var itemTeac in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() {PartitionKey =new PartitionKey($"Teacher-{school}") }))
+                string sqlTxt = $"select value(c.id) from c where ARRAY_CONTAINS(c.roles,'{rolesName}',true) and c.status = 'join'";
+                await foreach (var itemTeac in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school}") }))
                 {
-                    using var json = await JsonDocument.ParseAsync(itemTeac.ContentStream);
-                    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
-                    {
-                        teachers.Add(obj.GetProperty("id").GetString());
-                    }
+                    teachers.Add(itemTeac);
                 }
+                //string sqlTxt = $"select c.id from c where ARRAY_CONTAINS(c.roles,'{rolesName}',true) and c.status = 'join'";
+                //await foreach (var itemTeac in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() {PartitionKey =new PartitionKey($"Teacher-{school}") }))
+                //{
+                //    using var json = await JsonDocument.ParseAsync(itemTeac.ContentStream);
+                //    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                //    {
+                //        teachers.Add(obj.GetProperty("id").GetString());
+                //    }
+                //}
             }
             return teachers;
         }
@@ -191,7 +201,7 @@ namespace TEAMModelBI.Tool
         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 ");
+            StringBuilder sqlTxt = new("select value(count(c.id)) as totals from c ");
             if (!string.IsNullOrEmpty(sqlWhere)) 
             {
                 sqlTxt.Append(sqlWhere);
@@ -201,17 +211,22 @@ namespace TEAMModelBI.Tool
             {
                 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}") }))
+                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(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();
-                            }
-                        }
+                        totals += item;
                     }
+
+                    //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();
+                    //        }
+                    //    }
+                    //}
                 }
             }
 
@@ -229,7 +244,7 @@ namespace TEAMModelBI.Tool
         public static async Task<int> GetSqlValueCount(CosmosClient cosmosClient, string container, string SqlTxt,string code = null) 
         {
             int totals = 0;
-            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: SqlTxt,requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: SqlTxt,requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
             {
                 totals += item;
             }
@@ -250,7 +265,7 @@ namespace TEAMModelBI.Tool
             int totals = 0;
             foreach (var container in containers)
             {
-                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: SqlTxt, requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: SqlTxt, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
                 {
                     totals += item;
                 }
@@ -258,5 +273,76 @@ namespace TEAMModelBI.Tool
 
             return totals;
         }
+
+        /// <summary>
+        /// 通过SQL 语句返回实体信息
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="cosmosClient"></param>
+        /// <param name="container"></param>
+        /// <param name="sqlTxt"></param>
+        /// <param name="code"></param>
+        /// <param name="ids"></param>
+        /// <returns></returns>
+        public static async Task<List<T>> GetObject<T>(CosmosClient cosmosClient, string container, string sqlTxt, string code = null,List<string> ids = null)
+        {
+            List<T> temps = new();
+            if (ids.Count > 0)
+            {
+                foreach (var item in ids)
+                {
+                    string sql = $"{sqlTxt} c.id='{item}'";
+                    await foreach (var items in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<T>(queryText: sql, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+                    {
+                        temps.Add(items);
+                    }
+                }
+            }
+            else
+            {
+                await foreach (var items in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<T>(queryText: sqlTxt, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+                {
+                    temps.Add(items);
+                }
+            }
+            return temps;
+        }
+
+        /// <summary>
+        /// 通过SQL 语句返回实体信息
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="cosmosClient"></param>
+        /// <param name="containers"></param>
+        /// <param name="sqlTxt"></param>
+        /// <param name="code"></param>
+        /// <param name="ids"></param>
+        /// <returns></returns>
+        public static async Task<List<T>> GetObject<T>(CosmosClient cosmosClient, List<string> containers, string sqlTxt, string code = null, List<string> ids = null)
+        {
+            List<T> temps = new();
+            foreach (var container in containers)
+            {
+                if (ids.Count > 0)
+                {
+                    foreach (var item in ids)
+                    {
+                        string sql = $"{sqlTxt} c.id='{item}'";
+                        await foreach (var items in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<T>(queryText: sql, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+                        {
+                            temps.Add(items);
+                        }
+                    }
+                }
+                else
+                {
+                    await foreach (var items in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<T>(queryText: sqlTxt, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+                    {
+                        temps.Add(items);
+                    }
+                }
+            }
+            return temps;
+        }
     }
 }

+ 5 - 0
TEAMModelOS.SDK/Context/Constant/RespondCode.cs

@@ -50,6 +50,11 @@ namespace TEAMModelOS.SDK.Context.Constant
         /// 服务器拒绝  403
         /// </summary>
         public readonly static int Forbidden = 403;
+        
+        /// <summary>
+        /// 密码错误
+        /// </summary>
+        public readonly static int ForbiddenPwd = 40301;
 
         /// <summary>
         /// 未找到    404

+ 27 - 3
TEAMModelOS.SDK/Models/Table/BusinessConfig.cs

@@ -103,18 +103,32 @@ namespace TEAMModelOS.SDK.Models.Table
             PartitionKey = "BusinessUser";
         }
 
+        /// <summary>
+        /// 人员名称
+        /// </summary>
+        public string name { get; set; }
+
+        /// <summary>
+        /// 头像
+        /// </summary>
+        public string picture { get; set; }
+
         /// <summary>
         /// 醍摩豆账户
         /// </summary>
-        [Required(ErrorMessage = "第三方账户ID 必须填写")]
         public string tmdId { get; set; }
-
+        
         /// <summary>
         /// 手机号
         /// </summary>
         [Required(ErrorMessage = "第三方账户手机号 必须填写")]
         public string mobile { get; set; }
 
+        /// <summary>
+        /// 邮箱
+        /// </summary>
+        public string mail { get; set; }
+
         /// <summary>
         /// 密码生成秘钥
         /// </summary>
@@ -131,17 +145,27 @@ namespace TEAMModelOS.SDK.Models.Table
     /// </summary>
     public class BizRelUser : TableEntity
     {
-        //rowKey   tmdid-bizid
+        //rowKey   userid-bizid
         public BizRelUser()
         {
             PartitionKey = "BizRelUser";
         }
 
+        /// <summary>
+        /// 用户rowKey
+        /// </summary>
+        public string userId { get; set; }
+
         /// <summary>
         /// 企业id
         /// </summary>
         public string bizId { get; set; }
 
+        /// <summary>
+        /// 企业名称
+        /// </summary>
+        public string bizName { get; set; }
+
         /// <summary>
         /// 角色
         /// </summary>