|
@@ -36,6 +36,8 @@ using Microsoft.AspNetCore.Hosting;
|
|
using TEAMModelBI.Tool;
|
|
using TEAMModelBI.Tool;
|
|
using TEAMModelBI.DI.BIAzureStorage;
|
|
using TEAMModelBI.DI.BIAzureStorage;
|
|
using TEAMModelBI.Tool.Context;
|
|
using TEAMModelBI.Tool.Context;
|
|
|
|
+using TEAMModelOS.SDK.Models.Table;
|
|
|
|
+using TEAMModelOS.SDK.Context.Constant;
|
|
//using static DingTalk.Api.Response.OapiV2UserGetResponse;
|
|
//using static DingTalk.Api.Response.OapiV2UserGetResponse;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers
|
|
namespace TEAMModelBI.Controllers
|
|
@@ -583,11 +585,13 @@ namespace TEAMModelBI.Controllers
|
|
/// <param name="jsonElement"></param>
|
|
/// <param name="jsonElement"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
- [HttpPost("get-commpany")]
|
|
|
|
|
|
+ [HttpPost("get-bizuserlogin")]
|
|
public async Task<IActionResult> GetCommpanyLogin(JsonElement jsonElement)
|
|
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);
|
|
jsonElement.TryGetProperty("site", out JsonElement site);
|
|
|
|
|
|
string Website = "China";
|
|
string Website = "China";
|
|
@@ -601,54 +605,77 @@ namespace TEAMModelBI.Controllers
|
|
blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
|
|
blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
|
|
Website = 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>
|
|
- /// 企业注册信息
|
|
|
|
|
|
+ /// 用户信息注册
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="jsonElement"></param>
|
|
/// <param name="jsonElement"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- [HttpPost("set-registered")]
|
|
|
|
|
|
+ [HttpPost("set-ropen")]
|
|
public async Task<IActionResult> SetRegistered(JsonElement jsonElement)
|
|
public async Task<IActionResult> SetRegistered(JsonElement jsonElement)
|
|
{
|
|
{
|
|
if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
|
|
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("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);
|
|
jsonElement.TryGetProperty("site", out JsonElement site);
|
|
|
|
|
|
string Website = "China";
|
|
string Website = "China";
|
|
@@ -663,48 +690,27 @@ namespace TEAMModelBI.Controllers
|
|
Website = BIConst.Global;
|
|
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
|
|
public record DingDingbinds
|