@@ -30,14 +30,7 @@ namespace Learun.Application.Web.Areas.LR_OAModule.Controllers | |||||
public class NoticeController : MvcControllerBase | public class NoticeController : MvcControllerBase | ||||
{ | { | ||||
private NoticeIBLL noticeIBLL = new NoticeBLL(); | private NoticeIBLL noticeIBLL = new NoticeBLL(); | ||||
private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL(); | |||||
private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL(); | |||||
private UserIBLL userIbll = new UserBLL(); | |||||
private UserRelationIBLL userRelationIBLL = new UserRelationBLL(); | |||||
private DataItemIBLL dataItemIbll = new DataItemBLL(); | private DataItemIBLL dataItemIbll = new DataItemBLL(); | ||||
private DepartmentIBLL departmentIbll = new DepartmentBLL(); | |||||
private Sys_InformationPushIBLL sys_InformationPushIBLL = new Sys_InformationPushBLL(); | |||||
private MessageRindIBLL messageRindIBLL = new MessageRindBLL(); | |||||
private DepartmentReleasePermissionsIBLL departmentReleasePermissionsIbll = | private DepartmentReleasePermissionsIBLL departmentReleasePermissionsIbll = | ||||
new DepartmentReleasePermissionsBLL(); | new DepartmentReleasePermissionsBLL(); | ||||
@@ -318,113 +311,12 @@ namespace Learun.Application.Web.Areas.LR_OAModule.Controllers | |||||
{ | { | ||||
entity.F_NewsContent = WebHelper.HtmlEncode(entity.F_NewsContent); | entity.F_NewsContent = WebHelper.HtmlEncode(entity.F_NewsContent); | ||||
noticeIBLL.SaveEntity(keyValue, entity); | noticeIBLL.SaveEntity(keyValue, entity); | ||||
//读取信息推送管理-通知公告推送(01)的配置 | |||||
var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("01"); | |||||
if (informationPushEntity != null && informationPushEntity.Status == true) | |||||
{ | |||||
//推送微信 | |||||
Task.Run(async () => { await DoWeixinPush(entity); }); | |||||
} | |||||
if (entity.F_IsSendFX.HasValue && entity.F_IsSendFX == true) | |||||
{ | |||||
Task.Run(async () => | |||||
{ | |||||
using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"])) | |||||
{ | |||||
var hubProxy = hubConnection.CreateHubProxy("SignalRHub"); | |||||
await hubConnection.Start(); | |||||
await hubProxy.Invoke("PushAnnouncement", entity.F_NewsId, entity.F_FullHead, Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(entity.F_NewsContent)).Length < 20 ? Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(entity.F_NewsContent)) : Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(entity.F_NewsContent)).Substring(0, 20), "news", entity.F_SendPostId, entity.F_SendDeptId); | |||||
} | |||||
}); | |||||
} | |||||
return Success("保存成功!"); | return Success("保存成功!"); | ||||
} | } | ||||
Task DoWeixinPush(NewsEntity entity) | |||||
{ | |||||
//微信推送 | |||||
try | |||||
{ | |||||
var allteacherlist = userIbll.GetAllList().Where(m => | |||||
m.F_DeleteMark != 1 && m.F_EnabledMark == 1 && m.F_Description == "教师"); | |||||
var userralationlist = userRelationIBLL.GetUserIdList("2"); | |||||
var needpostuserlist = new List<UserEntity>(); | |||||
if (!string.IsNullOrEmpty(entity.F_SendDeptId)) | |||||
{ | |||||
if (!entity.F_SendDeptId.Contains(",")) | |||||
{ | |||||
var departteacherlist = allteacherlist.Where(m => entity.F_SendDeptId == m.F_DepartmentId); | |||||
needpostuserlist.AddRange(departteacherlist.ToList()); | |||||
if (!string.IsNullOrEmpty(entity.F_SendPostId)) | |||||
{ | |||||
var newpostuserlist = new List<UserEntity>(); | |||||
foreach (var uuitem in needpostuserlist) | |||||
{ | |||||
var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId)); | |||||
if (postids > 0) | |||||
{ | |||||
newpostuserlist.Add(uuitem); | |||||
} | |||||
} | |||||
needpostuserlist = newpostuserlist; | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
foreach (var senddeptid in entity.F_SendDeptId.Split(',')) | |||||
{ | |||||
var departteacherlist = allteacherlist.Where(m => senddeptid == m.F_DepartmentId); | |||||
needpostuserlist.AddRange(departteacherlist.ToList()); | |||||
if (!string.IsNullOrEmpty(entity.F_SendPostId)) | |||||
{ | |||||
var newpostuserlist = new List<UserEntity>(); | |||||
foreach (var uuitem in needpostuserlist) | |||||
{ | |||||
var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId)); | |||||
if (postids > 0) | |||||
{ | |||||
newpostuserlist.Add(uuitem); | |||||
} | |||||
} | |||||
needpostuserlist = newpostuserlist; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
if (!string.IsNullOrEmpty(entity.F_SendPostId)) | |||||
{ | |||||
//岗位下发 | |||||
var newpostuserlist = new List<UserEntity>(); | |||||
foreach (var uuitem in allteacherlist) | |||||
{ | |||||
var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId)); | |||||
if (postids > 0) | |||||
{ | |||||
newpostuserlist.Add(uuitem); | |||||
} | |||||
} | |||||
needpostuserlist = newpostuserlist; | |||||
} | |||||
else | |||||
{ | |||||
//全员下发 | |||||
needpostuserlist = allteacherlist.ToList(); | |||||
} | |||||
} | |||||
PushWeixin(needpostuserlist, entity.F_FullHead); | |||||
//消息提醒表 | |||||
PushMessageRemind(needpostuserlist, entity); | |||||
return Task.CompletedTask; | |||||
} | |||||
catch (Exception e) | |||||
{ | |||||
return Task.FromException(e); | |||||
} | |||||
} | |||||
/// <summary> | /// <summary> | ||||
/// 删除表单数据 | /// 删除表单数据 | ||||
@@ -438,87 +330,7 @@ namespace Learun.Application.Web.Areas.LR_OAModule.Controllers | |||||
noticeIBLL.DeleteEntity(keyValue); | noticeIBLL.DeleteEntity(keyValue); | ||||
return Success("删除成功!"); | return Success("删除成功!"); | ||||
} | } | ||||
public void PushWeixin(List<UserEntity> needpostuserlist, 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); | |||||
OperateLogModel operateLogModel = new OperateLogModel(); | |||||
operateLogModel.title = title; | |||||
operateLogModel.type = OperationType.Other; | |||||
operateLogModel.url = "NoticeController"; | |||||
operateLogModel.sourceObjectId = "002"; | |||||
operateLogModel.sourceContentJson = responsejson; | |||||
OperatorHelper.Instance.WriteOperateLog(operateLogModel); | |||||
foreach (UserEntity userinfo in needpostuserlist) | |||||
{ | |||||
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\":\"您有新的未读通知公告\",\"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); | |||||
operateLogModel.title = title; | |||||
operateLogModel.type = OperationType.Other; | |||||
operateLogModel.url = "NoticeController"; | |||||
operateLogModel.sourceObjectId = "002"; | |||||
operateLogModel.sourceContentJson = pushresult; | |||||
OperatorHelper.Instance.WriteOperateLog(operateLogModel); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// 消息提醒 | |||||
/// </summary> | |||||
/// <param name="needpostuserlist"></param> | |||||
/// <param name="title"></param> | |||||
public void PushMessageRemind(List<UserEntity> needpostuserlist, NewsEntity model) | |||||
{ | |||||
foreach (UserEntity userinfo in needpostuserlist) | |||||
{ | |||||
MessageRemindEntity entity = new MessageRemindEntity(); | |||||
entity.ReceiptId = userinfo.F_UserId; | |||||
entity.ReceiptName = userinfo.F_RealName; | |||||
entity.SenderId = model.F_CreateUserId; | |||||
entity.SenderName = model.F_CreateUserName; | |||||
entity.TheTitle = "通知公告"; | |||||
entity.TheContent = model.F_FullHead; | |||||
entity.InstanceId = model.F_NewsId; | |||||
entity.ConnectionUrl = "/Utility/ListContentIndex?id="; | |||||
entity.SendTime = DateTime.Now; | |||||
entity.ReadSigns = false; | |||||
messageRindIBLL.SaveEntity("", entity); | |||||
} | |||||
} | |||||
#endregion | #endregion | ||||
@@ -547,11 +359,8 @@ namespace Learun.Application.Web.Areas.LR_OAModule.Controllers | |||||
public ActionResult GetFormDataByProcessId(string processId) | public ActionResult GetFormDataByProcessId(string processId) | ||||
{ | { | ||||
NewsEntity OANewsData = noticeIBLL.GetEntityByProcessId(processId); | NewsEntity OANewsData = noticeIBLL.GetEntityByProcessId(processId); | ||||
var jsonData = new | |||||
{ | |||||
OANews = OANewsData, | |||||
}; | |||||
return Success(jsonData); | |||||
OANewsData.F_NewsContent = WebHelper.HtmlDecode(OANewsData.F_NewsContent); | |||||
return Success(OANewsData); | |||||
} | } | ||||
#endregion | #endregion | ||||
@@ -61,17 +61,21 @@ var bootstrap = function ($, learun) { | |||||
setFormData = function (processId) { | setFormData = function (processId) { | ||||
if (!!processId) { | if (!!processId) { | ||||
$.lrSetForm(top.$.rootUrl + '/LR_OAModule/Notice/GetFormDataByProcessId?processId=' + processId, function (data) { | $.lrSetForm(top.$.rootUrl + '/LR_OAModule/Notice/GetFormDataByProcessId?processId=' + processId, function (data) { | ||||
for (var id in data) { | |||||
if (!!data[id] && data[id].length > 0) { | |||||
$('#' + id).jfGridSet('refreshdata', data[id]); | |||||
} | |||||
else { | |||||
if (id == 'Sys_ReceiveFile') { | |||||
keyValue = data[id].F_DeptRelationId; | |||||
} | |||||
$('[data-table="' + id + '"]').lrSetFormData(data[id]); | |||||
} | |||||
} | |||||
$('#form').lrSetFormData(data); | |||||
setTimeout(function () { | |||||
ue.setContent(data.F_NewsContent); | |||||
}, 100); | |||||
//for (var id in data) { | |||||
// if (!!data[id] && data[id].length > 0) { | |||||
// $('#' + id).jfGridSet('refreshdata', data[id]); | |||||
// } | |||||
// else { | |||||
// if (id == 'Sys_ReceiveFile') { | |||||
// keyValue = data[id].F_DeptRelationId; | |||||
// } | |||||
// $('[data-table="' + id + '"]').lrSetFormData(data[id]); | |||||
// } | |||||
//} | |||||
}); | }); | ||||
} | } | ||||
} | } | ||||
@@ -84,17 +88,62 @@ var bootstrap = function ($, learun) { | |||||
}; | }; | ||||
// 保存数据 | // 保存数据 | ||||
save = function (processId, callBack, i) { | save = function (processId, callBack, i) { | ||||
if (!$('#form').lrValidform()) { | |||||
return false; | |||||
} | |||||
var formData = $('body').lrGetFormData(); | var formData = $('body').lrGetFormData(); | ||||
if (!!processId) { | if (!!processId) { | ||||
formData.RProcessId = processId; | formData.RProcessId = processId; | ||||
} | } | ||||
$.lrSaveForm(top.$.rootUrl + '/LR_OAModule/Notice/SaveForm?keyValue=' + keyValue, formData, function (res) { | |||||
// 保存成功后才回调 | |||||
if (!!callBack) { | |||||
callBack(res, formData, i); | |||||
learun.clientdata.getAsync('dataItem', | |||||
{ | |||||
key: $("#F_CategoryId").lrselectGet(), | |||||
code: 'NoticeCategory', | |||||
callback: function (_data) { | |||||
$("#F_Category").val(_data.text); | |||||
var postData = $('#form').lrGetFormData(keyValue); | |||||
postData["F_NewsContent"] = ue.getContent(null, null, true); | |||||
$.lrSaveForm(top.$.rootUrl + '/LR_OAModule/Notice/SaveForm?keyValue=' + keyValue, | |||||
postData, | |||||
function (res) { | |||||
// 保存成功后才回调 | |||||
if (!!callBack) { | |||||
callBack(res, formData, i); | |||||
} | |||||
}); | |||||
} | |||||
}); | |||||
//$.lrSaveForm(top.$.rootUrl + '/LR_OAModule/Notice/SaveForm?keyValue=' + keyValue, formData, function (res) { | |||||
// // 保存成功后才回调 | |||||
// if (!!callBack) { | |||||
// callBack(res, formData, i); | |||||
// } | |||||
//}); | |||||
}; | |||||
acceptClick = function (callBack) { | |||||
if (!$('#form').lrValidform()) { | |||||
return false; | |||||
} | |||||
learun.clientdata.getAsync('dataItem', { | |||||
key: $("#F_CategoryId").lrselectGet(), | |||||
code: 'NoticeCategory', | |||||
callback: function (_data) { | |||||
$("#F_Category").val(_data.text); | |||||
var postData = $('#form').lrGetFormData(keyValue); | |||||
postData["F_NewsContent"] = ue.getContent(null, null, true); | |||||
$.lrSaveForm(top.$.rootUrl + '/LR_OAModule/Notice/SaveForm?keyValue=' + keyValue, postData, function (res) { | |||||
// 保存成功后才回调 | |||||
if (!!callBack) { | |||||
callBack(); | |||||
} | |||||
}); | |||||
} | } | ||||
}); | }); | ||||
}; | |||||
} | |||||
page.init(); | page.init(); | ||||
} | } | ||||
@@ -60,14 +60,10 @@ var bootstrap = function ($, learun) { | |||||
setFormData = function (processId, param, callback) { | setFormData = function (processId, param, callback) { | ||||
if (!!processId) { | if (!!processId) { | ||||
$.lrSetForm(top.$.rootUrl + '/LR_OAModule/Notice/GetFormDataByProcessId?processId=' + processId, function (data) { | $.lrSetForm(top.$.rootUrl + '/LR_OAModule/Notice/GetFormDataByProcessId?processId=' + processId, function (data) { | ||||
for (var id in data) { | |||||
if (!!data[id] && data[id].length > 0) { | |||||
$('#' + id).jfGridSet('refreshdata', data[id]); | |||||
} | |||||
else { | |||||
$('[data-table="' + id + '"]').lrSetFormData(data[id]); | |||||
} | |||||
} | |||||
$('#form').lrSetFormData(data); | |||||
setTimeout(function () { | |||||
ue.setContent(data.F_NewsContent); | |||||
}, 100); | |||||
}); | }); | ||||
} | } | ||||
callback && callback(); | callback && callback(); | ||||
@@ -84,9 +84,7 @@ var bootstrap = function ($, learun) { | |||||
url: top.$.rootUrl + '/Permission/DepartmentReleasePermissions/Index?departmentId=' + keyValue, | url: top.$.rootUrl + '/Permission/DepartmentReleasePermissions/Index?departmentId=' + keyValue, | ||||
width: 700, | width: 700, | ||||
height: 400, | height: 400, | ||||
callBack: function (id) { | |||||
return top[id].acceptClick(refreshGirdData); | |||||
} | |||||
btn:null | |||||
}); | }); | ||||
} | } | ||||
}); | }); | ||||
@@ -225,7 +225,7 @@ namespace Learun.Application.OA | |||||
this.F_CreateDate = DateTime.Now; | this.F_CreateDate = DateTime.Now; | ||||
this.F_ReleaseTime = DateTime.Now; | this.F_ReleaseTime = DateTime.Now; | ||||
this.F_DeleteMark = 0; | this.F_DeleteMark = 0; | ||||
this.F_EnabledMark = 1; | |||||
this.F_EnabledMark = 0; | |||||
this.F_PV = 0; | this.F_PV = 0; | ||||
UserInfo userInfo = LoginUserInfo.Get(); | UserInfo userInfo = LoginUserInfo.Get(); | ||||
@@ -184,6 +184,10 @@ namespace Learun.Application.OA | |||||
if (null != newEntity) | if (null != newEntity) | ||||
{ | { | ||||
newEntity.F_Status = status.ToString(); | newEntity.F_Status = status.ToString(); | ||||
if (status==2) | |||||
{ | |||||
newEntity.F_EnabledMark = 1; | |||||
} | |||||
} | } | ||||
this.BaseRepository().Update(newEntity); | this.BaseRepository().Update(newEntity); | ||||
@@ -77,6 +77,7 @@ | |||||
<Reference Include="System.Configuration" /> | <Reference Include="System.Configuration" /> | ||||
<Reference Include="System.Core" /> | <Reference Include="System.Core" /> | ||||
<Reference Include="System.Runtime.Serialization" /> | <Reference Include="System.Runtime.Serialization" /> | ||||
<Reference Include="System.Web" /> | |||||
<Reference Include="System.Xml.Linq" /> | <Reference Include="System.Xml.Linq" /> | ||||
<Reference Include="System.Data.DataSetExtensions" /> | <Reference Include="System.Data.DataSetExtensions" /> | ||||
<Reference Include="Microsoft.CSharp" /> | <Reference Include="Microsoft.CSharp" /> | ||||
@@ -220,6 +221,10 @@ | |||||
<Project>{81c03609-ae0d-414c-829b-16b990487add}</Project> | <Project>{81c03609-ae0d-414c-829b-16b990487add}</Project> | ||||
<Name>Learun.Ioc</Name> | <Name>Learun.Ioc</Name> | ||||
</ProjectReference> | </ProjectReference> | ||||
<ProjectReference Include="..\..\Learun.Util\Learun.Util.Operat\Learun.Util.Operat.csproj"> | |||||
<Project>{ad556b7a-e0d1-41bd-9d5b-18f8502e9f33}</Project> | |||||
<Name>Learun.Util.Operat</Name> | |||||
</ProjectReference> | |||||
<ProjectReference Include="..\..\Learun.Util\Learun.Util\Learun.Util.csproj"> | <ProjectReference Include="..\..\Learun.Util\Learun.Util\Learun.Util.csproj"> | ||||
<Project>{cf8ae293-88ab-436c-9720-a8386ba5d7b7}</Project> | <Project>{cf8ae293-88ab-436c-9720-a8386ba5d7b7}</Project> | ||||
<Name>Learun.Util</Name> | <Name>Learun.Util</Name> | ||||
@@ -1,9 +1,19 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Configuration; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using System.Web; | |||||
using Learun.Application.Base.AuthorizeModule; | |||||
using Learun.Application.Base.SystemModule; | |||||
using Learun.Application.OA; | using Learun.Application.OA; | ||||
using Learun.Application.Organization; | |||||
using Learun.Application.TwoDevelopment.EducationalAdministration; | |||||
using Learun.Application.TwoDevelopment.LR_Desktop; | |||||
using Learun.Util.Operat; | |||||
using Microsoft.AspNet.SignalR.Client; | |||||
using Newtonsoft.Json; | |||||
namespace Learun.Application.WorkFlow | namespace Learun.Application.WorkFlow | ||||
{ | { | ||||
@@ -11,16 +21,211 @@ namespace Learun.Application.WorkFlow | |||||
{ | { | ||||
NewsIBLL newsIBLL=new NewsBLL(); | NewsIBLL newsIBLL=new NewsBLL(); | ||||
private NoticeIBLL noticeIBLL = new NoticeBLL(); | |||||
private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL(); | |||||
private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL(); | |||||
private UserIBLL userIbll = new UserBLL(); | |||||
private UserRelationIBLL userRelationIBLL = new UserRelationBLL(); | |||||
private Sys_InformationPushIBLL sys_InformationPushIBLL = new Sys_InformationPushBLL(); | |||||
private MessageRindIBLL messageRindIBLL = new MessageRindBLL(); | |||||
public void Execute(WfMethodParameter parameter) | public void Execute(WfMethodParameter parameter) | ||||
{ | { | ||||
if (parameter.code == "agree") | if (parameter.code == "agree") | ||||
{ | { | ||||
newsIBLL.ChangeStatusByProcessId(parameter.processId, 2); | newsIBLL.ChangeStatusByProcessId(parameter.processId, 2); | ||||
var entity = noticeIBLL.GetEntityByProcessId(parameter.processId); | |||||
//推送通知 | |||||
//读取信息推送管理-通知公告推送(01)的配置 | |||||
var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("01"); | |||||
if (informationPushEntity != null && informationPushEntity.Status == true) | |||||
{ | |||||
//推送微信 | |||||
Task.Run(async () => { await DoWeixinPush(entity); }); | |||||
} | |||||
if (entity.F_IsSendFX.HasValue && entity.F_IsSendFX == true) | |||||
{ | |||||
Task.Run(async () => | |||||
{ | |||||
using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"])) | |||||
{ | |||||
var hubProxy = hubConnection.CreateHubProxy("SignalRHub"); | |||||
await hubConnection.Start(); | |||||
await hubProxy.Invoke("PushAnnouncement", entity.F_NewsId, entity.F_FullHead, Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(entity.F_NewsContent)).Length < 20 ? Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(entity.F_NewsContent)) : Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(entity.F_NewsContent)).Substring(0, 20), "news", entity.F_SendPostId, entity.F_SendDeptId); | |||||
} | |||||
}); | |||||
} | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
newsIBLL.ChangeStatusByProcessId(parameter.processId, 0); | newsIBLL.ChangeStatusByProcessId(parameter.processId, 0); | ||||
} | } | ||||
} | } | ||||
Task DoWeixinPush(NewsEntity entity) | |||||
{ | |||||
//微信推送 | |||||
try | |||||
{ | |||||
var allteacherlist = userIbll.GetAllList().Where(m => | |||||
m.F_DeleteMark != 1 && m.F_EnabledMark == 1 && m.F_Description == "教师"); | |||||
var userralationlist = userRelationIBLL.GetUserIdList("2"); | |||||
var needpostuserlist = new List<UserEntity>(); | |||||
if (!string.IsNullOrEmpty(entity.F_SendDeptId)) | |||||
{ | |||||
if (!entity.F_SendDeptId.Contains(",")) | |||||
{ | |||||
var departteacherlist = allteacherlist.Where(m => entity.F_SendDeptId == m.F_DepartmentId); | |||||
needpostuserlist.AddRange(departteacherlist.ToList()); | |||||
if (!string.IsNullOrEmpty(entity.F_SendPostId)) | |||||
{ | |||||
var newpostuserlist = new List<UserEntity>(); | |||||
foreach (var uuitem in needpostuserlist) | |||||
{ | |||||
var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId)); | |||||
if (postids > 0) | |||||
{ | |||||
newpostuserlist.Add(uuitem); | |||||
} | |||||
} | |||||
needpostuserlist = newpostuserlist; | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
foreach (var senddeptid in entity.F_SendDeptId.Split(',')) | |||||
{ | |||||
var departteacherlist = allteacherlist.Where(m => senddeptid == m.F_DepartmentId); | |||||
needpostuserlist.AddRange(departteacherlist.ToList()); | |||||
if (!string.IsNullOrEmpty(entity.F_SendPostId)) | |||||
{ | |||||
var newpostuserlist = new List<UserEntity>(); | |||||
foreach (var uuitem in needpostuserlist) | |||||
{ | |||||
var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId)); | |||||
if (postids > 0) | |||||
{ | |||||
newpostuserlist.Add(uuitem); | |||||
} | |||||
} | |||||
needpostuserlist = newpostuserlist; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
if (!string.IsNullOrEmpty(entity.F_SendPostId)) | |||||
{ | |||||
//岗位下发 | |||||
var newpostuserlist = new List<UserEntity>(); | |||||
foreach (var uuitem in allteacherlist) | |||||
{ | |||||
var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId)); | |||||
if (postids > 0) | |||||
{ | |||||
newpostuserlist.Add(uuitem); | |||||
} | |||||
} | |||||
needpostuserlist = newpostuserlist; | |||||
} | |||||
else | |||||
{ | |||||
//全员下发 | |||||
needpostuserlist = allteacherlist.ToList(); | |||||
} | |||||
} | |||||
PushWeixin(needpostuserlist, entity.F_FullHead); | |||||
//消息提醒表 | |||||
PushMessageRemind(needpostuserlist, entity); | |||||
return Task.CompletedTask; | |||||
} | |||||
catch (Exception e) | |||||
{ | |||||
return Task.FromException(e); | |||||
} | |||||
} | |||||
public void PushWeixin(List<UserEntity> needpostuserlist, 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); | |||||
OperateLogModel operateLogModel = new OperateLogModel(); | |||||
operateLogModel.title = title; | |||||
operateLogModel.type = OperationType.Other; | |||||
operateLogModel.url = "NoticeController"; | |||||
operateLogModel.sourceObjectId = "002"; | |||||
operateLogModel.sourceContentJson = responsejson; | |||||
OperatorHelper.Instance.WriteOperateLog(operateLogModel); | |||||
foreach (UserEntity userinfo in needpostuserlist) | |||||
{ | |||||
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\":\"您有新的未读通知公告\",\"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); | |||||
operateLogModel.title = title; | |||||
operateLogModel.type = OperationType.Other; | |||||
operateLogModel.url = "NoticeController"; | |||||
operateLogModel.sourceObjectId = "002"; | |||||
operateLogModel.sourceContentJson = pushresult; | |||||
OperatorHelper.Instance.WriteOperateLog(operateLogModel); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// 消息提醒 | |||||
/// </summary> | |||||
/// <param name="needpostuserlist"></param> | |||||
/// <param name="title"></param> | |||||
public void PushMessageRemind(List<UserEntity> needpostuserlist, NewsEntity model) | |||||
{ | |||||
foreach (UserEntity userinfo in needpostuserlist) | |||||
{ | |||||
MessageRemindEntity entity = new MessageRemindEntity(); | |||||
entity.ReceiptId = userinfo.F_UserId; | |||||
entity.ReceiptName = userinfo.F_RealName; | |||||
entity.SenderId = model.F_CreateUserId; | |||||
entity.SenderName = model.F_CreateUserName; | |||||
entity.TheTitle = "通知公告"; | |||||
entity.TheContent = model.F_FullHead; | |||||
entity.InstanceId = model.F_NewsId; | |||||
entity.ConnectionUrl = "/Utility/ListContentIndex?id="; | |||||
entity.SendTime = DateTime.Now; | |||||
entity.ReadSigns = false; | |||||
messageRindIBLL.SaveEntity("", entity); | |||||
} | |||||
} | |||||
} | } | ||||
} | } |