MyFaceDao.java
2.55 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
package com.vion.dao;
import com.vion.entity.FaceEntity;
import com.vion.entity.OssClientEntity;
import com.vion.job.MyUpdateJob;
import com.vion.utils.FileUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @author 谢明辉
* @createDate 2018-10-31
* @description
*/
@Slf4j
public class MyFaceDao implements IDao {
@Autowired
private JdbcTemplate jdbcTemplate;
public static long DAY = 3600L * 24L * 1000L;
public static final String FIND_ALL = "SELECT chanel_id,frr_arrival_face_picture1,frr_arrival_showbody_picture FROM r_face_recognition_record WHERE frr_count_date=?";
@Override
public void getAll(Date beginDate, Date endDate, OssClientEntity ossClientEntity, String facePath, String featurePath, ThreadPoolExecutor threadPool) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
// 按天循环
for (long count = beginDate.getTime(); count <= endDate.getTime(); count += DAY) {
log.info(count + "================================================");
// 查询一天的数据
List<FaceEntity> list = jdbcTemplate.query(FIND_ALL, new Object[]{new Date(count)}, (r, i) -> {
FaceEntity entity = new FaceEntity();
entity.setBodyPic(r.getString("frr_arrival_showbody_picture"));
entity.setFacePic(r.getString("frr_arrival_face_picture1"));
entity.setChannelSerialNum(r.getString("chanel_id"));
return entity;
});
// 平均分成50份,每个线程执行其中的一份,共50个线程
List<List<FaceEntity>> lists = FileUtils.averageAssign(list, 50);
Integer pathDate = Integer.parseInt(format.format(new Date(count)));
lists.forEach(faceEntities -> threadPool.execute(new MyUpdateJob(faceEntities, ossClientEntity, pathDate, facePath, featurePath)));
// 等待线程池执行完成,执行下个循环
while (threadPool.getActiveCount() != 0) {
}
log.info("==============================={}结束=========================================", new Date(count));
System.gc();
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}