SysOpLogDaoImpl.java 3.16 KB
package com.zteits.sys.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import org.apache.commons.lang3.StringUtils;
import com.clouds.common.utils.ListCopyUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.sys.param.SysOpLogQueryRequest;
import com.zteits.clouds.api.dto.sys.param.SysOpLogRequest;
import com.zteits.sys.dao.SysOpLogDao;
import com.zteits.sys.domain.SysOpLogExample;
import com.zteits.sys.domain.SysOpLogExample.Criteria;
import com.zteits.sys.domain.SysOpLogWithBLOBs;
import com.zteits.sys.mapper.SysOpLogMapper;
@Component
public class SysOpLogDaoImpl implements SysOpLogDao{
	
	@Autowired
	private SysOpLogMapper sysOpLogMapper;

	@Override
	public Integer saveSysOpLog(SysOpLogRequest req) {
		SysOpLogWithBLOBs sysOpLog = new SysOpLogWithBLOBs();
        if (req == null) {
            throw new BizException(ErrorType.PARAMM_NULL, "入参为空!");
        }
        BeanUtils.copyProperties(req, sysOpLog);
        int insertCount = sysOpLogMapper.insertSelective(sysOpLog);
        return insertCount;
	}

	@Override
	public Integer batchSaveSysOpLog(List<SysOpLogRequest> saveList) {
		List<SysOpLogWithBLOBs> sysOpLogs = new ArrayList<SysOpLogWithBLOBs>();
        if (CollectionUtils.isEmpty(saveList)) {
            throw new BizException(ErrorType.PARAMM_NULL, "入参为空!");
        }
        ListCopyUtil.listCopyProperties(saveList, sysOpLogs,SysOpLogWithBLOBs.class);
        saveList.parallelStream().forEach(e->{
        	 SysOpLogWithBLOBs s = new SysOpLogWithBLOBs();
        	 BeanUtils.copyProperties(e, s);
        	 sysOpLogMapper.insertSelective(s);
        });
        return saveList.size();
	}

	@Override
	public PageInfo<SysOpLogWithBLOBs> querySysOpLogForPage(SysOpLogQueryRequest request) {
		PageHelper.startPage(request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize());
    	SysOpLogExample example = new SysOpLogExample();
    	Criteria sql = example.createCriteria();
    	if(StringUtils.isNotEmpty(request.getOpCode())){
    		sql.andOpCodeLike("%"+request.getOpCode()+"%");
    	}
    	if(StringUtils.isNotEmpty(request.getOpName())){
    		sql.andOpNameLike("%"+request.getOpName()+"%");
    	}
    	if(StringUtils.isNotEmpty(request.getMethodDesc())){
    		sql.andMethodDescLike("%"+request.getMethodDesc()+"%");
    	}
        if(request.getBeginTime() != null){
        	sql.andCreateTimeGreaterThanOrEqualTo(request.getBeginTime());
        }
        if(request.getEndTime() != null){
        	sql.andCreateTimeLessThanOrEqualTo(request.getEndTime());
        }
        if(request.getOrgId() != null){
        	sql.andOrgIdEqualTo(request.getOrgId());
        }
        example.setOrderByClause("id desc");
        List<SysOpLogWithBLOBs> list = sysOpLogMapper.selectByExampleWithBLOBs(example);
        return new PageInfo<>(list);
	}
	
}