|
@@ -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 });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|