TrafPrcsServerApplicationTests.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package com.its.traf;
  2. import com.its.traf.dto.its.IfscCngsDto;
  3. import com.its.traf.global.eTrafPrcsJob;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.junit.jupiter.api.Test;
  6. import org.springframework.test.context.ActiveProfiles;
  7. import java.text.ParseException;
  8. import java.text.SimpleDateFormat;
  9. import java.util.*;
  10. @Slf4j
  11. //@SpringBootTest
  12. @ActiveProfiles(profiles = "dev")
  13. public class TrafPrcsServerApplicationTests {
  14. enum LogLevel {
  15. VERB,
  16. INFO,
  17. DEBUG,
  18. WARN,
  19. ERROR,
  20. }
  21. public String getCurr05MinString(Date paramDt) {
  22. Calendar cal = Calendar.getInstance();
  23. cal.setTime(paramDt);
  24. cal.set(Calendar.SECOND, 0);
  25. cal.set(Calendar.MILLISECOND, 0);
  26. int min = cal.get(Calendar.MINUTE);
  27. cal.add(Calendar.MINUTE, -(min % 5));
  28. return new SimpleDateFormat("yyyyMMddHHmmss").format(cal.getTime());
  29. }
  30. public String getCurr15MinString(Date paramDt) {
  31. Calendar cal = Calendar.getInstance();
  32. cal.setTime(paramDt);
  33. cal.set(Calendar.SECOND, 0);
  34. cal.set(Calendar.MILLISECOND, 0);
  35. int min = cal.get(Calendar.MINUTE);
  36. cal.add(Calendar.MINUTE, -(min % 15));
  37. return new SimpleDateFormat("yyyyMMddHHmmss").format(cal.getTime());
  38. }
  39. public Date convertString2Date(String paramTime) {
  40. SimpleDateFormat transFormat = new SimpleDateFormat("yyyyMMddHHmmss");
  41. Date to = null;
  42. try {
  43. to = transFormat.parse(paramTime);
  44. } catch (ParseException e) {
  45. e.printStackTrace();
  46. }
  47. return to;
  48. }
  49. @Test
  50. void testTime() {
  51. String[] timeArr = {
  52. "20230309160000", "20230309160500", "20230309161000", "20230309161500",
  53. "20230309162000", "20230309162500", "20230309163000", "20230309163500",
  54. "20230309164000", "20230309164500", "20230309165000", "20230309165500",};
  55. for (String t : timeArr) {
  56. String str05M = getCurr05MinString(convertString2Date(t));
  57. String str15M = getCurr15MinString(convertString2Date(str05M));
  58. log.info("{}", str05M);
  59. log.info("{}", str15M);
  60. }
  61. }
  62. @Test
  63. void test1() {
  64. for (int ii = 0; ii < 24; ii++) {
  65. for (int jj = 0; jj < 12; jj++) {
  66. log.error("{}:{}", ii, jj*5);
  67. }
  68. }
  69. String prcsDt = "20220120173526";
  70. log.error("{}", prcsDt.substring(0, 2));
  71. log.error("{}", prcsDt.substring(8, 10));
  72. log.error("{}", prcsDt.substring(10, 12));
  73. String svcDt = "20210120173526";
  74. log.error("compareTo: {}", svcDt.compareTo(prcsDt));
  75. }
  76. void test2Func(LogLevel level) {
  77. log.error("{}", level.name());
  78. }
  79. @Test
  80. void test2() {
  81. test2Func(LogLevel.INFO);
  82. test2Func(LogLevel.ERROR);
  83. test2Func(LogLevel.DEBUG);
  84. }
  85. @Test
  86. void test3() {
  87. Calendar calStat = Calendar.getInstance();
  88. String YMD = new SimpleDateFormat("yyyyMMddHHmmss").format(calStat.getTime());
  89. log.error("{}", YMD);
  90. calStat.add(Calendar.DAY_OF_MONTH, -1); // 하루전
  91. calStat.set(Calendar.HOUR_OF_DAY, 0);
  92. calStat.set(Calendar.MINUTE, 0);
  93. calStat.set(Calendar.SECOND, 0);
  94. YMD = new SimpleDateFormat("yyyyMMddHHmmss").format(calStat.getTime());
  95. log.error("{}", YMD);
  96. }
  97. Hashtable<Long, Hashtable<String, List<IfscCngsDto>>> cngsMap = new Hashtable<>();
  98. private void addIfscCngs(IfscCngsDto cngs) {
  99. if (cngs != null) {
  100. Long key = cngs.getIfscId();
  101. Hashtable<String, List<IfscCngsDto>> hhMiMap = cngsMap.computeIfAbsent(key, k -> new Hashtable<>());
  102. List<IfscCngsDto> lists = hhMiMap.computeIfAbsent(cngs.getPrcnTm(), k -> new ArrayList<>());
  103. lists.add(cngs);
  104. }
  105. }
  106. @Test
  107. void test4() {
  108. Long ifscId = 3505426700L;
  109. IfscCngsDto cngs1 = IfscCngsDto.builder()
  110. .ifscId(ifscId)
  111. .prcnDt("20220101000000")
  112. .prcnHh("00")
  113. .prcnMi("00")
  114. .prcnTm("0000")
  115. .timeIdx(0)
  116. .sped(10)
  117. .trvlHh(10)
  118. .build();
  119. IfscCngsDto cngs2 = IfscCngsDto.builder()
  120. .ifscId(ifscId)
  121. .prcnDt("20220101000000")
  122. .prcnHh("00")
  123. .prcnMi("05")
  124. .prcnTm("0005")
  125. .timeIdx(1)
  126. .sped(10)
  127. .trvlHh(10)
  128. .build();
  129. IfscCngsDto cngs3 = IfscCngsDto.builder()
  130. .ifscId(ifscId)
  131. .prcnDt("20220101000000")
  132. .prcnHh("00")
  133. .prcnMi("10")
  134. .prcnTm("0010")
  135. .timeIdx(2)
  136. .sped(10)
  137. .trvlHh(10)
  138. .build();
  139. addIfscCngs(cngs3);
  140. addIfscCngs(cngs1);
  141. addIfscCngs(cngs2);
  142. log.error("{}", cngsMap);
  143. TreeMap<Integer, IfscCngsDto> treeMap = new TreeMap<>();
  144. treeMap.put(cngs3.getTimeIdx(), cngs3);
  145. treeMap.put(cngs1.getTimeIdx(), cngs1);
  146. treeMap.put(cngs2.getTimeIdx(), cngs2);
  147. log.error("{}", treeMap);
  148. }
  149. @Test
  150. void test5() {
  151. eTrafPrcsJob arr[] = eTrafPrcsJob.values();
  152. for (eTrafPrcsJob col : arr) {
  153. log.info("{}, {}, {}, {}", col.ordinal(), col.getValue(), col.getName(), col.getDesc());
  154. }
  155. }
  156. }