Переглянути джерело

更新配置文件里面参数获取工具类

9060 3 тижнів тому
батько
коміт
1045302431

+ 6 - 1
src/com/kingdee/eas/custom/beisen/utils/BeisenParam.java

@@ -8,7 +8,12 @@ public class BeisenParam {
     /**
      * 渠道id
      */
-    public static final String CHANNELID="237";
+    public static final String BEISEN_CONFIG_CHANNELID="CHANNELID";
+    /**
+     * 北森配置文件路径
+     */
+    public static final String BEISEN_CONFIG_PATH="/server/properties/beisen/beisenConfig.properties";
+
     //创建需求
     public static final String CREATE_REQUIREMENT_URL = "https://openapi.italent.cn/RecruitV6/api/v1/Requirement/CreateRequirement";
     //更新需求

+ 53 - 0
src/com/kingdee/eas/custom/beisen/utils/BeisenParamByProperties.java

@@ -0,0 +1,53 @@
+package com.kingdee.eas.custom.beisen.utils;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.log4j.Logger;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * 获取配置文件参数值
+ * description: BeisenParamByProperties <br>
+ * date: 2025/7/7 16:03 <br>
+ * author: lhbj <br>
+ * version: 1.0 <br>
+ */
+public class BeisenParamByProperties {
+    private static Logger logger =Logger.getLogger(BeisenParamByProperties.class);
+    private Properties propt = new Properties();//共用参数
+    /**
+     * filePath地址从server开始,例:/server/properties/beisen/beisenConfig.properties
+     * @param filePath
+     */
+    public BeisenParamByProperties(String filePath) throws IOException {
+        this.initConfig(System.getProperty("EAS_HOME") + filePath);
+    }
+    public BeisenParamByProperties() throws IOException {
+        this.initConfig(System.getProperty("EAS_HOME") + BeisenParam.BEISEN_CONFIG_PATH);
+    }
+    public void initConfig(String filePath) throws IOException {
+        try {
+            if(StringUtils.isBlank(filePath)){
+                throw new IOException("filePath参数为空");
+            }
+            this.propt.load(new FileInputStream(filePath));
+        }catch (IOException e){
+            e.printStackTrace();
+            logger.error("未找到"+filePath+"配置文件。");
+            throw e;
+        }
+    }
+    public Map<String,String> getConfig() {
+        Map<String,String> map = Maps.newHashMap();
+        Set<Map.Entry<Object, Object>> set = this.propt.entrySet();
+        for(Map.Entry<Object, Object> entry : set){
+            map.put((String)entry.getKey(),(String)entry.getValue());
+        }
+        return map;
+    }
+}