package com.dxhy.jxpt.baseService.config.service.impl;

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.api.model.config.sys.SysLogEntity;
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 com.dxhy.jxpt.baseService.config.dao.SysLogDao;
import com.dxhy.jxpt.baseService.config.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author jiaohongyang
 */
@Service("baseServicesysLogService")
@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);
    }
}
