All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.didiglobal.logi.security.dao.impl.OplogDaoImpl Maven / Gradle / Ivy

Go to download

logi-security 提供项目大多都需要的一些基础功能(用户、角色、权限、登录、注册、操作记录)

There is a newer version: 2.10.19
Show newest version
package com.didiglobal.logi.security.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.didiglobal.logi.security.common.constant.FieldConstant;
import com.didiglobal.logi.security.common.dto.oplog.OplogQueryDTO;
import com.didiglobal.logi.security.common.entity.Oplog;
import com.didiglobal.logi.security.common.po.OplogPO;
import com.didiglobal.logi.security.dao.OplogDao;
import com.didiglobal.logi.security.dao.mapper.OplogMapper;
import com.didiglobal.logi.security.util.CopyBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.sql.Timestamp;

/**
 * @author cjm
 */
@Component
public class OplogDaoImpl extends BaseDaoImpl implements OplogDao {

    @Autowired
    private OplogMapper oplogMapper;

    @Override
    public IPage selectPageWithoutDetail(OplogQueryDTO queryDTO) {
        // 分页查询
        IPage pageInfo = new Page<>(queryDTO.getPage(), queryDTO.getSize());

        QueryWrapper queryWrapper = getQueryWrapperWithAppName();
        // 不查找detail字段
        queryWrapper.select(OplogPO.class, oplog -> !FieldConstant.DETAIL.equals(oplog.getColumn()));
        String operatorIp = queryDTO.getOperatorIp();
        String operatorUsername = queryDTO.getOperatorUsername();
        queryWrapper
                .eq(queryDTO.getOperateType() != null, FieldConstant.OPERATE_TYPE, queryDTO.getOperateType())
                .eq(queryDTO.getTargetType() != null, FieldConstant.TARGET_TYPE, queryDTO.getTargetType())
                .eq(queryDTO.getTargetType() != null, FieldConstant.TARGET_TYPE, queryDTO.getTargetType())
                .like(!StringUtils.isEmpty(queryDTO.getTarget()), FieldConstant.TARGET, queryDTO.getTarget())
                .like(!StringUtils.isEmpty(operatorIp), FieldConstant.OPERATOR_IP, operatorIp)
                .like(!StringUtils.isEmpty(operatorUsername), FieldConstant.OPERATOR_USERNAME, operatorUsername);
        if(queryDTO.getStartTime() != null) {
            queryWrapper.ge(FieldConstant.CREATE_TIME, new Timestamp(queryDTO.getStartTime()));
        }
        if(queryDTO.getEndTime() != null) {
            queryWrapper.le(FieldConstant.CREATE_TIME, new Timestamp(queryDTO.getEndTime()));
        }

        queryWrapper.orderByDesc(FieldConstant.UPDATE_TIME);

        pageInfo.setTotal(oplogMapper.selectCount(queryWrapper));
        return CopyBeanUtil.copyPage(oplogMapper.selectPage(pageInfo, queryWrapper), Oplog.class);
    }

    @Override
    public Oplog selectByOplogId(Integer oplogId) {
        if(oplogId == null) {
            return null;
        }
        QueryWrapper queryWrapper = getQueryWrapperWithAppName();
        queryWrapper.eq(FieldConstant.ID, oplogId);
        return CopyBeanUtil.copy(oplogMapper.selectOne(queryWrapper), Oplog.class);
    }

    @Override
    public void insert(Oplog oplog) {
        OplogPO oplogPO = CopyBeanUtil.copy(oplog, OplogPO.class);
        oplogPO.setAppName(logiSecurityProper.getAppName());
        oplogMapper.insert(oplogPO);
        oplog.setId(oplogPO.getId());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy