CmmnCdManager.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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_UNKNOWN = "CMS2";
  84. public static final String CMNC_STTS_ERROR_DT = "19700101000000";
  85. public static final String CMNC_STTS_CD = "CMS"; // 통신상태코드
  86. public static final String MODL_STTS_CD = "MOS"; // 모듈상태
  87. public static final String PWER_STTS_CD = "PWS"; // 전원상태
  88. public static final String DOOR_STTS_CD = "CDS"; // 도어상태
  89. public static final String FAN_STTS_CD = "PAS"; // 팬상태
  90. public static final String HETR_STTS_CD = "HTS"; // 히터상태
  91. public static final String VIDEO_INPUT_CD = "VDI"; // VIDEO Input 상태
  92. public static final String CCTV_TYPE_CD = "CCTVT"; // CCTV 유형 코드
  93. public static final String DTCT_TYPE_CD = "DTT"; // 검지기유형
  94. //public static final String DTCT_TYPE_CD = "ACD"; // 검지기방향
  95. public static final String VMS_USAG_TYPE_CD = "VUT"; // VMS 용도 유형 코드
  96. public static final String VMS_TYPE_CD = "VMP"; // VMS 유형 코드
  97. public static final String REPT_CNGS_CD = "RCS"; // 반복정체 원본 코드
  98. public static final String FCLT_TYPE_CD = "FTC"; // 시설물 유형 코드
  99. public static final String FCLT_FAIL_TYPE_CD = "FFA"; // 시설물 장애 유형 코드
  100. // 시설물 관리
  101. public static final String FMS_CLASS = "FMS"; // 시설물 대분류
  102. public static final String FMS_FMITS = "FMITS"; // ITS 시설물
  103. public static final String FMS_FMSCRS = "FMSCRS"; // 스마트 교차로
  104. public static final String FMS_FMCNTR = "FMCNTR"; // 센터장비
  105. public static final String FMS_FMSIG = "FMSIG"; // 신호시설물
  106. public static final String FMS_WSTEP = "WSTEP"; // 사업단계
  107. public static final String FMS_FMSTP = "FMSTP"; // 시설물 구분
  108. public static final String FMS_FSTEP = "FSTEP"; // 시설물 장애진행상태구분
  109. public static final String FMS_FREG = "FREG"; // 시설물 장애등록구분
  110. public static final String FMS_FLVL = "FLVL"; // 시설물 장애등급구분
  111. public static final String FMS_FWTHR = "FWTHR"; // 시설물 장애발생시 날씨
  112. public static final String FMS_FMSG = "FMSG"; // 사용자 메지시 종류
  113. private static ConcurrentHashMap<String, HashMap<String, Code>> codes = new ConcurrentHashMap<>();
  114. @PostConstruct
  115. void init() {
  116. load();
  117. }
  118. public void load() {
  119. List<TbCmmnCd> codeList = this.repo.findAll();
  120. for (TbCmmnCd entity : codeList) {
  121. TbCmmnCdDto cd = entity.toDto();
  122. HashMap<String, Code> codeMap = codes.get(cd.getCmmnClsfCd());
  123. if (codeMap == null) {
  124. codeMap = new HashMap<>();
  125. Code code = new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm());
  126. codeMap.put(cd.getCmmnCd(), code);
  127. HashMap<String, Code> result = codes.putIfAbsent(cd.getCmmnClsfCd(), codeMap);
  128. if (result != null) {
  129. result.put(cd.getCmmnCd(), code);
  130. }
  131. //codes.put(cd.getCmmnClsfCd(), codeMap);
  132. }
  133. else {
  134. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  135. }
  136. }
  137. }
  138. private static void setCodes(ConcurrentHashMap<String, HashMap<String, Code>> codeMap) {
  139. codes = codeMap;
  140. }
  141. public List<TbCmmnCd> reload() {
  142. ConcurrentHashMap<String, HashMap<String, Code>> tempMap = new ConcurrentHashMap<>();
  143. List<TbCmmnCd> codeList = this.repo.findAll();
  144. for (TbCmmnCd entity : codeList) {
  145. TbCmmnCdDto cd = entity.toDto();
  146. HashMap<String, Code> codeMap = tempMap.get(cd.getCmmnClsfCd());
  147. if (codeMap == null) {
  148. codeMap = new HashMap<>();
  149. Code code = new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm());
  150. codeMap.put(cd.getCmmnCd(), code);
  151. HashMap<String, Code> result = tempMap.putIfAbsent(cd.getCmmnClsfCd(), codeMap);
  152. if (result != null) {
  153. result.put(cd.getCmmnCd(), code);
  154. }
  155. //tempMap.put(cd.getCmmnClsfCd(), codeMap);
  156. }
  157. else {
  158. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  159. }
  160. }
  161. setCodes(tempMap);
  162. //codes = tempMap;
  163. return codeList;
  164. }
  165. public void refresh(List<TbCmmnCdDto> codeList) {
  166. if (codeList == null) {
  167. return;
  168. }
  169. ConcurrentHashMap<String, HashMap<String, Code>> tempMap = new ConcurrentHashMap<>();
  170. for (TbCmmnCdDto cd : codeList) {
  171. HashMap<String, Code> codeMap = tempMap.get(cd.getCmmnClsfCd());
  172. if (codeMap == null) {
  173. codeMap = new HashMap<>();
  174. Code code = new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm());
  175. codeMap.put(cd.getCmmnCd(), code);
  176. HashMap<String, Code> result = tempMap.putIfAbsent(cd.getCmmnClsfCd(), codeMap);
  177. if (result != null) {
  178. result.put(cd.getCmmnCd(), code);
  179. }
  180. //tempMap.put(cd.getCmmnClsfCd(), codeMap);
  181. }
  182. else {
  183. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  184. }
  185. }
  186. setCodes(tempMap);
  187. //codes = tempMap;
  188. }
  189. public void merge(TbCmmnCdDto cd) {
  190. if (cd == null) {
  191. return;
  192. }
  193. HashMap<String, Code> codeMap = codes.get(cd.getCmmnClsfCd());
  194. if (codeMap == null) {
  195. HashMap<String, Code> codeMap_ = new HashMap<>();
  196. Code code = new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm());
  197. codeMap_.put(cd.getCmmnCd(), code);
  198. HashMap<String, Code> result = codes.putIfAbsent(cd.getCmmnClsfCd(), codeMap_);
  199. if (result != null) {
  200. result.put(cd.getCmmnCd(), code);
  201. }
  202. //codes.put(cd.getCmmnClsfCd(), codeMap_);
  203. }
  204. else {
  205. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  206. }
  207. }
  208. public void remove(String cmmnClsfCd, String cmmnCd) {
  209. HashMap<String, Code> codeMap = codes.get(cmmnClsfCd);
  210. if (codeMap != null) {
  211. codeMap.remove(cmmnCd);
  212. }
  213. }
  214. public void update(String cmmnClsfCd, List<TbCmmnCdDto> result) {
  215. if (result == null) {
  216. return;
  217. }
  218. HashMap<String, Code> codeMap = new HashMap<>();
  219. for (TbCmmnCdDto cd : result) {
  220. codeMap.put(cd.getCmmnCd(), new Code(cd.getCmmnCd(), cd.getCmmnCdKorNm(), cd.getCmmnDescEnglNm()));
  221. }
  222. codes.put(cmmnClsfCd, codeMap);
  223. }
  224. public static String getCodeDesc(String CMMN_CLSF_CD, String CMMN_CD) {
  225. HashMap<String, Code> codeMap = codes.get(CMMN_CLSF_CD);
  226. if (codeMap != null) {
  227. Code code = codeMap.get(CMMN_CD);
  228. if (code != null) {
  229. return "[" + CMMN_CD + "] " + code.getDesc();
  230. }
  231. }
  232. return "[" + CMMN_CD + "] " + defUnknownDesc;
  233. }
  234. public static String getCodeDescShort(String CMMN_CLSF_CD, String CMMN_CD) {
  235. HashMap<String, Code> codeMap = codes.get(CMMN_CLSF_CD);
  236. if (codeMap != null) {
  237. Code code = codeMap.get(CMMN_CD);
  238. if (code != null) {
  239. return code.getDesc();
  240. }
  241. }
  242. return defUnknownDesc;
  243. }
  244. public static String getCodeEtcDescShort(String CMMN_CLSF_CD, String CMMN_CD) {
  245. HashMap<String, Code> codeMap = codes.get(CMMN_CLSF_CD);
  246. if (codeMap != null) {
  247. Code code = codeMap.get(CMMN_CD);
  248. if (code != null) {
  249. return code.getDesc();
  250. }
  251. }
  252. return defUnknownEtcDesc;
  253. }
  254. public static String getFcltGroupNm(String FCLT_TYPE) {
  255. HashMap<String, Code> codeMap = codes.get(FMS_CLASS);
  256. if (codeMap != null) {
  257. for (String key : codeMap.keySet()) {
  258. HashMap<String, Code> subCodeMap = codes.get(key);
  259. for (String subKey : subCodeMap.keySet()) {
  260. if (subKey.equals(FCLT_TYPE)) {
  261. return codeMap.get(key).getDesc();
  262. }
  263. }
  264. }
  265. }
  266. return defUnknownDesc;
  267. }
  268. public static String getFcltTypeNm(String FCLT_TYPE) {
  269. HashMap<String, Code> codeMap = codes.get(FMS_CLASS);
  270. if (codeMap != null) {
  271. for (String key : codeMap.keySet()) {
  272. HashMap<String, Code> subCodeMap = codes.get(key);
  273. for (Map.Entry<String, Code> e: subCodeMap.entrySet()) {
  274. if (e.getKey().equals(FCLT_TYPE)) {
  275. return e.getValue().getDesc();
  276. }
  277. }
  278. // for (String subKey : subCodeMap.keySet()) {
  279. // if (subKey.equals(FCLT_TYPE)) {
  280. // return subCodeMap.get(subKey).getDesc();
  281. // }
  282. // }
  283. }
  284. }
  285. return defUnknownDesc;
  286. }
  287. public static String getWeatherCode(String CMMN_CD_KOR_NM) {
  288. HashMap<String, Code> codeMap = codes.get(CmmnCdManager.INCD_CODE_DFW);
  289. if (codeMap != null) {
  290. for (Map.Entry<String, Code> e: codeMap.entrySet()) {
  291. Code code = e.getValue();
  292. if (StringUtils.equals(code.getDesc(), CMMN_CD_KOR_NM)) {
  293. return code.getCode();
  294. }
  295. }
  296. // for (String key : codeMap.keySet()) {
  297. // Code code = codeMap.get(key);
  298. // if (StringUtils.equals(code.getDesc(), CMMN_CD_KOR_NM)) {
  299. // return code.getCode();
  300. // }
  301. // }
  302. }
  303. return "NB0";
  304. }
  305. @Getter
  306. @ToString
  307. @AllArgsConstructor
  308. public static class Code {
  309. private String code;
  310. private String desc;
  311. private String englDesc;
  312. }
  313. }