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

import com.github.microservice.auth.security.helper.AuthHelper;
import com.github.microservice.core.helper.SpringBeanHelper;
import com.zhongshu.payment.client.service.v2.OrderService2;
import com.zswl.cloud.shop.client.service.ShopService;
import com.zswl.cloud.springBtach.server.core.helper.RedisHelper;
import com.zswl.cloud.springBtach.server.core.job.Ypp.YppOrderJob;
import lombok.experimental.Delegate;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import javax.annotation.Resource;

@Configuration
public class CreateOrderStep2Demo {

    @Resource
    private StepBuilderFactory stepBuilderFactory;

    @Resource
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    OrderService2 orderService2;

    @Autowired
    ShopService shopService;

    @Autowired
    AuthHelper authHelper;

    @Autowired
    RedisHelper redisHelper;

    @Lazy
    @Autowired
    YppOrderJob createOrderStep;


    @Autowired
    @Delegate
    private StandardOrderJobDemo standardStep;

    @Autowired
    private SpringBeanHelper springBeanHelper;


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


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

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

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

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


//        var user = new User();
//        Map<String,Object>  map = BeanMap.create(user);
//
//        map.get("name").equals(user.getName());
//        user.setName("sss");
//
//        map.put("name","sss");
//
//        map.entrySet().forEach(it->{
//            System.out.println(it.getKey()+" - "+ it.getValue());
//        });


        return stepBuilderFactory.get("createCommon")
                .tasklet((contribution, chunkContext) -> {


                    //todo OderService.create()

                    return RepeatStatus.FINISHED;
                })
                .build();
    }


//    @Bean
//    public Job creatOrder() {
//        return jobBuilderFactory
//                .get("creatOrder")
//                .incrementer(new RunIdIncrementer())
//                .start(createOrderStep.createCommonStep())
//                .next(this.checkFrom())
//                .next(check2Step())
//                .next(buildPlatformOrder())
//                .listener(new JobExecutionListener() {
//                    @Override
//                    public void beforeJob(JobExecution jobExecution) {
//
//                    }
//
//                    @Override
//                    public void afterJob(JobExecution jobExecution) {
//                        publish("order", jobExecution.getJobId(), Map.of());
//                    }
//                })
//                .build();
//    }

}
