package com.jiayue.ssi.service.impl;

import com.jiayue.ssi.entity.SysParameter;
import com.jiayue.ssi.mapper.SysParameterMapper;
import com.jiayue.ssi.service.SysParameterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


/**
* 参数管理服务类
* @author xsl
* @date 2023/2/16
*/
@Service
public class SysParameterServiceImpl extends ServiceImpl<SysParameterMapper, SysParameter> implements SysParameterService {
    @Autowired
    SysParameterMapper sysParameterMapper;

    /**
     * 根据账号查找
     * @param key
     * @param defaultValue 默认值
     * @return SysParameter
     */
    @Override
    public String queryByKey(String key,String defaultValue){
        LambdaQueryWrapper<SysParameter> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysParameter::getSysKey,key);
        SysParameter sysParameter = sysParameterMapper.selectOne(queryWrapper);
        if (sysParameter==null){
            return defaultValue;
        }
        return sysParameter.getSysValue();
    }
}
