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. 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 =
  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. //读取信息推送管理-通知公告推送(01)的配置
  300. var informationPushEntity = sys_InformationPushIBLL.GetEntityByPushItem("01");
  301. if (informationPushEntity != null && informationPushEntity.Status == true)
  302. {
  303. //推送微信
  304. Task.Run(async () => { await DoWeixinPush(entity); });
  305. }
  306. if (entity.F_IsSendFX.HasValue && entity.F_IsSendFX == true)
  307. {
  308. Task.Run(async () =>
  309. {
  310. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  311. {
  312. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  313. await hubConnection.Start();
  314. 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);
  315. }
  316. });
  317. }
  318. return Success("保存成功!");
  319. }
  320. Task DoWeixinPush(NewsEntity entity)
  321. {
  322. //微信推送
  323. try
  324. {
  325. var allteacherlist = userIbll.GetAllList().Where(m =>
  326. m.F_DeleteMark != 1 && m.F_EnabledMark == 1 && m.F_Description == "教师");
  327. var userralationlist = userRelationIBLL.GetUserIdList("2");
  328. var needpostuserlist = new List<UserEntity>();
  329. if (!string.IsNullOrEmpty(entity.F_SendDeptId))
  330. {
  331. if (!entity.F_SendDeptId.Contains(","))
  332. {
  333. var departteacherlist = allteacherlist.Where(m => entity.F_SendDeptId == m.F_DepartmentId);
  334. needpostuserlist.AddRange(departteacherlist.ToList());
  335. if (!string.IsNullOrEmpty(entity.F_SendPostId))
  336. {
  337. var newpostuserlist = new List<UserEntity>();
  338. foreach (var uuitem in needpostuserlist)
  339. {
  340. var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId));
  341. if (postids > 0)
  342. {
  343. newpostuserlist.Add(uuitem);
  344. }
  345. }
  346. needpostuserlist = newpostuserlist;
  347. }
  348. }
  349. else
  350. {
  351. foreach (var senddeptid in entity.F_SendDeptId.Split(','))
  352. {
  353. var departteacherlist = allteacherlist.Where(m => senddeptid == m.F_DepartmentId);
  354. needpostuserlist.AddRange(departteacherlist.ToList());
  355. if (!string.IsNullOrEmpty(entity.F_SendPostId))
  356. {
  357. var newpostuserlist = new List<UserEntity>();
  358. foreach (var uuitem in needpostuserlist)
  359. {
  360. var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId));
  361. if (postids > 0)
  362. {
  363. newpostuserlist.Add(uuitem);
  364. }
  365. }
  366. needpostuserlist = newpostuserlist;
  367. }
  368. }
  369. }
  370. }
  371. else
  372. {
  373. if (!string.IsNullOrEmpty(entity.F_SendPostId))
  374. {
  375. //岗位下发
  376. var newpostuserlist = new List<UserEntity>();
  377. foreach (var uuitem in allteacherlist)
  378. {
  379. var postids = userralationlist?.Count(m => m.F_UserId == uuitem.F_UserId && entity.F_SendPostId.Contains(m.F_ObjectId));
  380. if (postids > 0)
  381. {
  382. newpostuserlist.Add(uuitem);
  383. }
  384. }
  385. needpostuserlist = newpostuserlist;
  386. }
  387. else
  388. {
  389. //全员下发
  390. needpostuserlist = allteacherlist.ToList();
  391. }
  392. }
  393. PushWeixin(needpostuserlist, entity.F_FullHead);
  394. return Task.CompletedTask;
  395. }
  396. catch (Exception e)
  397. {
  398. return Task.FromException(e);
  399. }
  400. }
  401. /// <summary>
  402. /// 删除表单数据
  403. /// </summary>
  404. /// <param name="keyValue">主键</param>
  405. /// <returns></returns>
  406. [HttpPost]
  407. [AjaxOnly]
  408. public ActionResult DeleteForm(string keyValue)
  409. {
  410. noticeIBLL.DeleteEntity(keyValue);
  411. return Success("删除成功!");
  412. }
  413. public void PushWeixin(List<UserEntity> needpostuserlist, string title)
  414. {
  415. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  416. string appid = WeChatConfigentity.APPId;
  417. string secret = WeChatConfigentity.secret;
  418. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  419. string weixintaskurl = wechatemplete.TUrl;
  420. string weixintasktempid = wechatemplete.TempId;
  421. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  422. OperateLogModel operateLogModel = new OperateLogModel();
  423. operateLogModel.title = title;
  424. operateLogModel.type = OperationType.Other;
  425. operateLogModel.url = "NoticeController";
  426. operateLogModel.sourceObjectId = "002";
  427. operateLogModel.sourceContentJson = responsejson;
  428. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  429. foreach (UserEntity userinfo in needpostuserlist)
  430. {
  431. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  432. {
  433. //执行推送任务
  434. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  435. {
  436. if (!string.IsNullOrEmpty(responsejson))
  437. {
  438. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  439. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  440. {
  441. string access_token = weixintokenobj.access_token;
  442. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  443. "\"template_id\":\"" + weixintasktempid + "\"," +
  444. "\"url\":\"" + weixintaskurl + "\"," +
  445. "\"data\":{" +
  446. "\"first\": {\"value\":\"您有新的未读通知公告\",\"color\":\"#173177\"}," +
  447. "\"keyword1\":{\"value\":\"未读通知公告\",\"color\":\"#173177\"}," +
  448. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  449. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  450. "\"keyword4\": {\"value\":\"您有新的未读通知公告【" + title + "】\",\"color\":\"#173177\"}" +
  451. "}" +
  452. "}";
  453. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  454. operateLogModel.title = title;
  455. operateLogModel.type = OperationType.Other;
  456. operateLogModel.url = "NoticeController";
  457. operateLogModel.sourceObjectId = "002";
  458. operateLogModel.sourceContentJson = pushresult;
  459. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  460. }
  461. }
  462. }
  463. }
  464. }
  465. }
  466. #endregion
  467. #region 流程
  468. /// <summary>
  469. /// 提交
  470. /// </summary>
  471. /// <param name="keyValue"></param>
  472. /// <returns></returns>
  473. [HttpPost]
  474. [AjaxOnly]
  475. public ActionResult ChangeStatusById(string keyValue, string processId)
  476. {
  477. noticeIBLL.ChangeStatusById(keyValue, 1, processId);
  478. return Success("操作成功!");
  479. }
  480. /// <summary>
  481. /// 获取表单数据
  482. /// <summary>
  483. /// <returns></returns>
  484. [HttpGet]
  485. [AjaxOnly]
  486. public ActionResult GetFormDataByProcessId(string processId)
  487. {
  488. NewsEntity OANewsData = noticeIBLL.GetEntityByProcessId(processId);
  489. var jsonData = new
  490. {
  491. OANews = OANewsData,
  492. };
  493. return Success(jsonData);
  494. }
  495. #endregion
  496. }
  497. }