Przeglądaj źródła

修正 SystemProperties

deason 4 lat temu
rodzic
commit
1e092efaed

+ 42 - 82
examcloud-web/src/main/java/cn/com/qmth/examcloud/web/config/SystemProperties.java

@@ -1,17 +1,8 @@
 package cn.com.qmth.examcloud.web.config;
 
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
-import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
-import cn.com.qmth.examcloud.commons.util.PathUtil;
-import cn.com.qmth.examcloud.web.support.ClasspathHelper;
-
 /**
  * 系统配置
  *
@@ -20,79 +11,48 @@ import cn.com.qmth.examcloud.web.support.ClasspathHelper;
  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
  */
 @Component
-@ConfigurationProperties("examcloud.web.sys")
 public class SystemProperties {
 
-	private String dataDir;
-
-	private String tempDataDir;
-
-	private String logDir;
-
-	/**
-	 * 构造函数
-	 *
-	 */
-	public SystemProperties() {
-
-		if (StringUtils.isBlank(dataDir)) {
-			String classpath = ClasspathHelper.getClasspath();
-			String path = new File(classpath).getParent() + File.separator + "data";
-			dataDir = PathUtil.getCanonicalPath(new File(path));
-		}
-
-		if (StringUtils.isBlank(tempDataDir)) {
-			String classpath = ClasspathHelper.getClasspath();
-			String path = new File(classpath).getParent() + File.separator + "temp";
-			tempDataDir = PathUtil.getCanonicalPath(new File(path));
-		}
-
-		if (StringUtils.isBlank(logDir)) {
-			String classpath = ClasspathHelper.getClasspath();
-			String path = new File(classpath).getParent() + File.separator + "logs";
-			logDir = PathUtil.getCanonicalPath(new File(path));
-		}
-
-		try {
-			FileUtils.forceMkdir(new File(dataDir));
-		} catch (IOException e) {
-			throw new ExamCloudRuntimeException("fail to make data dir. path=" + dataDir);
-		}
-
-		try {
-			FileUtils.forceMkdir(new File(tempDataDir));
-		} catch (IOException e) {
-			throw new ExamCloudRuntimeException("fail to make temp data dir. path=" + tempDataDir);
-		}
-
-		System.setProperty("dataDir", dataDir);
-		System.setProperty("empDataDir", tempDataDir);
-		System.setProperty("logDir", logDir);
-
-	}
-
-	public String getDataDir() {
-		return dataDir;
-	}
-
-	public void setDataDir(String dataDir) {
-		this.dataDir = dataDir;
-	}
-
-	public String getTempDataDir() {
-		return tempDataDir;
-	}
-
-	public void setTempDataDir(String tempDataDir) {
-		this.tempDataDir = tempDataDir;
-	}
-
-	public String getLogDir() {
-		return logDir;
-	}
-
-	public void setLogDir(String logDir) {
-		this.logDir = logDir;
-	}
+    /**
+     * 配置文件环境
+     */
+    @Value("${spring.profiles.active:}")
+    private String profile;
+
+    /**
+     * 文件存放目录
+     */
+    @Value("${examcloud.web.sys.dataDir:dataDir}")
+    private String dataDir;
+
+    /**
+     * 文件存放临时目录
+     */
+    @Value("${examcloud.web.sys.tempDataDir:tempDataDir}")
+    private String tempDataDir;
+
+    public String getProfile() {
+        return profile;
+    }
+
+    public void setProfile(String profile) {
+        this.profile = profile;
+    }
+
+    public String getDataDir() {
+        return dataDir;
+    }
+
+    public void setDataDir(String dataDir) {
+        this.dataDir = dataDir;
+    }
+
+    public String getTempDataDir() {
+        return tempDataDir;
+    }
+
+    public void setTempDataDir(String tempDataDir) {
+        this.tempDataDir = tempDataDir;
+    }
 
 }