package com.seeyon.apps.jync_file.kit;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 读取参数
 */

public class PropKit {
	
	private static long lastModify;
	
	private static ConcurrentHashMap<String, String> props;
    
    public static final String PROFILE = "profile";
    
    public static final String PAYBILLFILEURL = "paybillFileUrl";
    public static final String GENERALBILLURL = "generalbillUrl";
    public static final String TRANSFORMURL = "transformUrl";
    public static final String XCFZCANCELURL = "xcfzCancelUrl";
    public static final String SBFZCANCELURL = "sbfzCancelUrl";
    public static final String OATOKENURL = "oaTokenUrl";
    public static final String DOWURL = "dowUrl";
    public static final String JYNCFILE = "jyncFile";
    public static final String RESTNAME = "restname";
    public static final String RESTPASSWORD = "restpassword";
    
    public static final String PROD_PAYBILLFILEURL = "prod.paybillFileUrl";
    public static final String PROD_GENERALBILLURL = "prod.generalbillUrl";
    public static final String PROD_TRANSFORMURL = "prod.transformUrl";
    public static final String PROD_XCFZCANCELURL = "prod.xcfzCancelUrl";
    public static final String PROD_SBFZCANCELURL = "prod.sbfzCancelUrl";
    public static final String PROD_OATOKENURL = "prod.oaTokenUrl";
    public static final String PROD_DOWURL = "prod.dowUrl";
    public static final String PROD_JYNCFILE = "prod.jyncFile";
    public static final String PROD_RESTNAME = "prod.restname";
    public static final String PROD_RESTPASSWORD = "prod.restpassword";
    
    /**
     * @return
     * @throws IOException 
     * @throws FileNotFoundException 
     */
    public static String getProp(String key) throws FileNotFoundException, IOException {
		File f = new File(A8FolderKit.getPropFile());
		if(null == props) {
			props = new ConcurrentHashMap<String, String>();
		}
		if(f.lastModified() != lastModify) {
			/**
			 * huangzhengguo 
			 * 2022-10-18
			 */
			Properties prop = new Properties();
			prop.load(new FileInputStream(f));
//			Properties prop = PropertiesUtil.getFromFile((CtpLocalFile) f);
			/**
			 * end
			 */
			String profile = prop.getProperty(PROFILE);
			if("prod".equals(profile)) {
				props.put(PAYBILLFILEURL, prop.getProperty(PROD_PAYBILLFILEURL));
				props.put(GENERALBILLURL, prop.getProperty(PROD_GENERALBILLURL));
				props.put(TRANSFORMURL, prop.getProperty(PROD_TRANSFORMURL));
				props.put(XCFZCANCELURL, prop.getProperty(PROD_XCFZCANCELURL));
				props.put(OATOKENURL, prop.getProperty(PROD_OATOKENURL));
				props.put(DOWURL, prop.getProperty(PROD_DOWURL));
				props.put(JYNCFILE, prop.getProperty(PROD_JYNCFILE));
				props.put(RESTNAME, prop.getProperty(PROD_RESTNAME));
				props.put(RESTPASSWORD, prop.getProperty(PROD_RESTPASSWORD));
				props.put(SBFZCANCELURL, prop.getProperty(PROD_SBFZCANCELURL));
			} else {
				props.put(PAYBILLFILEURL, prop.getProperty(PROD_PAYBILLFILEURL));
				props.put(GENERALBILLURL, prop.getProperty(PROD_GENERALBILLURL));
				props.put(TRANSFORMURL, prop.getProperty(PROD_TRANSFORMURL));
				props.put(XCFZCANCELURL, prop.getProperty(PROD_XCFZCANCELURL));
				props.put(OATOKENURL, prop.getProperty(PROD_OATOKENURL));
				props.put(DOWURL, prop.getProperty(PROD_DOWURL));
				props.put(JYNCFILE, prop.getProperty(PROD_JYNCFILE));
				props.put(RESTNAME, prop.getProperty(PROD_RESTNAME));
				props.put(RESTPASSWORD, prop.getProperty(PROD_RESTPASSWORD));
			}
		}
		return props.get(key);
    }
  
}
