package com.its.op.global; import com.its.op.dao.repository.its.code.TbCmmnCdRepository; import com.its.op.dto.its.code.TbCmmnCdDto; import com.its.op.entity.its.code.TbCmmnCd; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.ToString; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @Slf4j @RequiredArgsConstructor @Getter @Component public class CmmnCdManager { private final TbCmmnCdRepository repo; //private final TbSectGradClsfRepository sectGradClsfRepository; // 소통정보 결측 소통등급 코드 public static final String MISS_SPED_GRAD = "LTC0"; // 돌발상황 출처 유형 public static final String INCD_ORGN_IST1 = "IST1"; //운영자 public static final String INCD_ORGN_IST2 = "IST2"; //제보 public static final String INCD_ORGN_IST3 = "IST3"; //연계기관 public static final String INCD_ORGN_IST4 = "IST4"; //OBE public static final String INCD_ORGN_IST5 = "IST5"; //도로교통공단 public static final String INCD_ORGN_IST6 = "IST6"; //자동돌발검지 public static final String INCD_ORGN_IST7 = "IST7"; //기타 // 돌발상황 진행 단계 유형 public static final String INCD_PRGR_STEP_ISS1 = "ISS1"; //접수/미확인 public static final String INCD_PRGR_STEP_ISS2 = "ISS2"; //진행 public static final String INCD_PRGR_STEP_ISS3 = "ISS3"; //종료 public static final String INCD_PRGR_STEP_ISS4 = "ISS4"; //오보 // 돌발상황관리 코드 public static final String INCD_CODE_IST = "IST"; //돌발상황 원본 코드 : IST public static final String INCD_CODE_LTCU = "LTCU"; //소통 등급 코드 : LTCU public static final String INCD_CODE_ICM = "ICM"; //돌발상황 확인 방법 코드 : ICM public static final String INCD_CODE_IDTU = "IDTU"; //돌발상황 유형 분류 코드 : IDTU public static final String INCD_CODE_ACTU = "ACTU"; //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나 // 사고 public static final String INCD_CODE_CRTU = "CRTU"; //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나 // 공사 public static final String INCD_CODE_EVTU = "EVTU"; //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나 // 행사 public static final String INCD_CODE_WETU = "WETU"; //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나 // 기상 public static final String INCD_CODE_SRLU = "SRLU"; //돌발상황 심각도 코드 : SRLU public static final String INCD_CODE_PRTU = "PRTU"; //통행 제한 유형 코드 : PRTU public static final String INCD_CODE_RSL = "RSL"; //대응 수준 코드 : RSL public static final String INCD_CODE_ISS = "ISS"; //돌발상황 진행 단계 코드 : ISS public static final String INCD_CODE_DFW = "DFW"; //기상 코드 : DFW public static final String INCD_CODE_VIT = "VIT"; //VMS 돌발 유형 코드 : VIT public static final String INCD_CODE_IDT = "IDT"; //VMS 돌발 유형 세부 코드 : IDT public static final String INCD_CODE_EDT = "EDT"; //VMS 돌발 유형 세부 코드 : EDT public static final String INCD_CODE_VRT = "VRT"; //VMS 돌발 통제 코드 : VRT // 코드 private static final String defUnknownCode = "X"; public static final String defUnknownDesc = "UNKNOWN"; public static final String defUnknownEtcDesc = "기타"; public static final String EDTN_CD = "EDI"; // 편집모드 public static final String DAY_TYPE_CD = "DTW"; // 요일유형 public static final String SYST_STTS_CD = "SPS"; // 프로세스 상태 public static final String CMTR_GRAD_CD = "LTC"; // 소통등급 public static final String PRCN_SORC = "CST"; // 가공소스 public static final String ADJS_SORC = "MCS"; // 보정소스 public static final String NODE_TYPE = "NDT"; // 노드유형 public static final String ROAD_USE = "RDU"; // 도로사용여부 public static final String ROAD_RANK = "RDR"; // 도로등급 public static final String ROAD_TYPE = "RDT"; // 도로유형 public static final String MULTI_LINK = "MLT"; // 중용구간 public static final String LINK_CONNECT = "CTR"; // 연결로 public static final String REST_VEH = "PLV"; // 통행제한차량 public static final String SECT_GRAD_CD = "SRT"; // 구간 등급 코드 public static final String DRCT_CD = "IFD"; // 방향 코드 public static final String HLDY_DAY_CD = "LHT"; // 휴일유형코드 public static final String CNCT_INTN_TYPE_CD = "COT"; // 연계기관유형코드 public static final String VEH_TYPE = "RCT"; // DSRC OBU 차종 public static final String OBU_KIND = "OBU"; // OBU 종류 public static final String STTS_UNKNOWN = "-"; public static final String CMNC_STTS_NORMAL = "CMS0"; public static final String CMNC_STTS_ERROR = "CMS1"; public static final String CMNC_STTS_ERROR_DT = "19700101000000"; public static final String CMNC_STTS_CD = "CMS"; // 통신상태코드 public static final String MODL_STTS_CD = "MOS"; // 모듈상태 public static final String PWER_STTS_CD = "PWS"; // 전원상태 public static final String DOOR_STTS_CD = "CDS"; // 도어상태 public static final String FAN_STTS_CD = "PAS"; // 팬상태 public static final String HETR_STTS_CD = "HTS"; // 히터상태 public static final String VIDEO_INPUT_CD = "VDI"; // VIDEO Input 상태 public static final String CCTV_TYPE_CD = "CCTVT"; // CCTV 유형 코드 public static final String DTCT_TYPE_CD = "DTT"; // 검지기유형 //public static final String DTCT_TYPE_CD = "ACD"; // 검지기방향 public static final String VMS_USAG_TYPE_CD = "VUT"; // VMS 용도 유형 코드 public static final String VMS_TYPE_CD = "VMP"; // VMS 유형 코드 public static final String REPT_CNGS_CD = "RCS"; // 반복정체 원본 코드 public static final String FCLT_TYPE_CD = "FTC"; // 시설물 유형 코드 public static final String FCLT_FAIL_TYPE_CD = "FFA"; // 시설물 장애 유형 코드 // 시설물 관리 public static final String FMS_CLASS = "FMS"; // 시설물 대분류 public static final String FMS_FMITS = "FMITS"; // ITS 시설물 public static final String FMS_FMSCRS = "FMSCRS"; // 스마트 교차로 public static final String FMS_FMCNTR = "FMCNTR"; // 센터장비 public static final String FMS_FMSIG = "FMSIG"; // 신호시설물 public static final String FMS_WSTEP = "WSTEP"; // 사업단계 public static final String FMS_FMSTP = "FMSTP"; // 시설물 구분 public static final String FMS_FSTEP = "FSTEP"; // 시설물 장애진행상태구분 public static final String FMS_FREG = "FREG"; // 시설물 장애등록구분 public static final String FMS_FLVL = "FLVL"; // 시설물 장애등급구분 public static final String FMS_FWTHR = "FWTHR"; // 시설물 장애발생시 날씨 public static final String FMS_FMSG = "FMSG"; // 사용자 메지시 종류 private static ConcurrentHashMap> codes = new ConcurrentHashMap<>(); @PostConstruct void init() { load(); } public void load() { List codeList = this.repo.findAll(); for (TbCmmnCd entity : codeList) { TbCmmnCdDto cd = entity.toDto(); HashMap codeMap = codes.get(cd.getCmmnClsfCd()); if (codeMap == null) { codeMap = new HashMap<>(); codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm())); codes.put(cd.getCmmnClsfCd(), codeMap); } else { codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm())); } } } public List reload() { ConcurrentHashMap> tempMap = new ConcurrentHashMap<>(); List codeList = this.repo.findAll(); for (TbCmmnCd entity : codeList) { TbCmmnCdDto cd = entity.toDto(); HashMap codeMap = tempMap.get(cd.getCmmnClsfCd()); if (codeMap == null) { codeMap = new HashMap<>(); codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm())); tempMap.put(cd.getCmmnClsfCd(), codeMap); } else { codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm())); } } codes = tempMap; return codeList; } public void refresh(List codeList) { if (codeList == null) { return; } ConcurrentHashMap> tempMap = new ConcurrentHashMap<>(); for (TbCmmnCdDto cd : codeList) { HashMap codeMap = tempMap.get(cd.getCmmnClsfCd()); if (codeMap == null) { codeMap = new HashMap<>(); codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm())); tempMap.put(cd.getCmmnClsfCd(), codeMap); } else { codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm())); } } codes = tempMap; } public void merge(TbCmmnCdDto cd) { if (cd == null) { return; } HashMap codeMap = codes.get(cd.getCmmnClsfCd()); if (codeMap == null) { HashMap codeMap_ = new HashMap<>(); codeMap_.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm())); codes.put(cd.getCmmnClsfCd(), codeMap_); } else { codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm())); } } public void remove(String cmmnClsfCd, String cmmnCd) { HashMap codeMap = codes.get(cmmnClsfCd); if (codeMap != null) { codeMap.remove(cmmnCd); } } public void update(String cmmnClsfCd, List result) { if (result == null) { return; } HashMap codeMap = new HashMap<>(); for (TbCmmnCdDto cd : result) { codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm())); } codes.put(cmmnClsfCd, codeMap); } public static String getCodeDesc(String CMMN_CLSF_CD, String CMMN_CD) { HashMap codeMap = codes.get(CMMN_CLSF_CD); if (codeMap != null) { Code code = codeMap.get(CMMN_CD); if (code != null) { return "[" + CMMN_CD + "] " + code.getDesc(); } } return "[" + CMMN_CD + "] " + defUnknownDesc; } public static String getCodeDescShort(String CMMN_CLSF_CD, String CMMN_CD) { HashMap codeMap = codes.get(CMMN_CLSF_CD); if (codeMap != null) { Code code = codeMap.get(CMMN_CD); if (code != null) { return code.getDesc(); } } return defUnknownDesc; } public static String getCodeEtcDescShort(String CMMN_CLSF_CD, String CMMN_CD) { HashMap codeMap = codes.get(CMMN_CLSF_CD); if (codeMap != null) { Code code = codeMap.get(CMMN_CD); if (code != null) { return code.getDesc(); } } return defUnknownEtcDesc; } public static String getFcltGroupNm(String FCLT_TYPE) { HashMap codeMap = codes.get(FMS_CLASS); if (codeMap != null) { for (String key : codeMap.keySet()) { HashMap subCodeMap = codes.get(key); for (String subKey : subCodeMap.keySet()) { if (subKey.equals(FCLT_TYPE)) { return codeMap.get(key).getDesc(); } } } } return defUnknownDesc; } public static String getFcltTypeNm(String FCLT_TYPE) { HashMap codeMap = codes.get(FMS_CLASS); if (codeMap != null) { for (String key : codeMap.keySet()) { HashMap subCodeMap = codes.get(key); for (Map.Entry e: subCodeMap.entrySet()) { if (e.getKey().equals(FCLT_TYPE)) { return e.getValue().getDesc(); } } // for (String subKey : subCodeMap.keySet()) { // if (subKey.equals(FCLT_TYPE)) { // return subCodeMap.get(subKey).getDesc(); // } // } } } return defUnknownDesc; } public static String getWeatherCode(String CMMN_CD_KOR_NM) { HashMap codeMap = codes.get(CmmnCdManager.INCD_CODE_DFW); if (codeMap != null) { for (Map.Entry e: codeMap.entrySet()) { Code code = e.getValue(); if (StringUtils.equals(code.getDesc(), CMMN_CD_KOR_NM)) { return code.getCode(); } } // for (String key : codeMap.keySet()) { // Code code = codeMap.get(key); // if (StringUtils.equals(code.getDesc(), CMMN_CD_KOR_NM)) { // return code.getCode(); // } // } } return "NB0"; } @Getter @ToString @AllArgsConstructor public static class Code { private String code; private String desc; private String englDesc; } }