package com.tax.token.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author caosongqing
 * @date 2022/7/18
 * @description
 */
@Component
@Slf4j
public class WatchJob implements DataflowJob<String> {
    public static final int LIMIT_PROCESS_DEFAULT = 200;

    @Override
    public List<String> fetchData(ShardingContext shardingContext) {
        int limit = LIMIT_PROCESS_DEFAULT;
        String jobParameter = shardingContext.getJobParameter();
        if (StringUtils.isNotBlank(jobParameter)) {
            limit = Integer.valueOf(jobParameter);
        }
        int totalCount = shardingContext.getShardingTotalCount();
        int item = shardingContext.getShardingItem();
        log.info("watch job parameter totalCount:{}, item:{}, limit:{}", totalCount, item, limit);
        return Lists.newArrayList("a", "b", "c");
    }

    @Override
    public void processData(ShardingContext shardingContext, List<String> list) {
        log.info("process token list size:{}", list.size());
        for (String str : list) {
            log.info("process with:{}", str);
        }
    }
}
