package com.dxhy.admin.sys.service.impl;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxhy.admin.sys.dao.SysLogDao;
import com.dxhy.admin.sys.entity.SysLogEntity;
import com.dxhy.admin.sys.service.SysLogService;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.utils.PageUtils;
import com.dxhy.common.utils.Query;

import lombok.extern.slf4j.Slf4j;

/**
 * @author jiaohongyang
 */
@Service("sysLogService")
@Slf4j
public class SysLogServiceImpl extends ServiceImpl<SysLogDao, SysLogEntity> implements SysLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        DynamicContextHolder.push(DbConstant.BASICS_READ);
        String key = (String)params.get("key");

        IPage<SysLogEntity> page = this.page(new Query<SysLogEntity>().getPage(params), new QueryWrapper<SysLogEntity>()
            .like(StringUtils.isNotBlank(key), "username", key).orderByDesc("create_date"));

        return new PageUtils(page);
    }
}
