CmmnCdManager.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. package com.its.op.global;
  2. import com.its.op.dao.repository.its.code.TbCmmnCdRepository;
  3. import com.its.op.dto.its.code.TbCmmnCdDto;
  4. import com.its.op.entity.its.code.TbCmmnCd;
  5. import lombok.AllArgsConstructor;
  6. import lombok.Getter;
  7. import lombok.RequiredArgsConstructor;
  8. import lombok.ToString;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.apache.commons.lang.StringUtils;
  11. import org.springframework.stereotype.Component;
  12. import javax.annotation.PostConstruct;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. import java.util.concurrent.ConcurrentHashMap;
  17. @Slf4j
  18. @RequiredArgsConstructor
  19. @Getter
  20. @Component
  21. public class CmmnCdManager {
  22. private final TbCmmnCdRepository repo;
  23. //private final TbSectGradClsfRepository sectGradClsfRepository;
  24. // 소통정보 결측 소통등급 코드
  25. public static final String MISS_SPED_GRAD = "LTC0";
  26. // 돌발상황 출처 유형
  27. public static final String INCD_ORGN_IST1 = "IST1"; //운영자
  28. public static final String INCD_ORGN_IST2 = "IST2"; //제보
  29. public static final String INCD_ORGN_IST3 = "IST3"; //연계기관
  30. public static final String INCD_ORGN_IST4 = "IST4"; //OBE
  31. public static final String INCD_ORGN_IST5 = "IST5"; //도로교통공단
  32. public static final String INCD_ORGN_IST6 = "IST6"; //자동돌발검지
  33. public static final String INCD_ORGN_IST7 = "IST7"; //기타
  34. // 돌발상황 진행 단계 유형
  35. public static final String INCD_PRGR_STEP_ISS1 = "ISS1"; //접수/미확인
  36. public static final String INCD_PRGR_STEP_ISS2 = "ISS2"; //진행
  37. public static final String INCD_PRGR_STEP_ISS3 = "ISS3"; //종료
  38. public static final String INCD_PRGR_STEP_ISS4 = "ISS4"; //오보
  39. // 돌발상황관리 코드
  40. public static final String INCD_CODE_IST = "IST"; //돌발상황 원본 코드 : IST
  41. public static final String INCD_CODE_LTCU = "LTCU"; //소통 등급 코드 : LTCU
  42. public static final String INCD_CODE_ICM = "ICM"; //돌발상황 확인 방법 코드 : ICM
  43. public static final String INCD_CODE_IDTU = "IDTU"; //돌발상황 유형 분류 코드 : IDTU
  44. public static final String INCD_CODE_ACTU = "ACTU"; //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나 // 사고
  45. public static final String INCD_CODE_CRTU = "CRTU"; //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나 // 공사
  46. public static final String INCD_CODE_EVTU = "EVTU"; //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나 // 행사
  47. public static final String INCD_CODE_WETU = "WETU"; //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나 // 기상
  48. public static final String INCD_CODE_SRLU = "SRLU"; //돌발상황 심각도 코드 : SRLU
  49. public static final String INCD_CODE_PRTU = "PRTU"; //통행 제한 유형 코드 : PRTU
  50. public static final String INCD_CODE_RSL = "RSL"; //대응 수준 코드 : RSL
  51. public static final String INCD_CODE_ISS = "ISS"; //돌발상황 진행 단계 코드 : ISS
  52. public static final String INCD_CODE_DFW = "DFW"; //기상 코드 : DFW
  53. public static final String INCD_CODE_VIT = "VIT"; //VMS 돌발 유형 코드 : VIT
  54. public static final String INCD_CODE_IDT = "IDT"; //VMS 돌발 유형 세부 코드 : IDT
  55. public static final String INCD_CODE_EDT = "EDT"; //VMS 돌발 유형 세부 코드 : EDT
  56. public static final String INCD_CODE_VRT = "VRT"; //VMS 돌발 통제 코드 : VRT
  57. // 코드
  58. private static final String defUnknownCode = "X";
  59. public static final String defUnknownDesc = "UNKNOWN";
  60. public static final String defUnknownEtcDesc = "기타";
  61. public static final String EDTN_CD = "EDI"; // 편집모드
  62. public static final String DAY_TYPE_CD = "DTW"; // 요일유형
  63. public static final String SYST_STTS_CD = "SPS"; // 프로세스 상태
  64. public static final String CMTR_GRAD_CD = "LTC"; // 소통등급
  65. public static final String PRCN_SORC = "CST"; // 가공소스
  66. public static final String ADJS_SORC = "MCS"; // 보정소스
  67. public static final String NODE_TYPE = "NDT"; // 노드유형
  68. public static final String ROAD_USE = "RDU"; // 도로사용여부
  69. public static final String ROAD_RANK = "RDR"; // 도로등급
  70. public static final String ROAD_TYPE = "RDT"; // 도로유형
  71. public static final String MULTI_LINK = "MLT"; // 중용구간
  72. public static final String LINK_CONNECT = "CTR"; // 연결로
  73. public static final String REST_VEH = "PLV"; // 통행제한차량
  74. public static final String SECT_GRAD_CD = "SRT"; // 구간 등급 코드
  75. public static final String DRCT_CD = "IFD"; // 방향 코드
  76. public static final String HLDY_DAY_CD = "LHT"; // 휴일유형코드
  77. public static final String CNCT_INTN_TYPE_CD = "COT"; // 연계기관유형코드
  78. public static final String VEH_TYPE = "RCT"; // DSRC OBU 차종
  79. public static final String OBU_KIND = "OBU"; // OBU 종류
  80. public static final String STTS_UNKNOWN = "-";
  81. public static final String CMNC_STTS_NORMAL = "CMS0";
  82. public static final String CMNC_STTS_ERROR = "CMS1";
  83. public static final String CMNC_STTS_ERROR_DT = "19700101000000";
  84. public static final String CMNC_STTS_CD = "CMS"; // 통신상태코드
  85. public static final String MODL_STTS_CD = "MOS"; // 모듈상태
  86. public static final String PWER_STTS_CD = "PWS"; // 전원상태
  87. public static final String DOOR_STTS_CD = "CDS"; // 도어상태
  88. public static final String FAN_STTS_CD = "PAS"; // 팬상태
  89. public static final String HETR_STTS_CD = "HTS"; // 히터상태
  90. public static final String VIDEO_INPUT_CD = "VDI"; // VIDEO Input 상태
  91. public static final String CCTV_TYPE_CD = "CCTVT"; // CCTV 유형 코드
  92. public static final String DTCT_TYPE_CD = "DTT"; // 검지기유형
  93. //public static final String DTCT_TYPE_CD = "ACD"; // 검지기방향
  94. public static final String VMS_USAG_TYPE_CD = "VUT"; // VMS 용도 유형 코드
  95. public static final String VMS_TYPE_CD = "VMP"; // VMS 유형 코드
  96. public static final String REPT_CNGS_CD = "RCS"; // 반복정체 원본 코드
  97. public static final String FCLT_TYPE_CD = "FTC"; // 시설물 유형 코드
  98. public static final String FCLT_FAIL_TYPE_CD = "FFA"; // 시설물 장애 유형 코드
  99. // 시설물 관리
  100. public static final String FMS_CLASS = "FMS"; // 시설물 대분류
  101. public static final String FMS_FMITS = "FMITS"; // ITS 시설물
  102. public static final String FMS_FMSCRS = "FMSCRS"; // 스마트 교차로
  103. public static final String FMS_FMCNTR = "FMCNTR"; // 센터장비
  104. public static final String FMS_FMSIG = "FMSIG"; // 신호시설물
  105. public static final String FMS_WSTEP = "WSTEP"; // 사업단계
  106. public static final String FMS_FMSTP = "FMSTP"; // 시설물 구분
  107. public static final String FMS_FSTEP = "FSTEP"; // 시설물 장애진행상태구분
  108. public static final String FMS_FREG = "FREG"; // 시설물 장애등록구분
  109. public static final String FMS_FLVL = "FLVL"; // 시설물 장애등급구분
  110. public static final String FMS_FWTHR = "FWTHR"; // 시설물 장애발생시 날씨
  111. public static final String FMS_FMSG = "FMSG"; // 사용자 메지시 종류
  112. private static ConcurrentHashMap<String, HashMap<String, Code>> codes = new ConcurrentHashMap<>();
  113. @PostConstruct
  114. void init() {
  115. load();
  116. }
  117. public void load() {
  118. List<TbCmmnCd> codeList = this.repo.findAll();
  119. for (TbCmmnCd entity : codeList) {
  120. TbCmmnCdDto cd = entity.toDto();
  121. HashMap<String, Code> codeMap = codes.get(cd.getCmmnClsfCd());
  122. if (codeMap == null) {
  123. codeMap = new HashMap<>();
  124. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  125. codes.put(cd.getCmmnClsfCd(), codeMap);
  126. }
  127. else {
  128. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  129. }
  130. }
  131. }
  132. public List<TbCmmnCd> reload() {
  133. ConcurrentHashMap<String, HashMap<String, Code>> tempMap = new ConcurrentHashMap<>();
  134. List<TbCmmnCd> codeList = this.repo.findAll();
  135. for (TbCmmnCd entity : codeList) {
  136. TbCmmnCdDto cd = entity.toDto();
  137. HashMap<String, Code> codeMap = tempMap.get(cd.getCmmnClsfCd());
  138. if (codeMap == null) {
  139. codeMap = new HashMap<>();
  140. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  141. tempMap.put(cd.getCmmnClsfCd(), codeMap);
  142. }
  143. else {
  144. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  145. }
  146. }
  147. codes = tempMap;
  148. return codeList;
  149. }
  150. public void refresh(List<TbCmmnCdDto> codeList) {
  151. if (codeList == null) {
  152. return;
  153. }
  154. ConcurrentHashMap<String, HashMap<String, Code>> tempMap = new ConcurrentHashMap<>();
  155. for (TbCmmnCdDto cd : codeList) {
  156. HashMap<String, Code> codeMap = tempMap.get(cd.getCmmnClsfCd());
  157. if (codeMap == null) {
  158. codeMap = new HashMap<>();
  159. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  160. tempMap.put(cd.getCmmnClsfCd(), codeMap);
  161. }
  162. else {
  163. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  164. }
  165. }
  166. codes = tempMap;
  167. }
  168. public void merge(TbCmmnCdDto cd) {
  169. if (cd == null) {
  170. return;
  171. }
  172. HashMap<String, Code> codeMap = codes.get(cd.getCmmnClsfCd());
  173. if (codeMap == null) {
  174. HashMap<String, Code> codeMap_ = new HashMap<>();
  175. codeMap_.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  176. codes.put(cd.getCmmnClsfCd(), codeMap_);
  177. }
  178. else {
  179. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  180. }
  181. }
  182. public void remove(String cmmnClsfCd, String cmmnCd) {
  183. HashMap<String, Code> codeMap = codes.get(cmmnClsfCd);
  184. if (codeMap != null) {
  185. codeMap.remove(cmmnCd);
  186. }
  187. }
  188. public void update(String cmmnClsfCd, List<TbCmmnCdDto> result) {
  189. if (result == null) {
  190. return;
  191. }
  192. HashMap<String, Code> codeMap = new HashMap<>();
  193. for (TbCmmnCdDto cd : result) {
  194. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  195. }
  196. codes.put(cmmnClsfCd, codeMap);
  197. }
  198. public static String getCodeDesc(String CMMN_CLSF_CD, String CMMN_CD) {
  199. HashMap<String, Code> codeMap = codes.get(CMMN_CLSF_CD);
  200. if (codeMap != null) {
  201. Code code = codeMap.get(CMMN_CD);
  202. if (code != null) {
  203. return "[" + CMMN_CD + "] " + code.getDesc();
  204. }
  205. }
  206. return "[" + CMMN_CD + "] " + defUnknownDesc;
  207. }
  208. public static String getCodeDescShort(String CMMN_CLSF_CD, String CMMN_CD) {
  209. HashMap<String, Code> codeMap = codes.get(CMMN_CLSF_CD);
  210. if (codeMap != null) {
  211. Code code = codeMap.get(CMMN_CD);
  212. if (code != null) {
  213. return code.getDesc();
  214. }
  215. }
  216. return defUnknownDesc;
  217. }
  218. public static String getCodeEtcDescShort(String CMMN_CLSF_CD, String CMMN_CD) {
  219. HashMap<String, Code> codeMap = codes.get(CMMN_CLSF_CD);
  220. if (codeMap != null) {
  221. Code code = codeMap.get(CMMN_CD);
  222. if (code != null) {
  223. return code.getDesc();
  224. }
  225. }
  226. return defUnknownEtcDesc;
  227. }
  228. public static String getFcltGroupNm(String FCLT_TYPE) {
  229. HashMap<String, Code> codeMap = codes.get(FMS_CLASS);
  230. if (codeMap != null) {
  231. for (String key : codeMap.keySet()) {
  232. HashMap<String, Code> subCodeMap = codes.get(key);
  233. for (String subKey : subCodeMap.keySet()) {
  234. if (subKey.equals(FCLT_TYPE)) {
  235. return codeMap.get(key).getDesc();
  236. }
  237. }
  238. }
  239. }
  240. return defUnknownDesc;
  241. }
  242. public static String getFcltTypeNm(String FCLT_TYPE) {
  243. HashMap<String, Code> codeMap = codes.get(FMS_CLASS);
  244. if (codeMap != null) {
  245. for (String key : codeMap.keySet()) {
  246. HashMap<String, Code> subCodeMap = codes.get(key);
  247. for (Map.Entry<String, Code> e: subCodeMap.entrySet()) {
  248. if (e.getKey().equals(FCLT_TYPE)) {
  249. return e.getValue().getDesc();
  250. }
  251. }
  252. // for (String subKey : subCodeMap.keySet()) {
  253. // if (subKey.equals(FCLT_TYPE)) {
  254. // return subCodeMap.get(subKey).getDesc();
  255. // }
  256. // }
  257. }
  258. }
  259. return defUnknownDesc;
  260. }
  261. public static String getWeatherCode(String CMMN_CD_KOR_NM) {
  262. HashMap<String, Code> codeMap = codes.get(CmmnCdManager.INCD_CODE_DFW);
  263. if (codeMap != null) {
  264. for (Map.Entry<String, Code> e: codeMap.entrySet()) {
  265. Code code = e.getValue();
  266. if (StringUtils.equals(code.getDesc(), CMMN_CD_KOR_NM)) {
  267. return code.getCode();
  268. }
  269. }
  270. // for (String key : codeMap.keySet()) {
  271. // Code code = codeMap.get(key);
  272. // if (StringUtils.equals(code.getDesc(), CMMN_CD_KOR_NM)) {
  273. // return code.getCode();
  274. // }
  275. // }
  276. }
  277. return "NB0";
  278. }
  279. @Getter
  280. @ToString
  281. @AllArgsConstructor
  282. public static class Code {
  283. private String code;
  284. private String desc;
  285. private String englDesc;
  286. }
  287. }