Sfoglia il codice sorgente

배치ID로 배치명 가져오기 추가, 배치로그 생성 및 종료 처리 추가

gagamel 5 anni fa
parent
commit
a89d12b380

+ 52 - 3
style24.batch/src/main/java/com/style24/batch/biz/job/TsbAbstractJob.java

@@ -3,6 +3,11 @@ package com.style24.batch.biz.job;
 import java.sql.Timestamp;
 import java.util.Collection;
 
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.style24.batch.biz.service.TsbBatchService;
+
 import lombok.extern.slf4j.Slf4j;
 
 /**
@@ -17,7 +22,8 @@ public abstract class TsbAbstractJob<I, O, R> {
 	private long startTime = 0L;
 	private long endTime = 0L;
 
-	protected String batchName;
+	private String batchId;
+	private String batchName;
 
 	private I readItem = null;
 	private O convertedItem = null;
@@ -25,10 +31,23 @@ public abstract class TsbAbstractJob<I, O, R> {
 
 	public int totalCount = 0;
 
+	@Autowired
+	private TsbBatchService batchService;
+
+	private Integer batchLogSq;	// 배치로그일련번호
+
 	/**
 	 * Batch Job 시작 로그를 출력한다.
 	 */
 	protected void printStart() {
+		if (StringUtils.isNotBlank(batchId)) {
+			// 배치명 조회
+			batchName = batchService.getBatchName(batchId);
+
+			// 배치로그 생성
+			batchLogSq = batchService.createBatchLog(batchId);
+		}
+
 		startTime = System.currentTimeMillis();
 
 		log.info("################################################################################");
@@ -63,6 +82,11 @@ public abstract class TsbAbstractJob<I, O, R> {
 	 * Batch Job 종료 로그를 출력한다.
 	 */
 	protected void printEnd() {
+		if (StringUtils.isNotBlank(batchId)) {
+			// 배치로그 종료 처리
+			batchService.updateBatchLog(batchLogSq);
+		}
+
 		endTime = System.currentTimeMillis();
 
 		log.info("Start Time: {}", new Timestamp(startTime));
@@ -73,8 +97,33 @@ public abstract class TsbAbstractJob<I, O, R> {
 	}
 
 	/**
-	 * 배치를 실행한다.
-	 * @param batchName - 배치명
+	 * 배치ID로 배치를 실행한다.
+	 * @param batchId - 배치ID
+	 * @throws Exception
+	 */
+	public void runById(String batchId) throws Exception {
+		this.batchId = batchId;
+
+		this.printStart();
+
+		readItem = this.read();
+
+		if (readItem != null) {
+			convertedItem = this.process(readItem);
+
+			resultItem = this.write(convertedItem);
+
+			this.notify(resultItem);
+		} else { // 배치 처리할 대상 데이터가 없으면 종료
+			log.info("처리할 데이터가 없습니다.\n");
+		}
+
+		this.printEnd();
+	}
+
+	/**
+	 * 배치명으로 배치를 실행한다.
+	 * @param batchId - 배치ID
 	 * @throws Exception
 	 */
 	public void run(String batchName) throws Exception {