QiYeWeChatApiService.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. using OASystem.Domain.Dtos.QiYeWeChat;
  2. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  3. using OASystem.Domain.ViewModels.QiYeWeChat;
  4. using Org.BouncyCastle.Ocsp;
  5. using System.Collections.Generic;
  6. using System.Text.Json;
  7. using Ubiety.Dns.Core;
  8. namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
  9. {
  10. /// <summary>
  11. /// 聚合Api 服务
  12. /// </summary>
  13. public class QiYeWeChatApiService: IQiYeWeChatApiService
  14. {
  15. private readonly HttpClient _httpClient;
  16. private readonly string CorpId = "wwe978bef5495a0728"; //企业Id
  17. private readonly string PersonnelAssistant_AgentId = "3010011"; //人事助手Id
  18. private readonly string PersonnelAssistant_Corpsecret = "ig--IJd6TxWDMJ1wT4e-RDRcRX12v5GjB359DNATwJ4"; //人事助手凭证密钥
  19. private readonly string PunchCard_AgentId = "3010185"; //打卡Id
  20. private readonly string PunchCard_Corpsecret = "Xhrl37GOqlAjsu0VzUSJECaJdjzkDXQLbvrzRsZQb8M"; //打卡凭证密钥
  21. private readonly string Email_AgentId = "1000004"; //E-Mail Id
  22. private readonly string Email_Corpsecret = "NA1zbJM15GmgjPYwDOqz59dIo1Wnug-MbU107MeUemc"; //E-Mail 凭证密钥
  23. private readonly string AddressBook_Corpsecret = "Y1tnjh7j-BvbqAytAoXZPUbmDR6dqLTL6mXtc6PZ7fo"; //通讯录同步 凭证密钥
  24. private readonly string Approve_AgentId = "3010040"; //审批 Id
  25. private readonly string Approve_Corpsecret = "k_Jo69Jw9Hqg_in-Rypbs30PNbxOYa1t4e-dxYuT-kw"; //审批 凭证密钥
  26. private readonly DateTime _1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  27. private readonly JobPostRepository _jobPostRep;
  28. /// <summary>
  29. /// 初始化
  30. /// </summary>
  31. /// <param name="clientFactory"></param>
  32. /// <param name="jobPostRep"></param>
  33. public QiYeWeChatApiService(IHttpClientFactory clientFactory, JobPostRepository jobPostRep)
  34. {
  35. _httpClient = clientFactory.CreateClient("PublicQiYeWeChatApi"); ;
  36. _jobPostRep = jobPostRep;
  37. }
  38. /// <summary>
  39. /// 获取access_token
  40. /// </summary>
  41. /// <param name="applicationType">
  42. /// 1:人事助手
  43. /// 2:打卡
  44. /// 3:邮件
  45. /// 4:通讯录同步
  46. /// 5:审批
  47. /// </param>
  48. /// <returns></returns>
  49. private async Task<Access_TokenView> GetTokenAsync(int applicationType)
  50. {
  51. Access_TokenView tokenResult = new Access_TokenView();
  52. Access_Token_Request access_Token = new Access_Token_Request();
  53. string cacheName = string.Empty;
  54. if (applicationType == 1)
  55. {
  56. access_Token.corpsecret = PersonnelAssistant_Corpsecret; //人事助手
  57. cacheName = "PersonnelAssistant_Access_Token";
  58. }
  59. else if (applicationType == 2)
  60. {
  61. access_Token.corpsecret = PunchCard_Corpsecret; //打卡
  62. cacheName = "PunchCard_Access_Token";
  63. }
  64. else if (applicationType == 3)
  65. {
  66. access_Token.corpsecret = Email_Corpsecret; //E-Mail
  67. cacheName = "Enail_Access_Token";
  68. }
  69. else if (applicationType == 4) //通讯录同步
  70. {
  71. access_Token.corpsecret = AddressBook_Corpsecret;
  72. cacheName = "AddressBook_Access_Token";
  73. }
  74. else if (applicationType == 5) //审批
  75. {
  76. access_Token.corpsecret = Approve_Corpsecret;
  77. cacheName = "Approve_Access_Token";
  78. }
  79. else
  80. {
  81. tokenResult.errmsg = "未识别应用类型Id!";
  82. return tokenResult;
  83. }
  84. string access_token = await RedisRepository.RedisFactory
  85. .CreateRedisRepository()
  86. .StringGetAsync<string>(cacheName);//string 取
  87. if (string.IsNullOrEmpty(access_token))
  88. {
  89. string access_token_url = string.Format(@"/cgi-bin/gettoken?corpid={0}&corpsecret={1}", access_Token.corpid, access_Token.corpsecret);
  90. var access_tokenReq = await _httpClient.GetAsync(access_token_url);
  91. if (access_tokenReq.IsSuccessStatusCode)
  92. {
  93. var stringResponse = await access_tokenReq.Content.ReadAsStringAsync();
  94. tokenResult = System.Text.Json.JsonSerializer.Deserialize<Access_TokenView>(stringResponse,
  95. new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
  96. if (tokenResult.errcode == 0)
  97. {
  98. TimeSpan ts = DateTime.Now.AddMinutes(118) - DateTime.Now; //设置redis 过期时间 118分钟
  99. await RedisRepository
  100. .RedisFactory
  101. .CreateRedisRepository()
  102. .StringSetAsync<string>(cacheName, tokenResult.access_token, ts);//string 存
  103. }
  104. }
  105. else
  106. {
  107. tokenResult.errmsg = "企业微信Token未获取到!";
  108. }
  109. }
  110. else
  111. {
  112. tokenResult.errcode = 0;
  113. tokenResult.access_token = access_token;
  114. }
  115. return tokenResult;
  116. }
  117. #region 添加员工
  118. /// <summary>
  119. /// 获取成员ID列表
  120. /// </summary>
  121. /// <returns></returns>
  122. private async Task<UserIdListView> GetUserIdListAsync()
  123. {
  124. UserIdListView userIdListView = new UserIdListView();
  125. Access_TokenView access_Token = await GetTokenAsync(4);
  126. if (access_Token.errcode != 0)
  127. {
  128. userIdListView.errcode = access_Token.errcode;
  129. userIdListView.errmsg = access_Token.errmsg;
  130. return userIdListView;
  131. }
  132. string url = string.Format("/cgi-bin/user/list_id?access_token={0}&debug=1", access_Token.access_token);
  133. var jsonData = new
  134. {
  135. access_token = access_Token.access_token, //调用接口凭证
  136. };
  137. var json = System.Text.Json.JsonSerializer.Serialize(jsonData);
  138. var content = new StringContent(json, Encoding.UTF8, "application/json");
  139. var create_Req = await _httpClient.PostAsync(url, content);
  140. var stringResponse = await create_Req.Content.ReadAsStringAsync();
  141. userIdListView = System.Text.Json.JsonSerializer.Deserialize<UserIdListView>(stringResponse,
  142. new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
  143. return userIdListView;
  144. }
  145. /// <summary>
  146. /// 获取部门列表
  147. /// </summary>
  148. /// <param name="access_token"></param>
  149. /// <returns></returns>
  150. private async Task<DepartmentListView> GetDepartmentAsync(string access_token)
  151. {
  152. DepartmentListView result = new DepartmentListView();
  153. string dep_url = string.Format("/cgi-bin/department/list?access_token={0}&debug=1", access_token);
  154. var depReq = await _httpClient.GetAsync(dep_url);
  155. if (depReq.IsSuccessStatusCode)
  156. {
  157. var stringResponse = await depReq.Content.ReadAsStringAsync();
  158. result = System.Text.Json.JsonSerializer.Deserialize<DepartmentListView>(stringResponse,
  159. new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
  160. }
  161. else
  162. {
  163. result.errcode = -1;
  164. result.errmsg = "企业微信部门列表未获取到!";
  165. }
  166. return result;
  167. }
  168. /// <summary>
  169. /// 创建员工
  170. /// </summary>
  171. /// <param name="create_Request"></param>
  172. /// <returns></returns>
  173. public async Task<ResponseBase> CreateAsync(Create_Request create_Request)
  174. {
  175. ResponseBase responseBase = new ResponseBase();
  176. #region 职位
  177. string depName = string.Empty,
  178. jobName = string.Empty;
  179. List<Sys_JobPostI> jobs = await _jobPostRep.QueryJobPost(string.Empty);
  180. Sys_JobPostI jobPost = jobs.Where(it => it.IsDel == 0 && it.Id == Convert.ToInt32(create_Request.position)).FirstOrDefault();
  181. if (jobPost != null)
  182. {
  183. depName = jobPost.DepName;
  184. jobName = jobPost.JobName;
  185. }
  186. create_Request.position = jobName;
  187. if (string.IsNullOrEmpty(create_Request.biz_mail))
  188. {
  189. create_Request.biz_mail = string.Format("{0}@pan-american-intl.com", create_Request.userid);
  190. }
  191. #endregion
  192. Access_TokenView access_Token = new Access_TokenView();
  193. access_Token = await GetTokenAsync(4);
  194. if (access_Token.errcode == 0)
  195. {
  196. create_Request.access_token = access_Token.access_token;
  197. #region 处理部门
  198. Access_TokenView dep_Access_Token = await GetTokenAsync(1);
  199. if (dep_Access_Token.errcode != 0)
  200. {
  201. responseBase.errcode = dep_Access_Token.errcode;
  202. responseBase.errmsg = dep_Access_Token.errmsg;
  203. }
  204. DepartmentListView depData = await GetDepartmentAsync(dep_Access_Token.access_token);
  205. if (depData.errcode == 0)
  206. {
  207. var depData1 = depData.department.Where(x => x.name == depName).FirstOrDefault();
  208. if (depData1 != null)
  209. {
  210. create_Request.department = new List<long> { depData1.id };
  211. }
  212. else
  213. {
  214. responseBase.errcode = -1;
  215. responseBase.errmsg = "未在企业微信上找到OA内设置的部门";
  216. return responseBase;
  217. }
  218. }
  219. else
  220. {
  221. responseBase.errcode = depData.errcode;
  222. responseBase.errmsg = depData.errmsg;
  223. return responseBase;
  224. }
  225. #endregion
  226. create_Request.access_token = access_Token.access_token;
  227. string create_url = string.Format("/cgi-bin/user/create?access_token={0}", create_Request.access_token);
  228. var json = System.Text.Json.JsonSerializer.Serialize(create_Request);
  229. var content = new StringContent(json, Encoding.UTF8, "application/json");
  230. var create_Req = await _httpClient.PostAsync(create_url, content);
  231. var stringResponse = await create_Req.Content.ReadAsStringAsync();
  232. responseBase = System.Text.Json.JsonSerializer.Deserialize<ResponseBase>(stringResponse,
  233. new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
  234. }
  235. else
  236. {
  237. responseBase.errcode = access_Token.errcode;
  238. responseBase.errmsg = access_Token.errmsg;
  239. }
  240. return responseBase;
  241. }
  242. #endregion
  243. #region 打卡
  244. /// <summary>
  245. /// 获取月打卡数据(redis缓存)
  246. /// </summary>
  247. /// <param name="startDt"></param>
  248. /// <param name="endDt"></param>
  249. /// <returns></returns>
  250. public async Task<CheckInView> GetCheckin_MonthDataAsync(DateTime startDt,DateTime endDt)
  251. {
  252. CheckInView checkInView = new CheckInView();
  253. //获取员工Id
  254. UserIdListView userIdListView = await GetUserIdListAsync();
  255. if (userIdListView.errcode != 0)
  256. {
  257. checkInView.errcode = userIdListView.errcode;
  258. checkInView.errmsg = string.Format("【企业微信】【获取员工IdList】【Msg】{0}",userIdListView.errmsg);
  259. return checkInView;
  260. }
  261. if (userIdListView.dept_user == null || userIdListView.dept_user.Count <= 0)
  262. {
  263. checkInView.errmsg = string.Format("【企业微信】【获取员工IdList】【Msg】未查出员工Id");
  264. return checkInView;
  265. }
  266. //获取月打卡数据 token
  267. Access_TokenView access_Token = await GetTokenAsync(2);
  268. if (access_Token.errcode != 0)
  269. {
  270. checkInView.errcode = access_Token.errcode;
  271. checkInView.errmsg = string.Format("【企业微信】【获取月打卡数据】【Token】【Msg】{0}", access_Token.errmsg);
  272. return checkInView;
  273. }
  274. string url = string.Format("/cgi-bin/checkin/getcheckin_monthdata?access_token={0}", access_Token.access_token);
  275. Checkin_MonthData_Request checkInReq = new Checkin_MonthData_Request();
  276. checkInReq.access_token = access_Token.access_token;
  277. checkInReq.starttime = (uint)(startDt - _1970).TotalSeconds;
  278. checkInReq.endtime = (uint)(endDt - _1970).TotalSeconds;
  279. checkInReq.useridlist = userIdListView.dept_user.Select(it => it.userid).ToList();
  280. var json = System.Text.Json.JsonSerializer.Serialize(checkInReq);
  281. var content = new StringContent(json, Encoding.UTF8, "application/json");
  282. var create_Req = await _httpClient.PostAsync(url, content);
  283. var stringResponse = await create_Req.Content.ReadAsStringAsync();
  284. checkInView = System.Text.Json.JsonSerializer.Deserialize<CheckInView>(stringResponse,
  285. new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
  286. return checkInView;
  287. }
  288. /// <summary>
  289. /// 获取月打卡数据(redis缓存)
  290. /// </summary>
  291. /// <param name="startDt"></param>
  292. /// <param name="endDt"></param>
  293. /// <returns></returns>
  294. public async Task<CheckInView> GetCheckin_MonthDataRedisAsync(DateTime startDt, DateTime endDt)
  295. {
  296. CheckInView checkInView = new CheckInView();
  297. string checkInDatastring = await RedisRepository.RedisFactory
  298. .CreateRedisRepository()
  299. .StringGetAsync<string>("Checkin_MonthData");//List<T> 取
  300. if (!string.IsNullOrEmpty(checkInDatastring))
  301. {
  302. checkInView = JsonConvert.DeserializeObject<CheckInView>(checkInDatastring);
  303. return checkInView;
  304. }
  305. //获取员工Id
  306. UserIdListView userIdListView = await GetUserIdListAsync();
  307. if (userIdListView.errcode != 0)
  308. {
  309. checkInView.errcode = userIdListView.errcode;
  310. checkInView.errmsg = string.Format("【企业微信】【获取员工IdList】【Msg】{0}", userIdListView.errmsg);
  311. return checkInView;
  312. }
  313. if (userIdListView.dept_user == null || userIdListView.dept_user.Count <= 0)
  314. {
  315. checkInView.errmsg = string.Format("【企业微信】【获取员工IdList】【Msg】未查出员工Id");
  316. return checkInView;
  317. }
  318. //获取月打卡数据 token
  319. Access_TokenView access_Token = await GetTokenAsync(2);
  320. if (access_Token.errcode != 0)
  321. {
  322. checkInView.errcode = access_Token.errcode;
  323. checkInView.errmsg = string.Format("【企业微信】【获取月打卡数据】【Token】【Msg】{0}", access_Token.errmsg);
  324. return checkInView;
  325. }
  326. string url = string.Format("/cgi-bin/checkin/getcheckin_monthdata?access_token={0}", access_Token.access_token);
  327. Checkin_MonthData_Request checkInReq = new Checkin_MonthData_Request();
  328. checkInReq.access_token = access_Token.access_token;
  329. checkInReq.starttime = (uint)(startDt - _1970).TotalSeconds;
  330. checkInReq.endtime = (uint)(endDt - _1970).TotalSeconds;
  331. checkInReq.useridlist = userIdListView.dept_user.Select(it => it.userid).ToList();
  332. var json = System.Text.Json.JsonSerializer.Serialize(checkInReq);
  333. var content = new StringContent(json, Encoding.UTF8, "application/json");
  334. var create_Req = await _httpClient.PostAsync(url, content);
  335. var stringResponse = await create_Req.Content.ReadAsStringAsync();
  336. checkInView = System.Text.Json.JsonSerializer.Deserialize<CheckInView>(stringResponse,
  337. new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
  338. if (checkInView.errcode == 0)
  339. {
  340. TimeSpan ts = DateTime.Now.AddMinutes(60) - DateTime.Now; //设置redis 过期时间 60分钟
  341. await RedisRepository
  342. .RedisFactory
  343. .CreateRedisRepository()
  344. .StringSetAsync<string>("Checkin_MonthData", JsonConvert.SerializeObject(checkInView), ts);//List<T> 存
  345. }
  346. return checkInView;
  347. }
  348. #endregion
  349. #region 审批
  350. /// <summary>
  351. /// 获取审批数据(旧)
  352. /// </summary>
  353. /// <param name="startDt"></param>
  354. /// <param name="endDt"></param>
  355. /// <returns></returns>
  356. public async Task<ApprovalDataView> GetApprovalDataAsync(DateTime startDt, DateTime endDt)
  357. {
  358. ApprovalDataView approvalDataView = new ApprovalDataView();
  359. //获取审批数据 token
  360. Access_TokenView access_Token = await GetTokenAsync(5);
  361. if (access_Token.errcode != 0)
  362. {
  363. approvalDataView.errcode = access_Token.errcode;
  364. approvalDataView.errmsg = string.Format("【企业微信】【获取审批数据】【Token】【Msg】{0}", access_Token.errmsg);
  365. return approvalDataView;
  366. }
  367. string url = string.Format("/cgi-bin/corp/getapprovaldata?access_token={0}", access_Token.access_token);
  368. ApprovalData_Request approvalDataReq = new ApprovalData_Request();
  369. approvalDataReq.access_token = access_Token.access_token;
  370. approvalDataReq.starttime = (uint)(startDt - _1970).TotalSeconds;
  371. approvalDataReq.endtime = (uint)(endDt - _1970).TotalSeconds;
  372. var json = System.Text.Json.JsonSerializer.Serialize(approvalDataReq);
  373. var content = new StringContent(json, Encoding.UTF8, "application/json");
  374. var create_Req = await _httpClient.PostAsync(url, content);
  375. var stringResponse = await create_Req.Content.ReadAsStringAsync();
  376. approvalDataView = System.Text.Json.JsonSerializer.Deserialize<ApprovalDataView>(stringResponse,
  377. new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
  378. List<Sp_Info> sp_datas = new List<Sp_Info>();
  379. sp_datas.AddRange(approvalDataView.data);
  380. int index = 0;
  381. //多次访问审批接口
  382. if (approvalDataView.total>=100)
  383. {
  384. approvalDataView.total -= 100;
  385. int forTotal = approvalDataView.total % 100 == 0 ? approvalDataView.total / 100 : approvalDataView.total / 100 + 1;
  386. long? next_spnum = approvalDataView.next_spnum;
  387. approvalDataReq.next_spnum = next_spnum;
  388. for (int i = 0; i < forTotal; i++)
  389. {
  390. index++;
  391. var for_json = System.Text.Json.JsonSerializer.Serialize(approvalDataReq);
  392. var for_content = new StringContent(for_json, Encoding.UTF8, "application/json");
  393. var for_create_Req = await _httpClient.PostAsync(url, for_content);
  394. var for_stringResponse = await for_create_Req.Content.ReadAsStringAsync();
  395. ApprovalDataView for_approvalDataView = System.Text.Json.JsonSerializer.Deserialize<ApprovalDataView>(for_stringResponse,
  396. new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
  397. approvalDataReq.next_spnum = for_approvalDataView.next_spnum; //重新定义游标
  398. sp_datas.AddRange(for_approvalDataView.data); //追加数据
  399. }
  400. approvalDataView.total += 100;
  401. }
  402. approvalDataView.data = sp_datas;
  403. return approvalDataView;
  404. }
  405. /// <summary>
  406. /// 获取审批数据(旧)(redis缓存)
  407. /// </summary>
  408. /// <param name="startDt"></param>
  409. /// <param name="endDt"></param>
  410. /// <returns></returns>
  411. public async Task<List<Sp_Info>> GetApprovalDatasAsync(DateTime startDt, DateTime endDt)
  412. {
  413. List<Sp_Info> sp_Infos = new List<Sp_Info>();
  414. //获取所有打卡补卡,审批 数据 前后范围增加10天
  415. DateTime sp_startDt = startDt.AddDays(-10);
  416. DateTime sp_centerDt = sp_startDt.AddDays(30);
  417. DateTime sp_endDt = endDt.AddDays(10);
  418. ApprovalDataView approvalData_1 = await GetApprovalDataAsync(sp_startDt, sp_centerDt); //时间段内所有 审批数据
  419. ApprovalDataView approvalData_2 = await GetApprovalDataAsync(sp_centerDt, sp_endDt); //时间段内所有 审批数据
  420. if (approvalData_1.errcode != 0)
  421. {
  422. Log.Error("企业微信 获取 " + sp_startDt + " - " + sp_centerDt + " 内审批 Msg:" + approvalData_1.errmsg);
  423. return sp_Infos;
  424. }
  425. sp_Infos.AddRange(approvalData_1.data);
  426. if (approvalData_2.errcode != 0)
  427. {
  428. Log.Error("企业微信 获取 " + sp_centerDt + " - " + sp_endDt + " 内审批 Msg:" + approvalData_2.errmsg);
  429. return sp_Infos;
  430. }
  431. sp_Infos.AddRange(approvalData_2.data);
  432. sp_Infos = sp_Infos.Where(it => it.sp_status == 2).ToList(); //存储已审核的数据
  433. return sp_Infos;
  434. }
  435. /// <summary>
  436. /// 获取审批数据(旧)(redis缓存)
  437. /// </summary>
  438. /// <param name="startDt"></param>
  439. /// <param name="endDt"></param>
  440. /// <returns></returns>
  441. public async Task<List<Sp_Info>> GetApprovalDatasRedisAsync(DateTime startDt, DateTime endDt)
  442. {
  443. List<Sp_Info> sp_Infos = new List<Sp_Info>();
  444. //获取所有打卡补卡,审批 数据 前后范围增加10天
  445. DateTime sp_startDt = startDt.AddDays(-10);
  446. DateTime sp_centerDt = sp_startDt.AddDays(30);
  447. DateTime sp_endDt = endDt.AddDays(10);
  448. string redisName = "ApprovalData" + sp_startDt.ToString("yyyyMMdd") + "-" + sp_endDt.ToString("yyyyMMdd");
  449. string sp_InfosString = string.Empty;
  450. //sp_InfosString = await RedisRepository.RedisFactory
  451. // .CreateRedisRepository()
  452. // .StringGetAsync<string>(redisName);//string 取
  453. if (string.IsNullOrEmpty(sp_InfosString))
  454. {
  455. ApprovalDataView approvalData_1 = await GetApprovalDataAsync(sp_startDt, sp_centerDt); //时间段内所有 审批数据
  456. ApprovalDataView approvalData_2 = await GetApprovalDataAsync(sp_centerDt, sp_endDt); //时间段内所有 审批数据
  457. if (approvalData_1.errcode != 0)
  458. {
  459. Log.Error("企业微信 获取 "+ sp_startDt + " - "+ sp_centerDt + " 内审批 Msg:" + approvalData_1.errmsg);
  460. return sp_Infos;
  461. }
  462. sp_Infos.AddRange(approvalData_1.data);
  463. if (approvalData_2.errcode != 0)
  464. {
  465. Log.Error("企业微信 获取 "+ sp_centerDt + " - "+ sp_endDt + " 内审批 Msg:" + approvalData_2.errmsg);
  466. return sp_Infos;
  467. }
  468. sp_Infos.AddRange(approvalData_2.data);
  469. sp_Infos = sp_Infos.Where(it => it.sp_status == 2).ToList(); //存储已审核的数据
  470. TimeSpan ts = DateTime.Now.AddMinutes(60) - DateTime.Now; //设置redis 过期时间 60分钟
  471. await RedisRepository
  472. .RedisFactory
  473. .CreateRedisRepository()
  474. .StringSetAsync<string>(redisName, JsonConvert.SerializeObject(sp_Infos), ts);//string 存
  475. }
  476. else
  477. {
  478. sp_Infos = JsonConvert.DeserializeObject<List<Sp_Info>>(sp_InfosString);
  479. }
  480. return sp_Infos;
  481. }
  482. #endregion
  483. }
  484. }