package org.jeecg.config.ureport;

import com.bstek.ureport.UReportPropertyPlaceholderConfigurer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Slf4j
@Configuration
@ConditionalOnBean(UReportConfig.class)
public class PropertiesConfig extends UReportPropertyPlaceholderConfigurer implements InitializingBean {

    @Override
    public void afterPropertiesSet() throws Exception {
        // 将配置追加到UReport的配置类中
        setProperties(loadProperties());
    }

    /**
     * 加载配置文件
     */
    private Properties loadProperties() throws IOException {
        ClassPathResource classPathResource = new ClassPathResource("ureport.properties");
        InputStream inputStream = classPathResource.getInputStream();
        Properties properties = new Properties();
        properties.load(inputStream);
        return properties;
    }
}
