PostUpdateJob.java
4.67 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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("+++++++++++++++++++++++++++++上传完成++++++++++++++++++++++++");
}
}