package com.zswl.cloud.springBtach.server.core.config;

import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author Wy
 */
@Configuration
public class ChannelOrderBatchConfig {

    @Resource
    private StepBuilderFactory stepBuilderFactory;

    @Bean
    public Tasklet channelOrderTaskletA(){
        return new Tasklet() {
            @Override
            public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
                System.out.println("----------------channelOrderTaskletA---------------" + chunkContext.getStepContext().getJobParameters().get("name"));
                return RepeatStatus.FINISHED;
            }
        };
    }

    @Bean
    public Tasklet channelOrderTaskletB(){
        return new Tasklet() {
            @Override
            public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
                System.out.println("------------channelOrderTaskletB-------------------");
                return RepeatStatus.FINISHED;
            }
        };
    }

    @Bean
    public Tasklet channelOrderTaskletC(){
        return new Tasklet() {
            @Override
            public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
                System.out.println("----------------channelOrderTaskletC---------------");
                return RepeatStatus.FINISHED;
            }
        };
    }

    @Bean
    public Step channelOrderStepA(){
        //tasklet 执行step逻辑， 类似 Thread()--->可以执行runable接口
        return stepBuilderFactory.get("channelOrderStepA")
                .tasklet(channelOrderTaskletA())
                .build();
    }

    @Bean
    public Step channelOrderStepB(){
        //tasklet 执行step逻辑， 类似 Thread()--->可以执行runable接口
        return stepBuilderFactory.get("channelOrderStepB")
                .tasklet(channelOrderTaskletB())
                .build();
    }

    @Bean
    public Step channelOrderStepC(){
        //tasklet 执行step逻辑， 类似 Thread()--->可以执行runable接口
        return stepBuilderFactory.get("channelOrderStepC")
                .tasklet(channelOrderTaskletC())
                .build();
    }

}
