MyUpdateJob.java
3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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("+++++++++++++++++++++++++++++上传完成++++++++++++++++++++++++");
}
}