PostUpdateJob.java 4.67 KB
package com.vion.job;


import com.vion.entity.FaceEntity;
import com.vion.entity.OssClientEntity;
import com.vion.utils.FileUtils;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.List;

import static com.vion.Application.*;


/**
 * @author 谢明辉
 * @createDate 2018-10-30
 * @description 一个线程的job
 */
@Slf4j
public class PostUpdateJob implements Runnable {

    private List<FaceEntity> faces;
    private OssClientEntity ossClientEntity;
    private Integer dateNumber;
    private String facePath;
    private String featurePath;

    public PostUpdateJob(List<FaceEntity> face, OssClientEntity entity, Integer dateNumber, String facePath, String featurePath) {
        this.ossClientEntity = entity;
        this.faces = face;
        this.dateNumber = dateNumber;
        this.facePath = facePath;
        this.featurePath = featurePath;
    }

    @Override
    public void run() {
        
        faces.forEach(face -> {
            String md5 = "";
            String md6 = "";
            File pic;
            File feature;
            try {
                if (FileUtils.isNotNull(face.getFacePic())) {
                    pic = new File(FileUtils.getPathName(facePath, dateNumber, face.getChannelSerialNum(), face.getFacePic(), false));
                    feature = new File(FileUtils.getPathName(featurePath, dateNumber, face.getChannelSerialNum(), face.getFacePic(), true));

                    if (pic.exists()) {
                        md5 = ossClientEntity.getOssClient().putObject(ossClientEntity.getBucket(), FileUtils.generator(face.getFacePic(), PICTURE, null, face.getChannelSerialNum()), pic).getETag();
                    } else if (FileUtils.isNotNull(face.getBodyPic())) {
                        pic = new File(FileUtils.getPathName(facePath, dateNumber, face.getChannelSerialNum(), face.getBodyPic(), false));
                        if (pic.exists()) {
                            md5 = ossClientEntity.getOssClient().putObject(ossClientEntity.getBucket(), FileUtils.generator(face.getBodyPic(), PICTURE, null, face.getChannelSerialNum()), pic).getETag();
                        }
                    }

                    if (feature.exists()) {
                        md6 = ossClientEntity.getOssClient().putObject(ossClientEntity.getBucket(), FileUtils.generator(face.getFacePic(), FEATURE, POSTFIX, face.getChannelSerialNum()), feature).getETag();
                    } else if (FileUtils.isNotNull(face.getBodyPic())) {
                        feature = new File(FileUtils.getPathName(facePath, dateNumber, face.getChannelSerialNum(), face.getBodyPic(), true));
                        if (feature.exists()) {
                            md6 = ossClientEntity.getOssClient().putObject(ossClientEntity.getBucket(), FileUtils.generator(face.getBodyPic(), FEATURE, POSTFIX, face.getChannelSerialNum()), feature).getETag();
                        }
                    }


                } else if (FileUtils.isNotNull(face.getBodyPic())) {
                    pic = new File(FileUtils.getPathName(facePath, dateNumber, face.getChannelSerialNum(), face.getBodyPic(), false));
                    feature = new File(FileUtils.getPathName(featurePath, dateNumber, face.getChannelSerialNum(), face.getBodyPic(), true));

                    if (pic.exists()) {
                        md5 = ossClientEntity.getOssClient().putObject(ossClientEntity.getBucket(), FileUtils.generator(face.getBodyPic(), PICTURE, null, face.getChannelSerialNum()), pic).getETag();
                    }
                    if (feature.exists()) {
                        md6 = ossClientEntity.getOssClient().putObject(ossClientEntity.getBucket(), FileUtils.generator(face.getBodyPic(), FEATURE, POSTFIX, face.getChannelSerialNum()), feature).getETag();
                    }
                }
                pic = null;
                feature = null;
                if (FileUtils.isNotNull(md5)) {
                    log.info("上传成功,picture:{}", md5);
                } else {
                    log.info("找不到文件,picture:{}", face.getFacePic());
                }
                if (FileUtils.isNotNull(md6)) {
                    System.out.println();
                    log.info("上传成功,feature:{}", md6);
                } else {
                    System.out.println();
                    log.info("找不到文件,feature:{}", face.getFacePic() + ".feature");
                }
            } catch (Exception e) {
                log.error("上传出错" + face.getFacePic());
                pic = null;
                feature = null;
                e.printStackTrace();
            }
        });
        log.info("+++++++++++++++++++++++++++++上传完成++++++++++++++++++++++++");
    }
}