Przeglądaj źródła

第三方用户相关接口

Li 3 lat temu
rodzic
commit
9c396eae28

+ 157 - 0
TEAMModelBI/Controllers/BINormal/CompanyUserController.cs

@@ -0,0 +1,157 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using System;
+using System.Collections.Generic;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelBI.Tool.Context;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models.Table;
+
+namespace TEAMModelBI.Controllers.BINormal
+{
+    [Route("bizuser")]
+    [ApiController]
+    public class CompanyUserController : ControllerBase
+    {
+        public readonly AzureCosmosFactory _azureCosmos;
+        public readonly AzureStorageFactory _azureStorage;
+        public readonly DingDing _dingDing;
+        public readonly Option _option;
+
+        public CompanyUserController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option)
+        {
+            _azureCosmos = azureCosmos;
+            _azureStorage = azureStorage;
+            _dingDing = dingDing;
+            _option = option?.Value;
+        }
+
+        /// <summary>
+        /// 新增和修改第三方用户信息
+        /// </summary>
+        /// <param name="bizUser"></param>
+        /// <param name="site"></param>
+        /// <returns></returns>
+        [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.GlobalSite))
+            {
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+            }
+
+            var table = tableClient.GetTableReference("IESOpenApi");
+            if (bizUser.RowKey != null)
+            {
+                BusinessUser tempUser = table.Get<BusinessUser>(partitionKey: "BusinessUser", rowKey: $"{bizUser.RowKey}");
+                if (tempUser != null)
+                {
+                    bizUser.PartitionKey = "BusinessUser";
+                    bizUser = await table.SaveOrUpdate<BusinessUser>(bizUser);
+                }
+                else
+                {
+                    bizUser.PartitionKey = "BusinessUser";
+                    bizUser.RowKey = Guid.NewGuid().ToString();
+                    string salt = Utils.CreatSaltString(8);
+                    bizUser.salt = string.IsNullOrEmpty(bizUser.pwd) ? Utils.HashedPassword(bizUser.mobile, salt) : Utils.HashedPassword(bizUser.pwd, salt);
+
+                    bizUser = await table.SaveOrUpdate<BusinessUser>(bizUser);
+                }
+            }
+            else
+            {
+                bizUser.PartitionKey = "BusinessUser";
+                bizUser.RowKey = Guid.NewGuid().ToString();
+                string salt = Utils.CreatSaltString(8);
+                bizUser.salt = string.IsNullOrEmpty(bizUser.pwd) ? Utils.HashedPassword(bizUser.mobile, salt) : Utils.HashedPassword(bizUser.pwd, salt);
+
+                bizUser = await table.SaveOrUpdate<BusinessUser>(bizUser);
+            }
+
+            return Ok(new { state = 200, bizUser });
+        }
+        
+        /// <summary>
+        /// 重置密码
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [HttpPost("res-pwd")]
+        public async Task<IActionResult> ResetPwd(JsonElement jsonElement) 
+        {
+            try
+            {
+                if (jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
+                jsonElement.TryGetProperty("pwd", out JsonElement pwd);
+                jsonElement.TryGetProperty("site", out JsonElement site);
+
+                var cosmosClient = _azureCosmos.GetCosmosClient();
+                var tableClient = _azureStorage.GetCloudTableClient();
+                if ($"{site}".Equals(BIConst.GlobalSite))
+                {
+                    cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                    tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+                }
+                var table = tableClient.GetTableReference("IESOpenApi");
+
+                List<BusinessUser> bizUsers = await table.QueryWhereString<BusinessUser>($" PartitionKey eq 'BusinessUser' and mobile eq '{mobile}'");
+
+                string salt = Utils.CreatSaltString(8);
+                string resPwd = string.IsNullOrEmpty($"{pwd}") ? Utils.HashedPassword($"{mobile}", salt) : Utils.HashedPassword($"{pwd}", salt);
+                foreach (var item in bizUsers)
+                {
+                    item.salt = salt;
+                    item.pwd = resPwd;
+                }
+
+                bizUsers = await table.SaveOrUpdateAll<BusinessUser>(bizUsers);
+
+                //BusinessUser bizUser = table.Get<BusinessUser>(partitionKey: "BusinessUser", rowKey: $"{mobile}");
+                //bizUser.RowKey = Guid.NewGuid().ToString();
+                //bizUser.pwd = string.IsNullOrEmpty($"{pwd}") ? Utils.HashedPassword(bizUser.mobile, salt) : Utils.HashedPassword(bizUser.pwd, salt);
+                //bizUser = await table.SaveOrUpdate<BusinessUser>(bizUser);
+
+                return Ok(new { state = 200, bizUsers });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"open ,{_option.Location} , /business/set-companyschool   \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
+                return BadRequest();
+            }
+        }
+
+        /// <summary>
+        /// 查询用户的关联
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [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.GlobalSite))
+            {
+                cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
+                tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
+            }
+            var table = tableClient.GetTableReference("IESOpenApi");
+            List<BusinessUser> bizUsers = await table.QueryWhereString<BusinessUser>($" PartitionKey eq 'BusinessUser' and tmdId eq '{tmdId}'");
+
+            return Ok(new { state = 200 , bizUsers });
+        }
+
+
+    }
+}

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

