From 961073ec96bfbb920f9afd952052c20b3791eb4d Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期二, 15 二月 2022 10:45:04 +0800 Subject: [PATCH] update 优化 TreeBuildUtils 工具 使用反射自动获取顶级父id --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java | 121 +++++++++++++++++++++++++++++++--------- 1 files changed, 93 insertions(+), 28 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java index 5489815..8610d97 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java @@ -1,76 +1,141 @@ package com.ruoyi.system.service.impl; -import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ArrayUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.core.domain.PageQuery; +import com.ruoyi.common.core.domain.dto.OperLogDTO; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.core.service.OperLogService; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.ip.AddressUtils; import com.ruoyi.system.domain.SysOperLog; import com.ruoyi.system.mapper.SysOperLogMapper; import com.ruoyi.system.service.ISysOperLogService; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; /** * 鎿嶄綔鏃ュ織 鏈嶅姟灞傚鐞� - * - * @author ruoyi + * + * @author Lion Li */ +@RequiredArgsConstructor @Service -public class SysOperLogServiceImpl implements ISysOperLogService -{ - @Autowired - private SysOperLogMapper operLogMapper; +public class SysOperLogServiceImpl implements ISysOperLogService, OperLogService { + + private final SysOperLogMapper baseMapper; + + /** + * 鎿嶄綔鏃ュ織璁板綍 + * + * @param operLogDTO 鎿嶄綔鏃ュ織淇℃伅 + */ + @Async + @Override + public void recordOper(final OperLogDTO operLogDTO) { + SysOperLog operLog = BeanUtil.toBean(operLogDTO, SysOperLog.class); + // 杩滅▼鏌ヨ鎿嶄綔鍦扮偣 + operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp())); + insertOperlog(operLog); + } + + @Override + public TableDataInfo<SysOperLog> selectPageOperLogList(SysOperLog operLog, PageQuery pageQuery) { + Map<String, Object> params = operLog.getParams(); + LambdaQueryWrapper<SysOperLog> lqw = new LambdaQueryWrapper<SysOperLog>() + .like(StringUtils.isNotBlank(operLog.getTitle()), SysOperLog::getTitle, operLog.getTitle()) + .eq(operLog.getBusinessType() != null && operLog.getBusinessType() > 0, + SysOperLog::getBusinessType, operLog.getBusinessType()) + .func(f -> { + if (ArrayUtil.isNotEmpty(operLog.getBusinessTypes())) { + f.in(SysOperLog::getBusinessType, Arrays.asList(operLog.getBusinessTypes())); + } + }) + .eq(operLog.getStatus() != null, + SysOperLog::getStatus, operLog.getStatus()) + .like(StringUtils.isNotBlank(operLog.getOperName()), SysOperLog::getOperName, operLog.getOperName()) + .between(params.get("beginTime") != null && params.get("endTime") != null, + SysOperLog::getOperTime, params.get("beginTime"), params.get("endTime")); + if (StringUtils.isBlank(pageQuery.getOrderByColumn())) { + pageQuery.setOrderByColumn("oper_id"); + pageQuery.setIsAsc("desc"); + } + Page<SysOperLog> page = baseMapper.selectPage(pageQuery.build(), lqw); + return TableDataInfo.build(page); + } /** * 鏂板鎿嶄綔鏃ュ織 - * + * * @param operLog 鎿嶄綔鏃ュ織瀵硅薄 */ @Override - public void insertOperlog(SysOperLog operLog) - { - operLogMapper.insertOperlog(operLog); + public void insertOperlog(SysOperLog operLog) { + operLog.setOperTime(new Date()); + baseMapper.insert(operLog); } /** * 鏌ヨ绯荤粺鎿嶄綔鏃ュ織闆嗗悎 - * + * * @param operLog 鎿嶄綔鏃ュ織瀵硅薄 * @return 鎿嶄綔鏃ュ織闆嗗悎 */ @Override - public List<SysOperLog> selectOperLogList(SysOperLog operLog) - { - return operLogMapper.selectOperLogList(operLog); + public List<SysOperLog> selectOperLogList(SysOperLog operLog) { + Map<String, Object> params = operLog.getParams(); + return baseMapper.selectList(new LambdaQueryWrapper<SysOperLog>() + .like(StringUtils.isNotBlank(operLog.getTitle()), SysOperLog::getTitle, operLog.getTitle()) + .eq(operLog.getBusinessType() != null && operLog.getBusinessType() > 0, + SysOperLog::getBusinessType, operLog.getBusinessType()) + .func(f -> { + if (ArrayUtil.isNotEmpty(operLog.getBusinessTypes())) { + f.in(SysOperLog::getBusinessType, Arrays.asList(operLog.getBusinessTypes())); + } + }) + .eq(operLog.getStatus() != null && operLog.getStatus() > 0, + SysOperLog::getStatus, operLog.getStatus()) + .like(StringUtils.isNotBlank(operLog.getOperName()), SysOperLog::getOperName, operLog.getOperName()) + .between(params.get("beginTime") != null && params.get("endTime") != null, + SysOperLog::getOperTime, params.get("beginTime"), params.get("endTime")) + .orderByDesc(SysOperLog::getOperId)); } /** * 鎵归噺鍒犻櫎绯荤粺鎿嶄綔鏃ュ織 - * + * * @param operIds 闇�瑕佸垹闄ょ殑鎿嶄綔鏃ュ織ID * @return 缁撴灉 */ @Override - public int deleteOperLogByIds(Long[] operIds) - { - return operLogMapper.deleteOperLogByIds(operIds); + public int deleteOperLogByIds(Long[] operIds) { + return baseMapper.deleteBatchIds(Arrays.asList(operIds)); } /** * 鏌ヨ鎿嶄綔鏃ュ織璇︾粏 - * + * * @param operId 鎿嶄綔ID * @return 鎿嶄綔鏃ュ織瀵硅薄 */ @Override - public SysOperLog selectOperLogById(Long operId) - { - return operLogMapper.selectOperLogById(operId); + public SysOperLog selectOperLogById(Long operId) { + return baseMapper.selectById(operId); } /** * 娓呯┖鎿嶄綔鏃ュ織 */ @Override - public void cleanOperLog() - { - operLogMapper.cleanOperLog(); + public void cleanOperLog() { + baseMapper.delete(new LambdaQueryWrapper<>()); } } -- Gitblit v1.9.3