MyUpdateJob.java 3.45 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.PICTURE;


/**
 * @author 谢明辉
 * @createDate 2018-10-30
 * @description
 */
@Slf4j
public class MyUpdateJob implements Runnable {

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


    public MyUpdateJob(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;
            try {
                // 1.数据库中存在face则去找对应face图片,如果图片不存在,则在数据库找body,如果body存在则去找对应body图片,如果图片不存在则执行完成。
                // 2.数据库中不存在face则去找body,如果body存在则去找对应body图片,图片不存在则执行完成
                // 3.数据库不存在face,不存在body,执行完成

                if (FileUtils.isNotNull(face.getFacePic())) {
                    pic = new File(FileUtils.getPathName(facePath, dateNumber, null, face.getFacePic(), false));

                    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, null, face.getBodyPic(), false));
                        if (pic.exists()) {
                            md5 = ossClientEntity.getOssClient().putObject(ossClientEntity.getBucket(), FileUtils.generator(face.getBodyPic(), PICTURE, null, face.getChannelSerialNum()), pic).getETag();
                        }
                    }

                } else if (FileUtils.isNotNull(face.getBodyPic())) {
                    pic = new File(FileUtils.getPathName(facePath, dateNumber, null, face.getBodyPic(), false));
                    if (pic.exists()) {
                        md5 = ossClientEntity.getOssClient().putObject(ossClientEntity.getBucket(), FileUtils.generator(face.getBodyPic(), PICTURE, null, face.getChannelSerialNum()), pic).getETag();
                    }
                }
                pic = null;
                if (!FileUtils.isNotNull(md5)) {
                    if (FileUtils.isNotNull(face.getFacePic())) {
                        log.info("找不到文件,picture:{}", face.getFacePic());
                    } else if (FileUtils.isNotNull(face.getBodyPic())) {
                        log.info("找不到文件,picture:{}", face.getBodyPic());
                    }
                }
            } catch (Exception e) {
                log.error("上传出错" + face.getFacePic());
                pic = null;
                e.printStackTrace();
            }
        });
        log.info("+++++++++++++++++++++++++++++上传完成++++++++++++++++++++++++");
    }
}