You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

529 lines
21 KiB

  1. using Learun.Application.OA;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using System.Web;
  9. using System.Web.Mvc;
  10. using Learun.Application.Base.AuthorizeModule;
  11. using Learun.Application.Base.SystemModule;
  12. using Learun.Application.Organization;
  13. using Learun.Application.TwoDevelopment.LR_Desktop;
  14. using Learun.Util.Operat;
  15. using Microsoft.AspNet.SignalR.Client;
  16. using Microsoft.Owin.Logging;
  17. using Newtonsoft.Json;
  18. using Learun.Application.TwoDevelopment.EducationalAdministration;
  19. namespace Learun.Application.Web.Areas.LR_OAModule.Controllers
  20. {
  21. /// <summary>
  22. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  23. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  24. /// 创建人:陈彬彬
  25. /// 日 期:2017.04.01
  26. /// 描 述:公告管理
  27. /// </summary>
  28. public class NoticeController : MvcControllerBase
  29. {
  30. private NoticeIBLL noticeIBLL = new NoticeBLL();
  31. private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL();
  32. private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL();
  33. private UserIBLL userIbll = new UserBLL();
  34. private UserRelationIBLL userRelationIBLL = new UserRelationBLL();
  35. private DataItemIBLL dataItemIbll = new DataItemBLL();
  36. private DepartmentIBLL departmentIbll = new DepartmentBLL();
  37. private Sys_InformationPushIBLL sys_InformationPushIBLL = new Sys_InformationPushBLL();
  38. private MessageRindIBLL messageRindIBLL = new MessageRindBLL();
  39. #region 视图功能
  40. /// <summary>
  41. /// 管理页面
  42. /// </summary>
  43. /// <returns></returns>
  44. [HttpGet]
  45. public ActionResult Index()
  46. {
  47. return View();
  48. }
  49. /// <summary>
  50. /// 表单页面
  51. /// </summary>
  52. /// <returns></returns>
  53. [HttpGet]
  54. public ActionResult Form()
  55. {
  56. return View();
  57. }
  58. /// <summary>
  59. /// 通知公告(需要审核)
  60. /// </summary>
  61. /// <returns></returns>
  62. [HttpGet]
  63. public ActionResult IndexFlow()
  64. {
  65. return View();
  66. }
  67. /// <summary>
  68. /// 通知公告表单(需要审核)
  69. /// </summary>
  70. /// <returns></returns>
  71. [HttpGet]
  72. public ActionResult FormFlow()
  73. {
  74. return View();
  75. }
  76. /// <summary>
  77. /// 通知公告表单(需要审核)
  78. /// </summary>
  79. /// <returns></returns>
  80. [HttpGet]
  81. public ActionResult FormFlowView()
  82. {
  83. return View();
  84. }
  85. /// <summary>
  86. /// 管理页面【查看通知公告】
  87. /// </summary>
  88. /// <returns></returns>
  89. [HttpGet]
  90. public ActionResult ViewIndex()
  91. {
  92. return View();
  93. }
  94. /// <summary>
  95. /// 表单页面【查看通知公告】
  96. /// </summary>
  97. /// <returns></returns>
  98. [HttpGet]
  99. public ActionResult ViewForm()
  100. {
  101. return View();
  102. }
  103. #endregion
  104. #region 获取数据
  105. /// <summary>
  106. /// 获取分页数据
  107. /// </summary>
  108. /// <param name="pagination">分页参数</param>
  109. /// <param name="keyword">关键词</param>
  110. /// <returns></returns>
  111. public ActionResult GetPageList(string pagination, string keyword)
  112. {
  113. Pagination paginationobj = pagination.ToObject<Pagination>();
  114. var data = noticeIBLL.GetPageList(paginationobj, keyword);
  115. var jsonData = new
  116. {
  117. rows = data,
  118. total = paginationobj.total,
  119. page = paginationobj.page,
  120. records = paginationobj.records,
  121. };
  122. return JsonResult(jsonData);
  123. }
  124. /// <summary>
  125. /// 查看通知公告
  126. /// </summary>
  127. /// <param name="pagination">分页参数</param>
  128. /// <param name="keyword">关键词</param>
  129. /// <returns></returns>
  130. public ActionResult GetListOfSelf(string keyword, string categoryId = null)
  131. {
  132. var userinfo = LoginUserInfo.Get();
  133. Pagination paginationobj = new Pagination();
  134. var newsList = noticeIBLL.GetList(keyword, userinfo.userId, categoryId);
  135. var newsListOfSelf = new List<NewsEntity>();
  136. foreach (var newsitemEntity in newsList)
  137. {
  138. if (!string.IsNullOrEmpty(newsitemEntity.F_SendPostId))
  139. {
  140. if (!string.IsNullOrEmpty(userinfo.postIds))
  141. {
  142. if (userinfo.postIds.Contains(","))
  143. {
  144. foreach (var postid in userinfo.postIds.Split(','))
  145. {
  146. if (newsitemEntity.F_SendPostId.Contains(postid))
  147. {
  148. newsListOfSelf.Add(newsitemEntity);
  149. break;
  150. }
  151. }
  152. }
  153. else
  154. {
  155. if (newsitemEntity.F_SendPostId.Contains(userinfo.postIds))
  156. {
  157. newsListOfSelf.Add(newsitemEntity);
  158. }
  159. }
  160. }
  161. }
  162. else
  163. {
  164. if (!string.IsNullOrEmpty(newsitemEntity.F_SendDeptId))
  165. {
  166. if (newsitemEntity.F_SendDeptId.Contains(userinfo.departmentId))
  167. {
  168. newsListOfSelf.Add(newsitemEntity);
  169. }
  170. }
  171. else
  172. {
  173. newsListOfSelf.Add(newsitemEntity);
  174. }
  175. }
  176. }
  177. return JsonResult(newsListOfSelf);
  178. }
  179. /// <summary>
  180. /// 查看通知公告
  181. /// </summary>
  182. /// <param name="pagination">分页参数</param>
  183. /// <param name="keyword">关键词</param>
  184. /// <returns></returns>
  185. public ActionResult GetListOfSelfJY(string keyword, string categoryId = null)
  186. {
  187. var userinfo = LoginUserInfo.Get();
  188. Pagination paginationobj = new Pagination();
  189. var newsList = noticeIBLL.GetList(keyword, userinfo.userId, categoryId).
  190. Where(a => a.F_Status == "2");
  191. var newsListOfSelf = new List<NewsEntity>();
  192. foreach (var newsitemEntity in newsList)
  193. {
  194. if (!string.IsNullOrEmpty(newsitemEntity.F_SendPostId))
  195. {
  196. if (!string.IsNullOrEmpty(userinfo.postIds))
  197. {
  198. if (userinfo.postIds.Contains(","))
  199. {
  200. foreach (var postid in userinfo.postIds.Split(','))
  201. {
  202. if (newsitemEntity.F_SendPostId.Contains(postid))
  203. {
  204. newsListOfSelf.Add(newsitemEntity);
  205. break;
  206. }
  207. }
  208. }
  209. else
  210. {
  211. if (newsitemEntity.F_SendPostId.Contains(userinfo.postIds))
  212. {
  213. newsListOfSelf.Add(newsitemEntity);
  214. }
  215. }
  216. }
  217. }
  218. else
  219. {
  220. if (!string.IsNullOrEmpty(newsitemEntity.F_SendDeptId))
  221. {
  222. if (newsitemEntity.F_SendDeptId.Contains(userinfo.departmentId))
  223. {
  224. newsListOfSelf.Add(newsitemEntity);
  225. }
  226. }
  227. else
  228. {
  229. newsListOfSelf.Add(newsitemEntity);
  230. }
  231. }
  232. }
  233. return JsonResult(newsListOfSelf);
  234. }
  235. /// <summary>
  236. /// 获取实体数据
  237. /// </summary>
  238. /// <param name="keyValue">主键</param>
  239. /// <returns></returns>
  240. public ActionResult GetEntity(string keyValue)
  241. {
  242. var data = noticeIBLL.GetEntity(keyValue);
  243. data.F_NewsContent = WebHelper.HtmlDecode(data.F_NewsContent);
  244. return JsonResult(data);
  245. }
  246. public ActionResult GetNoticeCategoryByDepartment(string departmentId)
  247. {
  248. var typeList = dataItemIbll.GetDetailList("NoticeCategory");
  249. var departmentEntity = departmentIbll.GetEntity(departmentId);
  250. List<object> list = new List<object>();
  251. if (departmentEntity != null)
  252. {
  253. var typetext = departmentEntity.NoticeCategory?.Split(',');
  254. foreach (var item in typetext)
  255. {
  256. var entity = typeList.FirstOrDefault(a => a.F_ItemValue.Equals(item));
  257. if (entity != null)
  258. {
  259. list.Add(new { text = entity.F_ItemName, value = entity.F_ItemValue });
  260. }
  261. }
  262. }
  263. return JsonResult(list);
  264. }
  265. #endregion
  266. #region 提交数据
  267. /// <summary>
  268. /// 保存表单数据
  269. /// </summary>
  270. /// <param name="keyValue">主键</param>
  271. /// <param name="entity">实体</param>
  272. /// <returns></returns>
  273. [HttpPost, ValidateAntiForgeryToken, AjaxOnly, ValidateInput(false)]
  274. public ActionResult SaveForm(string keyValue, NewsEntity entity)
  275. {
  276. entity.F_NewsContent = WebHelper.HtmlEncode(entity.F_NewsContent);
  277. noticeIBLL.SaveEntity(keyValue, entity);
  278. //读取信息推送管理-通知公告推送(01)的配置
  279. var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("01");
  280. if (informationPushEntity != null && informationPushEntity.Status == true)
  281. {
  282. //推送微信
  283. Task.Run(async () => { await DoWeixinPush(entity); });
  284. }
  285. if (entity.F_IsSendFX.HasValue && entity.F_IsSendFX == true)
  286. {
  287. Task.Run(async () =>
  288. {
  289. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  290. {
  291. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  292. await hubConnection.Start();
  293. 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);
  294. }
  295. });
  296. }
  297. return Success("保存成功!");
  298. }
  299. Task DoWeixinPush(NewsEntity entity)
  300. {
  301. //微信推送
  302. try
  303. {
  304. var allteacherlist = userIbll.GetAllList().Where(m =>
  305. m.F_DeleteMark != 1 && m.F_EnabledMark == 1 && m.F_Description == "教师");
  306. var userralationlist = userRelationIBLL.GetUserIdList("2");
  307. var needpostuserlist = new List<UserEntity>();
  308. if (!string.IsNullOrEmpty(entity.F_SendDeptId))
  309. {
  310. if (!entity.F_SendDeptId.Contains(","))
  311. {
  312. var departteacherlist = allteacherlist.Where(m => entity.F_SendDeptId == m.F_DepartmentId);
  313. needpostuserlist.AddRange(departteacherlist.ToList());
  314. if (!string.IsNullOrEmpty(entity.F_SendPostId))
  315. {
  316. var newpostuserlist = new List<UserEntity>();
  317. foreach (var uuitem in needpostuserlist)
  318. {
  319. var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId));
  320. if (postids > 0)
  321. {
  322. newpostuserlist.Add(uuitem);
  323. }
  324. }
  325. needpostuserlist = newpostuserlist;
  326. }
  327. }
  328. else
  329. {
  330. foreach (var senddeptid in entity.F_SendDeptId.Split(','))
  331. {
  332. var departteacherlist = allteacherlist.Where(m => senddeptid == m.F_DepartmentId);
  333. needpostuserlist.AddRange(departteacherlist.ToList());
  334. if (!string.IsNullOrEmpty(entity.F_SendPostId))
  335. {
  336. var newpostuserlist = new List<UserEntity>();
  337. foreach (var uuitem in needpostuserlist)
  338. {
  339. var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId));
  340. if (postids > 0)
  341. {
  342. newpostuserlist.Add(uuitem);
  343. }
  344. }
  345. needpostuserlist = newpostuserlist;
  346. }
  347. }
  348. }
  349. }
  350. else
  351. {
  352. if (!string.IsNullOrEmpty(entity.F_SendPostId))
  353. {
  354. //岗位下发
  355. var newpostuserlist = new List<UserEntity>();
  356. foreach (var uuitem in allteacherlist)
  357. {
  358. var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId));
  359. if (postids > 0)
  360. {
  361. newpostuserlist.Add(uuitem);
  362. }
  363. }
  364. needpostuserlist = newpostuserlist;
  365. }
  366. else
  367. {
  368. //全员下发
  369. needpostuserlist = allteacherlist.ToList();
  370. }
  371. }
  372. PushWeixin(needpostuserlist, entity.F_FullHead);
  373. //消息提醒表
  374. PushMessageRemind(needpostuserlist, entity);
  375. return Task.CompletedTask;
  376. }
  377. catch (Exception e)
  378. {
  379. return Task.FromException(e);
  380. }
  381. }
  382. /// <summary>
  383. /// 删除表单数据
  384. /// </summary>
  385. /// <param name="keyValue">主键</param>
  386. /// <returns></returns>
  387. [HttpPost]
  388. [AjaxOnly]
  389. public ActionResult DeleteForm(string keyValue)
  390. {
  391. noticeIBLL.DeleteEntity(keyValue);
  392. return Success("删除成功!");
  393. }
  394. public void PushWeixin(List<UserEntity> needpostuserlist, string title)
  395. {
  396. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  397. string appid = WeChatConfigentity.APPId;
  398. string secret = WeChatConfigentity.secret;
  399. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  400. string weixintaskurl = wechatemplete.TUrl;
  401. string weixintasktempid = wechatemplete.TempId;
  402. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  403. OperateLogModel operateLogModel = new OperateLogModel();
  404. operateLogModel.title = title;
  405. operateLogModel.type = OperationType.Other;
  406. operateLogModel.url = "NoticeController";
  407. operateLogModel.sourceObjectId = "002";
  408. operateLogModel.sourceContentJson = responsejson;
  409. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  410. foreach (UserEntity userinfo in needpostuserlist)
  411. {
  412. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  413. {
  414. //执行推送任务
  415. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  416. {
  417. if (!string.IsNullOrEmpty(responsejson))
  418. {
  419. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  420. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  421. {
  422. string access_token = weixintokenobj.access_token;
  423. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  424. "\"template_id\":\"" + weixintasktempid + "\"," +
  425. "\"url\":\"" + weixintaskurl + "/#/?page=notice\"," +
  426. "\"data\":{" +
  427. "\"first\": {\"value\":\"您有新的未读通知公告\",\"color\":\"#173177\"}," +
  428. "\"keyword1\":{\"value\":\"未读通知公告\",\"color\":\"#173177\"}," +
  429. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  430. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  431. "\"keyword4\": {\"value\":\"您有新的未读通知公告【" + title + "】\",\"color\":\"#173177\"}" +
  432. "}" +
  433. "}";
  434. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  435. operateLogModel.title = title;
  436. operateLogModel.type = OperationType.Other;
  437. operateLogModel.url = "NoticeController";
  438. operateLogModel.sourceObjectId = "002";
  439. operateLogModel.sourceContentJson = pushresult;
  440. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  441. }
  442. }
  443. }
  444. }
  445. }
  446. }
  447. /// <summary>
  448. /// 消息提醒
  449. /// </summary>
  450. /// <param name="needpostuserlist"></param>
  451. /// <param name="title"></param>
  452. public void PushMessageRemind(List<UserEntity> needpostuserlist, NewsEntity model)
  453. {
  454. foreach (UserEntity userinfo in needpostuserlist)
  455. {
  456. MessageRemindEntity entity = new MessageRemindEntity();
  457. entity.ReceiptId = userinfo.F_UserId;
  458. entity.ReceiptName = userinfo.F_RealName;
  459. entity.SenderId = model.F_CreateUserId;
  460. entity.SenderName = model.F_CreateUserName;
  461. entity.TheTitle = "通知公告";
  462. entity.TheContent = model.F_FullHead;
  463. entity.InstanceId = model.F_NewsId;
  464. entity.ConnectionUrl = "/Utility/ListContentIndex?id=";
  465. entity.SendTime = DateTime.Now;
  466. entity.ReadSigns = false;
  467. messageRindIBLL.SaveEntity("", entity);
  468. }
  469. }
  470. #endregion
  471. #region 流程
  472. /// <summary>
  473. /// 提交
  474. /// </summary>
  475. /// <param name="keyValue"></param>
  476. /// <returns></returns>
  477. [HttpPost]
  478. [AjaxOnly]
  479. public ActionResult ChangeStatusById(string keyValue, string processId)
  480. {
  481. noticeIBLL.ChangeStatusById(keyValue, 1, processId);
  482. return Success("操作成功!");
  483. }
  484. /// <summary>
  485. /// 获取表单数据
  486. /// <summary>
  487. /// <returns></returns>
  488. [HttpGet]
  489. [AjaxOnly]
  490. public ActionResult GetFormDataByProcessId(string processId)
  491. {
  492. NewsEntity OANewsData = noticeIBLL.GetEntityByProcessId(processId);
  493. var jsonData = new
  494. {
  495. OANews = OANewsData,
  496. };
  497. return Success(jsonData);
  498. }
  499. #endregion
  500. }
  501. }