SysOperLogServiceImpl.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package com.ruoyi.system.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.util.ArrayUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
  6. import com.ruoyi.common.core.page.TableDataInfo;
  7. import com.ruoyi.common.core.service.OperLogService;
  8. import com.ruoyi.common.core.domain.dto.OperLogDTO;
  9. import com.ruoyi.common.utils.PageUtils;
  10. import com.ruoyi.common.utils.StringUtils;
  11. import com.ruoyi.common.utils.ip.AddressUtils;
  12. import com.ruoyi.system.domain.SysOperLog;
  13. import com.ruoyi.system.mapper.SysOperLogMapper;
  14. import com.ruoyi.system.service.ISysOperLogService;
  15. import org.springframework.scheduling.annotation.Async;
  16. import org.springframework.stereotype.Service;
  17. import java.util.Arrays;
  18. import java.util.Date;
  19. import java.util.List;
  20. import java.util.Map;
  21. /**
  22. * 操作日志 服务层处理
  23. *
  24. * @author ruoyi
  25. */
  26. @Service
  27. public class SysOperLogServiceImpl extends ServicePlusImpl<SysOperLogMapper, SysOperLog, SysOperLog> implements ISysOperLogService, OperLogService {
  28. /**
  29. * 操作日志记录
  30. *
  31. * @param operLogDTO 操作日志信息
  32. */
  33. @Async
  34. @Override
  35. public void recordOper(final OperLogDTO operLogDTO) {
  36. SysOperLog operLog = BeanUtil.toBean(operLogDTO, SysOperLog.class);
  37. // 远程查询操作地点
  38. operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp()));
  39. insertOperlog(operLog);
  40. }
  41. @Override
  42. public TableDataInfo<SysOperLog> selectPageOperLogList(SysOperLog operLog) {
  43. Map<String, Object> params = operLog.getParams();
  44. LambdaQueryWrapper<SysOperLog> lqw = new LambdaQueryWrapper<SysOperLog>()
  45. .like(StringUtils.isNotBlank(operLog.getTitle()), SysOperLog::getTitle, operLog.getTitle())
  46. .eq(operLog.getBusinessType() != null && operLog.getBusinessType() > 0,
  47. SysOperLog::getBusinessType, operLog.getBusinessType())
  48. .func(f -> {
  49. if (ArrayUtil.isNotEmpty(operLog.getBusinessTypes())) {
  50. f.in(SysOperLog::getBusinessType, Arrays.asList(operLog.getBusinessTypes()));
  51. }
  52. })
  53. .eq(operLog.getStatus() != null,
  54. SysOperLog::getStatus, operLog.getStatus())
  55. .like(StringUtils.isNotBlank(operLog.getOperName()), SysOperLog::getOperName, operLog.getOperName())
  56. .apply(StringUtils.isNotEmpty(params.get("beginTime")),
  57. "date_format(oper_time,'%y%m%d') >= date_format({0},'%y%m%d')",
  58. params.get("beginTime"))
  59. .apply(StringUtils.isNotEmpty(params.get("endTime")),
  60. "date_format(oper_time,'%y%m%d') <= date_format({0},'%y%m%d')",
  61. params.get("endTime"));
  62. return PageUtils.buildDataInfo(page(PageUtils.buildPage("oper_id","desc"), lqw));
  63. }
  64. /**
  65. * 新增操作日志
  66. *
  67. * @param operLog 操作日志对象
  68. */
  69. @Override
  70. public void insertOperlog(SysOperLog operLog) {
  71. operLog.setOperTime(new Date());
  72. save(operLog);
  73. }
  74. /**
  75. * 查询系统操作日志集合
  76. *
  77. * @param operLog 操作日志对象
  78. * @return 操作日志集合
  79. */
  80. @Override
  81. public List<SysOperLog> selectOperLogList(SysOperLog operLog) {
  82. Map<String, Object> params = operLog.getParams();
  83. return list(new LambdaQueryWrapper<SysOperLog>()
  84. .like(StringUtils.isNotBlank(operLog.getTitle()),SysOperLog::getTitle,operLog.getTitle())
  85. .eq(operLog.getBusinessType() != null && operLog.getBusinessType() > 0,
  86. SysOperLog::getBusinessType,operLog.getBusinessType())
  87. .func(f -> {
  88. if (ArrayUtil.isNotEmpty(operLog.getBusinessTypes())){
  89. f.in(SysOperLog::getBusinessType, Arrays.asList(operLog.getBusinessTypes()));
  90. }
  91. })
  92. .eq(operLog.getStatus() != null && operLog.getStatus() > 0,
  93. SysOperLog::getStatus,operLog.getStatus())
  94. .like(StringUtils.isNotBlank(operLog.getOperName()),SysOperLog::getOperName,operLog.getOperName())
  95. .apply(StringUtils.isNotEmpty(params.get("beginTime")),
  96. "date_format(oper_time,'%y%m%d') >= date_format({0},'%y%m%d')",
  97. params.get("beginTime"))
  98. .apply(StringUtils.isNotEmpty(params.get("endTime")),
  99. "date_format(oper_time,'%y%m%d') <= date_format({0},'%y%m%d')",
  100. params.get("endTime"))
  101. .orderByDesc(SysOperLog::getOperId));
  102. }
  103. /**
  104. * 批量删除系统操作日志
  105. *
  106. * @param operIds 需要删除的操作日志ID
  107. * @return 结果
  108. */
  109. @Override
  110. public int deleteOperLogByIds(Long[] operIds) {
  111. return baseMapper.deleteBatchIds(Arrays.asList(operIds));
  112. }
  113. /**
  114. * 查询操作日志详细
  115. *
  116. * @param operId 操作ID
  117. * @return 操作日志对象
  118. */
  119. @Override
  120. public SysOperLog selectOperLogById(Long operId) {
  121. return getById(operId);
  122. }
  123. /**
  124. * 清空操作日志
  125. */
  126. @Override
  127. public void cleanOperLog() {
  128. remove(new LambdaQueryWrapper<>());
  129. }
  130. }