package com.fjhx.service.system.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.entity.system.SystemConfig;
import com.fjhx.mapper.system.SystemConfigMapper;
import com.fjhx.service.system.SystemConfigService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 参数配置表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-12-08
 */
@Service
public class SystemConfigServiceImpl extends ServiceImpl<SystemConfigMapper, SystemConfig> implements SystemConfigService {

    @Override
    public <T> T getValue(String key, Class<T> cls) {
        return JSONObject.parseObject(getValue(key), cls);
    }

    @Override
    public String getValue(String key) {
        SystemConfig config = getOne(q -> q.eq(SystemConfig::getConfigKey, key));
        if (config == null) return null;
        return config.getConfigValue();
    }
}
