|
@@ -0,0 +1,287 @@
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using TEAMModelOS.SDK;
|
|
|
+using TEAMModelOS.SDK.Context.Constant;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.SDK.Models.Table;
|
|
|
+
|
|
|
+namespace TEAMModelOS.Controllers
|
|
|
+{
|
|
|
+ [Route("biz")]
|
|
|
+ [ApiController]
|
|
|
+ public class BizUsersController : ControllerBase
|
|
|
+ {
|
|
|
+ private readonly IConfiguration _configuration;
|
|
|
+ //数据容器
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ //文件容器
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ //钉钉提示信息
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ //隐式登录
|
|
|
+ private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
+ public BizUsersController(IConfiguration configuration, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, CoreAPIHttpService coreAPIHttpService)
|
|
|
+ {
|
|
|
+ _configuration = configuration;
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _option = option?.Value;
|
|
|
+ _coreAPIHttpService = coreAPIHttpService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 开放平台用户登录
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-bizuserlogin")]
|
|
|
+ public async Task<IActionResult> GetCommpanyLogin(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ 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();
|
|
|
+
|
|
|
+ var tableClient = _azureStorage.GetCloudTableClient();
|
|
|
+ var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
|
|
|
+ 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}"))
|
|
|
+ {
|
|
|
+ tableSql = $" PartitionKey eq 'BusinessUser' and tmdId eq '{tmdId}'";
|
|
|
+ //tableDic = new Dictionary<string, object>() { { "PartitionKey", "BizRelUser" }, { "tmdId", $"{tmdId}" } };
|
|
|
+ }
|
|
|
+ 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))
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ BusinessUser bizUser = new();
|
|
|
+ foreach (var item in findBizUsers)
|
|
|
+ {
|
|
|
+ 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();
|
|
|
+
|
|
|
+ List<RelBizInfo> relBizInfos = new();
|
|
|
+ if (bizUser != null)
|
|
|
+ {
|
|
|
+ string tableSqlUser = $"PartitionKey eq 'BizRelUser' and userId eq '{bizUser.RowKey}'";
|
|
|
+ bizRelUsers = await table.QueryWhereString<BizRelUser>(tableSqlUser);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var hashedPw = Utils.HashedPassword(password.ToString(), bizUser.salt.ToString());
|
|
|
+ if (hashedPw.Equals(bizUser.pwd))
|
|
|
+ {
|
|
|
+ string openid_token = JwtAuthExtension.CreateBizLoginAuthToken(_option.HostName, bizUser.RowKey?.ToString(), bizUser.name?.ToString(), bizUser.picture?.ToString(), $"{_option.Location}-Open", _option.JwtSecretKey, expire: 3);
|
|
|
+
|
|
|
+ await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{bizUser.name}【{bizUser.RowKey}】登录商务智能开放平台", _dingDing, tid: bizUser.RowKey, tname: bizUser.name, twebsite: _option.Location, httpContext: HttpContext);
|
|
|
+ return Ok(new { state = RespondCode.Ok, openid_token, bizUser, relBizInfos });
|
|
|
+ }
|
|
|
+ else return Ok(new { state = RespondCode.ForbiddenPwd, msg = "密码错误!" });
|
|
|
+ }
|
|
|
+ else return Ok(new { state = RespondCode.NotFound, msg = "该账户不存在" });
|
|
|
+ }
|
|
|
+ else return Ok(new { state = RespondCode.ParamsError, msg = "参数错误" });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 注册开放平台用户
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("set-ropen")]
|
|
|
+ public async Task<IActionResult> SetRegistered(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
|
|
|
+ jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
|
|
|
+ jsonElement.TryGetProperty("mail", out JsonElement mail);
|
|
|
+ jsonElement.TryGetProperty("pwd", out JsonElement pwd);
|
|
|
+
|
|
|
+ string Website = "China";
|
|
|
+ var tableClient = _azureStorage.GetCloudTableClient();
|
|
|
+ var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
|
|
|
+
|
|
|
+ var table = tableClient.GetTableReference("IESOpenApi");
|
|
|
+
|
|
|
+ string salt = Utils.CreatSaltString(8);
|
|
|
+
|
|
|
+ BusinessUser bizUser = null;
|
|
|
+ List<BusinessUser> findBizUsers = await table.QueryWhereString<BusinessUser>($" PartitionKey eq 'BusinessUser' and mobile eq '{mobile}'");
|
|
|
+ if (findBizUsers.Count <= 0)
|
|
|
+ {
|
|
|
+ var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{mobile}" } }, _option.Location, _configuration);
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ 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 = "该手机号已注册开放平台,请直接登录" });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询企业详细信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElenent"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-info")]
|
|
|
+ public async Task<IActionResult> GetInfo(JsonElement jsonElenent)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if(!jsonElenent.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ var tableClient = _azureStorage.GetCloudTableClient();
|
|
|
+
|
|
|
+ var table = tableClient.GetTableReference("IESOpenApi");
|
|
|
+ Dictionary<string, object> keyValue = new() { { "PartitionKey", "BusinessConfig" } };
|
|
|
+ if (!string.IsNullOrEmpty($"{id}"))
|
|
|
+ {
|
|
|
+ keyValue.Add("RowKey", $"{id}");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BusinessConfig> companys = table.FindListByDictSync<BusinessConfig>(keyValue);
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, companys });
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} , /biz/get-info \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 重新秘钥token
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("reset-bus")]
|
|
|
+ public async Task<IActionResult> ResetBus(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ var table = _azureStorage.GetCloudTableClient().GetTableReference("IESOpenApi");
|
|
|
+
|
|
|
+ List<BusinessConfig> busConfigs = await table.FindListByDict<BusinessConfig>(new Dictionary<string, object>() { { "PartitionKey", "BusinessConfig" }, { "RowKey", $"{id}" } });
|
|
|
+ if (busConfigs.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var busConfig in busConfigs)
|
|
|
+ {
|
|
|
+ var auth_token = JwtAuthExtension.CreateBusinessApiToken(_option.Location, busConfig.RowKey, _option.JwtSecretKey, "business");
|
|
|
+ busConfig.jti = auth_token.jti;
|
|
|
+ busConfig.token = auth_token.jwt;
|
|
|
+ }
|
|
|
+ await table.SaveOrUpdateAll(busConfigs);
|
|
|
+ return Ok(new { state = RespondCode.Ok, busConfigs });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return Ok(new { state = RespondCode.ParamsError, msg = "未找到企业信息" });
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} , /biz/reset-bus \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 依据企业ID查询关联的学校
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-companyschool")]
|
|
|
+ public async Task<IActionResult> GetCompanySc(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if(!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+
|
|
|
+ var table = _azureStorage.GetCloudTableClient().GetTableReference("IESOpenApi");
|
|
|
+ Dictionary<string, object> keyValue = new() { { "PartitionKey", $"BusinessSchool" } };
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{id}"))
|
|
|
+ {
|
|
|
+ keyValue.Add("bizid", $"{id}");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BusinessSchool> busSchools = await table.FindListByDict<BusinessSchool>(keyValue);
|
|
|
+
|
|
|
+ return Ok(new { state = 200, busSchools });
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} , /biz/get-companyschool \n {e.Message}\n{e.StackTrace} \n ", GroupNames.成都开发測試群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|