Application.java 2.98 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 org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

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


@ComponentScan(value = "com.vion")
@SpringBootApplication
@Slf4j
public class Application implements CommandLineRunner {

    public static final String PICTURE = "picture/";
    public static final String FEATURE = "feature/";
    public static final String POSTFIX = ".feature";


    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }


    @Autowired
    private IDao dao;
    @Resource
    private OssClientEntity ossClientEntity;

    @Value("${path.picture}")
    private String facePath;
    @Value("${path.feature}")
    private String featurePath;
    @Value("${date.begin}")
    private String begin;
    @Value("${date.end}")
    private String end;

    @Override
    public void run(String... args) throws Exception {
        /*下载文件*/
//        OssFileUtil ossFileUtil = new OssFileUtil();
//        ObjectListing objectListing = ossFileUtil.getFilesInPrefix(ossClientEntity.getBucket(), "picture/face/20180808/", ossClientEntity.getOssClient(), 1000, false);
//        objectListing.getObjectSummaries().forEach(summery -> {
//            String[] strings = summery.getKey().split("/");
//            File file = new File("D:/picture/face/20180808/" + strings[3]);
//            if (!file.exists()) {
//                if (!file.mkdir()) {
//                    System.out.println("创建文件夹失败:" + file.getName());
//                }
//            }
//            ossClientEntity.getOssClient().getObject(new GetObjectRequest(ossClientEntity.getBucket(), summery.getKey()), new File("D:\\" + summery.getKey().replace("\\", "/")));
//                }
//        );

        //上传文件
        // 建立线程池

        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);
    }
}