From d7cc157171381b5a78a6edbb468f0d19ba799299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A3=BC=EC=9D=BC?= Date: Sat, 23 May 2026 03:33:28 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20ACIKey=20=ED=86=A0=ED=81=B0=20=EB=B0=9C?= =?UTF-8?q?=EA=B8=89=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B0=B0=EC=B9=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(TASK=5FBATCH=5FACIKEY)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - acikey 패키지 신규 생성 - AciKeyTokenJobConfig.java: Job/Step 설정 - AciKeyTokenTasklet.java: API 호출 및 토큰 확인 로직 - application-dev.yaml: acikey 설정값 추가 (url/userid/apikey) --- .../acikey/AciKeyTokenJobConfig.java | 35 ++++++++ .../acikey/AciKeyTokenTasklet.java | 79 +++++++++++++++++++ src/main/resources/application-dev.yaml | 5 ++ 3 files changed, 119 insertions(+) create mode 100644 src/main/java/com/wb/domainserver/acikey/AciKeyTokenJobConfig.java create mode 100644 src/main/java/com/wb/domainserver/acikey/AciKeyTokenTasklet.java diff --git a/src/main/java/com/wb/domainserver/acikey/AciKeyTokenJobConfig.java b/src/main/java/com/wb/domainserver/acikey/AciKeyTokenJobConfig.java new file mode 100644 index 0000000..e7e2da3 --- /dev/null +++ b/src/main/java/com/wb/domainserver/acikey/AciKeyTokenJobConfig.java @@ -0,0 +1,35 @@ +package com.wb.domainserver.acikey; + +import org.springframework.batch.core.Job; +import org.springframework.batch.core.Step; +import org.springframework.batch.core.job.builder.JobBuilder; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.PlatformTransactionManager; +import lombok.RequiredArgsConstructor; + +// ACIKey 토큰 발급 테스트 배치 - Job/Step 설정 +@Configuration +@RequiredArgsConstructor +public class AciKeyTokenJobConfig { + + private final JobRepository jobRepository; + private final PlatformTransactionManager transactionManager; + private final AciKeyTokenTasklet aciKeyTokenTasklet; + + @Bean + public Job aciKeyTokenJob() { + return new JobBuilder("aciKeyTokenJob", jobRepository) + .start(aciKeyTokenStep()) + .build(); + } + + @Bean + public Step aciKeyTokenStep() { + return new StepBuilder("aciKeyTokenStep", jobRepository) + .tasklet(aciKeyTokenTasklet, transactionManager) + .build(); + } +} diff --git a/src/main/java/com/wb/domainserver/acikey/AciKeyTokenTasklet.java b/src/main/java/com/wb/domainserver/acikey/AciKeyTokenTasklet.java new file mode 100644 index 0000000..7a773ed --- /dev/null +++ b/src/main/java/com/wb/domainserver/acikey/AciKeyTokenTasklet.java @@ -0,0 +1,79 @@ +package com.wb.domainserver.acikey; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.batch.core.StepContribution; +import org.springframework.batch.core.scope.context.ChunkContext; +import org.springframework.batch.core.step.tasklet.Tasklet; +import org.springframework.batch.repeat.RepeatStatus; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.*; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import java.util.Map; + +// ACIKey 토큰 발급 테스트 배치 - API 호출 및 토큰 확인 로직 +@Slf4j +@Component +public class AciKeyTokenTasklet implements Tasklet { + + @Value("${acikey.url}") + private String aciKeyUrl; + + @Value("${acikey.userid}") + private String userId; + + @Value("${acikey.apikey}") + private String apiKey; + + @Override + public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) { + + log.info("[AciKeyBatch] 배치 시작"); + log.info("[AciKeyBatch] API URL: {}", aciKeyUrl); + + try { + // Header 설정 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("USERID", userId); + headers.set("APIKEY", apiKey); + + HttpEntity requestEntity = new HttpEntity<>("{}", headers); + + // API 호출 + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.exchange( + aciKeyUrl, + HttpMethod.POST, + requestEntity, + Map.class + ); + + Map body = response.getBody(); + log.info("[AciKeyBatch] 응답 전체: {}", body); + + String status = (String) body.get("Status"); + String aciKey = (String) body.get("ACIKey"); + String errMsg = (String) body.get("ErrMsg"); + + if ("A10".equals(status)) { + log.info("[AciKeyBatch] ✅ 토큰 발급 성공!"); + log.info("[AciKeyBatch] ACIKey: {}", aciKey); + contribution.incrementWriteCount(1); + } else { + log.error("[AciKeyBatch] ❌ 토큰 발급 실패. Status: {}, ErrMsg: {}", status, errMsg); + throw new RuntimeException("ACIKey 토큰 발급 실패. Status: " + status + ", ErrMsg: " + errMsg); + } + + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + log.error("[AciKeyBatch] ❌ API 호출 중 오류 발생: {}", e.getMessage(), e); + throw new RuntimeException("AciKey API 호출 오류", e); + } + + log.info("[AciKeyBatch] 배치 종료"); + return RepeatStatus.FINISHED; + } +} diff --git a/src/main/resources/application-dev.yaml b/src/main/resources/application-dev.yaml index 74f42b5..8b5558b 100644 --- a/src/main/resources/application-dev.yaml +++ b/src/main/resources/application-dev.yaml @@ -30,3 +30,8 @@ secret: mail: host: 10.2.1.76 port: 25 + +acikey: + url: https://acieshop.com/api/kr/token/ + userid: UNIHAN + apikey: DC94F29AFD5399F54AAE7FAA46045B65