Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

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