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.
 
 
 
 
 
 

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