ApplicationConfig.java 5.9 KB

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