Browse Source

Update GlobalConstant.java

master
许孟阳 4 years ago
parent
commit
04c2d1dae4
  1. 33
      src/main/java/vip/xumy/core/golbal/GlobalConstant.java

33
src/main/java/vip/xumy/core/golbal/GlobalConstant.java

@ -1,44 +1,35 @@
package vip.xumy.core.golbal; package vip.xumy.core.golbal;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.system.ApplicationHome; import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
@Component
public class GlobalConstant { public class GlobalConstant {
public static final String RESOURCES_ROOT_PATH; public static String RESOURCES_ROOT_PATH;
public static final String JAR_RESOURCES_PATH; public static String FILE_DOWNLOAD_PATH;
public static final String JAR_DOWNLOAD_PATH;
public static final String FILE_DOWNLOAD_PATH;
public static final String DEFAULT_PASSWORD = DigestUtils.md5DigestAsHex("888888".getBytes()); public static final String DEFAULT_PASSWORD = DigestUtils.md5DigestAsHex("888888".getBytes());
public static final String CODE_KEY_PREFIX = "login-code-"; public static final String CODE_KEY_PREFIX = "login-code-";
public static final String TIKEN_KEY_PREFIX = "login-token-"; public static final String TIKEN_KEY_PREFIX = "login-token-";
public static final String LOGIN_COOKIE_NAME = "UMLoginToken"; public static final String LOGIN_COOKIE_NAME = "UMLoginToken";
public static final String ENCODING_UTF8 = "UTF-8"; public static final String ENCODING_UTF8 = "UTF-8";
public static final Map<Integer, String> YYS_TYPES = new HashMap<>(); @Value("${service.package.type:war}")
static{ public void setPackageType(String type) {
RESOURCES_ROOT_PATH = GlobalConstant.class.getClassLoader().getResource("").getPath(); if("jar".equals(type)) {
FILE_DOWNLOAD_PATH = RESOURCES_ROOT_PATH + "/file/";
ApplicationHome h = new ApplicationHome(GlobalConstant.class); ApplicationHome h = new ApplicationHome(GlobalConstant.class);
File jarF = h.getSource(); File jarF = h.getSource();
JAR_RESOURCES_PATH = jarF.getParentFile().toString(); RESOURCES_ROOT_PATH = jarF.getParentFile().toString();
JAR_DOWNLOAD_PATH = JAR_RESOURCES_PATH + "/file/"; }else {
RESOURCES_ROOT_PATH = GlobalConstant.class.getClassLoader().getResource("").getPath();
YYS_TYPES.put(0, "移动");
YYS_TYPES.put(1, "联通");
YYS_TYPES.put(2, "电信");
} }
FILE_DOWNLOAD_PATH = RESOURCES_ROOT_PATH + "/file/";
private GlobalConstant(){
//Add a private constructor to hide the implicit public one.
} }
} }

Loading…
Cancel
Save