package com.docus.server.collect.dept.http;

import com.docus.log.annotation.TrackRetryListener;
import com.docus.server.collect.ICollector;
import com.docus.server.collect.web.job.AbstractCollectJob;
import com.docus.server.entity.TaskConfig;
import com.docus.server.sys.common.pojo.dto.DeptDTO;
import com.docus.server.util.PeriodTime;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 主动http请求科室数据job
 *
 * @see AbstractCollectJob
 * @see com.docus.server.collect.IJob
 */
@Component
public class DeptHttpCollectJob extends AbstractCollectJob<DeptDTO> {

    @Resource(name = "httpDeptCollectorImpl")
    private ICollector collector;

    /**
     * xxl jobhandler 手工执行
     */
    @XxlJob("startAllDeptHttpCollect")
    @TrackRetryListener("startAllDeptHttpCollect")
    public void startAllDeptHttpCollect(String param) {
        super.startCollectAll(getJobParam(param));
    }

    /**
     * xxl jobhandler 配置定时启动，如果未完成任务跳过。
     */
    @XxlJob("startIncDeptHttpCollect")
    @TrackRetryListener("startIncDeptHttpCollect")
    public void startIncDeptHttpCollect(String param) {
        super.startCollectIncrement(getJobParam(param));
    }

    @Override
    public void doHandle(List<DeptDTO> results, String param) {
        deptService.batchInsertOrUpdatePowerDept(results);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DeptDTO> execute(PeriodTime periodTime, TaskConfig taskConfig) {
        return collector.page(periodTime, taskConfig);
    }
}
