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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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.GenerateNearByYear();
  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 keyValueArr = keyValue.Split(',');
  141. foreach (var item in keyValueArr)
  142. {
  143. var entity = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(item);
  144. entity.MPConclusion = status ? 1 : 0;
  145. mP_ManagementPlanIBLL.SaveEntity(item, entity);
  146. }
  147. return Success("修改成功!");
  148. }
  149. /// <summary>
  150. /// 保存实体数据(新增、修改)
  151. /// <param name="keyValue">主键</param>
  152. /// <summary>
  153. /// <returns></returns>
  154. [HttpPost]
  155. [ValidateAntiForgeryToken]
  156. [AjaxOnly]
  157. public ActionResult SaveForm(string keyValue, string strEntity)
  158. {
  159. MP_ManageMentPlanEntity entity = strEntity.ToObject<MP_ManageMentPlanEntity>();
  160. entity.MPType = 0;
  161. mP_ManagementPlanIBLL.SaveEntity(keyValue, entity);
  162. return Success("保存成功!");
  163. }
  164. /// <summary>
  165. /// 保存实体数据(新增、修改)
  166. /// <param name="keyValue">主键</param>
  167. /// <summary>
  168. /// <returns></returns>
  169. [HttpPost]
  170. [ValidateAntiForgeryToken]
  171. [AjaxOnly]
  172. public ActionResult UploadForm(string keyValue, string strEntity)
  173. {
  174. MP_ManageMentPlanEntity entity = strEntity.ToObject<MP_ManageMentPlanEntity>();
  175. if (!string.IsNullOrEmpty(keyValue))
  176. {
  177. var entity2 = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(keyValue);
  178. if (!string.IsNullOrEmpty(entity.MPFileTwo))
  179. {
  180. entity.MPStatus = 0;//已提交
  181. entity.MPUploadTimes = $"{DateTime.Now.ToString()}, {entity2.MPUploadTimes}";
  182. entity.SUpdateTime = entity2.SUpdateTime + 1;
  183. }
  184. }
  185. else
  186. {
  187. entity.Create();
  188. if (!string.IsNullOrEmpty(entity.MPFileTwo))
  189. {
  190. entity.MPStatus = 0;//已提交
  191. entity.MPUploadTimes = DateTime.Now.ToString();
  192. entity.SUpdateTime = 1;
  193. entity.MPType = 0;
  194. }
  195. }
  196. entity.MPUploaderTwo = LoginUserInfo.Get().userId;
  197. mP_ManagementPlanIBLL.SaveEntity(keyValue, entity);
  198. return Success("保存成功!");
  199. }
  200. public void PushWeixin(string MPId)
  201. {
  202. var title = "";
  203. //获取内控模板信息
  204. var mpEntity = mP_ManagementPlanIBLL.GetMP_ManageMentPlanEntity(MPId);
  205. //根据部门获取所有需要推送的人员
  206. var UserList = new List<UserEntity>();
  207. if (mpEntity != null)
  208. {
  209. var departmentList = mpEntity.MPDepartment.Split(',').ToList();
  210. foreach (var departmentId in departmentList)
  211. {
  212. var entityList=userIBLL.GetListByDepartmentId(departmentId);
  213. if (entityList.Count>0)
  214. {
  215. UserList.Union(entityList);
  216. }
  217. }
  218. switch (mpEntity.MPType)
  219. {
  220. case 0:
  221. title = "您有内控检查材料需要上传,请查看";
  222. break;
  223. case 1:
  224. title = "您有绩效测试材料需要上传,请查看";
  225. break;
  226. case 2:
  227. title = "您有质量测试材料需要上传,请查看";
  228. break;
  229. }
  230. }
  231. var WeChatConfigentity = weChatConfigIbll.GetEnableEntity();
  232. string appid = WeChatConfigentity.APPId;
  233. string secret = WeChatConfigentity.secret;
  234. var wechatemplete = weChatTempletIbll.GetWeChatTemplateEntityByCodeConfigId(WeChatConfigentity.ID, "task");
  235. string weixintaskurl = wechatemplete.TUrl;
  236. string weixintasktempid = wechatemplete.TempId;
  237. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  238. OperateLogModel operateLogModel = new OperateLogModel();
  239. operateLogModel.title = title;
  240. operateLogModel.type = OperationType.Other;
  241. operateLogModel.url = "NoticeController";
  242. operateLogModel.sourceObjectId = "002";
  243. operateLogModel.sourceContentJson = responsejson;
  244. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  245. foreach (UserEntity userinfo in UserList)
  246. {
  247. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  248. {
  249. //执行推送任务
  250. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  251. {
  252. if (!string.IsNullOrEmpty(responsejson))
  253. {
  254. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  255. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  256. {
  257. string access_token = weixintokenobj.access_token;
  258. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  259. "\"template_id\":\"" + weixintasktempid + "\"," +
  260. "\"url\":\"" + weixintaskurl + "\"," +
  261. "\"data\":{" +
  262. "\"first\": {\"value\":\"您有新的未读通知公告\",\"color\":\"#173177\"}," +
  263. "\"keyword1\":{\"value\":\"未读通知公告\",\"color\":\"#173177\"}," +
  264. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  265. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  266. "\"keyword4\": {\"value\":\"您有新的未读通知公告【" + title + "】\",\"color\":\"#173177\"}" +
  267. "}" +
  268. "}";
  269. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  270. operateLogModel.title = title;
  271. operateLogModel.type = OperationType.Other;
  272. operateLogModel.url = "NoticeController";
  273. operateLogModel.sourceObjectId = "002";
  274. operateLogModel.sourceContentJson = pushresult;
  275. OperatorHelper.Instance.WriteOperateLog(operateLogModel);
  276. }
  277. }
  278. }
  279. }
  280. }
  281. }
  282. #endregion
  283. }
  284. }