feat: KT GIBIS 토큰 갱신 배치 반영
parent
64e505a29f
commit
db57a59690
@ -0,0 +1,114 @@
|
|||||||
|
package kr.xit.batch.ens.job;
|
||||||
|
|
||||||
|
import org.springframework.batch.core.Job;
|
||||||
|
import org.springframework.batch.core.Step;
|
||||||
|
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
|
||||||
|
import org.springframework.batch.core.configuration.annotation.JobScope;
|
||||||
|
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import kr.xit.batch.ens.task.KtGbsAccessTokenUpdateTasklet;
|
||||||
|
import kr.xit.biz.ens.service.IEnsBatchKtGbsAccessTokenUpdateService;
|
||||||
|
import kr.xit.core.biz.batch.CustomRunIdIncrementer;
|
||||||
|
import kr.xit.core.biz.batch.listener.CustomJobListener;
|
||||||
|
import kr.xit.core.biz.batch.listener.CustomStepListener;
|
||||||
|
import kr.xit.core.biz.batch.listener.NoWorkFoundStepListener;
|
||||||
|
import kr.xit.core.biz.batch.service.IBatchCmmService;
|
||||||
|
import kr.xit.core.biz.batch.task.BatchEndTasklet;
|
||||||
|
import kr.xit.core.biz.batch.task.BatchFailEndTasklet;
|
||||||
|
import kr.xit.core.biz.batch.task.BatchStartTasklet;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* description :
|
||||||
|
*
|
||||||
|
* packageName : kr.xit.batch.ens.job
|
||||||
|
* fileName : KtGbsAccessTokenUpdateJobConfig
|
||||||
|
* author : seojh
|
||||||
|
* date : 2024-08-29
|
||||||
|
* ======================================================================
|
||||||
|
* 변경일 변경자 변경 내용
|
||||||
|
* ----------------------------------------------------------------------
|
||||||
|
* 2024-08-29 julim 최초 생성
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Configuration
|
||||||
|
public class KtGbsAccessTokenUpdateJobConfig {
|
||||||
|
private static final String JOB_NAME = "ktGbsAccessTokenUpdateJob";
|
||||||
|
|
||||||
|
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
||||||
|
private final JobBuilderFactory jobBuilderFactory;
|
||||||
|
private final StepBuilderFactory stepBuilderFactory;
|
||||||
|
|
||||||
|
private final IBatchCmmService lockService;
|
||||||
|
private final IEnsBatchKtGbsAccessTokenUpdateService service;
|
||||||
|
|
||||||
|
@Bean(name = JOB_NAME)
|
||||||
|
public Job ktGbsAccessTokenUpdateJob() {
|
||||||
|
return jobBuilderFactory.get(JOB_NAME)
|
||||||
|
.incrementer(new CustomRunIdIncrementer())
|
||||||
|
.listener(new CustomJobListener())
|
||||||
|
.listener(new CustomStepListener())
|
||||||
|
.listener(new NoWorkFoundStepListener())
|
||||||
|
|
||||||
|
// JOB 시작
|
||||||
|
// start() 결과가 FAILED 인경우 종료
|
||||||
|
.start(start())
|
||||||
|
.on("FAILED")
|
||||||
|
.end()
|
||||||
|
|
||||||
|
// start()의 결과로 부터 FAILED를 제외한 모든 경우 to() 실행
|
||||||
|
//.from(start())
|
||||||
|
.on("*")
|
||||||
|
.to(execution())
|
||||||
|
.on("FAILED")
|
||||||
|
.to(fail())
|
||||||
|
|
||||||
|
.from(execution())
|
||||||
|
// to() 실행 결과와 상관 없이 end() 실행
|
||||||
|
.on("*")
|
||||||
|
.to(end())
|
||||||
|
|
||||||
|
// JOB 종료
|
||||||
|
.end()
|
||||||
|
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = JOB_NAME + "_step")
|
||||||
|
public Step execution() {
|
||||||
|
return stepBuilderFactory.get(JOB_NAME + "_step")
|
||||||
|
.tasklet(new KtGbsAccessTokenUpdateTasklet(service))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@JobScope
|
||||||
|
@Bean(name = JOB_NAME + "_start_step")
|
||||||
|
protected Step start() {
|
||||||
|
return stepBuilderFactory.get("Job_Locking")
|
||||||
|
.tasklet(new BatchStartTasklet(lockService))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@JobScope
|
||||||
|
@Bean(name = JOB_NAME + "_end_step")
|
||||||
|
protected Step end() {
|
||||||
|
return stepBuilderFactory.get("Lock_Release")
|
||||||
|
.tasklet(new BatchEndTasklet(lockService))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@JobScope
|
||||||
|
@Bean(name = JOB_NAME + "_fail_step")
|
||||||
|
protected Step fail() {
|
||||||
|
return stepBuilderFactory.get("Lock_Release")
|
||||||
|
.tasklet(new BatchFailEndTasklet(lockService))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package kr.xit.batch.ens.scheduler;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.batch.core.JobParameter;
|
||||||
|
import org.springframework.batch.core.JobParameters;
|
||||||
|
import org.springframework.batch.core.JobParametersInvalidException;
|
||||||
|
import org.springframework.batch.core.launch.JobLauncher;
|
||||||
|
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||||
|
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import kr.xit.batch.ens.job.KtGbsAccessTokenUpdateJobConfig;
|
||||||
|
import kr.xit.biz.common.ApiConstants;
|
||||||
|
import kr.xit.biz.common.ApiConstants.SignguCode;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* description :상태 close - send-ok
|
||||||
|
* 대상 : 연계 발송 마스터(tb_cntc_sndng_mastr)
|
||||||
|
* -> 연계 발송 마스터(tb_cntc_sndng_mastr)
|
||||||
|
* 통합 발송 마스터(tb_ens_unity_sndng_mastr)
|
||||||
|
* 발송 마스터(tb_ens_sndng_mastr)
|
||||||
|
* packageName : kr.xit.batch.ens.scheduler
|
||||||
|
* fileName : SndngCloseJobScheduler
|
||||||
|
* author : seojh
|
||||||
|
* date : 2023-06-14
|
||||||
|
* ======================================================================
|
||||||
|
* 변경일 변경자 변경 내용
|
||||||
|
* ----------------------------------------------------------------------
|
||||||
|
* 2023-06-14 seojh 최초 생성
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Component
|
||||||
|
public class KtGbsAccessTokenUpdateJobScheduler {
|
||||||
|
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
||||||
|
private final JobLauncher jobLauncher;
|
||||||
|
private final KtGbsAccessTokenUpdateJobConfig jobConfiguration;
|
||||||
|
@Value("${app.slack-webhook.enabled:false}")
|
||||||
|
private String isSlackEnabled;
|
||||||
|
|
||||||
|
@Scheduled(cron = "${app.batch.cron.ens.kt-gibis-token}")
|
||||||
|
public void runJob() {
|
||||||
|
|
||||||
|
Map<String, JobParameter> confMap = new HashMap<>();
|
||||||
|
confMap.put("startDate", new JobParameter(new Date()));
|
||||||
|
confMap.put("isSlackEnabled", new JobParameter(isSlackEnabled));
|
||||||
|
|
||||||
|
try {
|
||||||
|
for(SignguCode signguCode : SignguCode.values()) {
|
||||||
|
confMap.put("signguCode", new JobParameter(signguCode.getCode()));
|
||||||
|
confMap.put("ffnlgCode", new JobParameter(ApiConstants.FFNLN_CODE));
|
||||||
|
JobParameters jobParameters = new JobParameters(confMap);
|
||||||
|
jobLauncher.run(jobConfiguration.ktGbsAccessTokenUpdateJob(), jobParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (JobExecutionAlreadyRunningException | JobInstanceAlreadyCompleteException
|
||||||
|
| JobParametersInvalidException | org.springframework.batch.core.repository.JobRestartException e) {
|
||||||
|
|
||||||
|
log.error(e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
package kr.xit.batch.ens.task;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.slf4j.MDC;
|
||||||
|
import org.springframework.batch.core.ExitStatus;
|
||||||
|
import org.springframework.batch.core.StepContribution;
|
||||||
|
import org.springframework.batch.core.configuration.annotation.JobScope;
|
||||||
|
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||||
|
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||||
|
import org.springframework.batch.repeat.RepeatStatus;
|
||||||
|
|
||||||
|
import kr.xit.batch.ens.task.cmm.TaskCmmUtils;
|
||||||
|
import kr.xit.biz.ens.model.kt.KtCommonDTO;
|
||||||
|
import kr.xit.biz.ens.service.IEnsBatchKtGbsAccessTokenUpdateService;
|
||||||
|
import kr.xit.core.exception.ErrorParse;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* description :
|
||||||
|
*
|
||||||
|
* packageName : kr.xit.batch.ens.task
|
||||||
|
* fileName : SndngCloseTasklet
|
||||||
|
* author : seojh
|
||||||
|
* date : 2023-06-14
|
||||||
|
* ======================================================================
|
||||||
|
* 변경일 변경자 변경 내용
|
||||||
|
* ----------------------------------------------------------------------
|
||||||
|
* 2023-06-14 seojh 최초 생성
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class KtGbsAccessTokenUpdateTasklet implements Tasklet {
|
||||||
|
private final IEnsBatchKtGbsAccessTokenUpdateService service;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JobScope
|
||||||
|
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
|
||||||
|
final String isSlackEnabled = contribution.getStepExecution().getJobParameters().getString("isSlackEnabled");
|
||||||
|
|
||||||
|
try {
|
||||||
|
MDC.put("request_trace_batch_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
MDC.put("method", "POST");
|
||||||
|
MDC.put("service_error_msg", "");
|
||||||
|
|
||||||
|
service.modifyAccessToken(
|
||||||
|
KtCommonDTO.KtMnsRequest.builder()
|
||||||
|
.signguCode(contribution.getStepExecution().getJobParameters().getString("signguCode"))
|
||||||
|
.ffnlgCode(contribution.getStepExecution().getJobParameters().getString("ffnlgCode"))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}catch(Exception e){
|
||||||
|
String errMsg = ErrorParse.extractError(e).getMessage();
|
||||||
|
log.error("KtGbsAccessTokenUpdateTasklet error :: {}", e.getMessage());
|
||||||
|
MDC.put("service_error_msg", errMsg);
|
||||||
|
TaskCmmUtils.taskBatchErrorLog(
|
||||||
|
contribution.getStepExecution().getJobExecution().getJobInstance().getJobName(),
|
||||||
|
errMsg,
|
||||||
|
isSlackEnabled
|
||||||
|
);
|
||||||
|
contribution.setExitStatus(ExitStatus.FAILED);
|
||||||
|
return RepeatStatus.FINISHED;
|
||||||
|
}
|
||||||
|
contribution.setExitStatus(ExitStatus.COMPLETED);
|
||||||
|
return RepeatStatus.FINISHED;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
package kr.xit.biz.ens.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import kr.xit.biz.ens.cmm.CmmEnsBizUtils;
|
||||||
|
import kr.xit.biz.ens.model.kt.KtCommonDTO;
|
||||||
|
import kr.xit.core.model.ApiResponseDTO;
|
||||||
|
import kr.xit.core.service.AbstractService;
|
||||||
|
import kr.xit.core.spring.util.ApiWebClientUtil;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* description : 모바일 전자고지 배치 서비스
|
||||||
|
* - 배치에서 호출되는 클래스로 배치 로그등 Transaction 분리 필요
|
||||||
|
* packageName : kr.xit.biz.ens.service
|
||||||
|
* fileName : EnsBatchKtGbsAccessTokenUpdateService
|
||||||
|
* author : limju
|
||||||
|
* date : 2024-08-29
|
||||||
|
* ======================================================================
|
||||||
|
* 변경일 변경자 변경 내용
|
||||||
|
* ----------------------------------------------------------------------
|
||||||
|
* 2024-08-29 limju 최초 생성
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class EnsBatchKtGbsAccessTokenUpdateService extends AbstractService implements IEnsBatchKtGbsAccessTokenUpdateService {
|
||||||
|
@Value("${app.contract.host}")
|
||||||
|
private String apiHost;
|
||||||
|
|
||||||
|
@Value("${app.contract.kt.gibis.api.requestToken}")
|
||||||
|
private String requestToken;
|
||||||
|
|
||||||
|
private final ApiWebClientUtil apiWebClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
|
public void modifyAccessToken(final KtCommonDTO.KtMnsRequest dto) {
|
||||||
|
final String url = apiHost + requestToken;
|
||||||
|
|
||||||
|
apiWebClient.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
dto,
|
||||||
|
ApiResponseDTO.class,
|
||||||
|
CmmEnsBizUtils.getHeadeMap());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package kr.xit.biz.ens.service;
|
||||||
|
|
||||||
|
import kr.xit.biz.ens.model.kt.KtCommonDTO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* description :
|
||||||
|
* packageName : kr.xit.biz.ens.service
|
||||||
|
* fileName : IEnsBatchKtGbsAccessTokenUpdateService
|
||||||
|
* author : limju
|
||||||
|
* date : 2024 8월 29
|
||||||
|
* ======================================================================
|
||||||
|
* 변경일 변경자 변경 내용
|
||||||
|
* ----------------------------------------------------------------------
|
||||||
|
* 2024 8월 29 limju 최초 생성
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public interface IEnsBatchKtGbsAccessTokenUpdateService {
|
||||||
|
void modifyAccessToken(final KtCommonDTO.KtMnsRequest dto);
|
||||||
|
}
|
Loading…
Reference in New Issue