Skip to content

Commit

Permalink
Merge pull request #147 from cgk95/hotfix/product_filter
Browse files Browse the repository at this point in the history
[Hotfix] 사용하지 않는 제품을 product 테이블에서 삭제하는 작업 추가
  • Loading branch information
gunsight1 authored Feb 19, 2024
2 parents 9eb265d + f3958cf commit 495d4de
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kernel360.modulebatch.product.job.core;

import com.kernel360.ecolife.entity.ReportedProduct;
import com.kernel360.modulebatch.product.job.infra.FilterUnusedProductTasklet;
import com.kernel360.modulebatch.product.job.infra.ReportedProductToProductItemProcessor;
import com.kernel360.product.entity.Product;
import jakarta.persistence.EntityManagerFactory;
Expand Down Expand Up @@ -38,15 +39,19 @@ public class ImportProductFromReportedProductJobConfig {

private final ReportedProductToProductItemProcessor reportedProductToProductItemProcessor;

private final FilterUnusedProductTasklet filterUnusedProductTasklet;

private final EntityManagerFactory emf;

@Bean
public Job importProductFromReportedProductJob(JobRepository jobRepository,
@Qualifier("importProductFromReportedProductStep") Step importProductFromReportedProductStep) {
@Qualifier("importProductFromReportedProductStep") Step importProductFromReportedProductStep,
@Qualifier("filterUnusedProductStep") Step filterUnusedProductStep) {
log.info("Import Product from ReportedProduct by Brand Job Build Configuration");

return new JobBuilder("ImportProductFromReportedProductJob", jobRepository)
.start(importProductFromReportedProductStep)
.next(filterUnusedProductStep)
.incrementer(new RunIdIncrementer())
.listener(new ImportProductFromReportedProductJobListener())
.build();
Expand Down Expand Up @@ -101,6 +106,15 @@ public JpaItemWriter<Product> productJpaItemWriter() {
.build();
}

@Bean
public Step filterUnusedProductStep(JobRepository jobRepository, PlatformTransactionManager transactionManager) {

return new StepBuilder("filterUnusedProductStep", jobRepository)
.tasklet(filterUnusedProductTasklet, transactionManager)
.listener(new ImportProductFromReportedProductStepListener())
.build();
}

//-- Execution Listener --//

public static class ImportProductFromReportedProductJobListener implements JobExecutionListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.kernel360.modulebatch.product.job.infra;

import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.StepScope;
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.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
@StepScope
@RequiredArgsConstructor
public class FilterUnusedProductTasklet implements Tasklet {

private final JdbcTemplate jdbcTemplate;

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
jdbcTemplate.update("delete from product where product.upper_item like '%세탁%'");
jdbcTemplate.update("delete from product where product.product_name similar to '%(방향제|그라스|통풍구|선바이저|살라딘|세탁|체인)%'");

return RepeatStatus.FINISHED;
}
}

0 comments on commit 495d4de

Please sign in to comment.