package com.kingdee.eas.custom.sendmessage.utils;

import com.kingdee.bos.BOSException;
import org.apache.log4j.Logger;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;

// 用于获取消息配置的类
public class GetMessageConfig {

    private static Logger logger = Logger.getLogger(GetMessageConfig.class);
// 获取属性配置的方法
    public static Properties getProp() throws BOSException {
        Properties properties = new Properties();
        String syncOAConfigPath = System.getProperty("EAS_HOME") + "/server/properties/gyt/sendMessage.properties";
        BufferedReader reader = null;

        try {
            reader = Files.newBufferedReader(Paths.get(syncOAConfigPath), StandardCharsets.UTF_8);
            properties.load(reader);
        } catch (IOException e) {
            String errorMsg = "获取配置文件报错，请检查配置：" + syncOAConfigPath + "   " + e.getMessage();
            throw new BOSException(errorMsg, e);
        } finally {
            // 确保资源被关闭
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException closeException) {
                    closeException.printStackTrace();
                }
            }
        }

        return properties;
    }


}
