ApplicationConfig.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package com.its.vms.config;
  2. import com.its.app.utils.SysUtils;
  3. import com.its.vms.domain.VmsConstants;
  4. import lombok.Getter;
  5. import lombok.Setter;
  6. import lombok.ToString;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.boot.context.properties.ConfigurationProperties;
  9. import org.springframework.context.annotation.Configuration;
  10. import javax.annotation.PostConstruct;
  11. import java.io.File;
  12. import java.nio.file.Path;
  13. import java.nio.file.Paths;
  14. @Slf4j
  15. @Getter
  16. @Setter
  17. @ToString
  18. @Configuration
  19. @ConfigurationProperties(prefix = "application")
  20. public class ApplicationConfig {
  21. public static String FTP_FORM = "FORM";
  22. public static String FTP_VIDEO = "VIDEO";
  23. public static String FTP_STATIC = "STATIC";
  24. public static String FTP_IMAGE = "IMAGE";
  25. private String bootingDateTime;
  26. private boolean startSchedule;
  27. private String id = "VMS01";
  28. private String name = "VMS Communication Server";
  29. private boolean history = true;
  30. private boolean statistics = true;
  31. private String userId = "admin";
  32. private String userPswd = "1234";
  33. // Center Communication Config
  34. private boolean centerCommEnable = true;
  35. private int listenPort = 30200;
  36. protected String bindingAddr = "0.0.0.0";
  37. protected int backlog = 0;
  38. protected int acceptThreads = 0;
  39. protected int workerThreads = 0;
  40. protected int rcvBuf = 0;
  41. protected int sndBuf = 0;
  42. protected int readerIdleTimeSeconds = 0;
  43. protected int writerIdleTimeSeconds = 0;
  44. protected int allIdleTimeSeconds = 0;
  45. protected int connectTimeoutSeconds = 0;
  46. private String ftpHomeDir = "./ftp";
  47. private String ftpFormDir ; // FTP Form Directory
  48. private String ftpVideoDir; // FTP Video Directory
  49. private String ftpStaticDir; // FTP 정적폼 Directory
  50. private String ftpImageDir; // FTP Image Directory
  51. private boolean loadDb = true;
  52. private boolean requestDeviceId = true;
  53. private int maxDownloadForms = 10;
  54. private int cngstContCount = 2;
  55. private int maxCngstForms = 5;
  56. private int bottomTrafficMax = 1;
  57. private int bottomTrafficCycle = 0;
  58. private boolean figureTrafficCenter = true;
  59. private boolean textTrafficCenter = true;
  60. private String figureTrafGrad1 = "원활";
  61. private String figureTrafGrad2 = "지체";
  62. private String figureTrafGrad3 = "정체";
  63. private String textTrafGrad1 = "소통원활";
  64. private String textTrafGrad2 = "지 체";
  65. private String textTrafGrad3 = "정 체";
  66. private boolean imageSeqSave = false;
  67. private float fontSizeRatio = 1.35f;
  68. private boolean checkNewForm = true;
  69. private boolean downloadBitmapForm = false;
  70. private boolean useParking = false;
  71. @PostConstruct
  72. private void init() {
  73. this.startSchedule = false;
  74. final int DEFAULT_EVENT_THREADS = Runtime.getRuntime().availableProcessors() * 2;
  75. if (this.bindingAddr.equals("")) {
  76. this.bindingAddr = "0.0.0.0";
  77. }
  78. if (this.backlog == 0) {
  79. this.backlog = 32;
  80. }
  81. if (this.acceptThreads == 0) {
  82. this.acceptThreads = DEFAULT_EVENT_THREADS;
  83. }
  84. if (this.workerThreads == 0) {
  85. this.workerThreads = DEFAULT_EVENT_THREADS;
  86. }
  87. if (this.rcvBuf == 0) {
  88. this.rcvBuf = Short.MAX_VALUE / 2;
  89. }
  90. if (this.sndBuf == 0) {
  91. this.sndBuf = Short.MAX_VALUE / 2;
  92. }
  93. this.bootingDateTime = SysUtils.getSysTimeStr();
  94. if (this.maxDownloadForms < VmsConstants.VMS_MIN_DOWNLOAD_FORMS) this.maxDownloadForms = VmsConstants.VMS_MIN_DOWNLOAD_FORMS;
  95. if (this.maxDownloadForms > VmsConstants.VMS_MAX_DOWNLOAD_FORMS) this.maxDownloadForms = VmsConstants.VMS_MAX_DOWNLOAD_FORMS;
  96. if (this.ftpHomeDir == null || this.ftpHomeDir.trim().length() == 0) {
  97. Path filePath = Paths.get(System.getProperty("user.dir"), "ftp");
  98. this.ftpHomeDir = filePath.toFile().getAbsolutePath();
  99. }
  100. this.ftpHomeDir = this.ftpHomeDir.trim();
  101. this.ftpFormDir = this.ftpHomeDir + File.separator + FTP_FORM + File.separator; // FTP Form Directory
  102. this.ftpVideoDir = this.ftpHomeDir + File.separator + FTP_VIDEO + File.separator; // FTP Video Directory
  103. this.ftpStaticDir = this.ftpHomeDir + File.separator + FTP_STATIC + File.separator; // FTP 정적폼 Directory
  104. this.ftpImageDir = this.ftpHomeDir + File.separator + FTP_IMAGE + File.separator; // FTP Image Directory
  105. makeDirectory(this.ftpHomeDir, "ftp Home directory");
  106. makeDirectory(this.ftpFormDir, "ftp Form directory");
  107. makeDirectory(this.ftpVideoDir, "ftp Video directory");
  108. makeDirectory(this.ftpStaticDir, "ftp Static Form directory");
  109. makeDirectory(this.ftpImageDir, "ftp Image directory");
  110. if (this.fontSizeRatio == 0f) {
  111. this.fontSizeRatio = 1.35f;
  112. }
  113. log.info("{}", this);
  114. }
  115. public boolean makeDirectory(String path, String desc) {
  116. boolean result = false;
  117. File folder = new File(path);
  118. if (!folder.exists()) {
  119. try {
  120. result = folder.mkdir(); //폴더 생성합니다.
  121. log.info("{}, ({}) created.", folder.getAbsolutePath(), desc);
  122. }
  123. catch(Exception e) {
  124. log.error("{}, ({}) create failed. {}.", folder.getAbsolutePath(), desc, e.getMessage());
  125. }
  126. }
  127. return result;
  128. }
  129. }