Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

177 linhas
7.3 KiB

  1. using Nancy;
  2. using Learun.Util;
  3. using System.Collections.Generic;
  4. using Learun.Application.TwoDevelopment.EducationalAdministration;
  5. using System.Linq;
  6. using Learun.Application.Organization;
  7. using System;
  8. using System.Configuration;
  9. using System.Threading.Tasks;
  10. using System.Web;
  11. using Learun.Application.Base.AuthorizeModule;
  12. using Learun.Application.TwoDevelopment.LR_Desktop;
  13. using Learun.Application.TwoDevelopment.PersonnelManagement;
  14. using Learun.Util.Operat;
  15. using Microsoft.AspNet.SignalR.Client;
  16. using Newtonsoft.Json;
  17. namespace Learun.Application.WebApi
  18. {
  19. /// <summary>
  20. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  21. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  22. /// 创 建:超级管理员
  23. /// 日 期:2019-06-17 16:28
  24. /// 描 述:日志发送
  25. /// </summary>
  26. public class MpManagementApi : BaseNoLoginApi
  27. {
  28. private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL();
  29. private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL();
  30. private MP_ManagementPlanIBLL mP_ManagementPlanIBLL = new MP_ManagementPlanBLL();
  31. private RoleIBLL roleIBLL = new RoleBLL();
  32. private UserRelationIBLL userRelationIBLL = new UserRelationBLL();
  33. private UserIBLL userIBLL = new UserBLL();
  34. /// <summary>
  35. /// 注册接口
  36. /// <summary>
  37. public MpManagementApi()
  38. : base("/mpManagement")
  39. {
  40. Get["/pushWeixin"] = PushWeixin;
  41. }
  42. public Response PushWeixin(dynamic _)
  43. {
  44. //获取所有到期的内控计划
  45. var mpList = mP_ManagementPlanIBLL.GetMP_ManageMentPlanExpire();
  46. var RoleName = Config.GetValue("MPRoleName");
  47. var roleId = roleIBLL.GetIdByRoleName(RoleName);
  48. var roleUserList = userRelationIBLL.GetUserIdList(roleId).Select(a => a.F_UserId).ToList();
  49. foreach (var mpEntity in mpList)
  50. {
  51. //已经上传了的人员
  52. var hasUploadUsers = mP_ManagementPlanIBLL.GetListByParentId(mpEntity.MPId).Select(a => a.MPUploader).ToList();
  53. var departmentList = mpEntity.MPDepartment.Split(',').ToList();
  54. var UserList = new List<UserEntity>();
  55. var title = "";
  56. foreach (var departmentId in departmentList)
  57. {
  58. var entityList = userIBLL.GetUserByDepartmentId(departmentId).Where(a => roleUserList.Contains(a.F_UserId) && !hasUploadUsers.Contains(a.F_UserId)).ToList();
  59. if (entityList.Count() > 0)
  60. {
  61. foreach (var item in entityList)
  62. {
  63. UserList.Add(item);
  64. }
  65. }
  66. }
  67. if (mpEntity.MPType == 0)
  68. {
  69. title = "内控检查";
  70. FeiXinPush(title, "nk", UserList);
  71. }
  72. else if (mpEntity.MPType == 1)
  73. {
  74. title = "绩效跟踪";
  75. FeiXinPush(title, "jx", UserList);
  76. }
  77. else
  78. {
  79. title = "质量目标";
  80. FeiXinPush(title, "zl", UserList);
  81. }
  82. }
  83. return Success("推送成功");
  84. }
  85. public void FeiXinPush(string title,string code,List<UserEntity> UserList)
  86. {
  87. //飞星推送
  88. Task.Run(async () =>
  89. {
  90. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  91. {
  92. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  93. await hubConnection.Start();
  94. await hubProxy.Invoke("PushAnnouncement", "", title+"材料上传", title, code, string.Join(",", UserList.Select(m => m.F_UserId)), "");
  95. }
  96. });
  97. OperateLogModel operateLogModel = new OperateLogModel();
  98. operateLogModel.title = title;
  99. operateLogModel.type = OperationType.Other;
  100. operateLogModel.url = "NoticeController";
  101. operateLogModel.sourceObjectId = "002";
  102. operateLogModel.sourceContentJson = title;
  103. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  104. }
  105. public void WeiXinPush(List<UserEntity> userList, string title)
  106. {
  107. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  108. string appid = WeChatConfigentity.APPId;
  109. string secret = WeChatConfigentity.secret;
  110. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  111. string weixintaskurl = wechatemplete.TUrl;
  112. string weixintasktempid = wechatemplete.TempId;
  113. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  114. foreach (UserEntity userinfo in userList)
  115. {
  116. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  117. {
  118. //执行推送任务
  119. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  120. {
  121. if (!string.IsNullOrEmpty(responsejson))
  122. {
  123. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  124. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  125. {
  126. string access_token = weixintokenobj.access_token;
  127. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  128. "\"template_id\":\"" + weixintasktempid + "\"," +
  129. "\"url\":\"" + weixintaskurl + "\"," +
  130. "\"data\":{" +
  131. "\"first\": {\"value\":\"您有" + title + "需要上传\",\"color\":\"#173177\"}," +
  132. "\"keyword1\":{\"value\":\"内控管理\",\"color\":\"#173177\"}," +
  133. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  134. "\"keyword3\": {\"value\":\"待上传\",\"color\":\"#173177\"}," +
  135. "\"keyword4\": {\"value\":\"您有【" + title + "】需要上传\",\"color\":\"#173177\"}" +
  136. "}" +
  137. "}";
  138. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. #region 私有类
  146. /// <summary>
  147. /// 表单实体类
  148. /// <summary>
  149. private class ReqFormEntity
  150. {
  151. public string keyValue { get; set; }
  152. public string strEntity { get; set; }
  153. }
  154. #endregion
  155. }
  156. }