LogService.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using Lottomat.Application.Entity.SystemManage;
  2. using Lottomat.Application.IService.SystemManage;
  3. using Lottomat.Data.Repository;
  4. using Lottomat.Util;
  5. using Lottomat.Util.Extension;
  6. using Lottomat.Util.WebControl;
  7. using System;
  8. using System.Collections.Generic;
  9. using Lottomat.Application.Code;
  10. using Lottomat.Utils.Date;
  11. using Lottomat.Utils.Web;
  12. using Newtonsoft.Json.Linq;
  13. namespace Lottomat.Application.Service.SystemManage
  14. {
  15. /// <summary>
  16. /// 版 本 1.0
  17. /// Copyright (c) 2016-2017
  18. /// 创建人:赵轶
  19. /// 日 期:2016.1.8 9:56
  20. /// 描 述:系统日志
  21. /// </summary>
  22. public class LogService : RepositoryFactory<LogEntity>, ILogService
  23. {
  24. #region 获取数据
  25. /// <summary>
  26. /// 日志列表
  27. /// </summary>
  28. /// <param name="pagination">分页</param>
  29. /// <param name="queryJson">查询参数</param>
  30. /// <returns></returns>
  31. public IEnumerable<LogEntity> GetPageList(Pagination pagination, string queryJson)
  32. {
  33. var expression = LinqExtensions.True<LogEntity>();
  34. JObject queryParam = queryJson.ToJObject();
  35. if (queryParam != null)
  36. {
  37. //日志分类
  38. if (!queryParam["Category"].IsEmpty())
  39. {
  40. int categoryId = queryParam["CategoryId"].ToInt();
  41. expression = expression.And(t => t.CategoryId == categoryId);
  42. }
  43. //操作时间
  44. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  45. {
  46. DateTime startTime = queryParam["StartTime"].ToDate();
  47. DateTime endTime = queryParam["EndTime"].ToDate().AddDays(1);
  48. expression = expression.And(t => t.OperateTime >= startTime && t.OperateTime <= endTime);
  49. }
  50. //操作用户Id
  51. if (!queryParam["OperateUserId"].IsEmpty())
  52. {
  53. string OperateUserId = queryParam["OperateUserId"].ToString();
  54. expression = expression.And(t => t.OperateUserId == OperateUserId);
  55. }
  56. //操作用户账户
  57. if (!queryParam["OperateAccount"].IsEmpty())
  58. {
  59. string OperateAccount = queryParam["OperateAccount"].ToString();
  60. expression = expression.And(t => t.OperateAccount.Contains(OperateAccount));
  61. }
  62. //操作类型
  63. if (!queryParam["OperateType"].IsEmpty())
  64. {
  65. string operateType = queryParam["OperateType"].ToString();
  66. expression = expression.And(t => t.OperateType == operateType);
  67. }
  68. //功能模块
  69. if (!queryParam["Module"].IsEmpty())
  70. {
  71. string module = queryParam["Module"].ToString();
  72. expression = expression.And(t => t.Module.Contains(module));
  73. }
  74. }
  75. return this.BaseRepository().FindList(expression, pagination);
  76. }
  77. /// <summary>
  78. /// 日志实体
  79. /// </summary>
  80. /// <param name="keyValue">主键值</param>
  81. /// <returns></returns>
  82. public LogEntity GetEntity(string keyValue)
  83. {
  84. return this.BaseRepository().FindEntity(keyValue);
  85. }
  86. #endregion
  87. #region 提交数据
  88. /// <summary>
  89. /// 清空日志
  90. /// </summary>
  91. /// <param name="categoryId">日志分类Id</param>
  92. /// <param name="keepTime">保留时间段内</param>
  93. public void RemoveLog(int categoryId, string keepTime)
  94. {
  95. DateTime operateTime = DateTimeHelper.Now;
  96. if (keepTime == "7")//保留近一周
  97. {
  98. operateTime = DateTimeHelper.Now.AddDays(-7);
  99. }
  100. else if (keepTime == "1")//保留近一个月
  101. {
  102. operateTime = DateTimeHelper.Now.AddMonths(-1);
  103. }
  104. else if (keepTime == "3")//保留近三个月
  105. {
  106. operateTime = DateTimeHelper.Now.AddMonths(-3);
  107. }
  108. var expression = LinqExtensions.True<LogEntity>();
  109. expression = expression.And(t => t.OperateTime <= operateTime);
  110. expression = expression.And(t => t.CategoryId == categoryId);
  111. this.BaseRepository().Delete(expression);
  112. }
  113. /// <summary>
  114. /// 写日志
  115. /// </summary>
  116. /// <param name="logEntity">对象</param>
  117. public void WriteLog(LogEntity logEntity)
  118. {
  119. logEntity.LogId = CommonHelper.GetGuid().ToString();
  120. logEntity.OperateTime = DateTimeHelper.Now;
  121. logEntity.DeleteMark = (int)DeleteMarkEnum.NotDelete;
  122. logEntity.EnabledMark = (int)EnabledMarkEnum.Enabled;
  123. logEntity.IPAddress = NetHelper.Ip;
  124. logEntity.Host = NetHelper.Host;
  125. logEntity.Browser = NetHelper.Browser;
  126. this.BaseRepository().Insert(logEntity);
  127. }
  128. #endregion
  129. }
  130. }