|
@@ -1,284 +0,0 @@
|
|
|
-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.Models;
|
|
|
-using TEAMModelOS.Models;
|
|
|
-using TEAMModelOS.SDK.Context.BI;
|
|
|
-using TEAMModelOS.SDK.Context.Constant;
|
|
|
-using TEAMModelOS.SDK.DI;
|
|
|
-using TEAMModelOS.SDK.Extension;
|
|
|
-using TEAMModelOS.SDK.Models;
|
|
|
-using TEAMModelOS.SDK.Models.Table;
|
|
|
-
|
|
|
-namespace TEAMModelBI.Controllers.BITable
|
|
|
-{
|
|
|
- [Route("bizusertable")]
|
|
|
- [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>
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- [HttpPost("set-bizuser")]
|
|
|
- public async Task<IActionResult> SetBizUser([FromBody] BusinessUser bizUser, [FromHeader] string site)
|
|
|
- {
|
|
|
- var tableClient = _azureStorage.GetCloudTableClient();
|
|
|
- if ($"{site}".Equals(BIConst.Global))
|
|
|
- {
|
|
|
- tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
|
|
|
- }
|
|
|
-
|
|
|
- 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>
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- [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 tableClient = _azureStorage.GetCloudTableClient();
|
|
|
- if ($"{site}".Equals(BIConst.Global))
|
|
|
- {
|
|
|
- tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
|
|
|
- }
|
|
|
- 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>
|
|
|
- [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 tableClient = _azureStorage.GetCloudTableClient();
|
|
|
- if ($"{site}".Equals(BIConst.Global))
|
|
|
- {
|
|
|
- tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
|
|
|
- }
|
|
|
- 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 });
|
|
|
- }
|
|
|
-
|
|
|
- /// <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();
|
|
|
- List<RelBizInfo> relBizInfos = 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'");
|
|
|
- if (bizRelUsers.Count > 0)
|
|
|
- {
|
|
|
- if (bizRelUsers.Count > 0)
|
|
|
- {
|
|
|
- foreach (var item in bizRelUsers)
|
|
|
- {
|
|
|
- BusinessConfig businessConfig = table.Get<BusinessConfig>("BusinessConfig", item.bizId);
|
|
|
- RelBizInfo relBizInfo = new()
|
|
|
- {
|
|
|
- userRowKey = item.userId,
|
|
|
- relId = item.RowKey,
|
|
|
- bizRowKey = item.bizId,
|
|
|
- roles = !string.IsNullOrEmpty($"{item.roles}") ? new List<string>(item.roles.Split(',')) : new List<string>()
|
|
|
- };
|
|
|
- if (businessConfig != null)
|
|
|
- {
|
|
|
- relBizInfo.bizName = businessConfig.name;
|
|
|
- relBizInfo.bizCredit = businessConfig.credit;
|
|
|
- relBizInfo.bizPicture = businessConfig.picture;
|
|
|
- relBizInfos.Add(relBizInfo);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return Ok(new { state = RespondCode.Ok, relBizInfos });
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 获取企业用户信息
|
|
|
- /// </summary>
|
|
|
- /// <param name="jsonElement"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("get-bizusers")]
|
|
|
- public async Task<IActionResult> GetBizUsers(JsonElement jsonElement)
|
|
|
- {
|
|
|
- if (!jsonElement.TryGetProperty("bizId", out JsonElement bizId)) return BadRequest();
|
|
|
- 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<bizUsers> bizUsers = new();
|
|
|
- string bizSql = $" PartitionKey eq 'BizRelUser' and bizId eq '{bizId}'";
|
|
|
-
|
|
|
- List<BizRelUser> bizRelUsers = await table.QueryWhereString<BizRelUser>(bizSql);
|
|
|
- foreach (var item in bizRelUsers)
|
|
|
- {
|
|
|
- BusinessUser busUser = table.Get<BusinessUser>("BusinessUser", $"{item.userId}");
|
|
|
- bizUsers bizUser = new() { RowKey = $"{busUser.RowKey}", name = busUser.name, mail = busUser.mail, mobile = busUser.mobile, roles = !string.IsNullOrEmpty(item.roles) ? new List<string>(item.roles.Split(',')) : new List<string>() };
|
|
|
- bizUsers.Add(bizUser);
|
|
|
- }
|
|
|
-
|
|
|
- return Ok(new { state = 200, bizUsers });
|
|
|
- }
|
|
|
-
|
|
|
- public record bizUsers
|
|
|
- {
|
|
|
- public string RowKey { get; set; }
|
|
|
- public string name { get; set; }
|
|
|
- public string mail { get; set; }
|
|
|
- public string mobile { get; set; }
|
|
|
- public List<string> roles { get; set; }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-}
|