@@ -39,13 +39,13 @@ namespace TEAMModelOS.SDK.Models.Table
         /// <summary>
         /// <summary>
         /// 合作方名称
         /// 合作方名称
         /// </summary>
         /// </summary>
-        [Required(ErrorMessage = "{0} 必须填写")]
+        [Required(ErrorMessage = "合作方名称 必须填写")]
         public string name { get; set; }
         public string name { get; set; }
 
 
         /// <summary>
         /// <summary>
         /// 统一社会信用代码
         /// 统一社会信用代码
         /// </summary>
         /// </summary>
-        [Required(ErrorMessage = "{0} 必须填写")]
+        [Required(ErrorMessage = "合作方统一社会信用代码 必须填写")]
         public string credit { get; set; }
         public string credit { get; set; }
 
 
         /// <summary>
         /// <summary>
@@ -56,7 +56,7 @@ namespace TEAMModelOS.SDK.Models.Table
         /// <summary>
         /// <summary>
         /// 联系人手机号
         /// 联系人手机号
         /// </summary>
         /// </summary>
-        [Required(ErrorMessage = "{0} 必须填写")]
+        [Required(ErrorMessage = "合作方联系人手机号 必须填写")]
         public string mobile { get; set; }
         public string mobile { get; set; }
 
 
         /// <summary>
         /// <summary>
@@ -90,4 +90,61 @@ namespace TEAMModelOS.SDK.Models.Table
         /// </summary>
         /// </summary>
         public long createTime { get; set; }
         public long createTime { get; set; }
     }
     }
+
+    /// <summary>
+    /// 开放平台用户
+    /// </summary>
+    [TableName(Name = "IESOpenApi")]
+    public class BusinessUser : TableEntity 
+    {
+        //rowKey   tmdid
+        public BusinessUser()
+        {
+            PartitionKey = "BusinessUser";
+        }
+
+        /// <summary>
+        /// 醍摩豆账户
+        /// </summary>
+        [Required(ErrorMessage = "第三方账户ID 必须填写")]
+        public string tmdId { get; set; }
+
+        /// <summary>
+        /// 手机号
+        /// </summary>
+        [Required(ErrorMessage = "第三方账户手机号 必须填写")]
+        public string mobile { get; set; }
+
+        /// <summary>
+        /// 密码生成秘钥
+        /// </summary>
+        public string salt { get; set; }
+
+        /// <summary>
+        /// 密码
+        /// </summary>
+        public string pwd { get; set; }
+    }
+
+    /// <summary>
+    /// 关联信息
+    /// </summary>
+    public class BizRelUser : TableEntity
+    {
+        //rowKey   tmdid-bizid
+        public BizRelUser()
+        {
+            PartitionKey = "BizRelUser";
+        }
+
+        /// <summary>
+        /// 企业id
+        /// </summary>
+        public string bizId { get; set; }
+
+        /// <summary>
+        /// 角色
+        /// </summary>
+        public string roles { get; set; }
+    }
 }
 }