|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- using Nancy;
- using Learun.Util;
- using System.Collections.Generic;
- using Learun.Application.TwoDevelopment.EducationalAdministration;
- using System.Linq;
- using Learun.Application.Organization;
- using System;
- using System.Configuration;
- using System.Threading.Tasks;
- using System.Web;
- using Learun.Application.Base.AuthorizeModule;
- using Learun.Application.TwoDevelopment.LR_Desktop;
- using Learun.Application.TwoDevelopment.PersonnelManagement;
- using Learun.Util.Operat;
- using Microsoft.AspNet.SignalR.Client;
- using Newtonsoft.Json;
-
- namespace Learun.Application.WebApi
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创 建:超级管理员
- /// 日 期:2019-06-17 16:28
- /// 描 述:日志发送
- /// </summary>
- public class MpManagementApi : BaseNoLoginApi
- {
- private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL();
- private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL();
- private MP_ManagementPlanIBLL mP_ManagementPlanIBLL = new MP_ManagementPlanBLL();
- private RoleIBLL roleIBLL = new RoleBLL();
- private UserRelationIBLL userRelationIBLL = new UserRelationBLL();
- private UserIBLL userIBLL = new UserBLL();
- private Sys_InformationPushIBLL sys_InformationPushIBLL = new Sys_InformationPushBLL();
-
-
- /// <summary>
- /// 注册接口
- /// <summary>
- public MpManagementApi()
- : base("/mpManagement")
- {
- Get["/pushWeixin"] = PushWeixin;
- }
-
-
-
- public Response PushWeixin(dynamic _)
- {
- //获取所有到期的内控计划
- var mpList = mP_ManagementPlanIBLL.GetMP_ManageMentPlanExpire();
- var RoleName = Config.GetValue("MPRoleName");
- var roleId = roleIBLL.GetIdByRoleName(RoleName);
- var roleUserList = userRelationIBLL.GetUserIdList(roleId).Select(a => a.F_UserId).ToList();
- foreach (var mpEntity in mpList)
- {
- //已经上传了的人员
- var hasUploadUsers = mP_ManagementPlanIBLL.GetListByParentId(mpEntity.MPId).Select(a => a.MPUploader).ToList();
- var departmentList = mpEntity.MPDepartment.Split(',').ToList();
- var UserList = new List<UserEntity>();
- var title = "";
-
- foreach (var departmentId in departmentList)
- {
- var entityList = userIBLL.GetUserByDepartmentId(departmentId).Where(a => roleUserList.Contains(a.F_UserId) && !hasUploadUsers.Contains(a.F_UserId)).ToList();
- if (entityList.Count() > 0)
- {
- foreach (var item in entityList)
- {
- UserList.Add(item);
- }
- }
- }
-
- if (mpEntity.MPType == 0)
- {
- title = "内控检查";
- //读取信息推送管理-内控管理推送(06)的配置
- var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("06");
- if (informationPushEntity != null && informationPushEntity.Status == true)
- {
- //飞星推送
- FeiXinPush(title, "nk", UserList);
- }
-
- }
- else if (mpEntity.MPType == 1)
- {
- title = "绩效跟踪";
- //读取信息推送管理-内控管理推送(06)的配置
- var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("06");
- if (informationPushEntity != null && informationPushEntity.Status == true)
- {
- //飞星推送
- FeiXinPush(title, "jx", UserList);
- }
-
- }
- else
- {
- title = "质量目标";
- //读取信息推送管理-内控管理推送(06)的配置
- var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("06");
- if (informationPushEntity != null && informationPushEntity.Status == true)
- {
- //飞星推送
- FeiXinPush(title, "zl", UserList);
- }
-
- }
-
-
-
- }
-
- return Success("推送成功");
- }
-
- public void FeiXinPush(string title, string code, List<UserEntity> UserList)
- {
- //飞星推送
- Task.Run(async () =>
- {
- using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
- {
- var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
- await hubConnection.Start();
- await hubProxy.Invoke("PushAnnouncement", "", title + "材料上传", title, code, string.Join(",", UserList.Select(m => m.F_UserId)), "");
- }
- });
- OperateLogModel operateLogModel = new OperateLogModel();
- operateLogModel.title = title;
- operateLogModel.type = OperationType.Other;
- operateLogModel.url = "NoticeController";
- operateLogModel.sourceObjectId = "002";
- operateLogModel.sourceContentJson = title;
- OperatorHelper.Instance.WriteOperateLog(operateLogModel);
- }
-
- public void WeiXinPush(List<UserEntity> userList, string title)
- {
- var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
- string appid = WeChatConfigentity.APPId;
- string secret = WeChatConfigentity.secret;
- var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
- string weixintaskurl = wechatemplete.TUrl;
- string weixintasktempid = wechatemplete.TempId;
- var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
-
-
- foreach (UserEntity userinfo in userList)
- {
- if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
- {
- //执行推送任务
- if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
- {
- if (!string.IsNullOrEmpty(responsejson))
- {
- var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
- if (string.IsNullOrEmpty(weixintokenobj.errcode))
- {
- string access_token = weixintokenobj.access_token;
- string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
- "\"template_id\":\"" + weixintasktempid + "\"," +
- "\"url\":\"" + weixintaskurl + "\"," +
- "\"data\":{" +
- "\"first\": {\"value\":\"您有" + title + "需要上传\",\"color\":\"#173177\"}," +
- "\"keyword1\":{\"value\":\"内控管理\",\"color\":\"#173177\"}," +
- "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
- "\"keyword3\": {\"value\":\"待上传\",\"color\":\"#173177\"}," +
- "\"keyword4\": {\"value\":\"您有【" + title + "】需要上传\",\"color\":\"#173177\"}" +
- "}" +
- "}";
- string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
-
- }
- }
- }
- }
- }
- }
-
-
- #region 私有类
-
- /// <summary>
- /// 表单实体类
- /// <summary>
- private class ReqFormEntity
- {
- public string keyValue { get; set; }
- public string strEntity { get; set; }
- }
- #endregion
-
- }
- }
|