TableDingDingInfoController.cs 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using TEAMModelOS.Models;
  8. using TEAMModelOS.SDK.DI;
  9. using Microsoft.Extensions.Options;
  10. using System.Net.Http;
  11. using Microsoft.Extensions.Configuration;
  12. using DingTalk.Api;
  13. using DingTalk.Api.Request;
  14. using DingTalk.Api.Response;
  15. using System.Text.Json;
  16. using System.Net.Http.Json;
  17. using TEAMModelOS.SDK.Models.Cosmos.BI;
  18. using System.Net;
  19. using TEAMModelOS.SDK.Extension;
  20. using OpenXmlPowerTools;
  21. using System.Text;
  22. using Azure.Cosmos;
  23. using Microsoft.Azure.Cosmos.Table;
  24. using TEAMModelBI.Filter;
  25. using TEAMModelBI.Tool.Extension;
  26. using TEAMModelBI.Models;
  27. using TEAMModelBI.Tool.CosmosBank;
  28. using TEAMModelOS.SDK;
  29. using TEAMModelOS.SDK.Context.BI;
  30. using TEAMModelOS.SDK.Models;
  31. using TEAMModelOS.SDK.Context.Constant;
  32. namespace TEAMModelBI.Controllers.BITable
  33. {
  34. [Route("tabledd")]
  35. [ApiController]
  36. public class TableDingDingInfoController : ControllerBase
  37. {
  38. //读取配置文件
  39. private readonly IConfiguration _configuration;
  40. //数据容器
  41. private readonly AzureCosmosFactory _azureCosmos;
  42. //blob和table容器
  43. private readonly AzureStorageFactory _azureStorage;
  44. //钉钉提示信息
  45. private readonly DingDing _dingDing;
  46. private readonly Option _option;
  47. private readonly IHttpClientFactory _http;
  48. private readonly CoreAPIHttpService _coreAPIHttpService;
  49. public TableDingDingInfoController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService)
  50. {
  51. _azureCosmos = azureCosmos;
  52. _dingDing = dingDing;
  53. _azureStorage = azureStorage;
  54. _option = option?.Value;
  55. _http = http;
  56. _configuration = configuration;
  57. _coreAPIHttpService = coreAPIHttpService;
  58. }
  59. /// <summary>
  60. /// 从钉钉的组织架构中人员信息数据,并保存或者更新至Blob中 已对接
  61. /// </summary>
  62. /// <returns></returns>
  63. [ProducesDefaultResponseType]
  64. [AuthToken(Roles = "admin,rdc")]
  65. [HttpPost("get-dingdingusers")]
  66. public async Task<IActionResult> GetDingDingUser(JsonElement jsonElement)
  67. {
  68. try
  69. {
  70. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  71. var tableClient = _azureStorage.GetCloudTableClient();
  72. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  73. ////分开部署,就不需要,一站多用时,取消注释
  74. //if ($"{site}".Equals(BIConst.Global))
  75. //{
  76. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  77. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  78. //}
  79. var table = tableClient.GetTableReference("BIDDUserInfo");
  80. string appKey = _configuration["DingDingAuth:appKey"];
  81. string appSecret = _configuration["DingDingAuth:appSecret"];
  82. //string divide = _configuration["CustomParam:SiteScope"];
  83. string divide = _option.Location;
  84. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  85. //HttpClient httpClient = _http.CreateClient();
  86. //string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
  87. //获取access_token
  88. IDingTalkClient tokenClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
  89. OapiGettokenRequest tokenRequest = new() { Appkey = appKey, Appsecret = appSecret };
  90. tokenRequest.SetHttpMethod("Get");
  91. OapiGettokenResponse tokenRespone = tokenClient.Execute(tokenRequest);
  92. if (tokenRespone.IsError)
  93. {
  94. return BadRequest();
  95. }
  96. //access_token的有效期为7200秒(2小时),有效期内重复获取会返回相同结果并自动续期,过期后获取会返回新的access_token
  97. string access_token = tokenRespone.AccessToken;
  98. //获取部门接口
  99. IDingTalkClient deptListClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
  100. //一级部门
  101. OapiV2DepartmentListsubRequest reqDeptList1 = new() { DeptId = 1L, Language = "zh_CN" };
  102. OapiV2DepartmentListsubResponse rspDeptList1 = deptListClient.Execute(reqDeptList1, access_token);
  103. List<DingDingUserInfo> ddUserInfos = new();
  104. if (rspDeptList1.Result != null)
  105. {
  106. foreach (var tempDept1 in rspDeptList1.Result)
  107. {
  108. //获取一级部门用户信息
  109. List<DingDingUserInfo> dingDingUserInfos1 = await GetDingDingUserInfo(divide, tempDept1.DeptId, tempDept1.ParentId, tempDept1.Name, access_token);
  110. //if (dingDingUserInfos1.Count > 0) ddUserInfos.AddRange(ddUserInfos.Union(dingDingUserInfos1.ToList()));
  111. if (dingDingUserInfos1.Count > 0) ddUserInfos.AddRange(dingDingUserInfos1);
  112. //获取二级部门
  113. OapiV2DepartmentListsubRequest reqDeptList2 = new() { DeptId = tempDept1.DeptId, Language = "zh_CN" };
  114. OapiV2DepartmentListsubResponse rspDeptList2 = deptListClient.Execute(reqDeptList2, access_token);
  115. if (rspDeptList2.Result != null)
  116. {
  117. foreach (var tempDept2 in rspDeptList2.Result)
  118. {
  119. //获取二级部门用户信息
  120. List<DingDingUserInfo> dingDingUserInfos2 = await GetDingDingUserInfo(divide, tempDept2.DeptId, tempDept2.ParentId, tempDept2.Name, access_token);
  121. //if (dingDingUserInfos2.Count > 0) ddUserInfos.AddRange(ddUserInfos.Union(dingDingUserInfos2.ToList()));
  122. if (dingDingUserInfos2.Count > 0) ddUserInfos.AddRange(dingDingUserInfos2);
  123. //获取三级部门
  124. OapiV2DepartmentListsubRequest reqDeptList3 = new() { DeptId = tempDept2.DeptId, Language = "zh_CN" };
  125. OapiV2DepartmentListsubResponse rspDeptList3 = deptListClient.Execute(reqDeptList3, access_token);
  126. if (rspDeptList3.Result != null)
  127. {
  128. foreach (var tempDept3 in rspDeptList3.Result)
  129. {
  130. //获取三级部门用户信息
  131. List<DingDingUserInfo> dingDingUserInfos3 = await GetDingDingUserInfo(divide, tempDept3.DeptId, tempDept3.ParentId, tempDept3.Name, access_token);
  132. //if (dingDingUserInfos3.Count > 0) ddUserInfos.AddRange(ddUserInfos.Union(dingDingUserInfos3.ToList()));
  133. if (dingDingUserInfos3.Count > 0) ddUserInfos.AddRange(dingDingUserInfos3);
  134. //获取四级部门
  135. OapiV2DepartmentListsubRequest reqDeptList4 = new() { DeptId = tempDept3.DeptId, Language = "zh_CN" };
  136. OapiV2DepartmentListsubResponse rspDeptList4 = deptListClient.Execute(reqDeptList4, access_token);
  137. if (rspDeptList4.Result != null)
  138. {
  139. foreach (var tempDept4 in rspDeptList4.Result)
  140. {
  141. //获取四级部门用户信息
  142. List<DingDingUserInfo> dingDingUserInfos4 = await GetDingDingUserInfo(divide, tempDept4.DeptId, tempDept4.ParentId, tempDept4.Name, access_token);
  143. //if (dingDingUserInfos4.Count > 0) ddUserInfos.AddRange(ddUserInfos.Union(dingDingUserInfos4.ToList()));
  144. if (dingDingUserInfos4.Count > 0) ddUserInfos.AddRange(dingDingUserInfos4);
  145. //获取五级部门
  146. OapiV2DepartmentListsubRequest reqDeptList5 = new() { DeptId = tempDept4.DeptId, Language = "zh_CN" };
  147. OapiV2DepartmentListsubResponse rspDeptList5 = deptListClient.Execute(reqDeptList5, access_token);
  148. if (rspDeptList5.Result != null)
  149. {
  150. foreach (var tempDept5 in rspDeptList5.Result)
  151. {
  152. //获取五级部门用户信息
  153. List<DingDingUserInfo> dingDingUserInfos5 = await GetDingDingUserInfo(divide, tempDept5.DeptId, tempDept5.ParentId, tempDept5.Name, access_token);
  154. //if (dingDingUserInfos5.Count > 0) ddUserInfos.AddRange(ddUserInfos.Union(dingDingUserInfos5).ToList());
  155. if (dingDingUserInfos5.Count > 0) ddUserInfos.AddRange(dingDingUserInfos5);
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. //保存操作记录
  167. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{_tmdName}【{_tmdId}】从钉钉组织结构更新至Azure Table表【DDUserInfo】中。", _dingDing, httpContext: HttpContext);
  168. var tempddUserInfos = ddUserInfos.GroupBy(c => c.userId).Select(c => c.First()).ToList();//去重
  169. //List<DingDingUserInfo> TempdingDingUserInfos = await _azureStorage.SaveOrUpdateAll(dingDingUserInfos); //只是保存至Table
  170. //查询数据的数据 并和钉钉查询的数据对比,找出不同的数据,并删除 待后期测试
  171. var users = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{divide}" } });
  172. List<DingDingUserInfo> noExisits = new();
  173. if (users.Count > 0)
  174. {
  175. //var temps = users.Union(tempddUserInfos).Except(users.Intersect(tempddUserInfos));
  176. List<DingDingUserInfo> existsUserInfo = users.Where(u => !tempddUserInfos.Exists(e => u.userId.Equals(e.userId) && u.PartitionKey.Equals(e.PartitionKey))).ToList();
  177. if (users.Count >= tempddUserInfos.Count)
  178. {
  179. existsUserInfo.AddRange(tempddUserInfos.Where(e => !users.Exists(u => e.userId.Equals(u.userId) && e.PartitionKey.Equals(u.PartitionKey))).ToList());
  180. }
  181. ////List<DingDingUserInfo> existsUserInfo = users.Where((x, i) => users.FindIndex(z => z.userId.Equals(x.userId) && x.PartitionKey.Equals(divide)) == i).Select(x => x).ToList();
  182. if (existsUserInfo.Count > 0)
  183. {
  184. noExisits = await table.DeleteAll(existsUserInfo);
  185. }
  186. }
  187. List<DingDingUserInfo> UserInfo = await table.SaveOrUpdateAll(tempddUserInfos); //保存和修改至Table
  188. return Ok(new { state = 200, UserInfo, noExisits });
  189. }
  190. catch (Exception ex)
  191. {
  192. await _dingDing.SendBotMsg($"BI,{_option.Location} /tabledd/get-dingdingusers \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  193. return BadRequest();
  194. }
  195. }
  196. /// <summary>
  197. /// 查询钉钉信息和醍摩豆信息 //已对接
  198. /// </summary>
  199. /// <returns></returns>
  200. [ProducesDefaultResponseType]
  201. [HttpPost("get-ddusers")]
  202. public async Task<IActionResult> GetDingDingUsers(JsonElement jsonElement)
  203. {
  204. try
  205. {
  206. jsonElement.TryGetProperty("busy", out JsonElement busy);
  207. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  208. var cosmosCliet = _azureCosmos.GetCosmosClient();
  209. var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
  210. ////分开部署,就不需要,一站多用时,取消注释
  211. //if ($"{site}".Equals(BIConst.Global))
  212. // table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("BIDDUserInfo");
  213. //string divide = _configuration["CustomParam:SiteScope"];
  214. string divide = _option.Location;
  215. List<DDUserInfo> ddUserInfos = new();
  216. Dictionary<string, object> dic = new() { { "PartitionKey", $"{divide}" } };
  217. List<DingDingUserInfo> ddUserInfoList = await table.FindListByDict<DingDingUserInfo>(dic);
  218. switch ($"{busy}")
  219. {
  220. case "admin":
  221. foreach (var item in ddUserInfoList)
  222. {
  223. if (item.roles.Contains("admin"))
  224. {
  225. DDUserInfo ddUserInfo = new()
  226. {
  227. partitionKey = item.PartitionKey,
  228. rowKey = item.RowKey,
  229. userId = item.userId,
  230. unionId = item.unionId,
  231. name = item.name,
  232. title = item.title,
  233. stateCode = item.stateCode,
  234. mobile = item.mobile,
  235. jobNumber = item.jobNumber,
  236. pid = item.pid,
  237. deptId = item.deptId,
  238. deptName = item.deptName,
  239. depts = item.depts,
  240. avatar = item.avatar,
  241. isAdmin = item.isAdmin,
  242. tmdId = item.tmdId,
  243. tmdName = item.tmdName,
  244. tmdMobile = item.tmdMobile,
  245. mail = item.mail,
  246. picture = item.picture,
  247. roles = item.roles,
  248. joinTime = item.joinTime,
  249. permissions = item.permissions,
  250. handleRoles = !string.IsNullOrEmpty($"{item.roles}") ? new List<string>(item.roles.Split(",")) : new List<string>(),
  251. handlePermissions = !string.IsNullOrEmpty($"{item.permissions}") ? new List<string>(item.permissions.Split(",")) : new List<string>(),
  252. };
  253. if (!string.IsNullOrEmpty(item.schoolIds))
  254. {
  255. List<string> tempSchoolIds = new(item.schoolIds.Split("|"));
  256. ddUserInfo.handleSchools = await SchoolWay.GetSchoolInfos(cosmosCliet, tempSchoolIds);
  257. }
  258. ddUserInfos.Add(ddUserInfo);
  259. }
  260. }
  261. break;
  262. default:
  263. foreach (var item in ddUserInfoList)
  264. {
  265. DDUserInfo ddUserInfo = new()
  266. {
  267. partitionKey = item.PartitionKey,
  268. rowKey = item.RowKey,
  269. userId = item.userId,
  270. unionId = item.unionId,
  271. name = item.name,
  272. title = item.title,
  273. stateCode = item.stateCode,
  274. mobile = item.mobile,
  275. jobNumber = item.jobNumber,
  276. pid = item.pid,
  277. deptId = item.deptId,
  278. deptName = item.deptName,
  279. depts = item.depts,
  280. avatar = item.avatar,
  281. isAdmin = item.isAdmin,
  282. tmdId = item.tmdId,
  283. tmdName = item.tmdName,
  284. tmdMobile = item.tmdMobile,
  285. mail = item.mail,
  286. picture = item.picture,
  287. roles = item.roles,
  288. joinTime = item.joinTime,
  289. permissions = item.permissions,
  290. handleRoles = !string.IsNullOrEmpty($"{item.roles}") ? new List<string>(item.roles.Split(",")) : new List<string>(),
  291. handlePermissions = !string.IsNullOrEmpty($"{item.permissions}") ? new List<string>(item.permissions.Split(",")) : new List<string>(),
  292. };
  293. if (!string.IsNullOrEmpty(item.schoolIds))
  294. {
  295. List<string> tempSchoolIds = new(item.schoolIds.Split("|"));
  296. ddUserInfo.handleSchools = await SchoolWay.GetSchoolInfos(cosmosCliet, tempSchoolIds);
  297. }
  298. ddUserInfos.Add(ddUserInfo);
  299. }
  300. break;
  301. }
  302. return Ok(new { state = 200, ddUserInfos = ddUserInfos });
  303. }
  304. catch (Exception ex)
  305. {
  306. await _dingDing.SendBotMsg($"BI,{_option.Location} /tabledd/get-ddusers \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  307. return BadRequest();
  308. }
  309. }
  310. /// <summary>
  311. /// 更新钉钉和醍摩豆的BI权限 //已对接
  312. /// </summary>
  313. /// <param name="jsonElement"></param>
  314. /// <returns></returns>
  315. [ProducesDefaultResponseType]
  316. [AuthToken(Roles = "admin,rdc")]
  317. [HttpPost("set-rolesper")]
  318. public async Task<IActionResult> SetPermissions(JsonElement jsonElement)
  319. {
  320. try
  321. {
  322. if (!jsonElement.TryGetProperty("partitionKey", out JsonElement partitionKey)) return BadRequest();
  323. jsonElement.TryGetProperty("userId", out JsonElement userId);
  324. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  325. if (!jsonElement.TryGetProperty("permissions", out JsonElement _permissions)) return BadRequest();
  326. if (!jsonElement.TryGetProperty("roles", out JsonElement _roles)) return BadRequest();
  327. if (!jsonElement.TryGetProperty("isDisable", out JsonElement _isDisable)) return BadRequest();
  328. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  329. var tableClient = _azureStorage.GetCloudTableClient();
  330. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  331. ////分开部署,就不需要,一站多用时,取消注释
  332. //if ($"{site}".Equals(BIConst.Global))
  333. //{
  334. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  335. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  336. //}
  337. long isDisable = 0;
  338. try
  339. {
  340. isDisable = long.Parse($"{_isDisable}");
  341. if (isDisable != 1 || isDisable != 0)
  342. return Ok(new { state = RespondCode.ParamsError, msg = "禁用参数错误" });
  343. }
  344. catch
  345. {
  346. return Ok(new { state = RespondCode.ParamsError, msg = "禁用参数错误" });
  347. }
  348. var table = tableClient.GetTableReference("BIDDUserInfo");
  349. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  350. List<DingDingUserInfo> ddUserInfo = new();
  351. List<string> listper = _permissions.ToObject<List<string>>();
  352. List<string> listroles = _roles.ToObject<List<string>>();
  353. List<string> roles = new();//角色列表
  354. List<string> permissions = new();//权限列表
  355. StringBuilder stringBuilder = new($"{_tmdName}【{_tmdId}】醍摩豆账号");
  356. Dictionary<string, object> dic = new() { { "PartitionKey", $"{partitionKey}" } };
  357. if (!string.IsNullOrEmpty($"{userId}"))
  358. {
  359. dic.Add("userId", $"{userId}");
  360. }
  361. if (!string.IsNullOrEmpty($"{tmdId}"))
  362. {
  363. dic.Add("tmdId", $"{tmdId}");
  364. }
  365. if (string.IsNullOrEmpty($"{userId}") && string.IsNullOrEmpty($"{tmdId}"))
  366. {
  367. return BadRequest();
  368. }
  369. var tempUser = await table.FindListByDict<DingDingUserInfo>(dic);
  370. foreach (var item in tempUser)
  371. {
  372. stringBuilder.Append($"操作醍摩豆账户{item.tmdName}【{item.tmdId}】修改权限:{string.Join("|", listper.ToArray())}");
  373. item.roles = listroles.Count > 0 ? string.Join(",", listroles) : "assist";
  374. item.permissions = string.Join(",", listper);
  375. item.isDisable = isDisable;
  376. ddUserInfo.Add(item);
  377. roles = !string.IsNullOrEmpty($"{item.roles}") ? new List<string>(item.roles.Split(",")) : new List<string>();
  378. permissions = !string.IsNullOrEmpty($"{item.permissions}") ? new List<string>(item.permissions.Split(",")) : new List<string>();
  379. }
  380. ddUserInfo = await table.UpdateAll<DingDingUserInfo>(ddUserInfo);
  381. //保存操作记录
  382. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
  383. return Ok(new { state = 200, ddUserInfo, roles, permissions });
  384. }
  385. catch (Exception ex)
  386. {
  387. await _dingDing.SendBotMsg($"BI,{_option.Location} /tabledd/set-rolesper \n {ex.Message}\n{ex.StackTrace} ", GroupNames.成都开发測試群組);
  388. return BadRequest();
  389. }
  390. }
  391. /// <summary>
  392. /// 依据部门ID获取部门列表 //已对接
  393. /// </summary>
  394. /// <param name="jsonElement"></param>
  395. /// <returns></returns>
  396. [ProducesDefaultResponseType]
  397. [HttpPost("get-dddeptiduser")]
  398. public async Task<IActionResult> GetDDDeptIdUser(JsonElement jsonElement)
  399. {
  400. try
  401. {
  402. if (!jsonElement.TryGetProperty("deptId", out JsonElement deptId)) return BadRequest();
  403. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  404. var cosmosCliet = _azureCosmos.GetCosmosClient();
  405. var tableClient = _azureStorage.GetCloudTableClient();
  406. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  407. ////分开部署,就不需要,一站多用时,取消注释
  408. //if ($"{site}".Equals(BIConst.Global))
  409. //{
  410. // cosmosCliet = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  411. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  412. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  413. //};
  414. var table = tableClient.GetTableReference("BIDDUserInfo");
  415. //string divide = _configuration["CustomParam:SiteScope"];
  416. string divide = _option.Location;
  417. Dictionary<string, object> dic = new() { { "PartitionKey", $"{divide}" } };
  418. List<DingDingUserInfo> tempUserInfos = await table.FindListByDict<DingDingUserInfo>(dic);
  419. List<DingDingUserInfo> userInfo = new();
  420. tempUserInfos.ForEach(x => {
  421. if (x.depts.Contains($"{deptId}"))
  422. {
  423. userInfo.Add(x);
  424. }
  425. if (x.pid.Equals(long.Parse($"{deptId}")))
  426. {
  427. userInfo.Add(x);
  428. }
  429. });
  430. //userInfo.Distinct().ToList(); //Equals实现去重
  431. userInfo.Where((x, i) => userInfo.FindIndex(z => z.RowKey.Equals(x.RowKey)) == i);//Lambda表达式去重
  432. //userInfo.GroupBy(p => p).Select(p => p.Key).ToList();//去重复
  433. List<DDUserInfo> ddUserInfos = new();
  434. foreach (var item in userInfo)
  435. {
  436. DDUserInfo tempUserInfo = new DDUserInfo()
  437. {
  438. partitionKey = item.PartitionKey,
  439. rowKey = item.RowKey,
  440. userId = item.userId,
  441. unionId = item.unionId,
  442. name = item.name,
  443. title = item.title,
  444. stateCode = item.stateCode,
  445. mobile = item.mobile,
  446. jobNumber = item.jobNumber,
  447. pid = item.pid,
  448. deptId = item.deptId,
  449. deptName = item.deptName,
  450. depts = item.depts,
  451. avatar = item.avatar,
  452. isAdmin = item.isAdmin,
  453. tmdId = item.tmdId,
  454. tmdName = item.tmdName,
  455. tmdMobile = item.tmdMobile,
  456. mail = item.mail,
  457. picture = item.picture,
  458. roles = item.roles,
  459. joinTime = item.joinTime,
  460. permissions = item.permissions,
  461. handleRoles = !string.IsNullOrEmpty($"{item.roles}") ? new List<string>(item.roles.Split(",")) : new List<string>(),
  462. handlePermissions = !string.IsNullOrEmpty($"{item.permissions}") ? new List<string>(item.permissions.Split(",")) : new List<string>(),
  463. };
  464. if (!string.IsNullOrEmpty(item.schoolIds))
  465. {
  466. List<string> tempSchoolIds = new(item.schoolIds.Split("|"));
  467. tempUserInfo.handleSchools = await SchoolWay.GetSchoolInfos(cosmosCliet, tempSchoolIds);
  468. }
  469. ddUserInfos.Add(tempUserInfo);
  470. }
  471. return Ok(new { state = 200, ddUserInfos });
  472. }
  473. catch (Exception ex)
  474. {
  475. await _dingDing.SendBotMsg($"BI, {_option.Location} /tabledd/get-dddeptiduser \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  476. return BadRequest();
  477. }
  478. }
  479. /// <summary>
  480. /// 通过醍摩豆账户信息 设置BI后台管理员 //已对接
  481. /// </summary>
  482. /// <param name="jsonElement"></param>
  483. /// <returns></returns>
  484. [ProducesDefaultResponseType]
  485. [AuthToken(Roles = "admin,rdc")]
  486. [HttpPost("set-tmdadmin")]
  487. public async Task<IActionResult> SetTmdBackendAdmin(JsonElement jsonElement)
  488. {
  489. try
  490. {
  491. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  492. if (!jsonElement.TryGetProperty("tmdName", out JsonElement tmdName)) return BadRequest();
  493. if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
  494. jsonElement.TryGetProperty("picture ", out JsonElement picture);
  495. jsonElement.TryGetProperty("mail ", out JsonElement mail);
  496. //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
  497. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  498. var cosmosCliet = _azureCosmos.GetCosmosClient();
  499. var tableClient = _azureStorage.GetCloudTableClient();
  500. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  501. ////分开部署,就不需要,一站多用时,取消注释
  502. //if ($"{site}".Equals(BIConst.Global))
  503. //{
  504. // cosmosCliet = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  505. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  506. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  507. //}
  508. var table = tableClient.GetTableReference("BIDDUserInfo");
  509. List<DDUserInfo> ddUserInfos = new();
  510. List<string> roles = new();//角色列表
  511. List<string> permissions = new();//权限列表
  512. StringBuilder msg = new($"{_tmdName}【{_tmdId}】");
  513. //string divide = _configuration["CustomParam:SiteScope"];
  514. string divide = _option.Location;
  515. Dictionary<string, object> dic = new() { { "PartitionKey", $"{divide}" }, { "mobile", $"{mobile}" } };
  516. List<DingDingUserInfo> ddUserInfoList = await table.FindListByDict<DingDingUserInfo>(dic);
  517. if (ddUserInfoList.Count > 0)
  518. {
  519. foreach (var user in ddUserInfoList)
  520. {
  521. List<string> tempRoles = new(user.roles.Split(","));
  522. if (tempRoles.Count > 0)
  523. {
  524. if (!tempRoles.Contains("admin"))
  525. {
  526. tempRoles.Add("admin");
  527. }
  528. }
  529. else
  530. tempRoles.Add("admin");
  531. user.roles = string.Join(",", tempRoles);
  532. user.joinTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  533. user.tmdId = $"{tmdId}";
  534. user.tmdName = $"{tmdName}";
  535. user.tmdMobile = $"{mobile}";
  536. if (!string.IsNullOrEmpty($"{picture}"))
  537. {
  538. user.picture = $"{picture}";
  539. }
  540. if (!string.IsNullOrEmpty($"{mail}"))
  541. {
  542. user.mail = $"{mail}";
  543. }
  544. msg.Append($" 将:{tmdName}【{tmdId}】醍摩豆账号和({user.name}【{user.unionId}】) 钉钉账户绑定,并设置管理员");
  545. DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(user);
  546. if (respUser != null)
  547. {
  548. roles = !string.IsNullOrEmpty($"{respUser.roles}") ? new List<string>(respUser.roles.Split(",")) : new List<string>();
  549. }
  550. DDUserInfo dDUserInfo = new()
  551. {
  552. partitionKey = respUser.PartitionKey,
  553. rowKey = respUser.RowKey,
  554. userId = respUser.userId,
  555. unionId = respUser.unionId,
  556. name = respUser.name,
  557. title = respUser.title,
  558. stateCode = respUser.stateCode,
  559. mobile = respUser.mobile,
  560. jobNumber = respUser.jobNumber,
  561. pid = respUser.pid,
  562. deptId = respUser.deptId,
  563. deptName = respUser.deptName,
  564. depts = respUser.depts,
  565. avatar = respUser.avatar,
  566. isAdmin = respUser.isAdmin,
  567. tmdId = respUser.tmdId,
  568. tmdName = respUser.tmdName,
  569. tmdMobile = respUser.tmdMobile,
  570. mail = respUser.mail,
  571. picture = respUser.picture,
  572. roles = respUser.roles,
  573. joinTime = respUser.joinTime,
  574. permissions = respUser.permissions,
  575. handleRoles = !string.IsNullOrEmpty($"{respUser.roles}") ? new List<string>(respUser.roles.Split(",")) : new List<string>(),
  576. handlePermissions = !string.IsNullOrEmpty($"{respUser.permissions}") ? new List<string>(respUser.permissions.Split(",")) : new List<string>()
  577. };
  578. if (!string.IsNullOrEmpty(respUser.schoolIds))
  579. {
  580. List<string> tempSchoolIds = new(respUser.schoolIds.Split("|"));
  581. dDUserInfo.handleSchools = await SchoolWay.GetSchoolInfos(cosmosCliet, tempSchoolIds);
  582. }
  583. ddUserInfos.Add(dDUserInfo);
  584. }
  585. }
  586. else
  587. {
  588. DingDingUserInfo dingDingUserInfo = new()
  589. {
  590. PartitionKey = divide,
  591. RowKey = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(),
  592. roles = "admin",
  593. tmdId = $"{tmdId}",
  594. tmdName = $"{tmdName}",
  595. tmdMobile = $"{mobile}",
  596. };
  597. if (!string.IsNullOrEmpty($"{picture}"))
  598. {
  599. dingDingUserInfo.picture = $"{picture}";
  600. }
  601. if (!string.IsNullOrEmpty($"{mail}"))
  602. {
  603. dingDingUserInfo.mail = $"{mail}";
  604. }
  605. DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(dingDingUserInfo);
  606. return Ok(new { state = 201, msg = "新生成的BIadmin", respUser });
  607. }
  608. //保存操作记录
  609. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", msg.ToString(), _dingDing, httpContext: HttpContext);
  610. return Ok(new { state = 200, ddUserInfos });
  611. }
  612. catch (Exception ex)
  613. {
  614. await _dingDing.SendBotMsg($"BI,{_option.Location} /tabledd/set-tmdadmin \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  615. return BadRequest();
  616. }
  617. }
  618. /// <summary>
  619. /// 设置系统管理员 //已对接
  620. /// </summary>
  621. /// <param name="jsonElement"></param>
  622. /// <returns></returns>
  623. [ProducesDefaultResponseType]
  624. [AuthToken(Roles = "admin,rdc")]
  625. [HttpPost("set-backend")]
  626. public async Task<IActionResult> SetBackendAdmin(JsonElement jsonElement)
  627. {
  628. try
  629. {
  630. if (!jsonElement.TryGetProperty("partitionKey", out JsonElement partitionKey)) return BadRequest();
  631. if (!jsonElement.TryGetProperty("rowKey", out JsonElement rowKey)) return BadRequest();
  632. if (!jsonElement.TryGetProperty("isAdmin", out JsonElement isAdmin)) return BadRequest();
  633. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  634. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  635. var tableClient = _azureStorage.GetCloudTableClient();
  636. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  637. ////分开部署,就不需要,一站多用时,取消注释
  638. //if ($"{site}".Equals(BIConst.Global))
  639. //{
  640. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  641. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  642. //}
  643. var table = tableClient.GetTableReference("BIDDUserInfo");
  644. var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{rowKey}" } });
  645. List<DDUserInfo> ddUserInfos = new();
  646. List<string> roles = new();//角色列表
  647. List<string> permissions = new();//权限列表
  648. StringBuilder msg = new($"{_tmdName}【{_tmdId}】");
  649. if (bool.Parse($"{isAdmin}") == true)
  650. {
  651. foreach (var user in tempUser)
  652. {
  653. if (string.IsNullOrEmpty(user.roles))
  654. {
  655. user.roles = "admin,assist";
  656. }
  657. List<string> tempRoles = new(user.roles.Split(","));
  658. if (!tempRoles.Contains("admin"))
  659. {
  660. tempRoles.Add("admin");
  661. }
  662. user.roles = string.Join(",", tempRoles);
  663. user.joinTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  664. DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(user);
  665. if (respUser != null)
  666. {
  667. roles = !string.IsNullOrEmpty($"{respUser.roles}") ? new List<string>(respUser.roles.Split(",")) : new List<string>();
  668. }
  669. msg.Append($"添加{respUser.name}【{respUser.RowKey}】账号的BI管理员");
  670. }
  671. }
  672. else
  673. {
  674. var userInfos = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" } });
  675. var adminInfos = userInfos.FindAll(x => x.roles.Contains("admin"));
  676. if (adminInfos.Count == 1)
  677. {
  678. return Ok(new { state = 403, msg = "已经是最后一个管理员了" });
  679. }
  680. else
  681. {
  682. foreach (var user in tempUser)
  683. {
  684. if (!user.userId.Equals($"{did}"))
  685. {
  686. List<string> tempRoles = new(user.roles.Split(","));
  687. if (tempRoles.Contains("admin"))
  688. {
  689. tempRoles.Remove("admin");
  690. }
  691. user.roles = string.Join(",", tempRoles);
  692. DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(user);
  693. if (respUser != null)
  694. {
  695. roles = !string.IsNullOrEmpty($"{respUser.roles}") ? new List<string>(respUser.roles.Split(",")) : new List<string>();
  696. msg.Append($"取消{respUser.name}【{respUser.RowKey}】账号的BI管理员");
  697. }
  698. }
  699. else return Ok(new { state = 1, msg = "不能删除自己" });
  700. }
  701. }
  702. }
  703. //保存操作记录
  704. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", msg.ToString(), _dingDing, httpContext: HttpContext);
  705. return Ok(new { state = 200, roles });
  706. }
  707. catch (Exception ex)
  708. {
  709. await _dingDing.SendBotMsg($"BI, {_option.Location} /tabledd/set-backend \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  710. return BadRequest();
  711. }
  712. }
  713. /// <summary>
  714. /// 从钉钉的组织架构中人员信息数据,并保存或者更新至Blob中 初始化使用该接口
  715. /// </summary>
  716. /// <returns></returns>
  717. [ProducesDefaultResponseType]
  718. [HttpPost("get-dduserinitial")]
  719. public async Task<IActionResult> GetddUserInitial(JsonElement jsonElement)
  720. {
  721. try
  722. {
  723. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  724. var tableClient = _azureStorage.GetCloudTableClient();
  725. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  726. ////分开部署,就不需要,一站多用时,取消注释
  727. //if ($"{site}".Equals(BIConst.Global))
  728. //{
  729. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  730. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  731. //}
  732. var table = tableClient.GetTableReference("BIDDUserInfo");
  733. string appKey = _configuration["DingDingAuth:appKey"];
  734. string appSecret = _configuration["DingDingAuth:appSecret"];
  735. //string divide = _configuration["CustomParam:SiteScope"];
  736. string divide = _option.Location;
  737. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  738. //HttpClient httpClient = _http.CreateClient();
  739. //string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
  740. //获取access_token
  741. IDingTalkClient tokenClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
  742. OapiGettokenRequest tokenRequest = new() { Appkey = appKey, Appsecret = appSecret };
  743. tokenRequest.SetHttpMethod("Get");
  744. OapiGettokenResponse tokenRespone = tokenClient.Execute(tokenRequest);
  745. if (tokenRespone.IsError)
  746. {
  747. return BadRequest();
  748. }
  749. //access_token的有效期为7200秒(2小时),有效期内重复获取会返回相同结果并自动续期,过期后获取会返回新的access_token
  750. string access_token = tokenRespone.AccessToken;
  751. //获取部门接口
  752. IDingTalkClient deptListClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
  753. //一级部门
  754. OapiV2DepartmentListsubRequest reqDeptList1 = new() { DeptId = 1L, Language = "zh_CN" };
  755. OapiV2DepartmentListsubResponse rspDeptList1 = deptListClient.Execute(reqDeptList1, access_token);
  756. List<DingDingUserInfo> ddUserInfos = new();
  757. if (rspDeptList1.Result != null)
  758. {
  759. foreach (var tempDept1 in rspDeptList1.Result)
  760. {
  761. //获取一级部门用户信息
  762. List<DingDingUserInfo> dingDingUserInfos1 = await GetDingDingUserInfo(divide, tempDept1.DeptId, tempDept1.ParentId, tempDept1.Name, access_token);
  763. //if (dingDingUserInfos1.Count > 0) ddUserInfos.AddRange(ddUserInfos.Union(dingDingUserInfos1.ToList()));
  764. if (dingDingUserInfos1.Count > 0) ddUserInfos.AddRange(dingDingUserInfos1);
  765. //获取二级部门
  766. OapiV2DepartmentListsubRequest reqDeptList2 = new() { DeptId = tempDept1.DeptId, Language = "zh_CN" };
  767. OapiV2DepartmentListsubResponse rspDeptList2 = deptListClient.Execute(reqDeptList2, access_token);
  768. if (rspDeptList2.Result != null)
  769. {
  770. foreach (var tempDept2 in rspDeptList2.Result)
  771. {
  772. //获取二级部门用户信息
  773. List<DingDingUserInfo> dingDingUserInfos2 = await GetDingDingUserInfo(divide, tempDept2.DeptId, tempDept2.ParentId, tempDept2.Name, access_token);
  774. //if (dingDingUserInfos2.Count > 0) ddUserInfos.AddRange(ddUserInfos.Union(dingDingUserInfos2.ToList()));
  775. if (dingDingUserInfos2.Count > 0) ddUserInfos.AddRange(dingDingUserInfos2);
  776. //获取三级部门
  777. OapiV2DepartmentListsubRequest reqDeptList3 = new() { DeptId = tempDept2.DeptId, Language = "zh_CN" };
  778. OapiV2DepartmentListsubResponse rspDeptList3 = deptListClient.Execute(reqDeptList3, access_token);
  779. if (rspDeptList3.Result != null)
  780. {
  781. foreach (var tempDept3 in rspDeptList3.Result)
  782. {
  783. //获取三级部门用户信息
  784. List<DingDingUserInfo> dingDingUserInfos3 = await GetDingDingUserInfo(divide, tempDept3.DeptId, tempDept3.ParentId, tempDept3.Name, access_token);
  785. //if (dingDingUserInfos3.Count > 0) ddUserInfos.AddRange(ddUserInfos.Union(dingDingUserInfos3.ToList()));
  786. if (dingDingUserInfos3.Count > 0) ddUserInfos.AddRange(dingDingUserInfos3);
  787. //获取四级部门
  788. OapiV2DepartmentListsubRequest reqDeptList4 = new() { DeptId = tempDept3.DeptId, Language = "zh_CN" };
  789. OapiV2DepartmentListsubResponse rspDeptList4 = deptListClient.Execute(reqDeptList4, access_token);
  790. if (rspDeptList4.Result != null)
  791. {
  792. foreach (var tempDept4 in rspDeptList4.Result)
  793. {
  794. //获取四级部门用户信息
  795. List<DingDingUserInfo> dingDingUserInfos4 = await GetDingDingUserInfo(divide, tempDept4.DeptId, tempDept4.ParentId, tempDept4.Name, access_token);
  796. //if (dingDingUserInfos4.Count > 0) ddUserInfos.AddRange(ddUserInfos.Union(dingDingUserInfos4.ToList()));
  797. if (dingDingUserInfos4.Count > 0) ddUserInfos.AddRange(dingDingUserInfos4);
  798. //获取五级部门
  799. OapiV2DepartmentListsubRequest reqDeptList5 = new() { DeptId = tempDept4.DeptId, Language = "zh_CN" };
  800. OapiV2DepartmentListsubResponse rspDeptList5 = deptListClient.Execute(reqDeptList5, access_token);
  801. if (rspDeptList5.Result != null)
  802. {
  803. foreach (var tempDept5 in rspDeptList5.Result)
  804. {
  805. //获取五级部门用户信息
  806. List<DingDingUserInfo> dingDingUserInfos5 = await GetDingDingUserInfo(divide, tempDept5.DeptId, tempDept5.ParentId, tempDept5.Name, access_token);
  807. //if (dingDingUserInfos5.Count > 0) ddUserInfos.AddRange(ddUserInfos.Union(dingDingUserInfos5).ToList());
  808. if (dingDingUserInfos5.Count > 0) ddUserInfos.AddRange(dingDingUserInfos5);
  809. }
  810. }
  811. }
  812. }
  813. }
  814. }
  815. }
  816. }
  817. }
  818. }
  819. //保存操作记录
  820. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{_tmdName}【{_tmdId}】从钉钉组织结构初始化至Azure Table表【DDUserInfo】中。", _dingDing, httpContext: HttpContext);
  821. var tempddUserInfos = ddUserInfos.GroupBy(c => c.userId).Select(c => c.First()).ToList();//去重
  822. //List<DingDingUserInfo> TempdingDingUserInfos = await _azureStorage.SaveOrUpdateAll(dingDingUserInfos); //只是保存至Table
  823. //查询数据的数据 并和钉钉查询的数据对比,找出不同的数据,并删除 待后期测试
  824. var users = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{divide}" } });
  825. List<DingDingUserInfo> noExisits = new();
  826. if (users.Count > 0)
  827. {
  828. //var temps = users.Union(tempddUserInfos).Except(users.Intersect(tempddUserInfos));
  829. List<DingDingUserInfo> existsUserInfo = users.Where(u => !tempddUserInfos.Exists(e => u.userId.Equals(e.userId) && u.PartitionKey.Equals(e.PartitionKey))).ToList();
  830. if (users.Count >= tempddUserInfos.Count)
  831. {
  832. existsUserInfo.AddRange(tempddUserInfos.Where(e => !users.Exists(u => e.userId.Equals(u.userId) && e.PartitionKey.Equals(u.PartitionKey))).ToList());
  833. }
  834. ////List<DingDingUserInfo> existsUserInfo = users.Where((x, i) => users.FindIndex(z => z.userId.Equals(x.userId) && x.PartitionKey.Equals(divide)) == i).Select(x => x).ToList();
  835. if (existsUserInfo.Count > 0)
  836. {
  837. noExisits = await table.DeleteAll(existsUserInfo);
  838. }
  839. }
  840. List<DingDingUserInfo> UserInfo = await table.SaveOrUpdateAll(tempddUserInfos); //保存和修改至Table
  841. return Ok(new { state = 200, UserInfo, noExisits });
  842. }
  843. catch (Exception ex)
  844. {
  845. await _dingDing.SendBotMsg($"BI,{_option.Location} /tabledd/get-dingdingusers \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  846. return BadRequest();
  847. }
  848. }
  849. /// <summary>
  850. /// 后端钉钉账户和醍摩豆账户进行绑定
  851. /// </summary>
  852. /// <param name="jsonElement"></param>
  853. /// <returns></returns>
  854. [ProducesDefaultResponseType]
  855. [AuthToken(Roles = "admin,rdc")]
  856. [HttpPost("set-backenbind")]
  857. public async Task<IActionResult> SetBackenBind(JsonElement jsonElement)
  858. {
  859. try
  860. {
  861. if (!jsonElement.TryGetProperty("rowKey", out JsonElement rowKey)) return BadRequest();
  862. if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
  863. //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
  864. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  865. var tableClient = _azureStorage.GetCloudTableClient();
  866. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  867. ////分开部署,就不需要,一站多用时,取消注释
  868. //if ($"{site}".Equals(BIConst.Global))
  869. //{
  870. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  871. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  872. //}
  873. var table = tableClient.GetTableReference("BIDDUserInfo");
  874. List<DingDingUserInfo> tempddUsers = null;
  875. List<DingDingUserInfo> ddUsers = new();
  876. StringBuilder tableSql = new();
  877. if (!string.IsNullOrEmpty($"{rowKey}"))
  878. tableSql.Append($"RowKey {QueryComparisons.Equal} '{rowKey}'");
  879. string tmdId = null;
  880. string tmdName = null;
  881. string tmdMobile = null;
  882. string mail = null;
  883. string picture = null;
  884. var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{mobile}" } }, _option.Location, _configuration);
  885. if (coreUser != null && coreUser.id != null)
  886. {
  887. tmdId = coreUser.id;
  888. tmdName = coreUser.name;
  889. tmdMobile = coreUser.mobile;
  890. mail = coreUser.mail;
  891. picture = coreUser.picture;
  892. }else return Ok(new { state = 1, message = "该手机号未找到醍摩豆账户" });
  893. tempddUsers = await table.QueryWhereString<DingDingUserInfo>(tableSql.ToString());
  894. if (tempddUsers.Count > 0)
  895. {
  896. foreach (var item in tempddUsers)
  897. {
  898. if (item.RowKey.Equals($"{rowKey}"))
  899. {
  900. item.tmdId = tmdId;
  901. item.tmdName = tmdName;
  902. item.tmdMobile = tmdMobile;
  903. item.mail = mail;
  904. item.picture = picture;
  905. ddUsers.Add(item);
  906. }
  907. }
  908. }
  909. else return Ok(new { state = 2, message = "钉钉ID错误请检查钉钉ID" });
  910. if (ddUsers.Count > 0) ddUsers = await table.SaveOrUpdateAll(ddUsers);
  911. //保存操作记录
  912. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", $"{_tmdName}【{_tmdId}】操作:绑定钉钉账户[{rowKey}]和醍摩豆账户[{tmdId}]", _dingDing, httpContext: HttpContext);
  913. return Ok(new { state = 200, ddUsers });
  914. }
  915. catch (Exception ex)
  916. {
  917. await _dingDing.SendBotMsg($"BI, {_option.Location} /tabledd/set-backenbind \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  918. return BadRequest();
  919. }
  920. }
  921. /// <summary>
  922. /// 后端初始化管理员
  923. /// </summary>
  924. /// <param name="jsonElement"></param>
  925. /// <returns></returns>
  926. [ProducesDefaultResponseType]
  927. [HttpPost("set-apiphoneadmin")]
  928. public async Task<IActionResult> SetPhoneAdmin(JsonElement jsonElement)
  929. {
  930. jsonElement.TryGetProperty("partitionKey", out JsonElement partitionKey);
  931. if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
  932. //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
  933. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  934. var partKey = _option.Location;
  935. if (string.IsNullOrEmpty($"{partitionKey}"))
  936. {
  937. partKey = $"{partitionKey}";
  938. };
  939. var tableClient = _azureStorage.GetCloudTableClient();
  940. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  941. ////分开部署,就不需要,一站多用时,取消注释
  942. //if ($"{site}".Equals(BIConst.Global))
  943. //{
  944. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  945. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  946. //}
  947. var table = tableClient.GetTableReference("BIDDUserInfo");
  948. var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partKey}" }, { "mobile", $"{mobile}" } });
  949. List<string> roles = new();//角色列表
  950. List<string> permissions = new();//权限列表
  951. StringBuilder msg = new();
  952. foreach (var user in tempUser)
  953. {
  954. if (string.IsNullOrEmpty(user.roles))
  955. {
  956. user.roles = "admin,assist";
  957. }
  958. List<string> tempRoles = new(user.roles.Split(","));
  959. if (!tempRoles.Contains("admin"))
  960. {
  961. tempRoles.Add("admin");
  962. }
  963. user.roles = string.Join(",", tempRoles);
  964. user.joinTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  965. DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(user);
  966. if (respUser != null)
  967. {
  968. roles = !string.IsNullOrEmpty($"{respUser.roles}") ? new List<string>(respUser.roles.Split(",")) : new List<string>();
  969. }
  970. msg.Append($"初始将{respUser.name}【{respUser.RowKey}】账号的BI管理员");
  971. }
  972. //保存操作记录
  973. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-update", msg.ToString(), _dingDing, httpContext: HttpContext);
  974. return Ok(new { state = 200, roles });
  975. }
  976. /// <summary>
  977. /// 解除钉钉和醍摩豆的绑定
  978. /// </summary>
  979. /// <param name="jsonElement"></param>
  980. /// <returns></returns>
  981. [ProducesDefaultResponseType]
  982. [HttpPost("set-unbind")]
  983. public async Task<IActionResult> SetUnbind(JsonElement jsonElement)
  984. {
  985. jsonElement.TryGetProperty("mobile", out JsonElement mobile);
  986. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  987. var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
  988. ////分开部署,就不需要,一站多用时,取消注释
  989. //if ($"{site}".Equals(BIConst.Global))
  990. // table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("BIDDUserInfo");
  991. //string divide = _configuration["CustomParam:SiteScope"];
  992. string divide = _option.Location;
  993. Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", $"{divide}" } };
  994. if (!string.IsNullOrEmpty($"{mobile}"))
  995. dic.Add("tmdMobile", $"{mobile}");
  996. else
  997. dic.Add("tmdMobile", "18281911681");
  998. List<DingDingUserInfo> ddUserInfoList = await table.FindListByDict<DingDingUserInfo>(dic);
  999. List<DingDingUserInfo> tempDDUI = new();
  1000. if (ddUserInfoList.Count > 0)
  1001. {
  1002. foreach (var item in ddUserInfoList)
  1003. {
  1004. item.tmdId = null;
  1005. item.tmdName = null;
  1006. item.tmdMobile = null;
  1007. item.picture = null;
  1008. tempDDUI.Add(item);
  1009. }
  1010. }
  1011. else return Ok(new { state = 404, msg = "未找到手机号匹配的绑定号码!,请检查手机号" });
  1012. var userInfos = await table.SaveOrUpdateAll(tempDDUI); //保存和修改至Table
  1013. return Ok(new { state = 200, userInfos });
  1014. }
  1015. /// <summary>
  1016. /// 查询钉钉待入职人员的ID添加至Table数据表中
  1017. /// </summary>
  1018. /// <returns></returns>
  1019. [ProducesDefaultResponseType]
  1020. [AuthToken(Roles = "admin,rdc")]
  1021. [HttpPost("set-ddinductionuser")]
  1022. public async Task<IActionResult> SetDingDingInductionUser(JsonElement jsonElement)
  1023. {
  1024. try
  1025. {
  1026. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  1027. var tableClient = _azureStorage.GetCloudTableClient();
  1028. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  1029. ////分开部署,就不需要,一站多用时,取消注释
  1030. //if ($"{site}".Equals(BIConst.Global))
  1031. //{
  1032. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  1033. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  1034. //}
  1035. var table = tableClient.GetTableReference("BIDDUserInfo");
  1036. string appKey = _configuration["DingDingAuth:appKey"];
  1037. string appSecret = _configuration["DingDingAuth:appSecret"];
  1038. //string divide = _configuration["CustomParam:SiteScope"];
  1039. string divide = _option.Location;
  1040. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  1041. //获取access_token
  1042. IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
  1043. OapiGettokenRequest request = new() { Appkey = appKey, Appsecret = appSecret };
  1044. request.SetHttpMethod("Get");
  1045. OapiGettokenResponse response = client.Execute(request);
  1046. if (response.IsError)
  1047. {
  1048. return BadRequest();
  1049. }
  1050. //access_token的有效期为7200秒(2小时),有效期内重复获取会返回相同结果并自动续期,过期后获取会返回新的access_token
  1051. string access_token = response.AccessToken;
  1052. IDingTalkClient InductionClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/querypreentry");
  1053. OapiSmartworkHrmEmployeeQuerypreentryRequest reqInduction = new() { Offset = 0L, Size = 50 };
  1054. reqInduction.SetHttpMethod("GET");
  1055. OapiSmartworkHrmEmployeeQuerypreentryResponse rspInduction = InductionClient.Execute(reqInduction, access_token);
  1056. if (rspInduction.Result.DataList != null)
  1057. {
  1058. List<DingDingUserInfo> ddUserInfos = new();
  1059. foreach (var itemId in rspInduction.Result.DataList)
  1060. {
  1061. DingDingUserInfo ddUserInfo = new();
  1062. ddUserInfo.PartitionKey = divide;
  1063. ddUserInfo.RowKey = itemId;
  1064. ddUserInfos.Add(ddUserInfo);
  1065. }
  1066. List<DingDingUserInfo> tempddUserInfos = await table.SaveAll(ddUserInfos);
  1067. //保存操作记录
  1068. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-add", $"{_tmdName}【{_tmdId}】添加待入职员工至table数据表中", _dingDing, httpContext: HttpContext);
  1069. if (ddUserInfos.Count == tempddUserInfos.Count)
  1070. return Ok(new { state = 200, UserInfo = tempddUserInfos });
  1071. else
  1072. {
  1073. var diffArr = tempddUserInfos.Where(c => !ddUserInfos.Contains(c)).ToList();
  1074. return Ok(new { state = 201, notUserInfo = diffArr });
  1075. }
  1076. }
  1077. else
  1078. return Ok(new { state = 400, rspInduction.SubErrCode, rspInduction.SubErrMsg });
  1079. }
  1080. catch (Exception ex)
  1081. {
  1082. await _dingDing.SendBotMsg($"BI,{_option.Location} /tabledd/set-ddinductionuser \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1083. return BadRequest();
  1084. }
  1085. }
  1086. /// <summary>
  1087. /// 获取钉钉离职人员ID并删除Table表中的数据
  1088. /// </summary>
  1089. /// <returns></returns>
  1090. [ProducesDefaultResponseType]
  1091. [AuthToken(Roles = "admin,rdc")]
  1092. [HttpPost("del-ddquituser")]
  1093. public async Task<IActionResult> DeleteDDQuitUser(JsonElement jsonElement)
  1094. {
  1095. try
  1096. {
  1097. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  1098. var tableClient = _azureStorage.GetCloudTableClient();
  1099. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  1100. ////分开部署,就不需要,一站多用时,取消注释
  1101. //if ($"{site}".Equals(BIConst.Global))
  1102. //{
  1103. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  1104. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  1105. //}
  1106. var table = tableClient.GetTableReference("BIDDUserInfo");
  1107. string appKey = _configuration["DingDingAuth:appKey"];
  1108. string appSecret = _configuration["DingDingAuth:appSecret"];
  1109. //string divide = _configuration["CustomParam:SiteScope"];
  1110. string divide = _option.Location;
  1111. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  1112. //获取access_token
  1113. IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
  1114. OapiGettokenRequest request = new() { Appkey = appKey, Appsecret = appSecret };
  1115. request.SetHttpMethod("Get");
  1116. OapiGettokenResponse response = client.Execute(request);
  1117. if (response.IsError)
  1118. {
  1119. return BadRequest();
  1120. }
  1121. //access_token的有效期为7200秒(2小时),有效期内重复获取会返回相同结果并自动续期,过期后获取会返回新的access_token
  1122. string access_token = response.AccessToken;
  1123. IDingTalkClient quitStaffClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/querydimission");
  1124. OapiSmartworkHrmEmployeeQuerydimissionRequest reqDimission = new() { Offset = 0L, Size = 50L };
  1125. OapiSmartworkHrmEmployeeQuerydimissionResponse rspDimission = quitStaffClient.Execute(reqDimission, access_token);
  1126. if (rspDimission.Result != null)
  1127. {
  1128. List<DingDingUserInfo> ddUserInfos = new();
  1129. foreach (var itemId in rspDimission.Result.DataList)
  1130. {
  1131. await table.DeleteSingle<DingDingUserInfo>(divide, $"{itemId}");
  1132. }
  1133. //保存操作记录
  1134. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "tabledd-del", $"{_tmdName}【{_tmdId}】从table数据表中删除离职员工", _dingDing, httpContext: HttpContext);
  1135. return Ok(new { state = 200 });
  1136. }
  1137. else
  1138. {
  1139. return Ok(new { state = rspDimission.SubErrCode });
  1140. }
  1141. }
  1142. catch (Exception ex)
  1143. {
  1144. await _dingDing.SendBotMsg($"BI,{_option.Location} /tabledd/del-ddquituser \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1145. return BadRequest();
  1146. }
  1147. }
  1148. /// <summary>
  1149. /// 获取钉钉用户信息
  1150. /// 并查询本地Table数据表中是否存在
  1151. /// </summary>
  1152. /// <param name="deptId"></param>
  1153. /// <param name="parentId"></param>
  1154. /// <param name="name"></param>
  1155. /// <param name="access_token"></param>
  1156. /// <returns></returns>
  1157. public async Task<List<DingDingUserInfo>> GetDingDingUserInfo(string partitionKey, long deptId, long parentId, string name, string access_token)
  1158. {
  1159. List<DingDingUserInfo> ddUserInfos = new();
  1160. //获取部门人员信息
  1161. IDingTalkClient userListClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
  1162. long joinDate = DateTimeOffset.UtcNow.AddDays(-91).ToUnixTimeMilliseconds();
  1163. //获取部门用户
  1164. OapiV2UserListRequest reqUserList = new()
  1165. {
  1166. DeptId = deptId,
  1167. Cursor = 0L,
  1168. Size = 50L,
  1169. OrderField = "custom",
  1170. Language = "zh_CN"
  1171. };
  1172. reqUserList.SetHttpMethod("GET");
  1173. OapiV2UserListResponse rspV2UserList = userListClient.Execute(reqUserList, access_token);
  1174. if (rspV2UserList.Result.List != null)
  1175. {
  1176. foreach (var itemUser in rspV2UserList.Result.List)
  1177. {
  1178. long isDisble = 0;
  1179. if (!string.IsNullOrEmpty($"{itemUser.HiredDate}"))
  1180. {
  1181. if (itemUser.HiredDate < joinDate)
  1182. isDisble = 1;
  1183. else
  1184. isDisble = 0;
  1185. }
  1186. var tempInfo = ddUserInfos.Find(x => x.RowKey.Equals(itemUser.Unionid));
  1187. if (string.IsNullOrEmpty($"{tempInfo}"))
  1188. {
  1189. var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
  1190. var users = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "userId", $"{itemUser.Userid}" }, { "unionId", $"{itemUser.Unionid}" } });
  1191. if (users.Count > 0)
  1192. {
  1193. foreach (var user in users)
  1194. {
  1195. DingDingUserInfo ddUserInfo = new()
  1196. {
  1197. PartitionKey = user.PartitionKey,
  1198. RowKey = user.RowKey,
  1199. userId = itemUser.Userid,
  1200. unionId = itemUser.Unionid,
  1201. name = itemUser.Name,
  1202. email = itemUser.Email,
  1203. title = itemUser.Title,
  1204. stateCode = itemUser.StateCode,
  1205. mobile = itemUser.Mobile,
  1206. jobNumber = itemUser.JobNumber,
  1207. pid = parentId,
  1208. deptId = deptId,
  1209. deptName = name,
  1210. depts = string.Join(",", itemUser.DeptIdList.ToArray()),
  1211. avatar = itemUser.Avatar,
  1212. isAdmin = itemUser.Admin,
  1213. tmdId = user.tmdId,
  1214. tmdName = user.tmdName,
  1215. tmdMobile = user.tmdMobile,
  1216. mail = user.mail,
  1217. picture = user.picture,
  1218. roles = user.roles,
  1219. joinTime = user.joinTime,
  1220. permissions = user.permissions,
  1221. schoolIds = user.schoolIds,
  1222. isDisable = isDisble,
  1223. };
  1224. ddUserInfos.Add(ddUserInfo);
  1225. }
  1226. }
  1227. else
  1228. {
  1229. DingDingUserInfo ddUserInfo = new()
  1230. {
  1231. RowKey = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(),
  1232. userId = itemUser.Userid,
  1233. unionId = itemUser.Unionid,
  1234. name = itemUser.Name,
  1235. email = itemUser.Email,
  1236. title = itemUser.Title,
  1237. stateCode = itemUser.StateCode,
  1238. mobile = itemUser.Mobile,
  1239. jobNumber = itemUser.JobNumber,
  1240. pid = parentId,
  1241. deptId = deptId,
  1242. deptName = name,
  1243. depts = string.Join(",", itemUser.DeptIdList.ToArray()),
  1244. avatar = itemUser.Avatar,
  1245. isAdmin = itemUser.Admin,
  1246. PartitionKey = partitionKey,
  1247. tmdId = "",
  1248. tmdName = "",
  1249. tmdMobile = "",
  1250. mail = "",
  1251. picture = "",
  1252. roles = "",
  1253. joinTime = 0,
  1254. permissions = "areadata-read,areadata-upd,schooldata-read,schooldata-upd",
  1255. schoolIds = "",
  1256. isDisable = isDisble,
  1257. };
  1258. ddUserInfos.Add(ddUserInfo);
  1259. }
  1260. }
  1261. }
  1262. }
  1263. return ddUserInfos;
  1264. }
  1265. public record DDUserInfo
  1266. {
  1267. public string partitionKey { get; set; }
  1268. public string rowKey { get; set; }
  1269. public string userId { get; set; }
  1270. public string unionId { get; set; }
  1271. public string name { get; set; }
  1272. public string title { get; set; }
  1273. public string stateCode { get; set; }
  1274. public string mobile { get; set; }
  1275. public string jobNumber { get; set; }
  1276. public long pid { get; set; }
  1277. public long deptId { get; set; }
  1278. public string deptName { get; set; }
  1279. public string depts { get; set; }
  1280. public string avatar { get; set; }
  1281. public bool isAdmin { get; set; }
  1282. public string tmdId { get; set; }
  1283. public string tmdName { get; set; }
  1284. public string tmdMobile { get; set; }
  1285. public string mail { get; set; }
  1286. public string picture { get; set; }
  1287. public string roles { get; set; }
  1288. public long joinTime { get; set; }
  1289. public string permissions { get; set; }
  1290. public List<string> handleRoles { get; set; }
  1291. public List<string> handlePermissions { get; set; }
  1292. public List<BaseInfo> handleSchools { get; set; } = new List<BaseInfo>();
  1293. }
  1294. }
  1295. }