package com.fs.his.utils;

import com.alibaba.fastjson.JSON;
import com.fs.his.config.FsErpConfig;
import com.fs.his.config.FsSysConfig;
import com.fs.system.domain.SysConfig;
import com.fs.system.mapper.SysConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ConfigUtil {
    FsSysConfig fsSysConfig;
    FsErpConfig fsErpConfig;
    @Autowired
    SysConfigMapper sysConfigMapper;
    public FsSysConfig getSysConfig(){
        if (this.fsSysConfig==null){
            SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.config");
            String configValue = sysConfig.getConfigValue();
            FsSysConfig config = JSON.parseObject(configValue, FsSysConfig.class);
            this.fsSysConfig=config;
            return this.fsSysConfig;
        }else {
            return this.fsSysConfig ;
        }
    }
    public FsErpConfig getErpConfig(){
        if (this.fsErpConfig==null){
            SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("erp.config");
            String configValue = sysConfig.getConfigValue();
            FsErpConfig config = JSON.parseObject(configValue, FsErpConfig.class);
            this.fsErpConfig=config;
            return this.fsErpConfig;
        }else {
            return this.fsErpConfig ;
        }
    }
}
