package com.dxhy.core.task;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.dxhy.core.service.filemigration.FileMigrationService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author jiaohongyang（焦红阳）
 * @date 2021-01-05
 */
@Component("fileMigrationTask")
@Slf4j
public class FileMigrationTask {
    @Value("${migration.years}")
    private String years;
    @Resource
    private FileMigrationService fileMigrationService;

    public void fileMigration() {
        log.info("<线程:{}>，发票图片迁移定时任务开始", Thread.currentThread().getId());
        try {
            if (StringUtils.isNotBlank(years)) {
                String[] split = years.split(",");
                for (String year : split) {
                    fileMigrationService.fileMigrationOss(year);
                }
            }
            log.info("<线程:{}>，发票图片迁移定时任务结束", Thread.currentThread().getId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
