|
@@ -164,15 +164,15 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
//保存操作记录
|
|
|
await _azureStorage.SaveBILog("tabledd-update", $"{_tmdName}【{_tmdId}】从钉钉组织结构更新至Azure Table表【DDUserInfo】中。", _dingDing, httpContext: HttpContext);
|
|
|
|
|
|
- var tempddUserInfos = ddUserInfos.GroupBy(c => c.RowKey).Select(c => c.First()).ToList();//去重
|
|
|
+ var tempddUserInfos = ddUserInfos.GroupBy(c => c.userId).Select(c => c.First()).ToList();//去重
|
|
|
//List<DingDingUserInfo> TempdingDingUserInfos = await _azureStorage.SaveOrUpdateAll(dingDingUserInfos); //只是保存至Table
|
|
|
//查询数据的数据 并和钉钉查询的数据对比,找出不同的数据,并删除 待后期测试
|
|
|
var users = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{divide}" } });
|
|
|
List<DingDingUserInfo> noExisits = new();
|
|
|
if (users.Count > 0)
|
|
|
{
|
|
|
- List<DingDingUserInfo> existsUserInfo = users.Where(u => !tempddUserInfos.Exists(e => u.RowKey.Equals(e.RowKey) && u.PartitionKey.Equals(e.PartitionKey))).ToList();
|
|
|
- existsUserInfo.AddRange(tempddUserInfos.Where(e => !users.Exists(u => e.RowKey.Equals(u.RowKey) && e.PartitionKey.Equals(u.PartitionKey))).ToList());
|
|
|
+ List<DingDingUserInfo> existsUserInfo = users.Where(u => !tempddUserInfos.Exists(e => u.userId.Equals(e.userId) && u.PartitionKey.Equals(e.PartitionKey))).ToList();
|
|
|
+ existsUserInfo.AddRange(tempddUserInfos.Where(e => !users.Exists(u => e.userId.Equals(u.userId) && e.PartitionKey.Equals(u.PartitionKey))).ToList());
|
|
|
noExisits = await table.DeleteAll(existsUserInfo);
|
|
|
}
|
|
|
List<DingDingUserInfo> UserInfo = await table.SaveOrUpdateAll(tempddUserInfos); //保存和修改至Table
|
|
@@ -216,6 +216,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
{
|
|
|
partitionKey = item.PartitionKey,
|
|
|
rowKey = item.RowKey,
|
|
|
+ userId = item.userId,
|
|
|
unionId = item.unionId,
|
|
|
name = item.name,
|
|
|
title = item.title,
|
|
@@ -250,6 +251,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
{
|
|
|
partitionKey = item.PartitionKey,
|
|
|
rowKey = item.RowKey,
|
|
|
+ userId = item.userId,
|
|
|
unionId = item.unionId,
|
|
|
name = item.name,
|
|
|
title = item.title,
|
|
@@ -584,6 +586,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
{
|
|
|
partitionKey = item.PartitionKey,
|
|
|
rowKey = item.RowKey,
|
|
|
+ userId = item.userId,
|
|
|
unionId = item.unionId,
|
|
|
name = item.name,
|
|
|
title = item.title,
|
|
@@ -716,7 +719,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- if (!jsonElement.TryGetProperty("columnKey", out JsonElement partitionKey)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("partitionKey", out JsonElement partitionKey)) return BadRequest();
|
|
|
if (!jsonElement.TryGetProperty("rowKey", out JsonElement rowKey)) return BadRequest();
|
|
|
if (!jsonElement.TryGetProperty("isAdmin", out JsonElement isAdmin)) return BadRequest();
|
|
|
|
|
@@ -726,7 +729,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
|
|
|
List<DDUserInfo> ddUserInfos = new();
|
|
|
List<string> roles = new();//角色列表
|
|
|
- List<string> permissions = new List<string>();//权限列表
|
|
|
+ List<string> permissions = new();//权限列表
|
|
|
|
|
|
StringBuilder msg = new($"{_tmdName}【{_tmdId}】");
|
|
|
|
|
@@ -741,16 +744,18 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
List<string> tempRoles = new(user.roles.Split(","));
|
|
|
if (!tempRoles.Contains("admin"))
|
|
|
{
|
|
|
- tempRoles.Add("admin");
|
|
|
+ tempRoles.Add("admin");
|
|
|
}
|
|
|
user.roles = string.Join(",", tempRoles);
|
|
|
-
|
|
|
+ user.joinTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(user);
|
|
|
|
|
|
if (respUser != null)
|
|
|
{
|
|
|
roles = !string.IsNullOrEmpty($"{respUser.roles}") ? new List<string>(respUser.roles.Split(",")) : new List<string>();
|
|
|
}
|
|
|
+
|
|
|
+ msg.Append($"添加{respUser.name}【{respUser.RowKey}】账号的BI管理员");
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -788,6 +793,143 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 通过醍摩豆账户信息 设置BI后台管理员
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "admin")]
|
|
|
+ [HttpPost("set-tmdadmin")]
|
|
|
+ public async Task<IActionResult> SetTmdBackendAdmin(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("tmdName", out JsonElement tmdName)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
|
|
|
+ jsonElement.TryGetProperty("picture ", out JsonElement picture);
|
|
|
+ jsonElement.TryGetProperty("mail ", out JsonElement mail);
|
|
|
+
|
|
|
+ var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
|
|
|
+
|
|
|
+ List<DDUserInfo> ddUserInfos = new();
|
|
|
+ List<string> roles = new();//角色列表
|
|
|
+ List<string> permissions = new();//权限列表
|
|
|
+
|
|
|
+ StringBuilder msg = new($"{_tmdName}【{_tmdId}】");
|
|
|
+ var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
|
|
|
+ //string divide = _configuration["CustomParam:SiteScope"];
|
|
|
+ string divide = _option.Location;
|
|
|
+
|
|
|
+ Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", $"{divide}" }, { "mobile", $"{mobile}" } };
|
|
|
+ List<DingDingUserInfo> ddUserInfoList = await table.FindListByDict<DingDingUserInfo>(dic);
|
|
|
+
|
|
|
+ if (ddUserInfoList.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var user in ddUserInfoList)
|
|
|
+ {
|
|
|
+ List<string> tempRoles = new(user.roles.Split(","));
|
|
|
+ if (tempRoles.Count > 0)
|
|
|
+ {
|
|
|
+ if (!tempRoles.Contains("admin"))
|
|
|
+ {
|
|
|
+ tempRoles.Add("admin");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ tempRoles.Add("admin");
|
|
|
+
|
|
|
+ user.roles = string.Join(",", tempRoles);
|
|
|
+ user.joinTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ user.tmdId = $"{tmdId}";
|
|
|
+ user.tmdName = $"{tmdName}";
|
|
|
+ user.tmdMobile = $"{mobile}";
|
|
|
+ if (!string.IsNullOrEmpty($"{picture}"))
|
|
|
+ {
|
|
|
+ user.picture = $"{picture}";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{mail}"))
|
|
|
+ {
|
|
|
+ user.mail = $"{mail}";
|
|
|
+ }
|
|
|
+
|
|
|
+ msg.Append($" 将:{tmdName}【{tmdId}】醍摩豆账号和({user.name}【{user.unionId}】) 钉钉账户绑定,并设置管理员");
|
|
|
+ DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(user);
|
|
|
+
|
|
|
+ if (respUser != null)
|
|
|
+ {
|
|
|
+ roles = !string.IsNullOrEmpty($"{respUser.roles}") ? new List<string>(respUser.roles.Split(",")) : new List<string>();
|
|
|
+ }
|
|
|
+ DDUserInfo dDUserInfo = new()
|
|
|
+ {
|
|
|
+ partitionKey = respUser.PartitionKey,
|
|
|
+ rowKey = respUser.RowKey,
|
|
|
+ userId = respUser.userId,
|
|
|
+ unionId = respUser.unionId,
|
|
|
+ name = respUser.name,
|
|
|
+ title = respUser.title,
|
|
|
+ stateCode = respUser.stateCode,
|
|
|
+ mobile = respUser.mobile,
|
|
|
+ jobNumber = respUser.jobNumber,
|
|
|
+ pid = respUser.pid,
|
|
|
+ deptId = respUser.deptId,
|
|
|
+ deptName = respUser.deptName,
|
|
|
+ depts = respUser.depts,
|
|
|
+ avatar = respUser.avatar,
|
|
|
+ isAdmin = respUser.isAdmin,
|
|
|
+ tmdId = respUser.tmdId,
|
|
|
+ tmdName = respUser.tmdName,
|
|
|
+ tmdMobile = respUser.tmdMobile,
|
|
|
+ mail = respUser.mail,
|
|
|
+ picture = respUser.picture,
|
|
|
+ roles = respUser.roles,
|
|
|
+ permissions = respUser.permissions,
|
|
|
+ handleRoles = !string.IsNullOrEmpty($"{respUser.roles}") ? new List<string>(respUser.roles.Split(",")) : new List<string>(),
|
|
|
+ handlePermissions = !string.IsNullOrEmpty($"{respUser.permissions}") ? new List<string>(respUser.permissions.Split(",")) : new List<string>()
|
|
|
+ };
|
|
|
+ ddUserInfos.Add(dDUserInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DingDingUserInfo dingDingUserInfo = new()
|
|
|
+ {
|
|
|
+ PartitionKey = divide,
|
|
|
+ RowKey = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(),
|
|
|
+ roles = "admin",
|
|
|
+ tmdId = $"{tmdId}",
|
|
|
+ tmdName = $"{tmdName}",
|
|
|
+ tmdMobile = $"{mobile}",
|
|
|
+ };
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{picture}"))
|
|
|
+ {
|
|
|
+ dingDingUserInfo.picture = $"{picture}";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{mail}"))
|
|
|
+ {
|
|
|
+ dingDingUserInfo.mail = $"{mail}";
|
|
|
+ }
|
|
|
+ DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(dingDingUserInfo);
|
|
|
+
|
|
|
+ return Ok(new { state = 201, msg = "新生成的BIadmin", respUser });
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存操作记录
|
|
|
+ await _azureStorage.SaveBILog("tabledd-update",msg.ToString(), _dingDing, httpContext: HttpContext);
|
|
|
+
|
|
|
+ return Ok(new { state = 200, ddUserInfos });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} /tabledd/set-tmdadmin \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 解除钉钉和醍摩豆的绑定
|
|
|
/// </summary>
|
|
@@ -864,16 +1006,18 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
if (string.IsNullOrEmpty($"{tempInfo}"))
|
|
|
{
|
|
|
var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
|
|
|
- var users = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "RowKey", $"{itemUser.Userid}" }, { "unionId", $"{itemUser.Unionid}" } });
|
|
|
+ var users = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "userId", $"{itemUser.Userid}" }, { "unionId", $"{itemUser.Unionid}" } });
|
|
|
if (users.Count > 0)
|
|
|
{
|
|
|
foreach (var user in users)
|
|
|
{
|
|
|
DingDingUserInfo ddUserInfo = new();
|
|
|
ddUserInfo.PartitionKey = user.PartitionKey;
|
|
|
- ddUserInfo.RowKey = itemUser.Userid;
|
|
|
+ ddUserInfo.RowKey = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
|
|
+ ddUserInfo.userId = itemUser.Userid;
|
|
|
ddUserInfo.unionId = itemUser.Unionid;
|
|
|
ddUserInfo.name = itemUser.Name;
|
|
|
+ ddUserInfo.email = itemUser.Email;
|
|
|
ddUserInfo.title = itemUser.Title;
|
|
|
ddUserInfo.stateCode = itemUser.StateCode;
|
|
|
ddUserInfo.mobile = itemUser.Mobile;
|
|
@@ -884,7 +1028,6 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
ddUserInfo.depts = string.Join(",", itemUser.DeptIdList.ToArray());
|
|
|
ddUserInfo.avatar = itemUser.Avatar;
|
|
|
ddUserInfo.isAdmin = itemUser.Admin;
|
|
|
- ddUserInfo.PartitionKey = partitionKey;
|
|
|
ddUserInfo.tmdId = user.tmdId;
|
|
|
ddUserInfo.tmdName = user.tmdName;
|
|
|
ddUserInfo.tmdMobile = user.tmdMobile;
|
|
@@ -900,9 +1043,11 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
{
|
|
|
DingDingUserInfo ddUserInfo = new()
|
|
|
{
|
|
|
- RowKey = itemUser.Userid,
|
|
|
+ RowKey = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(),
|
|
|
+ userId = itemUser.Userid,
|
|
|
unionId = itemUser.Unionid,
|
|
|
name = itemUser.Name,
|
|
|
+ email = itemUser.Email,
|
|
|
title = itemUser.Title,
|
|
|
mobile = itemUser.Mobile,
|
|
|
jobNumber = itemUser.JobNumber,
|
|
@@ -931,12 +1076,11 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
return ddUserInfos;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
public record DDUserInfo
|
|
|
{
|
|
|
public string partitionKey { get; set; }
|
|
|
public string rowKey { get; set; }
|
|
|
+ public string userId { get; set; }
|
|
|
public string unionId { get; set; }
|
|
|
public string name { get; set; }
|
|
|
public string title { get; set; }
|