From b6c4c08a04f17ca248b2d30d6061d005fd5b578b Mon Sep 17 00:00:00 2001 From: damho Date: Thu, 21 Mar 2024 09:27:30 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor:=20application.properties=20dev?= =?UTF-8?q?=20=EB=82=98=EB=88=84=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.properties | 1 + src/main/resources/application.properties | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/application-dev.properties diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 0000000..fa71b44 --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1 @@ +database.mysql.url=65b73eab47984c8b9b70241c698406cd \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0e31f00..7b9a4ab 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,7 +6,6 @@ key.manager.path=/keymanager/v1.0/appkey/{app-key}/secrets/{key-id} key.manager.app-key=CuKPvJQR7enquqrZ key.manager.password=mybooks ## mysql -database.mysql.url=65b73eab47984c8b9b70241c698406cd database.mysql.userName=901b405fe80d4c00b14bc099a72a33ad database.mysql.password=cda93b8395b641bfbe9a967cd60fdd49 database.mysql.initialSize=10 @@ -17,4 +16,7 @@ database.mysql.maxWait=1000 spring.application.name=batch-service #mybatis spring.batch.jdbc.initialize-schema=always -mybatis.executor-type=batch \ No newline at end of file +mybatis.executor-type=batch +## +#spring.profiles.active=dev +database.mysql.url=9053ef8fd6e04a87aab73321a565c1b2 \ No newline at end of file From b343b77a1efdaa6036a9e5a4e84f4cff57744dac Mon Sep 17 00:00:00 2001 From: damho Date: Thu, 21 Mar 2024 09:36:53 +0900 Subject: [PATCH 02/10] =?UTF-8?q?refactor:=20application.properties=20dev?= =?UTF-8?q?=20=EB=82=98=EB=88=84=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java | 3 ++- .../batch/userstatuschange/UserStatusChangeBatchConfig.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java index bbe5a7c..dd583cc 100644 --- a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java @@ -69,7 +69,8 @@ public class BirthDayCouponBatchConfig { * 제공한 입력이 유요하지 않은 경우 발생 * @throws JobRestartException 작업을 다시 시작하려는 불법적인 시도를 나타내는 예외 */ - @Scheduled(cron = "0 30 23 L * *") +// @Scheduled(cron = "0 30 23 L * *") + @Scheduled(cron = "0 40 9 21 3 *") public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { diff --git a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java index 6f80e6a..b487c2f 100644 --- a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java @@ -62,7 +62,8 @@ public class UserStatusChangeBatchConfig { * 제공한 입력이 유효하지 않은 경우 발생 * @throws JobRestartException 작업을 다시 시작하려는 시도를 나타내는 예외 */ - @Scheduled(cron = "0 0 0 * * *") +// @Scheduled(cron = "0 0 0 * * *") + @Scheduled(cron = "0 40 9 21 3 *") public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd:HH:mm:ss"); From 0bc4b88f9185e1a4d3e63063a3dd021ea82c0cc9 Mon Sep 17 00:00:00 2001 From: damho Date: Thu, 21 Mar 2024 09:40:11 +0900 Subject: [PATCH 03/10] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=9C=84=ED=95=B4=20cron=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java | 2 +- .../batch/userstatuschange/UserStatusChangeBatchConfig.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java index dd583cc..e3de56c 100644 --- a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java @@ -70,7 +70,7 @@ public class BirthDayCouponBatchConfig { * @throws JobRestartException 작업을 다시 시작하려는 불법적인 시도를 나타내는 예외 */ // @Scheduled(cron = "0 30 23 L * *") - @Scheduled(cron = "0 40 9 21 3 *") + @Scheduled(cron = "0 45 9 21 3 *") public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { diff --git a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java index b487c2f..ca0ac55 100644 --- a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java @@ -63,7 +63,7 @@ public class UserStatusChangeBatchConfig { * @throws JobRestartException 작업을 다시 시작하려는 시도를 나타내는 예외 */ // @Scheduled(cron = "0 0 0 * * *") - @Scheduled(cron = "0 40 9 21 3 *") + @Scheduled(cron = "0 45 9 21 3 *") public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd:HH:mm:ss"); From 1490f325902f347a6551bcefb5e8b668941f7905 Mon Sep 17 00:00:00 2001 From: damho Date: Thu, 21 Mar 2024 09:48:39 +0900 Subject: [PATCH 04/10] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=9C=84=ED=95=B4=20cron=20=EC=88=98=EC=A0=95,=20zone=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java | 2 +- .../batch/userstatuschange/UserStatusChangeBatchConfig.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java index e3de56c..f85348d 100644 --- a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java @@ -70,7 +70,7 @@ public class BirthDayCouponBatchConfig { * @throws JobRestartException 작업을 다시 시작하려는 불법적인 시도를 나타내는 예외 */ // @Scheduled(cron = "0 30 23 L * *") - @Scheduled(cron = "0 45 9 21 3 *") + @Scheduled(cron = "0 55 9 21 3 *", zone = "Asia/Seoul") public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { diff --git a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java index ca0ac55..a8d0c2b 100644 --- a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java @@ -63,7 +63,7 @@ public class UserStatusChangeBatchConfig { * @throws JobRestartException 작업을 다시 시작하려는 시도를 나타내는 예외 */ // @Scheduled(cron = "0 0 0 * * *") - @Scheduled(cron = "0 45 9 21 3 *") + @Scheduled(cron = "0 55 9 21 3 *", zone = "Asia/Seoul") public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd:HH:mm:ss"); From 0da7fdeba428e33e58f514f50c27589405e7323e Mon Sep 17 00:00:00 2001 From: damho Date: Thu, 21 Mar 2024 09:53:02 +0900 Subject: [PATCH 05/10] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=9C=84=ED=95=B4=20cron=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java index f85348d..753581a 100644 --- a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java @@ -70,7 +70,7 @@ public class BirthDayCouponBatchConfig { * @throws JobRestartException 작업을 다시 시작하려는 불법적인 시도를 나타내는 예외 */ // @Scheduled(cron = "0 30 23 L * *") - @Scheduled(cron = "0 55 9 21 3 *", zone = "Asia/Seoul") + @Scheduled(cron = "0 56 9 21 3 *", zone = "Asia/Seoul") public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { From 9f16d783b7eb7a889d224a3eb4207f51bc0f1114 Mon Sep 17 00:00:00 2001 From: damho Date: Thu, 21 Mar 2024 10:01:53 +0900 Subject: [PATCH 06/10] =?UTF-8?q?refactor:=20=EC=83=9D=EC=9D=BC=EC=BF=A0?= =?UTF-8?q?=ED=8F=B0,=20=ED=9A=8C=EC=9B=90=EC=83=81=ED=83=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=99=84=EB=A3=8C.?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=9B=90=EB=9E=98=EB=8C=80=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java | 3 +-- .../batch/userstatuschange/UserStatusChangeBatchConfig.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java index 753581a..b9a6a5d 100644 --- a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java @@ -69,8 +69,7 @@ public class BirthDayCouponBatchConfig { * 제공한 입력이 유요하지 않은 경우 발생 * @throws JobRestartException 작업을 다시 시작하려는 불법적인 시도를 나타내는 예외 */ -// @Scheduled(cron = "0 30 23 L * *") - @Scheduled(cron = "0 56 9 21 3 *", zone = "Asia/Seoul") + @Scheduled(cron = "0 30 23 L * *", zone = "Asia/Seoul") public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { diff --git a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java index a8d0c2b..52c0bb0 100644 --- a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java @@ -62,8 +62,7 @@ public class UserStatusChangeBatchConfig { * 제공한 입력이 유효하지 않은 경우 발생 * @throws JobRestartException 작업을 다시 시작하려는 시도를 나타내는 예외 */ -// @Scheduled(cron = "0 0 0 * * *") - @Scheduled(cron = "0 55 9 21 3 *", zone = "Asia/Seoul") + @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd:HH:mm:ss"); From f769b599589121e3bc52c3c69bef742633c567e6 Mon Sep 17 00:00:00 2001 From: damho Date: Thu, 21 Mar 2024 16:41:24 +0900 Subject: [PATCH 07/10] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EB=93=B1?= =?UTF-8?q?=EA=B8=89=20=EB=B3=80=EA=B2=BD=20=EB=B0=B0=EC=B9=98=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserGradeChangeBatchConfig.java | 110 ++++++++++++++++++ .../mapper/UserActualPaymentMapper.java | 23 ++++ .../model/UserActualPayment.java | 23 ++++ .../useractualpayment/model/UserGrade.java | 22 ++++ .../mybatis-useractualpaymentmapper.xml | 47 ++++++++ 5 files changed, 225 insertions(+) create mode 100644 src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java create mode 100644 src/main/java/com/mybooks/batch/useractualpayment/mapper/UserActualPaymentMapper.java create mode 100644 src/main/java/com/mybooks/batch/useractualpayment/model/UserActualPayment.java create mode 100644 src/main/java/com/mybooks/batch/useractualpayment/model/UserGrade.java create mode 100644 src/main/resources/mapper/mybatis-useractualpaymentmapper.xml diff --git a/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java new file mode 100644 index 0000000..71f8b26 --- /dev/null +++ b/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java @@ -0,0 +1,110 @@ +package com.mybooks.batch.config.batch.usergradechangebatchconfig; + +import com.mybooks.batch.useractualpayment.model.UserActualPayment; +import com.mybooks.batch.useractualpayment.model.UserGrade; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import lombok.RequiredArgsConstructor; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.batch.MyBatisBatchItemWriter; +import org.mybatis.spring.batch.MyBatisPagingItemReader; +import org.mybatis.spring.batch.builder.MyBatisBatchItemWriterBuilder; +import org.mybatis.spring.batch.builder.MyBatisPagingItemReaderBuilder; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.JobParametersBuilder; +import org.springframework.batch.core.JobParametersInvalidException; +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.batch.core.configuration.annotation.StepScope; +import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; +import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; +import org.springframework.batch.core.repository.JobRestartException; +import org.springframework.batch.item.ItemProcessor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.Scheduled; + +/** + * packageName : com.mybooks.batch.config.batch.usergradechangebatchconfig + * fileName : UserGradeChangeBatchConfig + * author : damho-lee + * date : 3/21/24 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 3/21/24 damho-lee 최초 생성 + */ +@Configuration +@RequiredArgsConstructor +public class UserGradeChangeBatchConfig { + private final JobBuilderFactory jobBuilderFactory; + private final StepBuilderFactory stepBuilderFactory; + public final SqlSessionFactory sqlSessionFactory; + private final JobLauncher jobLauncher; + private static final int CHUNK_SIZE = 10; + + @Scheduled(cron = "30 * * * * *", zone = "Asia/Seoul") + public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, + JobParametersInvalidException, JobRestartException { + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd:HH:mm:ss"); + String formattedDateTime = LocalDateTime.now().format(formatter); + + JobParameters parameters = new JobParametersBuilder() + .addString("requestDate", formattedDateTime) + .toJobParameters(); + jobLauncher.run(userGradeChangeJob(), parameters); + } + + @Bean + public Job userGradeChangeJob() { + return jobBuilderFactory.get("changeUserGradeJob") + .start(changeUserGradeStep(null)) + .build(); + } + + @Bean + @JobScope + public Step changeUserGradeStep(@Value("#{jobParameters['requestDate']}") String requestDate) { + return stepBuilderFactory.get("changeUserGradeStep") + .chunk(CHUNK_SIZE) + .reader(userActualPaymentReader(null)) + .processor(userActualPaymentProcessor(null)) + .writer(updateUserGradeWriter(null)) + .build(); + } + + @Bean + @StepScope + public MyBatisPagingItemReader userActualPaymentReader( + @Value("#{jobParameters['requestDate']}") String requestDate) { + return new MyBatisPagingItemReaderBuilder() + .pageSize(CHUNK_SIZE) + .sqlSessionFactory(sqlSessionFactory) + .queryId("com.mybooks.batch.useractualpayment.mapper.UserActualPaymentMapper.getUserActualPayment") + .build(); + } + + @Bean + @StepScope + public ItemProcessor userActualPaymentProcessor( + @Value("#{jobParameters['requestDate']}") String requestDate) { + return userActualPayment -> new UserGrade(userActualPayment.getUserId(), userActualPayment.getUserGradeId()); + } + + @Bean + @StepScope + public MyBatisBatchItemWriter updateUserGradeWriter( + @Value("#{jobParameters['requestDate']}") String requestDate) { + return new MyBatisBatchItemWriterBuilder() + .sqlSessionFactory(sqlSessionFactory) + .statementId("com.mybooks.batch.useractualpayment.mapper.UserActualPaymentMapper.updateUserGrade") + .build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/mybooks/batch/useractualpayment/mapper/UserActualPaymentMapper.java b/src/main/java/com/mybooks/batch/useractualpayment/mapper/UserActualPaymentMapper.java new file mode 100644 index 0000000..78d6bbf --- /dev/null +++ b/src/main/java/com/mybooks/batch/useractualpayment/mapper/UserActualPaymentMapper.java @@ -0,0 +1,23 @@ +package com.mybooks.batch.useractualpayment.mapper; + +import com.mybooks.batch.useractualpayment.model.UserActualPayment; +import com.mybooks.batch.useractualpayment.model.UserGrade; +import org.apache.ibatis.annotations.Mapper; + +/** + * packageName : com.mybooks.batch.useractualpayment.mapper + * fileName : UserActualPaymentMapper + * author : damho-lee + * date : 3/21/24 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 3/21/24 damho-lee 최초 생성 + */ +@Mapper +public interface UserActualPaymentMapper { + UserActualPayment getUserActualPayment(); + + void updateUserGrade(UserGrade userGrade); +} diff --git a/src/main/java/com/mybooks/batch/useractualpayment/model/UserActualPayment.java b/src/main/java/com/mybooks/batch/useractualpayment/model/UserActualPayment.java new file mode 100644 index 0000000..5d26535 --- /dev/null +++ b/src/main/java/com/mybooks/batch/useractualpayment/model/UserActualPayment.java @@ -0,0 +1,23 @@ +package com.mybooks.batch.useractualpayment.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * packageName : com.mybooks.batch.order.model + * fileName : Order + * author : damho-lee + * date : 3/20/24 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 3/20/24 damho-lee 최초 생성 + */ +@Getter +@AllArgsConstructor +public class UserActualPayment { + private Long userId; + private Integer actualPayment; + private Integer userGradeId; +} diff --git a/src/main/java/com/mybooks/batch/useractualpayment/model/UserGrade.java b/src/main/java/com/mybooks/batch/useractualpayment/model/UserGrade.java new file mode 100644 index 0000000..6b1e06e --- /dev/null +++ b/src/main/java/com/mybooks/batch/useractualpayment/model/UserGrade.java @@ -0,0 +1,22 @@ +package com.mybooks.batch.useractualpayment.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * packageName : com.mybooks.batch.useractualpayment.model + * fileName : UserGrade + * author : damho-lee + * date : 3/21/24 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 3/21/24 damho-lee 최초 생성 + */ +@Getter +@AllArgsConstructor +public class UserGrade { + private Long userId; + private Integer userGradeId; +} diff --git a/src/main/resources/mapper/mybatis-useractualpaymentmapper.xml b/src/main/resources/mapper/mybatis-useractualpaymentmapper.xml new file mode 100644 index 0000000..1c447ff --- /dev/null +++ b/src/main/resources/mapper/mybatis-useractualpaymentmapper.xml @@ -0,0 +1,47 @@ + + + + + + + UPDATE user + SET user_grade_id = #{userGradeId}, + user_grade_changed_date = CURRENT_DATE + WHERE user_id = #{userId} + + \ No newline at end of file From 654c763c122ecf618287f11a09a5e59e928fd282 Mon Sep 17 00:00:00 2001 From: damho Date: Thu, 21 Mar 2024 16:47:30 +0900 Subject: [PATCH 08/10] =?UTF-8?q?docs:=20Javadoc=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserGradeChangeBatchConfig.java | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java index 71f8b26..feb5bc4 100644 --- a/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java @@ -45,11 +45,26 @@ public class UserGradeChangeBatchConfig { private final JobBuilderFactory jobBuilderFactory; private final StepBuilderFactory stepBuilderFactory; + /** + * The Sql session factory. + */ public final SqlSessionFactory sqlSessionFactory; private final JobLauncher jobLauncher; private static final int CHUNK_SIZE = 10; - @Scheduled(cron = "30 * * * * *", zone = "Asia/Seoul") + /** + * methodName : runJob
+ * author : damho-lee
+ * description : 최근 3개월의 실결제금액에 따라 회원 등급 조회해서 회원등급 변경하는 Job 을 실행시키는 메서드. 3개월에 한 번 1일 오전 1시에 실행
+ * + * @throws JobInstanceAlreadyCompleteException Job 이 이미 완료되어 실행시킬 Job 이 없다 -> JobParameter 가 다르면 다른 Job 으로 인식한다 + * @throws JobExecutionAlreadyRunningException Job 이 이미 실행중이다 -> 스프링 배치가 DB 의 테이블을 참조하는데 배치 프로그램이 + * 비정상적으로 종료되는 경우 DB 테이블에 완료되었다고 작성하지 못하기 때문에 발생 + * @throws JobParametersInvalidException JobParameter 가 유요하지 않다 -> 필요한 Parameter 가 제공되지 않거나 + * 제공한 입력이 유요하지 않은 경우 발생 + * @throws JobRestartException 작업을 다시 시작하려는 불법적인 시도를 나타내는 예외 + */ + @Scheduled(cron = "0 0 1 1 */3 *", zone = "Asia/Seoul") public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { @@ -62,6 +77,13 @@ public void runJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlr jobLauncher.run(userGradeChangeJob(), parameters); } + /** + * methodName : userGradeChangeJob
+ * author : damho-lee
+ * description : 회원 등급 변경 Job.
+ * + * @return job + */ @Bean public Job userGradeChangeJob() { return jobBuilderFactory.get("changeUserGradeJob") @@ -69,6 +91,14 @@ public Job userGradeChangeJob() { .build(); } + /** + * methodName : changeUserGradeStep
+ * author : damho-lee
+ * description : 회원 등급 변경하는 Step.
+ * + * @param requestDate String + * @return step + */ @Bean @JobScope public Step changeUserGradeStep(@Value("#{jobParameters['requestDate']}") String requestDate) { @@ -80,6 +110,14 @@ public Step changeUserGradeStep(@Value("#{jobParameters['requestDate']}") String .build(); } + /** + * methodName : userActualPaymentReader
+ * author : damho-lee
+ * description : userId 와 최근 3개월의 실결제금액으로 어느 등급에 해당하는지(userGradeId)를 조회하는 reader.
+ * + * @param requestDate String + * @return MyBatisPagingItemReader + */ @Bean @StepScope public MyBatisPagingItemReader userActualPaymentReader( @@ -91,6 +129,14 @@ public MyBatisPagingItemReader userActualPaymentReader( .build(); } + /** + * methodName : userActualPaymentProcessor
+ * author : damho-lee
+ * description : 회원 아이디, 실결제금액, 회원 등급 아이디 -> 회원 아이디, 회원 등급 아이디로 변환하는 processor.
+ * + * @param requestDate String + * @return ItemProcessor + */ @Bean @StepScope public ItemProcessor userActualPaymentProcessor( @@ -98,6 +144,14 @@ public ItemProcessor userActualPaymentProcessor( return userActualPayment -> new UserGrade(userActualPayment.getUserId(), userActualPayment.getUserGradeId()); } + /** + * methodName : updateUserGradeWriter
+ * author : damho-lee
+ * description : 회원 등급 변경하는 writer. 회원등급 변경일자는 현재시간으로.
+ * + * @param requestDate String + * @return MyBatisBatchItemWriter + */ @Bean @StepScope public MyBatisBatchItemWriter updateUserGradeWriter( From 1c964a035956d74f0b06c0ee6ecbdd7ef9ddfb8a Mon Sep 17 00:00:00 2001 From: damho Date: Sun, 24 Mar 2024 19:21:35 +0900 Subject: [PATCH 09/10] =?UTF-8?q?refactor:=20CHUNK=5FSIZE=2010000=20?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java | 2 +- .../usergradechangebatchconfig/UserGradeChangeBatchConfig.java | 2 +- .../batch/userstatuschange/UserStatusChangeBatchConfig.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java index b9a6a5d..e48158e 100644 --- a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java @@ -55,7 +55,7 @@ public class BirthDayCouponBatchConfig { public final SqlSessionFactory sqlSessionFactory; private final JobLauncher jobLauncher; private final CouponMapper couponMapper; - private static final int CHUNK_SIZE = 10; + private static final int CHUNK_SIZE = 10000; /** * methodName : runJob
diff --git a/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java index feb5bc4..3b28499 100644 --- a/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java @@ -50,7 +50,7 @@ public class UserGradeChangeBatchConfig { */ public final SqlSessionFactory sqlSessionFactory; private final JobLauncher jobLauncher; - private static final int CHUNK_SIZE = 10; + private static final int CHUNK_SIZE = 10000; /** * methodName : runJob
diff --git a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java index 52c0bb0..0df9c2c 100644 --- a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java @@ -48,7 +48,7 @@ public class UserStatusChangeBatchConfig { private final StepBuilderFactory stepBuilderFactory; public final SqlSessionFactory sqlSessionFactory; private final JobLauncher jobLauncher; - private static final int CHUNK_SIZE = 10; + private static final int CHUNK_SIZE = 10000; /** * methodName : runJob
From 0f72095454296514b311f68216fb10d52e959739 Mon Sep 17 00:00:00 2001 From: damho Date: Sun, 24 Mar 2024 19:30:25 +0900 Subject: [PATCH 10/10] =?UTF-8?q?refactor:=20public=20->=20private=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../batch/birthdaycoupon/BirthDayCouponBatchConfig.java | 2 +- .../UserGradeChangeBatchConfig.java | 5 +---- .../batch/userstatuschange/UserStatusChangeBatchConfig.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java index e48158e..f35c74d 100644 --- a/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/birthdaycoupon/BirthDayCouponBatchConfig.java @@ -52,7 +52,7 @@ public class BirthDayCouponBatchConfig { private final JobBuilderFactory jobBuilderFactory; private final StepBuilderFactory stepBuilderFactory; - public final SqlSessionFactory sqlSessionFactory; + private final SqlSessionFactory sqlSessionFactory; private final JobLauncher jobLauncher; private final CouponMapper couponMapper; private static final int CHUNK_SIZE = 10000; diff --git a/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java index 3b28499..d8c9cc1 100644 --- a/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/usergradechangebatchconfig/UserGradeChangeBatchConfig.java @@ -45,10 +45,7 @@ public class UserGradeChangeBatchConfig { private final JobBuilderFactory jobBuilderFactory; private final StepBuilderFactory stepBuilderFactory; - /** - * The Sql session factory. - */ - public final SqlSessionFactory sqlSessionFactory; + private final SqlSessionFactory sqlSessionFactory; private final JobLauncher jobLauncher; private static final int CHUNK_SIZE = 10000; diff --git a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java index 0df9c2c..a704c4c 100644 --- a/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java +++ b/src/main/java/com/mybooks/batch/config/batch/userstatuschange/UserStatusChangeBatchConfig.java @@ -46,7 +46,7 @@ public class UserStatusChangeBatchConfig { private final JobBuilderFactory jobBuilderFactory; private final StepBuilderFactory stepBuilderFactory; - public final SqlSessionFactory sqlSessionFactory; + private final SqlSessionFactory sqlSessionFactory; private final JobLauncher jobLauncher; private static final int CHUNK_SIZE = 10000;