PersonTrackDetailServiceImpl.java
3.85 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
104
105
106
107
108
109
110
111
112
113
114
115
package com.viontech.keliu.service.impl;
import com.viontech.keliu.dao.DPersonTrackDetailDao;
import com.viontech.keliu.dao.FaceRecognitionDao;
import com.viontech.keliu.entity.DPersonTrackDetail;
import com.viontech.keliu.entity.Person;
import com.viontech.keliu.service.PersonTrackDetailService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-12-21
* Time: 16:53
*/
@Service
public class PersonTrackDetailServiceImpl implements PersonTrackDetailService {
@Resource
private FaceRecognitionDao faceRecognitionDao;
@Resource
private DPersonTrackDetailDao dPersonTrackDetailDao;
@Override
public void handlePersonTrackDetail(Long mallId, Date countDate) {
List<Person> personList = faceRecognitionDao.queryGateFaceRecognitionList(mallId, countDate);
if (CollectionUtils.isEmpty(personList)) {
return;
}
//按照gateId分组
Map<Long, List<Person>> gatePersonMap = personList.stream().collect(Collectors.groupingBy(Person::getGateId));
gatePersonMap.forEach((key, value) -> createPersonTrack(value));
}
/**
* 按照区域进行统计
* @param personList
*/
private void createPersonTrack(List<Person> personList) {
if (personList.size() < 2) {
return;
}
//按personUnid分组
Map<String, List<Person>> personUnidMap = personList.stream().collect(Collectors.groupingBy(Person::getPersonUnid));
personUnidMap.forEach((key, value) -> {
List<DPersonTrackDetail> personTrackDetailList = getPersonTrackDetail(value);
if (CollectionUtils.isNotEmpty(personTrackDetailList)) {
//保存进数据库
dPersonTrackDetailDao.createDPersonTrackDetailBatch(personTrackDetailList);
}
});
}
/**
* 按personUnid进行区域进出匹配
* @param personList
* @return
*/
private List<DPersonTrackDetail> getPersonTrackDetail(List<Person> personList) {
if (personList.size() < 2) {
return null;
}
List<DPersonTrackDetail> dPersonTrackDetailList = new ArrayList<>();
Person arrivePerson = null;
int isEngage = 0;
for (Person person : personList) {
//进
if (person.getDirection() == 1) {
arrivePerson = person;
continue;
}
//试乘
if (person.getDirection() == 6) {
isEngage = 1;
continue;
}
//进出匹配的
if (person.getDirection() == -1 && arrivePerson != null) {
DPersonTrackDetail personTrackDetail = new DPersonTrackDetail();
personTrackDetail.setAccountId(person.getAccountId());
personTrackDetail.setMallId(person.getMallId());
personTrackDetail.setGateId(person.getGateId());
personTrackDetail.setPersonUnid(person.getPersonUnid());
personTrackDetail.setArriveTime(arrivePerson.getCountTime());
personTrackDetail.setLeaveTime(person.getCountTime());
long milli = personTrackDetail.getLeaveTime().getTime() - personTrackDetail.getArriveTime().getTime();
personTrackDetail.setVisitDuration(milli);
personTrackDetail.setIsEngage(isEngage);
arrivePerson = null;
dPersonTrackDetailList.add(personTrackDetail);
}
isEngage = 0;
}
return dPersonTrackDetailList;
}
}