EnvCommonService.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.cyksj.common;
  2. import lombok.Getter;
  3. import lombok.Setter;
  4. import org.springframework.beans.factory.annotation.Value;
  5. import org.springframework.stereotype.Component;
  6. import javax.annotation.PostConstruct;
  7. /*
  8. *项目名: netflix
  9. *文件名: EnvCommon
  10. *创建者: JavaZou
  11. *创建时间:2022/10/26 17:10
  12. */
  13. @Component
  14. @Getter
  15. @Setter
  16. public class EnvCommonService {
  17. public static final String active = "dev";
  18. public static final String active_prd = "prd";
  19. public static String DISTRIBUTE_DEFAULT_URL_PREFIX;
  20. public static String DISTRIBUTE_DESIGN_URL_PREFIX;
  21. @Value(value = "${spring.profiles.active}")
  22. private String env;
  23. @Value(value = "${wechat.domain}")
  24. private String domain;
  25. public String getHost() {
  26. return domain;
  27. }
  28. public String getDomain() {
  29. return this.getHost().substring(0, this.getHost().indexOf("8081"));
  30. }
  31. public String getDomain2() {
  32. return this.getHost().substring(0, this.getHost().indexOf("/8081"));
  33. }
  34. public Boolean isPrdEnv() {
  35. return EnvCommonService.active_prd.equals(getEnv());
  36. }
  37. @PostConstruct
  38. public void getDistributeUrl() {
  39. DISTRIBUTE_DEFAULT_URL_PREFIX = getDomain();
  40. if (!DISTRIBUTE_DEFAULT_URL_PREFIX.endsWith("/")) {
  41. DISTRIBUTE_DEFAULT_URL_PREFIX += "/";
  42. }
  43. if (!isPrdEnv()) {
  44. DISTRIBUTE_DEFAULT_URL_PREFIX += "yinhe/web";
  45. }
  46. DISTRIBUTE_DEFAULT_URL_PREFIX += "?sharedId=%s";
  47. DISTRIBUTE_DESIGN_URL_PREFIX = DISTRIBUTE_DEFAULT_URL_PREFIX.replace("sharedId", "dsCode");
  48. }
  49. }