LogOperateService.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Common;
  4. using System.Linq;
  5. using System.Linq.Expressions;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using YiSha.Data;
  9. using YiSha.Data.Repository;
  10. using YiSha.Entity.SystemManage;
  11. using YiSha.Enum;
  12. using YiSha.Model.Param.SystemManage;
  13. using YiSha.Util.Extension;
  14. using YiSha.Util.Model;
  15. namespace YiSha.Service.SystemManage
  16. {
  17. public partial class LogOperateService
  18. {
  19. private IRepositoryFactory _baseRepository;
  20. public LogOperateService(IRepositoryFactory baseRepository)
  21. {
  22. _baseRepository = baseRepository;
  23. }
  24. #region 获取数据
  25. public async Task<List<LogOperateEntity>> GetListPartial(LogOperateListParam param)
  26. {
  27. var strSql = new StringBuilder();
  28. List<DbParameter> filter = ListFilterPartial(param, strSql);
  29. var list = await _baseRepository.BaseRepository(dbConnectType).FindList<LogOperateEntity>(strSql.ToString(), filter.ToArray());
  30. return list.ToList();
  31. }
  32. public async Task<List<LogOperateEntity>> GetPageListPartial(LogOperateListParam param, Pagination pagination)
  33. {
  34. var strSql = new StringBuilder();
  35. List<DbParameter> filter = ListFilterPartial(param, strSql);
  36. var list = await _baseRepository.BaseRepository(dbConnectType).FindList<LogOperateEntity>(strSql.ToString(), filter.ToArray(), pagination);
  37. return list.ToList();
  38. }
  39. public async Task<LogOperateEntity> GetEntityPartial(int id)
  40. {
  41. return await _baseRepository.BaseRepository(dbConnectType).FindEntity<LogOperateEntity>(id);
  42. }
  43. #endregion
  44. #region 提交数据
  45. public async Task SaveFormPartial(LogOperateEntity entity)
  46. {
  47. if (entity.Id.IsNullOrZero())
  48. {
  49. await entity.Create();
  50. await _baseRepository.BaseRepository(dbConnectType).Insert(entity);
  51. }
  52. else
  53. {
  54. await _baseRepository.BaseRepository(dbConnectType).Update(entity);
  55. }
  56. }
  57. public async Task RemoveAllFormPartial()
  58. {
  59. await _baseRepository.BaseRepository(dbConnectType).ExecuteBySql("truncate table SysLogOperate");
  60. }
  61. #endregion
  62. #region 私有方法
  63. private List<DbParameter> ListFilterPartial(LogOperateListParam param, StringBuilder strSql)
  64. {
  65. strSql.Append(@"SELECT a.Id,
  66. a.BaseCreateTime,
  67. a.BaseCreatorId,
  68. a.LogStatus,
  69. a.IpAddress,
  70. a.IpLocation,
  71. a.Remark,
  72. a.ExecuteUrl,
  73. a.ExecuteParam,
  74. a.ExecuteResult,
  75. a.ExecuteTime,
  76. b.UserName,
  77. c.DepartmentName
  78. FROM SysLogOperate a
  79. LEFT JOIN SysUser b ON a.BaseCreatorId = b.Id
  80. LEFT JOIN SysDepartment c ON b.DepartmentId = c.Id
  81. WHERE 1 = 1 and a.BaseIsDelete = @BaseIsDelete ");
  82. var parameter = new List<DbParameter>();
  83. parameter.Add(DbParameterExtension.CreateDbParameter("@BaseIsDelete", (int)IsDeleteEnum.No, dbConnectType));
  84. if (param != null)
  85. {
  86. if (!string.IsNullOrEmpty(param.UserName))
  87. {
  88. strSql.Append(" AND b.UserName like @UserName");
  89. parameter.Add(DbParameterExtension.CreateDbParameter("@UserName", '%' + param.UserName + '%', dbConnectType));
  90. }
  91. if (param.LogStatus > -1)
  92. {
  93. strSql.Append(" AND a.LogStatus = @LogStatus");
  94. parameter.Add(DbParameterExtension.CreateDbParameter("@LogStatus", param.LogStatus, dbConnectType));
  95. }
  96. if (!string.IsNullOrEmpty(param.ExecuteUrl))
  97. {
  98. strSql.Append(" AND a.ExecuteUrl like @ExecuteUrl");
  99. parameter.Add(DbParameterExtension.CreateDbParameter("@ExecuteUrl", '%' + param.ExecuteUrl + '%', dbConnectType));
  100. }
  101. if (!string.IsNullOrEmpty(param.StartTime.ParseToString()))
  102. {
  103. strSql.Append(" AND a.BaseCreateTime >= @StartTime");
  104. parameter.Add(DbParameterExtension.CreateDbParameter("@StartTime", param.StartTime, dbConnectType));
  105. }
  106. if (!string.IsNullOrEmpty(param.EndTime.ParseToString()))
  107. {
  108. param.EndTime = param.EndTime.Value.Date.Add(new TimeSpan(23, 59, 59));
  109. strSql.Append(" AND a.BaseCreateTime <= @EndTime");
  110. parameter.Add(DbParameterExtension.CreateDbParameter("@EndTime", param.EndTime, dbConnectType));
  111. }
  112. }
  113. return parameter;
  114. }
  115. /// <summary>
  116. /// 列表条件过滤
  117. /// 建议该方法放在Partial部分类中,因为代码生成时当前类会被覆盖(该方法在生成时将会被注释)
  118. /// </summary>
  119. /// <param name="param"></param>
  120. /// <returns></returns>
  121. private Expression<Func<LogOperateEntity, bool>> ListFilterPartial(LogOperateListParam param)
  122. {
  123. var expression = LinqExtensions.True<LogOperateEntity>();
  124. expression = expression.And(t => t.BaseIsDelete == (int)IsDeleteEnum.No);
  125. if (param != null)
  126. {
  127. }
  128. return expression;
  129. }
  130. #endregion
  131. }
  132. }