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 static com.didiglobal.logi.security.common.constant.FieldConstant.CREATE_TIME;
import static com.didiglobal.logi.security.common.constant.FieldConstant.DETAIL;
import static com.didiglobal.logi.security.common.constant.FieldConstant.ID;
import static com.didiglobal.logi.security.common.constant.FieldConstant.OPERATE_TYPE;
import static com.didiglobal.logi.security.common.constant.FieldConstant.OPERATION_METHODS;
import static com.didiglobal.logi.security.common.constant.FieldConstant.OPERATOR;
import static com.didiglobal.logi.security.common.constant.FieldConstant.OPERATOR_IP;
import static com.didiglobal.logi.security.common.constant.FieldConstant.TARGET;
import static com.didiglobal.logi.security.common.constant.FieldConstant.TARGET_TYPE;
import static com.didiglobal.logi.security.common.constant.FieldConstant.UPDATE_TIME;

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 java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

/**
 * @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();
        queryWrapper
                .eq(queryDTO.getOperateType() != null, OPERATE_TYPE, queryDTO.getOperateType())
                .eq(queryDTO.getTargetType() != null, TARGET_TYPE, queryDTO.getTargetType())
            .eq(StringUtils.hasText(queryDTO.getOperationMethods()),OPERATION_METHODS, queryDTO.getOperationMethods())
                .like(!StringUtils.isEmpty(queryDTO.getDetail()), DETAIL, queryDTO.getDetail())
                .like(!StringUtils.isEmpty(queryDTO.getTarget()), TARGET, queryDTO.getTarget())
                .like(!StringUtils.isEmpty(queryDTO.getOperator()), OPERATOR, queryDTO.getOperator());
        if(queryDTO.getStartTime() != null) {
            queryWrapper.ge(CREATE_TIME, new Timestamp(queryDTO.getStartTime()));
        }
        if(queryDTO.getEndTime() != null) {
            queryWrapper.le(CREATE_TIME, new Timestamp(queryDTO.getEndTime()));
        }

        queryWrapper.select(ID);
        pageInfo.setTotal(oplogMapper.selectCount(queryWrapper));

        queryWrapper.orderByDesc(UPDATE_TIME);
        queryWrapper.select(ID, OPERATE_TYPE, DETAIL, TARGET, TARGET_TYPE, OPERATOR_IP, OPERATOR, CREATE_TIME, UPDATE_TIME);
        oplogMapper.selectPage(pageInfo, queryWrapper);

        return CopyBeanUtil.copyPage(pageInfo, 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());
    }

    @Override
    public List listTargetType() {
        QueryWrapper queryWrapper = getQueryWrapperWithAppName();
        queryWrapper.select( "distinct " + TARGET_TYPE);
        List oplogPOS = oplogMapper.selectList(queryWrapper);

        if(!CollectionUtils.isEmpty(oplogPOS)){
            return oplogPOS.stream().map(OplogPO::getTargetType).collect(Collectors.toList());
        }

        return new ArrayList<>();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy