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.

MP_ManagementPlanController.cs 11 KiB

4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using System;
  2. using Learun.Util;
  3. using System.Data;
  4. using Learun.Application.TwoDevelopment.PersonnelManagement;
  5. using System.Web.Mvc;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using Learun.Application.Organization;
  9. using Learun.Application.TwoDevelopment.LR_Desktop;
  10. using Learun.Util.Operat;
  11. using Newtonsoft.Json;
  12. namespace Learun.Application.Web.Areas.PersonnelManagement.Controllers
  13. {
  14. /// <summary>
  15. /// 版 本 Learun-ADMS-Ultimate V7.0.0 力软敏捷开发框架
  16. /// Copyright (c) 2013-2018 上海力软信息技术有限公司
  17. /// 创 建:超级管理员
  18. /// 日 期:2019-09-24 15:32
  19. /// 描 述:内控管理
  20. /// </summary>
  21. public class MP_ManagementPlanController : MvcControllerBase
  22. {
  23. private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL();
  24. private WeChatTempletIBLL weChatTempletIbll = new WeChatTempletBLL();
  25. private UserIBLL userIBLL=new UserBLL();
  26. private MP_ManagementPlanIBLL mP_ManagementPlanIBLL = new MP_ManagementPlanBLL();
  27. #region 视图功能
  28. /// <summary>
  29. /// 主页面
  30. /// <summary>
  31. /// <returns></returns>
  32. [HttpGet]
  33. public ActionResult Index()
  34. {
  35. return View();
  36. }
  37. /// <summary>
  38. /// 管理员页面
  39. /// <summary>
  40. /// <returns></returns>
  41. [HttpGet]
  42. public ActionResult IndexManagement()
  43. {
  44. return View();
  45. }
  46. /// <summary>
  47. /// 提交材料页面
  48. /// <summary>
  49. /// <returns></returns>
  50. [HttpGet]
  51. public ActionResult IndexChildren()
  52. {
  53. return View();
  54. }
  55. /// <summary>
  56. /// 表单页
  57. /// <summary>
  58. /// <returns></returns>
  59. [HttpGet]
  60. public ActionResult Form()
  61. {
  62. return View();
  63. }
  64. /// <summary>
  65. /// 表单页
  66. /// <summary>
  67. /// <returns></returns>
  68. [HttpGet]
  69. public ActionResult UploadForm()
  70. {
  71. return View();
  72. }
  73. #endregion
  74. #region 获取数据
  75. /// <summary>
  76. /// 获取页面显示列表数据
  77. /// <summary>
  78. /// <param name="queryJson">查询参数</param>
  79. /// <returns></returns>
  80. [HttpGet]
  81. [AjaxOnly]
  82. public ActionResult GetPageList(string pagination, string queryJson)
  83. {
  84. Pagination paginationobj = pagination.ToObject<Pagination>();
  85. var data = mP_ManagementPlanIBLL.GetPageList(paginationobj, queryJson);
  86. var jsonData = new
  87. {
  88. rows = data,
  89. total = paginationobj.total,
  90. page = paginationobj.page,
  91. records = paginationobj.records
  92. };
  93. return Success(jsonData);
  94. }
  95. /// <summary>
  96. /// 获取表单数据
  97. /// <summary>
  98. /// <returns></returns>
  99. [HttpGet]
  100. [AjaxOnly]
  101. public ActionResult GetFormData(string keyValue)
  102. {
  103. var MP_ManageMentPlanData = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(keyValue);
  104. var jsonData = new
  105. {
  106. MP_ManageMentPlan = MP_ManageMentPlanData,
  107. };
  108. return Success(jsonData);
  109. }
  110. [HttpGet]
  111. [AjaxOnly]
  112. public ActionResult GetAcademicYear()
  113. {
  114. var data = WebHelper.GenerateNearByAcademicTwo();
  115. return Success(data);
  116. }
  117. #endregion
  118. #region 提交数据
  119. /// <summary>
  120. /// 删除实体数据
  121. /// <param name="keyValue">主键</param>
  122. /// <summary>
  123. /// <returns></returns>
  124. [HttpPost]
  125. [AjaxOnly]
  126. public ActionResult DeleteForm(string keyValue)
  127. {
  128. mP_ManagementPlanIBLL.DeleteEntity(keyValue);
  129. return Success("删除成功!");
  130. }
  131. /// <summary>
  132. /// 合格/不合格
  133. /// <param name="keyValue">主键</param>
  134. /// <summary>
  135. /// <returns></returns>
  136. [HttpPost]
  137. [AjaxOnly]
  138. public ActionResult Qqualified(string keyValue, bool status)
  139. {
  140. var entity = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(keyValue);
  141. entity.MPConclusion = status?1:0;
  142. mP_ManagementPlanIBLL.SaveEntity(keyValue, entity);
  143. return Success("修改成功!");
  144. }
  145. /// <summary>
  146. /// 保存实体数据(新增、修改)
  147. /// <param name="keyValue">主键</param>
  148. /// <summary>
  149. /// <returns></returns>
  150. [HttpPost]
  151. [ValidateAntiForgeryToken]
  152. [AjaxOnly]
  153. public ActionResult SaveForm(string keyValue, string strEntity)
  154. {
  155. MP_ManageMentPlanEntity entity = strEntity.ToObject<MP_ManageMentPlanEntity>();
  156. entity.MPType = 0;
  157. mP_ManagementPlanIBLL.SaveEntity(keyValue, entity);
  158. return Success("保存成功!");
  159. }
  160. /// <summary>
  161. /// 保存实体数据(新增、修改)
  162. /// <param name="keyValue">主键</param>
  163. /// <summary>
  164. /// <returns></returns>
  165. [HttpPost]
  166. [ValidateAntiForgeryToken]
  167. [AjaxOnly]
  168. public ActionResult UploadForm(string keyValue, string strEntity)
  169. {
  170. MP_ManageMentPlanEntity entity = strEntity.ToObject<MP_ManageMentPlanEntity>();
  171. if (!string.IsNullOrEmpty(keyValue))
  172. {
  173. var entity2 = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(keyValue);
  174. if (!string.IsNullOrEmpty(entity.MPFileTwo))
  175. {
  176. entity.MPStatus = 0;//已提交
  177. entity.MPUploadTimes = $"{DateTime.Now.ToString()}, {entity2.MPUploadTimes}";
  178. entity.SUpdateTime = entity2.SUpdateTime + 1;
  179. }
  180. }
  181. else
  182. {
  183. entity.Create();
  184. if (!string.IsNullOrEmpty(entity.MPFileTwo))
  185. {
  186. entity.MPStatus = 0;//已提交
  187. entity.MPUploadTimes = DateTime.Now.ToString();
  188. entity.SUpdateTime = 1;
  189. entity.MPType = 0;
  190. }
  191. }
  192. entity.MPUploaderTwo = LoginUserInfo.Get().userId;
  193. mP_ManagementPlanIBLL.SaveEntity(keyValue, entity);
  194. return Success("保存成功!");
  195. }
  196. public void PushWeixin(string MPId)
  197. {
  198. var title = "";
  199. //获取内控模板信息
  200. var mpEntity = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(MPId);
  201. //根据部门获取所有需要推送的人员
  202. var UserList = new List<UserEntity>();
  203. if (mpEntity != null)
  204. {
  205. var departmentList = mpEntity.MPDepartment.Split(',').ToList();
  206. foreach (var departmentId in departmentList)
  207. {
  208. var entityList=userIBLL.GetListByDepartmentId(departmentId);
  209. if (entityList.Count>0)
  210. {
  211. UserList.Union(entityList);
  212. }
  213. }
  214. switch (mpEntity.MPType)
  215. {
  216. case 0:
  217. title = "您有内控检查材料需要上传,请查看";
  218. break;
  219. case 1:
  220. title = "您有绩效测试材料需要上传,请查看";
  221. break;
  222. case 2:
  223. title = "您有质量测试材料需要上传,请查看";
  224. break;
  225. }
  226. }
  227. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  228. string appid = WeChatConfigentity.APPId;
  229. string secret = WeChatConfigentity.secret;
  230. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  231. string weixintaskurl = wechatemplete.TUrl;
  232. string weixintasktempid = wechatemplete.TempId;
  233. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  234. OperateLogModel operateLogModel = new OperateLogModel();
  235. operateLogModel.title = title;
  236. operateLogModel.type = OperationType.Other;
  237. operateLogModel.url = "NoticeController";
  238. operateLogModel.sourceObjectId = "002";
  239. operateLogModel.sourceContentJson = responsejson;
  240. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  241. foreach (UserEntity userinfo in UserList)
  242. {
  243. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  244. {
  245. //执行推送任务
  246. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  247. {
  248. if (!string.IsNullOrEmpty(responsejson))
  249. {
  250. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  251. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  252. {
  253. string access_token = weixintokenobj.access_token;
  254. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  255. "\"template_id\":\"" + weixintasktempid + "\"," +
  256. "\"url\":\"" + weixintaskurl + "\"," +
  257. "\"data\":{" +
  258. "\"first\": {\"value\":\"您有新的未读通知公告\",\"color\":\"#173177\"}," +
  259. "\"keyword1\":{\"value\":\"未读通知公告\",\"color\":\"#173177\"}," +
  260. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  261. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  262. "\"keyword4\": {\"value\":\"您有新的未读通知公告【" + title + "】\",\"color\":\"#173177\"}" +
  263. "}" +
  264. "}";
  265. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  266. operateLogModel.title = title;
  267. operateLogModel.type = OperationType.Other;
  268. operateLogModel.url = "NoticeController";
  269. operateLogModel.sourceObjectId = "002";
  270. operateLogModel.sourceContentJson = pushresult;
  271. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  272. }
  273. }
  274. }
  275. }
  276. }
  277. }
  278. #endregion
  279. }
  280. }