TableDingDingInfoController.cs 77 KB

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