|
- using Learun.Application.OA;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Web;
- using System.Web.Mvc;
- using Learun.Application.Base.AuthorizeModule;
- using Learun.Application.Base.SystemModule;
- using Learun.Application.Organization;
- using Learun.Application.TwoDevelopment.LR_Desktop;
- using Learun.Util.Operat;
- using Microsoft.AspNet.SignalR.Client;
- using Microsoft.Owin.Logging;
- using Newtonsoft.Json;
- using Learun.Application.TwoDevelopment.EducationalAdministration;
- using Learun.Application.TwoDevelopment.Permission;
-
- namespace Learun.Application.Web.Areas.LR_OAModule.Controllers
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创建人:陈彬彬
- /// 日 期:2017.04.01
- /// 描 述:公告管理
- /// </summary>
- public class NoticeController : MvcControllerBase
- {
- private NoticeIBLL noticeIBLL = new NoticeBLL();
- private DataItemIBLL dataItemIbll = new DataItemBLL();
- private Sys_InformationPushIBLL sys_InformationPushIBLL = new Sys_InformationPushBLL();
- private MessageRindIBLL messageRindIBLL = new MessageRindBLL();
- private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL();
- private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL();
- private UserIBLL userIbll = new UserBLL();
- private UserRelationIBLL userRelationIBLL = new UserRelationBLL();
-
- private DepartmentReleasePermissionsIBLL departmentReleasePermissionsIbll =
- new DepartmentReleasePermissionsBLL();
- #region 视图功能
- /// <summary>
- /// 管理页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Index()
- {
- return View();
- }
- /// <summary>
- /// 表单页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Form()
- {
- return View();
- }
- /// <summary>
- /// 通知公告(需要审核)
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult IndexFlow()
- {
- return View();
- }
- /// <summary>
- /// 通知公告表单(需要审核)
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult FormFlow()
- {
- return View();
- }
- /// <summary>
- /// 通知公告表单(需要审核)
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult FormFlowView()
- {
- return View();
- }
- /// <summary>
- /// 管理页面【查看通知公告】
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult ViewIndex()
- {
- return View();
- }
- /// <summary>
- /// 表单页面【查看通知公告】
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult ViewForm()
- {
- return View();
- }
-
- /// <summary>
- /// 通知公告阅读统计
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult IndexStatistics()
- {
- return View();
- }
- #endregion
-
- #region 获取数据
- /// <summary>
- /// 获取分页数据
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="keyword">关键词</param>
- /// <returns></returns>
- public ActionResult GetPageList(string pagination, string keyword)
- {
- Pagination paginationobj = pagination.ToObject<Pagination>();
- var data = noticeIBLL.GetPageList(paginationobj, keyword);
- var jsonData = new
- {
- rows = data,
- total = paginationobj.total,
- page = paginationobj.page,
- records = paginationobj.records,
- };
- return JsonResult(jsonData);
- }
-
- /// <summary>
- /// 通知公告阅读统计
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="keyword">关键词</param>
- /// <returns></returns>
- public ActionResult GetPageListForStatistics(string pagination, string queryJson)
- {
- Pagination paginationobj = pagination.ToObject<Pagination>();
- //添加通知公告应阅读人数
- noticeIBLL.SaveNewsShouldRead();
- var data = noticeIBLL.GetPageListForStatistics(paginationobj, queryJson);
- var jsonData = new
- {
- rows = data,
- total = paginationobj.total,
- page = paginationobj.page,
- records = paginationobj.records,
- };
- return JsonResult(jsonData);
- }
- /// <summary>
- /// 查看通知公告
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="keyword">关键词</param>
- /// <returns></returns>
- public ActionResult GetListOfSelf(string keyword, string categoryId = null)
- {
- var userinfo = LoginUserInfo.Get();
- Pagination paginationobj = new Pagination();
- var newsList = noticeIBLL.GetList(keyword, categoryId);
- //var newsListOfSelf = new List<NewsEntity>();
-
- //foreach (var newsitemEntity in newsList)
- //{
- // if (!string.IsNullOrEmpty(newsitemEntity.F_SendPostId))
- // {
- // if (!string.IsNullOrEmpty(userinfo.postIds))
- // {
- // if (userinfo.postIds.Contains(","))
- // {
- // foreach (var postid in userinfo.postIds.Split(','))
- // {
- // if (newsitemEntity.F_SendPostId.Contains(postid))
- // {
- // newsListOfSelf.Add(newsitemEntity);
- // break;
- // }
- // }
- // }
- // else
- // {
- // if (newsitemEntity.F_SendPostId.Contains(userinfo.postIds))
- // {
- // newsListOfSelf.Add(newsitemEntity);
- // }
- // }
- // }
- // }
- // else
- // {
- // if (!string.IsNullOrEmpty(newsitemEntity.F_SendDeptId))
- // {
- // if (newsitemEntity.F_SendDeptId.Contains(userinfo.departmentId))
- // {
- // newsListOfSelf.Add(newsitemEntity);
- // }
- // }
- // else
- // {
- // newsListOfSelf.Add(newsitemEntity);
- // }
- // }
- //}
-
- return JsonResult(newsList);
- }
-
- public ActionResult GetListOfSelfForView(string queryJson)
- {
- var newsList = noticeIBLL.GetListOfSelf(queryJson);
- return JsonResult(newsList);
- }
-
- /// <summary>
- /// 查看通知公告
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="keyword">关键词</param>
- /// <returns></returns>
- public ActionResult GetListOfSelfJY(string keyword, string categoryId = null)
- {
- var userinfo = LoginUserInfo.Get();
- Pagination paginationobj = new Pagination();
- var newsList = noticeIBLL.GetList(keyword, categoryId).
- Where(a => a.F_Status == "2");
- //var newsListOfSelf = new List<NewsEntity>();
-
- //foreach (var newsitemEntity in newsList)
- //{
- // if (!string.IsNullOrEmpty(newsitemEntity.F_SendPostId))
- // {
- // if (!string.IsNullOrEmpty(userinfo.postIds))
- // {
- // if (userinfo.postIds.Contains(","))
- // {
- // foreach (var postid in userinfo.postIds.Split(','))
- // {
- // if (newsitemEntity.F_SendPostId.Contains(postid))
- // {
- // newsListOfSelf.Add(newsitemEntity);
- // break;
- // }
- // }
- // }
- // else
- // {
- // if (newsitemEntity.F_SendPostId.Contains(userinfo.postIds))
- // {
- // newsListOfSelf.Add(newsitemEntity);
- // }
- // }
- // }
- // }
- // else
- // {
- // if (!string.IsNullOrEmpty(newsitemEntity.F_SendDeptId))
- // {
- // if (newsitemEntity.F_SendDeptId.Contains(userinfo.departmentId))
- // {
- // newsListOfSelf.Add(newsitemEntity);
- // }
- // }
- // else
- // {
- // newsListOfSelf.Add(newsitemEntity);
- // }
- // }
- //}
-
- return JsonResult(newsList);
- }
- /// <summary>
- /// 获取实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public ActionResult GetEntity(string keyValue)
- {
- var data = noticeIBLL.GetEntity(keyValue);
- data.F_NewsContent = WebHelper.HtmlDecode(data.F_NewsContent);
- return JsonResult(data);
- }
-
- public ActionResult GetNoticeCategoryByDepartment(string userId)
- {
-
- var typeList = dataItemIbll.GetDetailList("NoticeCategory");
- var permissionsEntity = departmentReleasePermissionsIbll.GetTypesByUserId(userId);
-
- List<object> list = new List<object>();
- if (permissionsEntity != null)
- {
- var typetext = permissionsEntity.Permission?.Split(',');
-
- foreach (var item in typetext)
- {
- var entity = typeList.FirstOrDefault(a => a.F_ItemValue.Equals(item));
- if (entity != null)
- {
- list.Add(new { text = entity.F_ItemName, value = entity.F_ItemValue });
- }
- }
-
- }
- return JsonResult(list);
-
- }
-
-
- //public ActionResult GetNoticeCategoryByDepartment(string departmentId)
- //{
-
- // var typeList = dataItemIbll.GetDetailList("NoticeCategory");
- // var departmentEntity = departmentIbll.GetEntity(departmentId);
- // List<object> list = new List<object>();
- // if (departmentEntity != null)
- // {
- // var typetext = departmentEntity.NoticeCategory?.Split(',');
-
- // foreach (var item in typetext)
- // {
- // var entity = typeList.FirstOrDefault(a => a.F_ItemValue.Equals(item));
- // if (entity != null)
- // {
- // list.Add(new { text = entity.F_ItemName, value = entity.F_ItemValue });
- // }
- // }
-
- // }
- // return JsonResult(list);
-
- //}
-
- #endregion
-
- #region 提交数据
- /// <summary>
- /// 保存表单数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="entity">实体</param>
- /// <returns></returns>
- [HttpPost, ValidateAntiForgeryToken, AjaxOnly, ValidateInput(false)]
- public ActionResult SaveForm(string keyValue, NewsEntity entity)
- {
- entity.F_NewsContent = WebHelper.HtmlEncode(entity.F_NewsContent);
- noticeIBLL.SaveEntity(keyValue, entity);
-
-
- return Success("保存成功!");
- }
-
- [HttpPost, ValidateAntiForgeryToken, AjaxOnly, ValidateInput(false)]
- public ActionResult SaveFormAndSubmit(string keyValue, NewsEntity entity)
- {
- entity.F_NewsContent = WebHelper.HtmlEncode(entity.F_NewsContent);
- noticeIBLL.SaveFormAndSubmit(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("保存成功!");
- }
- 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);
- }
-
- }
-
-
- /// <summary>
- /// 删除表单数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- public ActionResult DeleteForm(string keyValue)
- {
- noticeIBLL.DeleteEntity(keyValue);
- return Success("删除成功!");
- }
-
-
- #endregion
-
- #region 流程
-
- /// <summary>
- /// 提交
- /// </summary>
- /// <param name="keyValue"></param>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- public ActionResult ChangeStatusById(string keyValue, string processId)
- {
- noticeIBLL.ChangeStatusById(keyValue, 1, processId);
- return Success("操作成功!");
- }
-
-
- /// <summary>
- /// 获取表单数据
- /// <summary>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetFormDataByProcessId(string processId)
- {
- NewsEntity OANewsData = noticeIBLL.GetEntityByProcessId(processId);
- OANewsData.F_NewsContent = WebHelper.HtmlDecode(OANewsData.F_NewsContent);
- return Success(OANewsData);
- }
-
- #endregion
- }
- }
|