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.
 
 
 
 
 
 

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