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.
 
 
 
 
 
 

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