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.
 
 
 
 
 
 

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