GgitsEtlpService.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. package com.ggits.etlp.server.service;
  2. import com.ggits.etlp.server.common.Elapsed;
  3. import com.ggits.etlp.server.common.TimeUtils;
  4. import com.ggits.etlp.server.config.ApplicationConfig;
  5. import com.ggits.etlp.server.dao.mapper.BatchDaoService;
  6. import com.ggits.etlp.server.dao.mapper.ggits.GgitsMapper;
  7. import com.ggits.etlp.server.dao.mapper.sig.SigMapper;
  8. import com.ggits.etlp.server.dao.mapper.sig.batch.SigDao;
  9. import com.ggits.etlp.server.dto.EtlpInfo;
  10. import com.ggits.etlp.server.dto.RegionCenter;
  11. import com.ggits.etlp.server.entity.ggits.*;
  12. import com.ggits.etlp.server.entity.sig.TbGgitsEtlp;
  13. import com.ggits.etlp.server.entity.sig.TbInt;
  14. import com.ggits.etlp.server.repository.ApplicationRepository;
  15. import com.ggits.etlp.server.repository.EtlpConst;
  16. import lombok.Getter;
  17. import lombok.RequiredArgsConstructor;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.slf4j.MDC;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import javax.annotation.PostConstruct;
  23. import javax.annotation.PreDestroy;
  24. import java.util.ArrayList;
  25. import java.util.Collections;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. @Slf4j
  29. @Getter
  30. @Service
  31. @RequiredArgsConstructor
  32. @Transactional(rollbackFor = {Exception.class})
  33. public class GgitsEtlpService {
  34. private final ApplicationConfig config;
  35. private final ApplicationRepository repo;
  36. private final GgitsMapper gitsMapper;
  37. private final SigMapper sigMapper;
  38. private final SigDao dao;
  39. private final String[] etlpTables = {
  40. EtlpConst.etlpTableInt,
  41. EtlpConst.etlpTableFlow,
  42. EtlpConst.etlpTableOperPlan,
  43. EtlpConst.etlpTableDyPlan,
  44. EtlpConst.etlpTableResrvPlan,
  45. EtlpConst.etlpTableSignalMap
  46. };
  47. private List<String> centerList;
  48. @PostConstruct
  49. private void init() {
  50. log.info("GgitsEtlpService.init: start.");
  51. log.info("GgitsEtlpService.init: ..end.");
  52. }
  53. @PreDestroy
  54. public void destroyService() {
  55. log.error("GgitsEtlpService.destroy. system terminated.......");
  56. }
  57. private void initEtlp() {
  58. this.repo.loadDb();
  59. this.centerList = new ArrayList<>(this.repo.getCenterMap().keySet());
  60. Collections.sort(this.centerList);
  61. for (String key : this.centerList) {
  62. RegionCenter center = this.repo.getCenterMap().get(key);
  63. if (center == null) {
  64. continue;
  65. }
  66. center.setElapsed(0);
  67. center.initEtlp();
  68. }
  69. for (String etlpTblNm : this.etlpTables) {
  70. List<TbGgitsEtlp> etlpList = this.sigMapper.selectGgitsEtlp(etlpTblNm);
  71. for (TbGgitsEtlp obj : etlpList) {
  72. RegionCenter center = this.repo.getCenterMap().get(obj.getRegionCd());
  73. if (center != null) {
  74. center.updateEtlp(etlpTblNm, obj);
  75. }
  76. }
  77. }
  78. }
  79. public void run() {
  80. Elapsed elapsed = new Elapsed();
  81. log.info("************************************************************************************************>");
  82. log.info("GGITS DBASE ETLP TO SIG START.");
  83. initEtlp();
  84. //교차로구성_연계, SCS_T_CON_INTLC
  85. etlpIntLc();
  86. //교차로이동류_연계, SCS_T_CON_INTFLOW
  87. etlpIntFlow();
  88. //교차로일계획_연계, SCS_T_CON_INTDPLAN
  89. etlpIntDPlan();
  90. //교차로주간계획_연계, SCS_T_CON_INTWEEK
  91. etlpIntWeek();
  92. //교차로예약계획_연계, SCS_T_CON_INTFPLAN
  93. etlpIntFPlan();
  94. //교차로시그널맵_연계, SCS_T_CON_INTSIGMAP
  95. etlpIntSigmap();
  96. log.info("GGITS DBASE ETLP TO SIG ..END. {}", elapsed.elapsedTimeStr());
  97. log.info("<************************************************************************************************");
  98. }
  99. private int getPageCount(int etlpCount) {
  100. int pageCount = (etlpCount / this.config.getPageCount()) + 1;
  101. if (0 == (etlpCount % this.config.getPageCount())) {
  102. pageCount--;
  103. }
  104. return pageCount;
  105. }
  106. private void updateEtlpResult(String tblName, List<HashMap<String, Object>> etlpLists) {
  107. int result;
  108. Elapsed elapsed = new Elapsed();
  109. try {
  110. result = this.dao.updateGgitsEtlp(etlpLists);
  111. log.info("updateGgitsEtlp: {}, {} EA, {}", tblName, result, elapsed.elapsedTimeStr());
  112. }
  113. catch (Exception e) {
  114. log.error("updateGgitsEtlp: {}, {}, Exceptions: {}", tblName, etlpLists, e.getMessage());
  115. }
  116. try {
  117. elapsed.reset();
  118. if (this.config.isLoggingHist()) {
  119. result = this.dao.insertGgitsEtlpHist(etlpLists);
  120. log.info("insertGgitsEtlpHist: {}, {} EA, {}", tblName, result, elapsed.elapsedTimeStr());
  121. }
  122. }
  123. catch (Exception e) {
  124. log.error("insertGgitsEtlpHist: {}, {}, Exceptions: {}", tblName, etlpLists, e.getMessage());
  125. }
  126. }
  127. //교차로구성_연계, SCS_T_CON_INTLC
  128. private void etlpIntLc() {
  129. log.info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^>");
  130. Elapsed elapsed = new Elapsed();
  131. Elapsed totElapsed = new Elapsed();
  132. log.info("TB_INT, SCS_T_CON_INTLC START. ETLP: {}", this.config.isEtlpInt());
  133. List<HashMap<String, Object>> etlpLists = new ArrayList<>();
  134. List<HashMap<String, Object>> lists;
  135. for (String key : this.centerList) {
  136. RegionCenter center = this.repo.getCenterMap().get(key);
  137. if (center == null) {
  138. continue;
  139. }
  140. TimeUtils.sleep(500);
  141. elapsed.reset();
  142. int writeCount = 0;
  143. Elapsed job = new Elapsed();
  144. EtlpInfo etlp = center.getEtlpIntLc();
  145. etlp.startEtlp();
  146. try {
  147. MDC.put("id", center.getLogKey());
  148. log.info("================================================================================================>");
  149. log.info("TB_INT, SCS_T_CON_INTLC START. {}, {}, {}, {}, ETLP: {}",
  150. center.getRegionCd(), center.getRegionNm(), center.getMinNodeId(), center.getMaxNodeId(), this.config.isEtlpInt());
  151. // this.sigMapper.initTbInt(center.getRegionCd());
  152. HashMap<Integer, TbInt> intMap = new HashMap<>();
  153. List<TbInt> intLists = this.sigMapper.selectTbInt(center.getRegionCd());
  154. for (TbInt intInt : intLists) {
  155. intMap.put(intInt.getIntNo(), intInt);
  156. }
  157. Integer dataCount = this.gitsMapper.selectScsTConIntLcCount(center, EtlpConst.qryCountAll);
  158. Integer etlpCount = this.gitsMapper.selectScsTConIntLcCount(center, etlp.getQryDt());
  159. etlp.setCount(dataCount, etlpCount);
  160. log.info("TB_INT, SCS_T_CON_INTLC .READ. {}, {}, SIG: {} EA, GGITS: DATA({}) ETLP({}) EA. {}, ETLP: {}",
  161. center.getRegionCd(), center.getRegionNm(), intLists.size(), dataCount, etlpCount, job.elapsedTimeStr(), this.config.isEtlpInt());
  162. if (etlpCount > 0) {
  163. List<TbScsTConIntLc> jobLists = this.gitsMapper.selectScsTConIntLc(center, etlp.getQryDt());
  164. log.info("TB_INT, SCS_T_CON_INTLC .READ. {}, {}, SIG: {} EA, GGITS: {} EA. {}, ETLP: {}",
  165. center.getRegionCd(), center.getRegionNm(), intLists.size(), jobLists.size(), job.elapsedTimeStr(), this.config.isEtlpInt());
  166. job.reset();
  167. if (this.config.isEtlpInt()) {
  168. lists = new ArrayList<>();
  169. for (TbScsTConIntLc obj : jobLists) {
  170. if (obj.getIntName() == null || obj.getIntName().isEmpty()) {
  171. TbInt orgInt = intMap.get(obj.getIntNo());
  172. if (orgInt != null) {
  173. obj.setIntName(orgInt.getIntNm());
  174. }
  175. if (obj.getIntName() == null || obj.getIntName().isEmpty()) {
  176. obj.setIntName("-");
  177. }
  178. }
  179. HashMap<String, Object> param = obj.toSig(center.getRegionCd());
  180. lists.add(param);
  181. if (lists.size() >= BatchDaoService.MAX_BATCH_SIZE) {
  182. writeCount += this.dao.updateTbInt(lists);
  183. lists = new ArrayList<>();
  184. }
  185. }
  186. if (!lists.isEmpty()) {
  187. writeCount += this.dao.updateTbInt(lists);
  188. }
  189. }
  190. }
  191. etlp.endEtlp(true, writeCount);
  192. log.info("TB_INT, SCS_T_CON_INTLC WRITE. {}, {}, {} EA. {}, ETLP: {}",
  193. center.getRegionCd(), center.getRegionNm(), writeCount, elapsed.elapsedTimeStr(), this.config.isEtlpInt());
  194. log.info("-------------------------------------------------------------------------------------------------");
  195. }
  196. catch (Exception e) {
  197. etlp.endEtlp(false, writeCount);
  198. log.error("TB_INT, SCS_T_CON_INTLC: {}, {}, Exceptions: {}", center.getRegionCd(), center.getRegionNm(), e.getMessage());
  199. }
  200. finally {
  201. center.setElapsed(center.getElapsed() + elapsed.milliSeconds());
  202. MDC.remove(center.getLogKey());
  203. MDC.clear();
  204. }
  205. etlpLists.add(etlp.toSig(center.getRegionCd(), EtlpConst.etlpTableInt));
  206. }
  207. updateEtlpResult(EtlpConst.etlpTableInt, etlpLists);
  208. log.info("TB_INT, SCS_T_CON_INTLC ..END. {}, ETLP: {}", totElapsed.elapsedTimeStr(), this.config.isEtlpInt());
  209. log.info("<^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
  210. }
  211. //교차로이동류_연계, SCS_T_CON_INTFLOW
  212. private void etlpIntFlow() {
  213. log.info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^>");
  214. Elapsed elapsed = new Elapsed();
  215. Elapsed totElapsed = new Elapsed();
  216. log.info("TB_INT_FLOW, SCS_T_CON_INTFLOW START.");
  217. List<HashMap<String, Object>> etlpLists = new ArrayList<>();
  218. List<HashMap<String, Object>> lists;
  219. for (String key : this.centerList) {
  220. RegionCenter center = this.repo.getCenterMap().get(key);
  221. if (center == null) {
  222. continue;
  223. }
  224. TimeUtils.sleep(500);
  225. elapsed.reset();
  226. int invalidData = 0;
  227. int writeCount = 0;
  228. int currWriteCount;
  229. Elapsed job = new Elapsed();
  230. EtlpInfo etlp = center.getEtlpFlow();
  231. etlp.startEtlp();
  232. try {
  233. MDC.put("id", center.getLogKey());
  234. log.info("TB_INT_FLOW, SCS_T_CON_INTFLOW START. {}, {}, {}, {}",
  235. center.getRegionCd(), center.getRegionNm(), center.getMinNodeId(), center.getMaxNodeId());
  236. Integer dataCount = this.gitsMapper.selectScsTConIntFlowCount(center, EtlpConst.qryCountAll);
  237. Integer etlpCount = this.gitsMapper.selectScsTConIntFlowCount(center, etlp.getQryDt());
  238. etlp.setCount(dataCount, etlpCount);
  239. log.info("TB_INT_FLOW, SCS_T_CON_INTFLOW .READ. {}, {}, DATA({}) ETLP({}) EA. {}",
  240. center.getRegionCd(), center.getRegionNm(), dataCount, etlpCount, job.elapsedTimeStr());
  241. if (etlpCount > 0) {
  242. int pageCount = getPageCount(etlpCount);
  243. for (int ii = 0; ii < pageCount; ii++) {
  244. int fromSeq = (ii * this.config.getPageCount());
  245. int toSeq = fromSeq + this.config.getPageCount();
  246. fromSeq++;
  247. List<TbScsTConIntFlow> result = this.gitsMapper.selectScsTConIntFlow(center, fromSeq, toSeq, etlp.getQryDt());
  248. log.info("TB_INT_FLOW, SCS_T_CON_INTFLOW .READ. {}, {}, {}. {}",
  249. center.getRegionCd(), center.getRegionNm(), String.format("%6d ~ %6d, %6d EA", fromSeq, toSeq, result.size()), job.elapsedTimeStr());
  250. TimeUtils.sleep(500);
  251. job.reset();
  252. lists = new ArrayList<>();
  253. currWriteCount = 0;
  254. for(TbScsTConIntFlow obj: result) {
  255. HashMap<String, Object> param = obj.toSig(center.getRegionCd());
  256. if (!param.isEmpty()) {
  257. lists.add(param);
  258. if (lists.size() >= BatchDaoService.MAX_BATCH_SIZE) {
  259. currWriteCount += this.dao.updateTbIntFlow(lists);
  260. lists = new ArrayList<>();
  261. }
  262. }
  263. else {
  264. invalidData++;
  265. }
  266. }
  267. if (!lists.isEmpty()) {
  268. currWriteCount += this.dao.updateTbIntFlow(lists);
  269. }
  270. writeCount += currWriteCount;
  271. log.info("TB_INT_FLOW, SCS_T_CON_INTFLOW WRITE. {}, {}, {}. {}",
  272. center.getRegionCd(), center.getRegionNm(), String.format("%6d ~ %6d, %6d EA", fromSeq, toSeq, currWriteCount), job.elapsedTimeStr());
  273. }
  274. }
  275. etlp.endEtlp(true, writeCount);
  276. log.info("TB_INT_FLOW, SCS_T_CON_INTFLOW WRITE. {}, {}, {} EA. Invalid Data {} EA. {}",
  277. center.getRegionCd(), center.getRegionNm(), writeCount, invalidData, elapsed.elapsedTimeStr());
  278. log.info("-------------------------------------------------------------------------------------------------");
  279. }
  280. catch (Exception e) {
  281. etlp.endEtlp(false, writeCount);
  282. log.error("TB_INT_FLOW, SCS_T_CON_INTFLOW: {}, {}, Exceptions: {}", center.getRegionCd(), center.getRegionNm(), e.getMessage());
  283. }
  284. finally {
  285. center.setElapsed(center.getElapsed() + elapsed.milliSeconds());
  286. MDC.remove(center.getLogKey());
  287. MDC.clear();
  288. }
  289. etlpLists.add(etlp.toSig(center.getRegionCd(), EtlpConst.etlpTableFlow));
  290. }
  291. updateEtlpResult(EtlpConst.etlpTableFlow, etlpLists);
  292. log.info("TB_INT_FLOW, SCS_T_CON_INTFLOW ..END. {}", totElapsed.elapsedTimeStr());
  293. log.info("<^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
  294. }
  295. //교차로일계획_연계, SCS_T_CON_INTDPLAN
  296. private void etlpIntDPlan() {
  297. log.info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^>");
  298. Elapsed elapsed = new Elapsed();
  299. Elapsed totElapsed = new Elapsed();
  300. log.info("TB_INT_OPER_PLAN, SCS_T_CON_INTDPLAN START.");
  301. List<HashMap<String, Object>> etlpLists = new ArrayList<>();
  302. List<HashMap<String, Object>> lists;
  303. for (String key : this.centerList) {
  304. RegionCenter center = this.repo.getCenterMap().get(key);
  305. if (center == null) {
  306. continue;
  307. }
  308. TimeUtils.sleep(500);
  309. elapsed.reset();
  310. int writeCount = 0;
  311. int currWriteCount;
  312. Elapsed job = new Elapsed();
  313. EtlpInfo etlp = center.getEtlpOperPlan();
  314. etlp.startEtlp();
  315. try {
  316. MDC.put("id", center.getLogKey());
  317. log.info("TB_INT_OPER_PLAN, SCS_T_CON_INTDPLAN START. {}, {}, {}, {}",
  318. center.getRegionCd(), center.getRegionNm(), center.getMinNodeId(), center.getMaxNodeId());
  319. Integer dataCount = this.gitsMapper.selectScsTConIntDPlanCount(center, EtlpConst.qryCountAll);
  320. Integer etlpCount = this.gitsMapper.selectScsTConIntDPlanCount(center, etlp.getQryDt());
  321. etlp.setCount(dataCount, etlpCount);
  322. log.info("TB_INT_OPER_PLAN, SCS_T_CON_INTDPLAN .READ. {}, {}, DATA({}) ETLP({}) EA. {}",
  323. center.getRegionCd(), center.getRegionNm(), dataCount, etlpCount, job.elapsedTimeStr());
  324. if (etlpCount > 0) {
  325. int pageCount = getPageCount(etlpCount);
  326. for (int ii = 0; ii < pageCount; ii++) {
  327. int fromSeq = (ii * this.config.getPageCount());
  328. int toSeq = fromSeq + this.config.getPageCount();
  329. fromSeq++;
  330. List<TbScsTConIntDPlan> result = this.gitsMapper.selectScsTConIntDPlan(center, fromSeq, toSeq, etlp.getQryDt());
  331. log.info("TB_INT_OPER_PLAN, SCS_T_CON_INTDPLAN .READ. {}, {}, {}. {}",
  332. center.getRegionCd(), center.getRegionNm(), String.format("%6d ~ %6d, %6d EA", fromSeq, toSeq, result.size()), job.elapsedTimeStr());
  333. TimeUtils.sleep(500);
  334. job.reset();
  335. lists = new ArrayList<>();
  336. currWriteCount = 0;
  337. for(TbScsTConIntDPlan obj: result) {
  338. HashMap<String, Object> param = obj.toSig(center.getRegionCd());
  339. lists.add(param);
  340. if (lists.size() >= BatchDaoService.MAX_BATCH_SIZE) {
  341. currWriteCount += this.dao.updateTbIntOperPlan(lists);
  342. lists = new ArrayList<>();
  343. }
  344. }
  345. if (!lists.isEmpty()) {
  346. currWriteCount += this.dao.updateTbIntOperPlan(lists);
  347. }
  348. writeCount += currWriteCount;
  349. log.info("TB_INT_OPER_PLAN, SCS_T_CON_INTDPLAN WRITE. {}, {}, {}. {}",
  350. center.getRegionCd(), center.getRegionNm(), String.format("%6d ~ %6d, %6d EA", fromSeq, toSeq, currWriteCount), job.elapsedTimeStr());
  351. }
  352. }
  353. etlp.endEtlp(true, writeCount);
  354. log.info("TB_INT_OPER_PLAN, SCS_T_CON_INTDPLAN WRITE. {}, {}, {} EA. {}",
  355. center.getRegionCd(), center.getRegionNm(), writeCount, elapsed.elapsedTimeStr());
  356. log.info("-------------------------------------------------------------------------------------------------");
  357. }
  358. catch (Exception e) {
  359. etlp.endEtlp(false, writeCount);
  360. log.error("TB_INT_OPER_PLAN, SCS_T_CON_INTDPLAN: {}, {}, Exceptions: {}", center.getRegionCd(), center.getRegionNm(), e.getMessage());
  361. }
  362. finally {
  363. center.setElapsed(center.getElapsed() + elapsed.milliSeconds());
  364. MDC.remove(center.getLogKey());
  365. MDC.clear();
  366. }
  367. etlpLists.add(etlp.toSig(center.getRegionCd(), EtlpConst.etlpTableOperPlan));
  368. }
  369. updateEtlpResult(EtlpConst.etlpTableOperPlan, etlpLists);
  370. log.info("TB_INT_OPER_PLAN, SCS_T_CON_INTDPLAN ..END. {}", totElapsed.elapsedTimeStr());
  371. log.info("<^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
  372. }
  373. //교차로주간계획_연계, SCS_T_CON_INTWEEK
  374. private void etlpIntWeek() {
  375. log.info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^>");
  376. Elapsed elapsed = new Elapsed();
  377. Elapsed totElapsed = new Elapsed();
  378. log.info("TB_INT_DY_PLAN, SCS_T_CON_INTWEEK START.");
  379. List<HashMap<String, Object>> etlpLists = new ArrayList<>();
  380. List<HashMap<String, Object>> lists;
  381. for (String key : this.centerList) {
  382. RegionCenter center = this.repo.getCenterMap().get(key);
  383. if (center == null) {
  384. continue;
  385. }
  386. TimeUtils.sleep(500);
  387. elapsed.reset();
  388. int writeCount = 0;
  389. int currWriteCount;
  390. Elapsed job = new Elapsed();
  391. EtlpInfo etlp = center.getEtlpDyPlan();
  392. etlp.startEtlp();
  393. try {
  394. MDC.put("id", center.getLogKey());
  395. log.info("TB_INT_DY_PLAN, SCS_T_CON_INTWEEK START. {}, {}, {}, {}",
  396. center.getRegionCd(), center.getRegionNm(), center.getMinNodeId(), center.getMaxNodeId());
  397. Integer dataCount = this.gitsMapper.selectScsTConIntWeekCount(center, EtlpConst.qryCountAll);
  398. Integer etlpCount = this.gitsMapper.selectScsTConIntWeekCount(center, etlp.getQryDt());
  399. etlp.setCount(dataCount, etlpCount);
  400. log.info("TB_INT_DY_PLAN, SCS_T_CON_INTWEEK .READ. {}, {}, DATA({}) ETLP({}) EA. {}",
  401. center.getRegionCd(), center.getRegionNm(), dataCount, etlpCount, job.elapsedTimeStr());
  402. if (etlpCount > 0) {
  403. int pageCount = getPageCount(etlpCount);
  404. for (int ii = 0; ii < pageCount; ii++) {
  405. int fromSeq = (ii * this.config.getPageCount());
  406. int toSeq = fromSeq + this.config.getPageCount();
  407. fromSeq++;
  408. List<TbScsTConIntWeek> result = this.gitsMapper.selectScsTConIntWeek(center, fromSeq, toSeq, etlp.getQryDt());
  409. log.info("TB_INT_DY_PLAN, SCS_T_CON_INTWEEK .READ. {}, {}, {}. {}",
  410. center.getRegionCd(), center.getRegionNm(), String.format("%6d ~ %6d, %6d EA", fromSeq, toSeq, result.size()), job.elapsedTimeStr());
  411. TimeUtils.sleep(500);
  412. job.reset();
  413. lists = new ArrayList<>();
  414. currWriteCount = 0;
  415. for(TbScsTConIntWeek obj: result) {
  416. HashMap<String, Object> param = obj.toSig(center.getRegionCd());
  417. lists.add(param);
  418. if (lists.size() >= BatchDaoService.MAX_BATCH_SIZE) {
  419. currWriteCount += this.dao.updateTbIntDyPlan(lists);
  420. lists = new ArrayList<>();
  421. }
  422. }
  423. if (!lists.isEmpty()) {
  424. currWriteCount += this.dao.updateTbIntDyPlan(lists);
  425. }
  426. writeCount += currWriteCount;
  427. log.info("TB_INT_DY_PLAN, SCS_T_CON_INTWEEK WRITE. {}, {}, {}. {}",
  428. center.getRegionCd(), center.getRegionNm(), String.format("%6d ~ %6d, %6d EA", fromSeq, toSeq, currWriteCount), job.elapsedTimeStr());
  429. }
  430. }
  431. etlp.endEtlp(true, writeCount);
  432. log.info("TB_INT_DY_PLAN, SCS_T_CON_INTWEEK WRITE. {}, {}, {} EA. {}",
  433. center.getRegionCd(), center.getRegionNm(), writeCount, elapsed.elapsedTimeStr());
  434. log.info("-------------------------------------------------------------------------------------------------");
  435. }
  436. catch (Exception e) {
  437. etlp.endEtlp(false, writeCount);
  438. log.error("TB_INT_DY_PLAN, SCS_T_CON_INTWEEK: {}, {}, Exceptions: {}", center.getRegionCd(), center.getRegionNm(), e.getMessage());
  439. }
  440. finally {
  441. center.setElapsed(center.getElapsed() + elapsed.milliSeconds());
  442. MDC.remove(center.getLogKey());
  443. MDC.clear();
  444. }
  445. etlpLists.add(etlp.toSig(center.getRegionCd(), EtlpConst.etlpTableDyPlan));
  446. }
  447. updateEtlpResult(EtlpConst.etlpTableDyPlan, etlpLists);
  448. log.info("TB_INT_DY_PLAN, SCS_T_CON_INTWEEK ..END. {}", totElapsed.elapsedTimeStr());
  449. log.info("<^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
  450. }
  451. //교차로예약계획_연계, SCS_T_CON_INTFPLAN
  452. private void etlpIntFPlan() {
  453. log.info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^>");
  454. Elapsed elapsed = new Elapsed();
  455. Elapsed totElapsed = new Elapsed();
  456. log.info("TB_INT_RESRV_PLAN, SCS_T_CON_INTFPLAN START.");
  457. List<HashMap<String, Object>> etlpLists = new ArrayList<>();
  458. List<HashMap<String, Object>> lists;
  459. for (String key : this.centerList) {
  460. RegionCenter center = this.repo.getCenterMap().get(key);
  461. if (center == null) {
  462. continue;
  463. }
  464. TimeUtils.sleep(500);
  465. elapsed.reset();
  466. int writeCount = 0;
  467. int currWriteCount;
  468. Elapsed job = new Elapsed();
  469. EtlpInfo etlp = center.getEtlpResrvPlan();
  470. etlp.startEtlp();
  471. try {
  472. MDC.put("id", center.getLogKey());
  473. log.info("TB_INT_RESRV_PLAN, SCS_T_CON_INTFPLAN START. {}, {}, {}, {}",
  474. center.getRegionCd(), center.getRegionNm(), center.getMinNodeId(), center.getMaxNodeId());
  475. Integer dataCount = this.gitsMapper.selectScsTConIntFPlanCount(center, EtlpConst.qryCountAll);
  476. Integer etlpCount = this.gitsMapper.selectScsTConIntFPlanCount(center, etlp.getQryDt());
  477. etlp.setCount(dataCount, etlpCount);
  478. log.info("TB_INT_RESRV_PLAN, SCS_T_CON_INTFPLAN .READ. {}, {}, DATA({}) ETLP({}) EA. {}",
  479. center.getRegionCd(), center.getRegionNm(), dataCount, etlpCount, job.elapsedTimeStr());
  480. if (etlpCount > 0) {
  481. int pageCount = getPageCount(etlpCount);
  482. for (int ii = 0; ii < pageCount; ii++) {
  483. int fromSeq = (ii * this.config.getPageCount());
  484. int toSeq = fromSeq + this.config.getPageCount();
  485. fromSeq++;
  486. List<TbScsTConIntFPlan> result = this.gitsMapper.selectScsTConIntFPlan(center, fromSeq, toSeq, etlp.getQryDt());
  487. log.info("TB_INT_RESRV_PLAN, SCS_T_CON_INTFPLAN .READ. {}, {}, {}. {}",
  488. center.getRegionCd(), center.getRegionNm(), String.format("%6d ~ %6d, %6d EA", fromSeq, toSeq, result.size()), job.elapsedTimeStr());
  489. TimeUtils.sleep(500);
  490. job.reset();
  491. lists = new ArrayList<>();
  492. currWriteCount = 0;
  493. for(TbScsTConIntFPlan obj: result) {
  494. HashMap<String, Object> param = obj.toSig(center.getRegionCd());
  495. lists.add(param);
  496. if (lists.size() >= BatchDaoService.MAX_BATCH_SIZE) {
  497. currWriteCount += this.dao.updateTbIntResrvPlan(lists);
  498. lists = new ArrayList<>();
  499. }
  500. }
  501. if (!lists.isEmpty()) {
  502. currWriteCount += this.dao.updateTbIntResrvPlan(lists);
  503. }
  504. writeCount += currWriteCount;
  505. log.info("TB_INT_RESRV_PLAN, SCS_T_CON_INTFPLAN WRITE. {}, {}, {}. {}",
  506. center.getRegionCd(), center.getRegionNm(), String.format("%6d ~ %6d, %6d EA", fromSeq, toSeq, currWriteCount), job.elapsedTimeStr());
  507. }
  508. }
  509. etlp.endEtlp(true, writeCount);
  510. log.info("TB_INT_RESRV_PLAN, SCS_T_CON_INTFPLAN WRITE. {}, {}, {} EA. {}",
  511. center.getRegionCd(), center.getRegionNm(), writeCount, elapsed.elapsedTimeStr());
  512. log.info("-------------------------------------------------------------------------------------------------");
  513. }
  514. catch (Exception e) {
  515. etlp.endEtlp(false, writeCount);
  516. log.error("TB_INT_RESRV_PLAN, SCS_T_CON_INTFPLAN: {}, {}, Exceptions: {}", center.getRegionCd(), center.getRegionNm(), e.getMessage());
  517. }
  518. finally {
  519. center.setElapsed(center.getElapsed() + elapsed.milliSeconds());
  520. MDC.remove(center.getLogKey());
  521. MDC.clear();
  522. }
  523. etlpLists.add(etlp.toSig(center.getRegionCd(), EtlpConst.etlpTableResrvPlan));
  524. }
  525. updateEtlpResult(EtlpConst.etlpTableResrvPlan, etlpLists);
  526. log.info("TB_INT_RESRV_PLAN, SCS_T_CON_INTFPLAN ..END. {}", totElapsed.elapsedTimeStr());
  527. log.info("<^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
  528. }
  529. //교차로시그널맵_연계, SCS_T_CON_INTSIGMAP
  530. private void etlpIntSigmap() {
  531. log.info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^>");
  532. Elapsed elapsed = new Elapsed();
  533. Elapsed totElapsed = new Elapsed();
  534. log.info("TB_INT_SIGNALMAP, SCS_T_CON_INTSIGMAP START.");
  535. List<HashMap<String, Object>> etlpLists = new ArrayList<>();
  536. List<HashMap<String, Object>> lists;
  537. for (String key : this.centerList) {
  538. RegionCenter center = this.repo.getCenterMap().get(key);
  539. if (center == null) {
  540. continue;
  541. }
  542. TimeUtils.sleep(500);
  543. elapsed.reset();
  544. int writeCount = 0;
  545. int currWriteCount;
  546. Elapsed job = new Elapsed();
  547. EtlpInfo etlp = center.getEtlpSigmap();
  548. etlp.startEtlp();
  549. try {
  550. MDC.put("id", center.getLogKey());
  551. log.info("TB_INT_SIGNALMAP, SCS_T_CON_INTSIGMAP START. {}, {}, {}, {}",
  552. center.getRegionCd(), center.getRegionNm(), center.getMinNodeId(), center.getMaxNodeId());
  553. Integer dataCount = this.gitsMapper.selectScsTConIntSigmapCount(center, EtlpConst.qryCountAll);
  554. Integer etlpCount = this.gitsMapper.selectScsTConIntSigmapCount(center, etlp.getQryDt());
  555. etlp.setCount(dataCount, etlpCount);
  556. log.info("TB_INT_SIGNALMAP, SCS_T_CON_INTSIGMAP .READ. {}, {}, DATA({}) ETLP({}) EA. {}",
  557. center.getRegionCd(), center.getRegionNm(), dataCount, etlpCount, job.elapsedTimeStr());
  558. if (etlpCount > 0) {
  559. int pageCount = getPageCount(etlpCount);
  560. for (int ii = 0; ii < pageCount; ii++) {
  561. int fromSeq = (ii * this.config.getPageCount());
  562. int toSeq = fromSeq + this.config.getPageCount();
  563. fromSeq++;
  564. List<TbScsTConIntSigmap> result = this.gitsMapper.selectScsTConIntSigmap(center, fromSeq, toSeq, etlp.getQryDt());
  565. log.info("TB_INT_SIGNALMAP, SCS_T_CON_INTSIGMAP .READ. {}, {}, {}. {}",
  566. center.getRegionCd(), center.getRegionNm(), String.format("%6d ~ %6d, %6d EA", fromSeq, toSeq, result.size()), job.elapsedTimeStr());
  567. TimeUtils.sleep(500);
  568. job.reset();
  569. lists = new ArrayList<>();
  570. currWriteCount = 0;
  571. for(TbScsTConIntSigmap obj: result) {
  572. HashMap<String, Object> param = obj.toSig(center.getRegionCd());
  573. lists.add(param);
  574. if (lists.size() >= BatchDaoService.MAX_BATCH_SIZE) {
  575. currWriteCount += this.dao.updateTbIntSignalMap(lists);
  576. lists = new ArrayList<>();
  577. }
  578. }
  579. if (!lists.isEmpty()) {
  580. currWriteCount += this.dao.updateTbIntSignalMap(lists);
  581. }
  582. writeCount += currWriteCount;
  583. log.info("TB_INT_SIGNALMAP, SCS_T_CON_INTSIGMAP WRITE. {}, {}, {}. {}",
  584. center.getRegionCd(), center.getRegionNm(), String.format("%6d ~ %6d, %6d EA", fromSeq, toSeq, currWriteCount), job.elapsedTimeStr());
  585. }
  586. }
  587. etlp.endEtlp(true, writeCount);
  588. log.info("TB_INT_SIGNALMAP, SCS_T_CON_INTSIGMAP WRITE. {}, {}, {} EA. {}",
  589. center.getRegionCd(), center.getRegionNm(), writeCount, elapsed.elapsedTimeStr());
  590. log.info("<================================================================================================");
  591. }
  592. catch (Exception e) {
  593. etlp.endEtlp(false, writeCount);
  594. log.error("TB_INT_SIGNALMAP, SCS_T_CON_INTSIGMAP: {}, {}, Exceptions: {}", center.getRegionCd(), center.getRegionNm(), e.getMessage());
  595. }
  596. finally {
  597. center.setElapsed(center.getElapsed() + elapsed.milliSeconds());
  598. MDC.remove(center.getLogKey());
  599. MDC.clear();
  600. }
  601. etlpLists.add(etlp.toSig(center.getRegionCd(), EtlpConst.etlpTableSignalMap));
  602. }
  603. updateEtlpResult(EtlpConst.etlpTableSignalMap, etlpLists);
  604. log.info("TB_INT_SIGNALMAP, SCS_T_CON_INTSIGMAP ..END. {}", totElapsed.elapsedTimeStr());
  605. log.info("<^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
  606. }
  607. }