Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

199 Zeilen
8.5 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. private Sys_InformationPushIBLL sys_InformationPushIBLL = new Sys_InformationPushBLL();
  35. /// <summary>
  36. /// 注册接口
  37. /// <summary>
  38. public MpManagementApi()
  39. : base("/mpManagement")
  40. {
  41. Get["/pushWeixin"] = PushWeixin;
  42. }
  43. public Response PushWeixin(dynamic _)
  44. {
  45. //获取所有到期的内控计划
  46. var mpList = mP_ManagementPlanIBLL.GetMP_ManageMentPlanExpire();
  47. var RoleName = Config.GetValue("MPRoleName");
  48. var roleId = roleIBLL.GetIdByRoleName(RoleName);
  49. var roleUserList = userRelationIBLL.GetUserIdList(roleId).Select(a => a.F_UserId).ToList();
  50. foreach (var mpEntity in mpList)
  51. {
  52. //已经上传了的人员
  53. var hasUploadUsers = mP_ManagementPlanIBLL.GetListByParentId(mpEntity.MPId).Select(a => a.MPUploader).ToList();
  54. var departmentList = mpEntity.MPDepartment.Split(',').ToList();
  55. var UserList = new List<UserEntity>();
  56. var title = "";
  57. foreach (var departmentId in departmentList)
  58. {
  59. var entityList = userIBLL.GetUserByDepartmentId(departmentId).Where(a => roleUserList.Contains(a.F_UserId) && !hasUploadUsers.Contains(a.F_UserId)).ToList();
  60. if (entityList.Count() > 0)
  61. {
  62. foreach (var item in entityList)
  63. {
  64. UserList.Add(item);
  65. }
  66. }
  67. }
  68. if (mpEntity.MPType == 0)
  69. {
  70. title = "内控检查";
  71. //读取信息推送管理-内控管理推送(06)的配置
  72. var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("06");
  73. if (informationPushEntity != null && informationPushEntity.Status == true)
  74. {
  75. //飞星推送
  76. FeiXinPush(title, "nk", UserList);
  77. }
  78. }
  79. else if (mpEntity.MPType == 1)
  80. {
  81. title = "绩效跟踪";
  82. //读取信息推送管理-内控管理推送(06)的配置
  83. var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("06");
  84. if (informationPushEntity != null && informationPushEntity.Status == true)
  85. {
  86. //飞星推送
  87. FeiXinPush(title, "jx", UserList);
  88. }
  89. }
  90. else
  91. {
  92. title = "质量目标";
  93. //读取信息推送管理-内控管理推送(06)的配置
  94. var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("06");
  95. if (informationPushEntity != null && informationPushEntity.Status == true)
  96. {
  97. //飞星推送
  98. FeiXinPush(title, "zl", UserList);
  99. }
  100. }
  101. }
  102. return Success("推送成功");
  103. }
  104. public void FeiXinPush(string title, string code, List<UserEntity> UserList)
  105. {
  106. //飞星推送
  107. Task.Run(async () =>
  108. {
  109. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  110. {
  111. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  112. await hubConnection.Start();
  113. await hubProxy.Invoke("PushAnnouncement", "", title + "材料上传", title, code, string.Join(",", UserList.Select(m => m.F_UserId)), "");
  114. }
  115. });
  116. OperateLogModel operateLogModel = new OperateLogModel();
  117. operateLogModel.title = title;
  118. operateLogModel.type = OperationType.Other;
  119. operateLogModel.url = "NoticeController";
  120. operateLogModel.sourceObjectId = "002";
  121. operateLogModel.sourceContentJson = title;
  122. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  123. }
  124. public void WeiXinPush(List<UserEntity> userList, string title)
  125. {
  126. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  127. string appid = WeChatConfigentity.APPId;
  128. string secret = WeChatConfigentity.secret;
  129. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  130. string weixintaskurl = wechatemplete.TUrl;
  131. string weixintasktempid = wechatemplete.TempId;
  132. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  133. foreach (UserEntity userinfo in userList)
  134. {
  135. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  136. {
  137. //执行推送任务
  138. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  139. {
  140. if (!string.IsNullOrEmpty(responsejson))
  141. {
  142. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  143. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  144. {
  145. string access_token = weixintokenobj.access_token;
  146. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  147. "\"template_id\":\"" + weixintasktempid + "\"," +
  148. "\"url\":\"" + weixintaskurl + "\"," +
  149. "\"data\":{" +
  150. "\"first\": {\"value\":\"您有" + title + "需要上传\",\"color\":\"#173177\"}," +
  151. "\"keyword1\":{\"value\":\"内控管理\",\"color\":\"#173177\"}," +
  152. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  153. "\"keyword3\": {\"value\":\"待上传\",\"color\":\"#173177\"}," +
  154. "\"keyword4\": {\"value\":\"您有【" + title + "】需要上传\",\"color\":\"#173177\"}" +
  155. "}" +
  156. "}";
  157. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. #region 私有类
  165. /// <summary>
  166. /// 表单实体类
  167. /// <summary>
  168. private class ReqFormEntity
  169. {
  170. public string keyValue { get; set; }
  171. public string strEntity { get; set; }
  172. }
  173. #endregion
  174. }
  175. }