123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- package com.its.traf;
- import com.its.traf.dto.its.IfscCngsDto;
- import com.its.traf.global.eTrafPrcsJob;
- import lombok.extern.slf4j.Slf4j;
- import org.junit.jupiter.api.Test;
- import org.springframework.test.context.ActiveProfiles;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- @Slf4j
- //@SpringBootTest
- @ActiveProfiles(profiles = "dev")
- public class TrafPrcsServerApplicationTests {
- enum LogLevel {
- VERB,
- INFO,
- DEBUG,
- WARN,
- ERROR,
- }
- public String getCurr05MinString(Date paramDt) {
- Calendar cal = Calendar.getInstance();
- cal.setTime(paramDt);
- cal.set(Calendar.SECOND, 0);
- cal.set(Calendar.MILLISECOND, 0);
- int min = cal.get(Calendar.MINUTE);
- cal.add(Calendar.MINUTE, -(min % 5));
- return new SimpleDateFormat("yyyyMMddHHmmss").format(cal.getTime());
- }
- public String getCurr15MinString(Date paramDt) {
- Calendar cal = Calendar.getInstance();
- cal.setTime(paramDt);
- cal.set(Calendar.SECOND, 0);
- cal.set(Calendar.MILLISECOND, 0);
- int min = cal.get(Calendar.MINUTE);
- cal.add(Calendar.MINUTE, -(min % 15));
- return new SimpleDateFormat("yyyyMMddHHmmss").format(cal.getTime());
- }
- public Date convertString2Date(String paramTime) {
- SimpleDateFormat transFormat = new SimpleDateFormat("yyyyMMddHHmmss");
- Date to = null;
- try {
- to = transFormat.parse(paramTime);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return to;
- }
- @Test
- void testTime() {
- String[] timeArr = {
- "20230309160000", "20230309160500", "20230309161000", "20230309161500",
- "20230309162000", "20230309162500", "20230309163000", "20230309163500",
- "20230309164000", "20230309164500", "20230309165000", "20230309165500",};
- for (String t : timeArr) {
- String str05M = getCurr05MinString(convertString2Date(t));
- String str15M = getCurr15MinString(convertString2Date(str05M));
- log.info("{}", str05M);
- log.info("{}", str15M);
- }
- }
- @Test
- void test1() {
- for (int ii = 0; ii < 24; ii++) {
- for (int jj = 0; jj < 12; jj++) {
- log.error("{}:{}", ii, jj*5);
- }
- }
- String prcsDt = "20220120173526";
- log.error("{}", prcsDt.substring(0, 2));
- log.error("{}", prcsDt.substring(8, 10));
- log.error("{}", prcsDt.substring(10, 12));
- String svcDt = "20210120173526";
- log.error("compareTo: {}", svcDt.compareTo(prcsDt));
- }
- void test2Func(LogLevel level) {
- log.error("{}", level.name());
- }
- @Test
- void test2() {
- test2Func(LogLevel.INFO);
- test2Func(LogLevel.ERROR);
- test2Func(LogLevel.DEBUG);
- }
- @Test
- void test3() {
- Calendar calStat = Calendar.getInstance();
- String YMD = new SimpleDateFormat("yyyyMMddHHmmss").format(calStat.getTime());
- log.error("{}", YMD);
- calStat.add(Calendar.DAY_OF_MONTH, -1); // 하루전
- calStat.set(Calendar.HOUR_OF_DAY, 0);
- calStat.set(Calendar.MINUTE, 0);
- calStat.set(Calendar.SECOND, 0);
- YMD = new SimpleDateFormat("yyyyMMddHHmmss").format(calStat.getTime());
- log.error("{}", YMD);
- }
- Hashtable<Long, Hashtable<String, List<IfscCngsDto>>> cngsMap = new Hashtable<>();
- private void addIfscCngs(IfscCngsDto cngs) {
- if (cngs != null) {
- Long key = cngs.getIfscId();
- Hashtable<String, List<IfscCngsDto>> hhMiMap = cngsMap.computeIfAbsent(key, k -> new Hashtable<>());
- List<IfscCngsDto> lists = hhMiMap.computeIfAbsent(cngs.getPrcnTm(), k -> new ArrayList<>());
- lists.add(cngs);
- }
- }
- @Test
- void test4() {
- Long ifscId = 3505426700L;
- IfscCngsDto cngs1 = IfscCngsDto.builder()
- .ifscId(ifscId)
- .prcnDt("20220101000000")
- .prcnHh("00")
- .prcnMi("00")
- .prcnTm("0000")
- .timeIdx(0)
- .sped(10)
- .trvlHh(10)
- .build();
- IfscCngsDto cngs2 = IfscCngsDto.builder()
- .ifscId(ifscId)
- .prcnDt("20220101000000")
- .prcnHh("00")
- .prcnMi("05")
- .prcnTm("0005")
- .timeIdx(1)
- .sped(10)
- .trvlHh(10)
- .build();
- IfscCngsDto cngs3 = IfscCngsDto.builder()
- .ifscId(ifscId)
- .prcnDt("20220101000000")
- .prcnHh("00")
- .prcnMi("10")
- .prcnTm("0010")
- .timeIdx(2)
- .sped(10)
- .trvlHh(10)
- .build();
- addIfscCngs(cngs3);
- addIfscCngs(cngs1);
- addIfscCngs(cngs2);
- log.error("{}", cngsMap);
- TreeMap<Integer, IfscCngsDto> treeMap = new TreeMap<>();
- treeMap.put(cngs3.getTimeIdx(), cngs3);
- treeMap.put(cngs1.getTimeIdx(), cngs1);
- treeMap.put(cngs2.getTimeIdx(), cngs2);
- log.error("{}", treeMap);
- }
- @Test
- void test5() {
- eTrafPrcsJob arr[] = eTrafPrcsJob.values();
- for (eTrafPrcsJob col : arr) {
- log.info("{}, {}, {}, {}", col.ordinal(), col.getValue(), col.getName(), col.getDesc());
- }
- }
- }
|