package com.jd.lightapplication.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import  com.jd.lightapplication.model.ConfigInfo;
import  com.jd.lightapplication.mapper.ConfigInfoMapper;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;


@Service
public class ConfigInfoService extends ServiceImpl<ConfigInfoMapper,ConfigInfo> {
    public IPage<ConfigInfo> page(Page page, ConfigInfo configInfo){
        LambdaQueryWrapper<ConfigInfo> wrapper = new LambdaQueryWrapper<>();
        if(StrUtil.isNotBlank(configInfo.getRemark())){
            wrapper.like(ConfigInfo::getRemark,configInfo.getRemark());
        }
        wrapper.orderByDesc(ConfigInfo::getCreateTime);
        return baseMapper.selectPage(page,wrapper);
    }

    public ConfigInfo findByKey(String key) {
        if(StrUtil.isBlank(key))
            return null;
        LambdaQueryWrapper<ConfigInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ConfigInfo::getConfigKey,key);
        return baseMapper.selectOne(wrapper);
    }
}