package com.mosty.common.config.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.mosty.common.base.constant.enums.ConfigKeyEnum;
import com.mosty.common.base.constant.enums.DeletedEnum;
import com.mosty.common.config.entity.SysConfig;
import com.mosty.common.config.entity.SysDict;
import com.mosty.common.config.entity.vo.ConfigPage;
import com.mosty.common.config.entity.vo.DictPage;
import com.mosty.common.config.mapper.SysConfigMapper;
import com.mosty.common.config.mapper.SysDictMapper;
import com.mosty.common.config.service.SysConfigService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 参数配置表 服务实现类
 * </p>
 *
 * @author kevin
 * @since 2022-02-10
 */
@Service
@AllArgsConstructor
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {

    private final SysConfigMapper sysConfigMapper;

    @Override
    public IPage<SysConfig> selectByPage(ConfigPage page) {
        QueryWrapper<SysConfig> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(page.getConfigName())) {
            queryWrapper.and(wrapper -> wrapper.like("pzmc", page.getConfigName()));
        }
        if (StringUtils.isNotBlank(page.getConfigKey())) {
            queryWrapper.and(wrapper -> wrapper.eq("pzj", page.getConfigKey()));
        }
        queryWrapper.and(wrapper -> wrapper.eq("xt_zxbz", DeletedEnum.NATURE.code));
//        LambdaQueryWrapper<SysConfig> eq = new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getPzmc, page.getConfigName());
        return getBaseMapper().selectPage(page, queryWrapper);
    }

    @Override
    public SysConfig getOneByKey(ConfigKeyEnum passwordLevel) {
        SysConfig one = this.getOne(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getPzj, passwordLevel.code)
                .eq(SysConfig::getXtZxbz, DeletedEnum.NATURE.code));
        return one;
    }


}
