UpdateRunner.java 2.09 KB
package com.vion;


import com.vion.configuration.OssConfigration;
import com.vion.dao.IDao;
import com.vion.entity.OssClientEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;

import javax.annotation.Resource;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


/**
 * .
 *
 * @author 谢明辉
 * @date 2019-7-29 14:44
 */


//@Component
//@Order(1)
@Slf4j
public class UpdateRunner implements CommandLineRunner {

    @Value("${date.begin}")
    private String begin;
    @Value("${date.end}")
    private String end;
    @Autowired
    private IDao dao;
    @Resource
    private OssClientEntity ossClientEntity;
    @Value("${path.picture}")
    private String facePath;
    @Value("${path.feature}")
    private String featurePath;

    @Override
    public void run(String... args) throws Exception {

                File file = new File(facePath);
                if (!file.exists()) {
                    log.error("face路径不存在!!!!!:{}", facePath);
                    System.exit(1);
                }
                File file1 = new File(featurePath);
                if (!file1.exists()) {
                    log.error("feature路径不存在!!!!!!!!!!{}", featurePath);
                    System.exit(2);
                }


        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(50, 100, 10, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(250), r -> {
            Thread t = new Thread(r);
            t.setName("线程" + OssConfigration.COUNT);
            OssConfigration.COUNT++;
            return t;
        });


        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        Date beginDate = format.parse(begin);
        Date endDate = format.parse(end);

        dao.getAll(beginDate, endDate, ossClientEntity, facePath, featurePath, threadPool);
    }
}