123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734 |
- using DingTalk.Api;
- using DingTalk.Api.Request;
- using DingTalk.Api.Response;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Options;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models.Service;
- using Microsoft.Azure.Cosmos;
- using TEAMModelOS.SDK.Models;
- using TEAMModelBI.Controllers.BISchool;
- using TEAMModelOS.SDK.Models.Cosmos.BI;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.Context.BI;
- namespace TEAMModelBI.Controllers.BITable
- {
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
- [Route("dd")]
- [ApiController]
- public class DDStructController : ControllerBase
- {
- private readonly IConfiguration _configuration;
- //数据容器
- private readonly AzureCosmosFactory _azureCosmos;
- //文件容器
- private readonly AzureStorageFactory _azureStorage;
- //钉钉提示信息
- private readonly DingDing _dingDing;
- //雪花ID
- private readonly SnowflakeId _snowflakeId;
- private readonly Option _option;
- public DDStructController(IConfiguration configuration, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, CoreAPIHttpService aoreAPIHttpService, SnowflakeId snowflakeId)
- {
- _configuration = configuration;
- _azureCosmos = azureCosmos;
- _azureStorage = azureStorage;
- _dingDing = dingDing;
- _option = option?.Value;
- _snowflakeId = snowflakeId;
- }
- /// <summary>
- /// 获取企业部门列表 //已对接
- /// </summary>
- [ProducesDefaultResponseType]
- [HttpPost("get-deptlist")]
- public async Task<IActionResult> GetDeptList()
- {
- try
- {
- string appKey = _configuration["DingDingAuth:appKey"];
- string appSecret = _configuration["DingDingAuth:appSecret"];
- //获取access_token
- DefaultDingTalkClient client = new("https://oapi.dingtalk.com/gettoken");
- OapiGettokenRequest request = new();
- request.Appkey = appKey;
- request.Appsecret = appSecret;
- request.SetHttpMethod("Get");
- OapiGettokenResponse response = client.Execute(request);
- if (response.IsError)
- {
- return BadRequest();
- }
- //access_token的有效期为7200秒(2小时),有效期内重复获取会返回相同结果并自动续期,过期后获取会返回新的access_token
- string access_token = response.AccessToken;
- //获取一级部门列表
- IDingTalkClient v2ListsubClient1 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
- OapiV2DepartmentListsubRequest reqlistsub1 = new OapiV2DepartmentListsubRequest() { DeptId = 1L, Language = "zh_CN" };
- OapiV2DepartmentListsubResponse rsplistsub1 = v2ListsubClient1.Execute(reqlistsub1, access_token);
- List<DeptInfo> templsit = new List<DeptInfo>();
- if (rsplistsub1.Result != null)
- {
- foreach (var deptList in rsplistsub1.Result)
- {
- DeptInfo deptInfo = new DeptInfo();
- deptInfo.deptId = deptList.DeptId;
- deptInfo.deptName = deptList.Name;
- deptInfo.parentId = deptList.ParentId;
- //获取一级部门用户列表
- IDingTalkClient userListClient1 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/listid");
- OapiUserListidRequest reqUserList1 = new() { DeptId = deptList.DeptId };
- OapiUserListidResponse rspUserList1 = userListClient1.Execute(reqUserList1, access_token);
- if (rspUserList1.Result != null)
- {
- deptInfo.ddUserList = rspUserList1.Result.UseridList;
- }
- //获取用户详细信息
- IDingTalkClient v2UserListClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
- OapiV2UserGetRequest reqv2UserList = new();
- OapiV2UserGetResponse rspv2UserList = v2UserListClient.Execute(reqv2UserList, access_token);
- //获取二级部门列表
- OapiV2DepartmentListsubRequest reqlistsub = new() { DeptId = deptList.DeptId, Language = "zh_CN" };
- OapiV2DepartmentListsubResponse rsplistsub = v2ListsubClient1.Execute(reqlistsub, access_token);
- List<DeptBaseResponseDomain> deptBaseResponseDomainList = new();
- if (rsplistsub.Result != null)
- {
- foreach (var deptlist2 in rsplistsub.Result)
- {
- //添加二级部门
- DeptBaseResponseDomain deptBaseResponseDomain2 = new();
- deptBaseResponseDomain2.deptId = deptlist2.DeptId;
- deptBaseResponseDomain2.Name = deptlist2.Name;
- deptBaseResponseDomain2.ParentId = deptlist2.ParentId;
- //获取三级部门用户列表
- OapiUserListidRequest reqUserList2 = new() { DeptId = deptlist2.DeptId };
- OapiUserListidResponse rspUserList2 = userListClient1.Execute(reqUserList2, access_token);
- if (rspUserList2.Result != null)
- {
- //添加三级部门用户
- deptBaseResponseDomain2.ddUserList = rspUserList2.Result.UseridList;
- }
- //获取三级部门列表
- OapiV2DepartmentListsubRequest reqlistsub3 = new() { DeptId = deptlist2.DeptId, Language = "zh_CN" };
- OapiV2DepartmentListsubResponse rsplistsub3 = v2ListsubClient1.Execute(reqlistsub3, access_token);
- List<DeptBaseResponseDomain> deptBaseResponseDomain3List = new();
- if (rsplistsub3.Result != null)
- {
- foreach (var dept3List in rsplistsub3.Result)
- {
- //添加三级部门
- DeptBaseResponseDomain deptBaseResponseDomain3 = new();
- deptBaseResponseDomain3.deptId = dept3List.DeptId;
- deptBaseResponseDomain3.Name = dept3List.Name;
- deptBaseResponseDomain3.ParentId = dept3List.ParentId;
- //获取部门用户列表
- OapiUserListidRequest reqUserList3 = new() { DeptId = dept3List.DeptId };
- OapiUserListidResponse rspUserList3 = userListClient1.Execute(reqUserList3, access_token);
- if (rspUserList3.Result != null)
- {
- //添加三级部门的用户
- deptBaseResponseDomain3.ddUserList = rspUserList3.Result.UseridList;
- }
- //获取部门列表 四级目录
- OapiV2DepartmentListsubRequest reqlistsub4 = new() { DeptId = dept3List.DeptId, Language = "zh_CN" };
- OapiV2DepartmentListsubResponse rsplistsu4 = v2ListsubClient1.Execute(reqlistsub4, access_token);
- List<DeptBaseResponseDomain> deptBaseResponseDomain4List = new();
- if (rsplistsu4.Result != null)
- {
- foreach (var dept4List in rsplistsu4.Result)
- {
- DeptBaseResponseDomain deptBaseResponseDomain4 = new();
- deptBaseResponseDomain4.deptId = dept4List.DeptId;
- deptBaseResponseDomain4.Name = dept4List.Name;
- deptBaseResponseDomain4.ParentId = dept4List.ParentId;
- deptBaseResponseDomain4List.Add(deptBaseResponseDomain4);
- //获取四级部门用户列表
- OapiUserListidRequest reqUserList4 = new() { DeptId = dept4List.DeptId };
- OapiUserListidResponse rspUserList4 = userListClient1.Execute(reqUserList4, access_token);
- if (rspUserList4.Result != null)
- {
- //添加四级部门的用户
- deptBaseResponseDomain4.ddUserList = rspUserList4.Result.UseridList;
- }
- }
- }
- //添加四级部门列表
- deptBaseResponseDomain3.LowerDeip_List = deptBaseResponseDomain4List;
- deptBaseResponseDomain3List.Add(deptBaseResponseDomain3);
- }
- }
- //添加三级部门列表
- deptBaseResponseDomain2.LowerDeip_List = deptBaseResponseDomain3List;
- deptBaseResponseDomainList.Add(deptBaseResponseDomain2);
- }
- }
- //添加二级部门列表
- deptInfo.deptList = deptBaseResponseDomainList;
- templsit.Add(deptInfo);
- }
- }
- return Ok(new { state = 200, deptlist = templsit });
- }
- catch (Exception ex)
- {
- return Ok(new { state = 1, message=$"查询失败!:状态:错误:{ex.Message}\n{ex.StackTrace}" }) ;
- }
- }
- /// <summary>
- /// 查询钉钉的研发中心B人员 //已对接
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-tmdandddusers")]
- public async Task<IActionResult> GetTmdAndDdUsers(JsonElement jsonElement)
- {
- try
- {
- jsonElement.TryGetProperty("deptId", out JsonElement deptId);
- //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
- string tempDeptId = string.IsNullOrEmpty($"{deptId}") ? "67863053" : $"{deptId}";
- string appKey = _configuration["DingDingAuth:appKey"];
- string appSecret = _configuration["DingDingAuth:appSecret"];
- Dictionary<string, object> dic = new() { { "PartitionKey", "authority-bi" } };
- var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
- List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
- //获取access_token
- DefaultDingTalkClient client = new("https://oapi.dingtalk.com/gettoken");
- OapiGettokenRequest request = new();
- request.Appkey = appKey;
- request.Appsecret = appSecret;
- request.SetHttpMethod("Get");
- OapiGettokenResponse response = client.Execute(request);
- if (response.IsError) return BadRequest();
- //access_token的有效期为7200秒(2小时),有效期内重复获取会返回相同结果并自动续期,过期后获取会返回新的access_token
- string access_token = response.AccessToken;
- IDingTalkClient userListClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
- OapiV2UserListRequest reqUserList1 = new()
- {
- DeptId = long.Parse($"{tempDeptId}"),
- Cursor = 0L,
- Size = 50L,
- ContainAccessLimit = false,
- OrderField = "custom",
- Language = "zh_CN"
- };
- reqUserList1.SetHttpMethod("GET");
- OapiV2UserListResponse rspV2UserList1 = userListClient.Execute(reqUserList1, access_token);
- List<DDUserInfoAndTMD> dDAndTmdInfos = new();
- List<DingDingUserInfo> ddUserInfos = new();
- var tabledd = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
- //if ($"{site}".Equals(BIConst.Global))
- // tabledd = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("BIDDUserInfo");
- if (rspV2UserList1.Result.List != null)
- {
- foreach (var itemUser in rspV2UserList1.Result.List)
- {
- List<DingDingUserInfo> temp = await tabledd.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "RowKey", $"{itemUser.Userid}" } });
- foreach (var item in temp)
- {
- ddUserInfos.Add(item);
- }
- //DDUserInfoAndTMD dDAndTmdInfo = new DDUserInfoAndTMD();
- //dDAndTmdInfo.unionid = itemUser.Unionid;
- //dDAndTmdInfo.userid = itemUser.Userid;
- //dDAndTmdInfo.title = itemUser.Title;
- //dDAndTmdInfo.name = itemUser.Name;
- //dDAndTmdInfo.mobile = itemUser.Mobile;
- //dDAndTmdInfo.jobNumber = itemUser.JobNumber;
- //dDAndTmdInfo.avatar = itemUser.Avatar;
- //dDAndTmdInfo.depts = itemUser.DeptIdList;
- //List<string> roles = new List<string>();//角色列表
- //List<string> power = new List<string>();//权限列表
- //string sqltxt = $"select distinct value(c) from c join A1 in c.ddbinds where A1.userid ='{itemUser.Userid}'";
- //try
- //{
- // await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIteratorSql<Teacher>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- // {
- // dDAndTmdInfo.tmdId = item.id;
- // dDAndTmdInfo.isexist = true;
- // if (!string.IsNullOrEmpty($"{item.defaultSchool}"))
- // {
- // var schoolRoles = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(item.id, new PartitionKey($"Teacher-{item.defaultSchool}"));
- // if (schoolRoles.Status == 200)
- // {
- // using var json = await JsonDocument.ParseAsync(schoolRoles.Content);
- // if (json.RootElement.TryGetProperty("roles", out JsonElement _roles) && _roles.ValueKind != JsonValueKind.Null)
- // {
- // foreach (var obj in _roles.EnumerateArray())
- // {
- // //初始定义顾问的assistant 更改为assist
- // if (obj.GetString().Equals($"assist"))
- // {
- // roles.Add(obj.GetString());
- // }
- // }
- // }
- // if (json.RootElement.TryGetProperty("permissions", out JsonElement _permissions) && _permissions.ValueKind != JsonValueKind.Null)
- // {
- // foreach (var obj in _permissions.EnumerateArray())
- // {
- // //显示BI权限
- // foreach (var aut in authorityBIList)
- // {
- // if (aut.RowKey.Equals(obj.GetString()))
- // {
- // power.Add(obj.GetString());
- // }
- // }
- // }
- // }
- // }
- // dDAndTmdInfo.tmdroles = roles;
- // dDAndTmdInfo.tmdpower = power;
- // }
- // }
- //}
- //catch { }
- }
- }
- if (!string.IsNullOrEmpty($"{tempDeptId}"))
- {
- //获取下级部门列表
- IDingTalkClient v2DeptListClient2 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
- OapiV2DepartmentListsubRequest reqDeptList2 = new() { DeptId = long.Parse($"{tempDeptId}"), Language = "zh_CN" };
- OapiV2DepartmentListsubResponse rspDeptLis2 = v2DeptListClient2.Execute(reqDeptList2, access_token);
- if (rspDeptLis2.Result != null)
- {
- foreach (var tempDept in rspDeptLis2.Result)
- {
- OapiV2UserListRequest reqUserList2 = new();
- reqUserList2.DeptId = long.Parse($"{tempDept.DeptId}");
- reqUserList2.Cursor = 0L;
- reqUserList2.Size = 50L;
- reqUserList2.ContainAccessLimit = false;
- reqUserList2.OrderField = "custom";
- reqUserList2.Language = "zh_CN";
- reqUserList2.SetHttpMethod("GET");
- OapiV2UserListResponse rspV2UserList2 = userListClient.Execute(reqUserList2, access_token);
- if (rspV2UserList2.Result.List != null)
- {
- foreach (var itemUser2 in rspV2UserList2.Result.List)
- {
- var tempInfo = dDAndTmdInfos.Find(x => x.unionid.Equals(itemUser2.Unionid));
- if (string.IsNullOrEmpty($"{tempInfo}"))
- {
- DDUserInfoAndTMD dDAndTmdInfo2 = new();
- dDAndTmdInfo2.unionid = itemUser2.Unionid;
- dDAndTmdInfo2.userid = itemUser2.Userid;
- dDAndTmdInfo2.title = itemUser2.Title;
- dDAndTmdInfo2.name = itemUser2.Name;
- dDAndTmdInfo2.mobile = itemUser2.Mobile;
- dDAndTmdInfo2.jobNumber = itemUser2.JobNumber;
- dDAndTmdInfo2.avatar = itemUser2.Avatar;
- dDAndTmdInfo2.depts = itemUser2.DeptIdList;
- List<string> roles = new List<string>();//角色列表
- List<string> power = new List<string>();//权限列表
- string sqltxt = $"select distinct value(c) from c join A1 in c.ddbinds where A1.userid ='{itemUser2.Userid}'";
- try
- {
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIteratorSql<Teacher>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- dDAndTmdInfo2.tmdId = item.id;
- dDAndTmdInfo2.isexist = true;
- if (!string.IsNullOrEmpty($"{item.defaultSchool}"))
- {
- var schoolRoles = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(item.id, new PartitionKey($"Teacher-{item.defaultSchool}"));
- if (schoolRoles.StatusCode == System.Net.HttpStatusCode.OK)
- {
- using var json = await JsonDocument.ParseAsync(schoolRoles.Content);
- if (json.RootElement.TryGetProperty("roles", out JsonElement _roles) && _roles.ValueKind != JsonValueKind.Null)
- {
- foreach (var obj in _roles.EnumerateArray())
- {
- //初始定义顾问的assistant 更改为assist
- if (obj.GetString().Equals($"assist"))
- {
- roles.Add(obj.GetString());
- }
- }
- }
- if (json.RootElement.TryGetProperty("permissions", out JsonElement _permissions) && _permissions.ValueKind != JsonValueKind.Null)
- {
- foreach (var obj in _permissions.EnumerateArray())
- {
- //显示BI权限
- foreach (var aut in authorityBIList)
- {
- if (aut.RowKey.Equals(obj.GetString()))
- {
- power.Add(obj.GetString());
- }
- }
- }
- }
- }
- dDAndTmdInfo2.tmdroles = roles;
- dDAndTmdInfo2.tmdpower = power;
- }
- }
- }
- catch { }
- dDAndTmdInfos.Add(dDAndTmdInfo2);
- }
- }
- }
- }
- }
- }
- return Ok(new { state = 200, count = ddUserInfos.Count, ddUserInfos }) ;
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} dd/get-tmdandddusers \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 依据钉钉UserID查询钉钉用户信息
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-dduserinfo")]
- public async Task<IActionResult> GetDDUserInfo(JsonElement jsonElement)
- {
- try
- {
- if (!jsonElement.TryGetProperty("userids", out JsonElement userIds)) return Ok(new { state = 1, message = "参数问题" });
- //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
- List<DDUserInfoAndTMD> dDUserInfoAndTMDs = new List<DDUserInfoAndTMD>();//返回钉钉信息和查询的醍摩豆信息
- string appKey = _configuration["DingDingAuth:appKey"];
- string appSecret = _configuration["DingDingAuth:appSecret"];
- //获取access_token
- DefaultDingTalkClient client = new("https://oapi.dingtalk.com/gettoken");
- OapiGettokenRequest request = new();
- request.Appkey = appKey;
- request.Appsecret = appSecret;
- request.SetHttpMethod("Get");
- OapiGettokenResponse response = client.Execute(request);
- if (response.IsError)
- {
- return BadRequest();
- }
- //access_token的有效期为7200秒(2小时),有效期内重复获取会返回相同结果并自动续期,过期后获取会返回新的access_token
- string access_token = response.AccessToken;
- IDingTalkClient userInfoClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
- Dictionary<string, object> dic = new() { { "PartitionKey", "authority-bi" } };
- var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
- var cosmosClient = _azureCosmos.GetCosmosClient();
- //if ($"{site}".Equals(BIConst.Global))
- //{
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- // table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("SchoolSetting");
- //}
- List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
- if (!string.IsNullOrEmpty($"{userIds}"))
- {
- //List<string> str_userids = userIds.ToObject<List<string>>().Distinct().ToList();//通过数组的Equals实现去重
- List<string> str_userids1 = userIds.ToObject<List<string>>();
- List<string> str_userids = str_userids1.Where((x, i) => str_userids1.FindIndex(z => z == x) == i).ToList();//Lambda表达式去重
- foreach (var tempid in str_userids)
- {
- OapiV2UserGetRequest reqUserInfo = new() { Userid = $"{tempid}", Language = "zh_CN" };
- OapiV2UserGetResponse rspUserInfo = userInfoClient.Execute(reqUserInfo, access_token);
- if (rspUserInfo.Result != null)
- {
- List<string> roles = new();//角色列表
- List<string> power = new();//权限列表
- DDUserInfoAndTMD dDUserInfoAndTMD = new();
- dDUserInfoAndTMD.unionid = rspUserInfo.Result.Unionid;
- dDUserInfoAndTMD.title = rspUserInfo.Result.Title;
- dDUserInfoAndTMD.userid = rspUserInfo.Result.Userid;
- dDUserInfoAndTMD.jobNumber = rspUserInfo.Result.JobNumber;
- dDUserInfoAndTMD.name = rspUserInfo.Result.Name;
- dDUserInfoAndTMD.depts = rspUserInfo.Result.DeptIdList;
- dDUserInfoAndTMD.mobile = rspUserInfo.Result.Mobile;
- dDUserInfoAndTMD.avatar = rspUserInfo.Result.Avatar;
- string sqltxt = $"select distinct value(c) from c join A1 in c.ddbinds where A1.userid ='{tempid}'";
- try
- {
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIteratorSql<Teacher>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- dDUserInfoAndTMD.tmdId = item.id;
- dDUserInfoAndTMD.isexist = true;
- if (!string.IsNullOrEmpty($"{item.defaultSchool}"))
- {
- var schoolRoles = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(item.id, new PartitionKey($"Teacher-{item.defaultSchool}"));
- if (schoolRoles.StatusCode == System.Net.HttpStatusCode.OK)
- {
- using var json = await JsonDocument.ParseAsync(schoolRoles.Content);
- if (json.RootElement.TryGetProperty("roles", out JsonElement _roles) && _roles.ValueKind != JsonValueKind.Null)
- {
- foreach (var obj in _roles.EnumerateArray())
- {
- //初始定义顾问的assistant 更改为assist
- if (obj.GetString().Equals($"assist"))
- {
- roles.Add(obj.GetString());
- }
- }
- }
- if (json.RootElement.TryGetProperty("permissions", out JsonElement _permissions) && _permissions.ValueKind != JsonValueKind.Null)
- {
- foreach (var obj in _permissions.EnumerateArray())
- {
- //显示BI权限
- foreach (var aut in authorityBIList)
- {
- if (aut.RowKey.Equals(obj.GetString()))
- {
- power.Add(obj.GetString());
- }
- }
- }
- }
- }
- dDUserInfoAndTMD.tmdroles = roles;
- dDUserInfoAndTMD.tmdpower = power;
- }
- }
- }
- catch { }
- dDUserInfoAndTMDs.Add(dDUserInfoAndTMD);
- }
- else return Ok(new { state = 2, message = "访问失败!" });
- }
- }
- return Ok(new { state = 200, ddUserInfos = dDUserInfoAndTMDs});
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location},dd/get-dduserinfo \n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 获取分支组织列表信息
- /// </summary>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("ddbranchstruc")]
- public async Task<IActionResult> DDBranchStruc()
- {
- string str_appKey = _configuration["DingDingAuth:appKey"];
- string str_appSecret = _configuration["DingDingAuth:appSecret"];
- //获取企业内部应用的accessToken
- IDingTalkClient Iclient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
- OapiGettokenRequest request = new();
- request.Appkey = str_appKey;
- request.Appsecret = str_appSecret;
- request.SetHttpMethod("GET");
- OapiGettokenResponse tokenResponse = Iclient.Execute(request);
- if (tokenResponse.IsError)
- {
- return Ok(new { state = 0, message = "请检查配置" });
- }
- IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/org/union/branch/get");
- OapiOrgUnionBranchGetRequest req = new();
- OapiOrgUnionBranchGetResponse rsp = client.Execute(req, tokenResponse.AccessToken);
- return Ok(new { Result = rsp.Result, Body = rsp.Body, RequestId = rsp.RequestId, SubErrCode = rsp.SubErrCode, Success = rsp.Success });
- }
- /// <summary>
- /// 返回钉钉和能查询到醍摩豆信息
- /// </summary>
- public class DDUserInfoAndTMD
- {
- /// <summary>
- /// 是否存在醍摩豆账户
- /// </summary>
- public bool isexist { get; set; }
- /// <summary>
- /// 绑定的醍摩豆账户
- /// </summary>
- public string tmdId { get; set; }
- /// <summary>
- /// 醍摩豆角色
- /// </summary>
- public List<string> tmdroles { get; set; }
- /// <summary>
- /// 醍摩豆角色权限
- /// </summary>
- public List<string> tmdpower { get; set; }
- /// <summary>
- /// 员工在当前开发者企业账号范围内的唯一标识
- /// </summary>
- public string unionid { get; set; }
- /// <summary>
- /// 用户ID
- /// </summary>
- public string userid { get; set; }
- /// <summary>
- /// 员工名称
- /// </summary>
- public string name { get; set; }
- /// <summary>
- /// 职位
- /// </summary>
- public string title { get; set; }
-
- /// <summary>
- /// 手机号
- /// </summary>
- public string mobile { get; set; }
- /// <summary>
- /// 员工工号
- /// </summary>
- public string jobNumber { get; set; }
- /// <summary>
- /// 所属部门
- /// </summary>
- public long deptId { get; set; }
- /// <summary>
- /// 部门名称
- /// </summary>
- public string deptName { get; set; }
- /// <summary>
- /// 所属部门id列表
- /// </summary>
- public List<long> depts { get; set; }
- /// <summary>
- /// 钉钉头像
- /// </summary>
- public string avatar { get; set; }
- }
- /// <summary>
- /// 部门信息
- /// </summary>
- public record DeptInfo
- {
- /// <summary>
- /// 部门ID
- /// </summary>
- public long deptId { get; set; }
- /// <summary>
- /// 部门名称
- /// </summary>
- public string deptName { get; set; }
- /// <summary>
- /// 父部门id,根部门为1
- /// </summary>
- public long parentId { get; set; }
- /// <summary>
- /// 部门集合
- /// </summary>
- public List<DeptBaseResponseDomain> deptList { get; set; }
- /// <summary>
- /// 钉钉用户列表
- /// </summary>
- public List<string> ddUserList { get; set; }
- }
- public record DeptBaseResponseDomain
- {
- /// <summary>
- /// 部门ID
- /// </summary>
- public long deptId { get; set; }
- /// <summary>
- /// 部门名称
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// 父部门ID
- /// </summary>
- public long ParentId { get; set; }
- /// <summary>
- /// 下级列表
- /// </summary>
- public List<DeptBaseResponseDomain> LowerDeip_List { get; set; }
- /// <summary>
- /// 钉钉用户列表
- /// </summary>
- public List<string> ddUserList { get; set; }
- }
- }
- }
|