OperateLogController.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Transactions;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using System.Web.Security;
  8. using DotNetOpenAuth.AspNet;
  9. using Microsoft.Web.WebPages.OAuth;
  10. using WebMatrix.WebData;
  11. using EMIS.CommonLogic.Log;
  12. using EMIS.ViewModel;
  13. using EMIS.Web.Controls;
  14. using Bowin.Common.Data;
  15. using Bowin.Web.Controls.Mvc;
  16. using Bowin.Common.Utility;
  17. namespace EMIS.Web.Controllers
  18. {
  19. [Authorization]
  20. public class OperateLogController : Controller
  21. {
  22. public IOperateLogServices OperateLogServices { get; set; }
  23. /// <summary>
  24. /// 操作日志页面
  25. /// </summary>
  26. /// <returns></returns>
  27. public ActionResult List()
  28. {
  29. return View();
  30. }
  31. /// <summary>
  32. /// 操作日志列表查询
  33. /// </summary>
  34. /// <param name="pararms"></param>
  35. /// <returns></returns>
  36. [HttpPost]
  37. public ActionResult List(QueryParamsModel pararms)
  38. {
  39. try
  40. {
  41. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  42. var startTime = pararms.getExtraDateTime("StartTime");
  43. var endTime = pararms.getExtraDateTime("EndTime");
  44. return base.Json(OperateLogServices.GetOperateLogViewList(configuretView, startTime.Value, endTime.Value, (int)pararms.page, (int)pararms.rows));
  45. }
  46. catch (Exception ex)
  47. {
  48. throw ex;
  49. }
  50. }
  51. /// <summary>
  52. /// 删除
  53. /// </summary>
  54. /// <param name="roleID"></param>
  55. /// <returns></returns>
  56. [HttpPost]
  57. public ActionResult Delete(string operateLogIDs)
  58. {
  59. try
  60. {
  61. var operateLogIDList = operateLogIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
  62. OperateLogServices.Delete(operateLogIDList);
  63. return base.Json("删除成功。");
  64. }
  65. catch (Exception ex)
  66. {
  67. return base.Json("删除失败,原因:" + ex.Message + "。");
  68. }
  69. }
  70. /// <summary>
  71. /// Excel导出
  72. /// </summary>
  73. /// <returns></returns>
  74. [HttpPost]
  75. public ActionResult Excel()
  76. {
  77. NpoiExcelHelper neh = new NpoiExcelHelper();
  78. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  79. var startTime = Request.Form["StartTime"].ParseStrTo<DateTime>();
  80. var endTime = Request.Form["EndTime"].ParseStrTo<DateTime>();
  81. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  82. var dt = OperateLogServices.GetOperateLogViewList(configuretView, startTime.Value, endTime.Value).Select(x => new
  83. {
  84. x.LoginID,
  85. x.UserName,
  86. x.IP,
  87. x.TableName,
  88. x.SourceUrl,
  89. x.Operate,
  90. x.Detail,
  91. x.IsSuccessDesc,
  92. x.OperateTime
  93. }).ToTable();
  94. string[] liststring = {
  95. "用户名", "姓名", "IP地址", "操作表名", "页面地址",
  96. "操作类型", "操作详情", "是否成功", "操作时间"
  97. };
  98. neh.Export(dt, liststring, "操作日志信息" + DateTime.Now.ToString("yyyyMMdd"));
  99. return RedirectToAction("MsgShow", "Common", new
  100. {
  101. msg = "导出成功。",
  102. url = Url.Content("~/OperateLog/List").AddMenuParameter()
  103. });
  104. }
  105. }
  106. }