爱思开
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.

94 lines
3.5 KiB

2 years ago
  1. using NFine.Code;
  2. using NFine.Domain.Entity.SystemSecurity;
  3. using NFine.Domain.IRepository.SystemSecurity;
  4. using NFine.Repository.SystemSecurity;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace NFine.Application.SystemSecurity
  8. {
  9. public class LogApp
  10. {
  11. private ILogRepository service = new LogRepository();
  12. public List<LogEntity> GetList(Pagination pagination, string queryJson)
  13. {
  14. var expression = ExtLinq.True<LogEntity>();
  15. var queryParam = queryJson.ToJObject();
  16. if (!queryParam["keyword"].IsEmpty())
  17. {
  18. string keyword = queryParam["keyword"].ToString();
  19. expression = expression.And(t => t.F_Account.Contains(keyword));
  20. }
  21. if (!queryParam["timeType"].IsEmpty())
  22. {
  23. string timeType = queryParam["timeType"].ToString();
  24. DateTime startTime = DateTime.Now.ToString("yyyy-MM-dd").ToDate();
  25. DateTime endTime = DateTime.Now.ToString("yyyy-MM-dd").ToDate().AddDays(1);
  26. switch (timeType)
  27. {
  28. case "1":
  29. break;
  30. case "2":
  31. startTime = DateTime.Now.AddDays(-7);
  32. break;
  33. case "3":
  34. startTime = DateTime.Now.AddMonths(-1);
  35. break;
  36. case "4":
  37. startTime = DateTime.Now.AddMonths(-3);
  38. break;
  39. default:
  40. break;
  41. }
  42. expression = expression.And(t => t.F_Date >= startTime && t.F_Date <= endTime);
  43. }
  44. return service.FindList(expression, pagination);
  45. }
  46. public void RemoveLog(string keepTime)
  47. {
  48. DateTime operateTime = DateTime.Now;
  49. if (keepTime == "7") //保留近一周
  50. {
  51. operateTime = DateTime.Now.AddDays(-7);
  52. }
  53. else if (keepTime == "1") //保留近一个月
  54. {
  55. operateTime = DateTime.Now.AddMonths(-1);
  56. }
  57. else if (keepTime == "3") //保留近三个月
  58. {
  59. operateTime = DateTime.Now.AddMonths(-3);
  60. }
  61. var expression = ExtLinq.True<LogEntity>();
  62. expression = expression.And(t => t.F_Date <= operateTime);
  63. service.Delete(expression);
  64. }
  65. public void WriteDbLog(bool result, string resultLog)
  66. {
  67. LogEntity logEntity = new LogEntity();
  68. logEntity.F_Id = Common.GuId();
  69. logEntity.F_Date = DateTime.Now;
  70. logEntity.F_Account = OperatorProvider.Provider.GetCurrent().UserCode;
  71. logEntity.F_NickName = OperatorProvider.Provider.GetCurrent().UserName;
  72. logEntity.F_IPAddress = Net.Ip;
  73. logEntity.F_IPAddressName = Net.GetLocation(logEntity.F_IPAddress);
  74. logEntity.F_Result = result;
  75. logEntity.F_Description = resultLog;
  76. logEntity.Create();
  77. service.Insert(logEntity);
  78. }
  79. public void WriteDbLog(LogEntity logEntity)
  80. {
  81. logEntity.F_Id = Common.GuId();
  82. logEntity.F_Date = DateTime.Now;
  83. logEntity.F_IPAddress = "117.81.192.182";
  84. logEntity.F_IPAddressName = Net.GetLocation(logEntity.F_IPAddress);
  85. logEntity.Create();
  86. service.Insert(logEntity);
  87. }
  88. }
  89. }