Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
VVAS-Match
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 525fd3ca
authored
Oct 15, 2024
by
姚冰
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[chg] 添加全天分析查询接口,添加personType字段
1 parent
b7916465
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
129 additions
and
16 deletions
pom.xml
src/main/java/com/viontech/match/controller/MainController.java
src/main/java/com/viontech/match/entity/PersonInfo.java
src/main/java/com/viontech/match/entity/SearchResultHit.java
src/main/java/com/viontech/match/service/PersonService.java
src/main/java/com/viontech/match/service/PoolService.java
pom.xml
View file @
525fd3c
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.5.1
</version>
<version>
2.5.1
5
</version>
<relativePath
/>
<!-- lookup parent from repository -->
<relativePath
/>
<!-- lookup parent from repository -->
</parent>
</parent>
<groupId>
com.viontech
</groupId>
<groupId>
com.viontech
</groupId>
...
...
src/main/java/com/viontech/match/controller/MainController.java
View file @
525fd3c
...
@@ -5,14 +5,11 @@ import com.viontech.match.entity.vo.ResponseVo;
...
@@ -5,14 +5,11 @@ import com.viontech.match.entity.vo.ResponseVo;
import
com.viontech.match.service.PersonService
;
import
com.viontech.match.service.PersonService
;
import
com.viontech.match.service.PoolService
;
import
com.viontech.match.service.PoolService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.List
;
/**
/**
* .
* .
...
@@ -53,7 +50,7 @@ public class MainController {
...
@@ -53,7 +50,7 @@ public class MainController {
return
ResponseVo
.
commandNotFound
(
rid
);
return
ResponseVo
.
commandNotFound
(
rid
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
log
.
error
(
"
match exception
"
,
e
);
return
ResponseVo
.
error
(
rid
,
e
.
getMessage
());
return
ResponseVo
.
error
(
rid
,
e
.
getMessage
());
}
}
}
}
...
@@ -66,4 +63,9 @@ public class MainController {
...
@@ -66,4 +63,9 @@ public class MainController {
return
ResponseVo
.
error
(
"error"
,
e
.
getMessage
());
return
ResponseVo
.
error
(
"error"
,
e
.
getMessage
());
}
}
}
}
@GetMapping
(
"/compare"
)
public
Object
compare
(
@RequestParam
(
name
=
"poolId"
)
List
<
String
>
poolId
,
@RequestParam
(
name
=
"unid"
)
String
unid
,
@RequestParam
(
name
=
"mallId"
)
Long
mallId
,
@RequestParam
(
name
=
"zoneId"
,
required
=
false
)
List
<
Long
>
zoneId
,
@RequestParam
(
name
=
"gateId"
)
List
<
Long
>
gateId
,
@RequestParam
(
name
=
"direction"
)
List
<
Integer
>
direction
,
@RequestParam
(
name
=
"size"
)
Integer
size
)
throws
IOException
{
return
personService
.
compare
(
poolId
,
unid
,
mallId
,
zoneId
,
gateId
,
direction
,
size
);
}
}
}
src/main/java/com/viontech/match/entity/PersonInfo.java
View file @
525fd3c
package
com
.
viontech
.
match
.
entity
;
package
com
.
viontech
.
match
.
entity
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Data
;
import
lombok.Data
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
java.util.Date
;
import
java.util.Date
;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@Data
@Data
public
class
PersonInfo
{
public
class
PersonInfo
{
private
String
unid
;
private
String
unid
;
...
@@ -17,13 +19,15 @@ public class PersonInfo {
...
@@ -17,13 +19,15 @@ public class PersonInfo {
private
String
gender
;
private
String
gender
;
private
Integer
bodyType
;
private
Integer
bodyType
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
counttime
;
private
Date
counttime
;
private
String
fid
;
private
String
fid
;
private
String
channelSerialNum
;
private
String
channelSerialNum
;
private
Long
gateId
;
private
Long
gateId
;
private
String
direction
;
private
String
direction
;
private
Integer
personType
;
public
PersonInfo
(
String
unid
,
String
personId
,
Double
[]
body
,
Double
[]
data
,
Integer
age
,
String
gender
,
Integer
bodyType
,
Date
countTime
,
String
fid
,
String
channelSerialNum
,
Long
gateId
,
String
direction
)
{
public
PersonInfo
(
String
unid
,
String
personId
,
Double
[]
body
,
Double
[]
data
,
Integer
age
,
String
gender
,
Integer
bodyType
,
Date
countTime
,
String
fid
,
String
channelSerialNum
,
Long
gateId
,
String
direction
,
Integer
personType
)
{
this
.
unid
=
unid
;
this
.
unid
=
unid
;
this
.
personId
=
personId
;
this
.
personId
=
personId
;
this
.
body
=
body
;
this
.
body
=
body
;
...
@@ -37,5 +41,10 @@ public class PersonInfo {
...
@@ -37,5 +41,10 @@ public class PersonInfo {
this
.
gateId
=
gateId
;
this
.
gateId
=
gateId
;
this
.
direction
=
direction
;
this
.
direction
=
direction
;
this
.
_score
=
"1"
;
this
.
_score
=
"1"
;
this
.
personType
=
personType
;
}
public
PersonInfo
()
{
this
.
_score
=
"1"
;
}
}
}
}
src/main/java/com/viontech/match/entity/SearchResultHit.java
View file @
525fd3c
...
@@ -16,7 +16,7 @@ public class SearchResultHit {
...
@@ -16,7 +16,7 @@ public class SearchResultHit {
private
String
_score
;
private
String
_score
;
private
Integer
age
;
private
Integer
age
;
private
String
gender
;
private
String
gender
;
private
Integer
body
T
ype
;
private
Integer
body
_t
ype
;
// @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
// @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
private
String
counttime
;
private
String
counttime
;
private
String
fid
;
private
String
fid
;
...
...
src/main/java/com/viontech/match/service/PersonService.java
View file @
525fd3c
...
@@ -257,6 +257,7 @@ public class PersonService {
...
@@ -257,6 +257,7 @@ public class PersonService {
String
direction
=
person
.
getDirection
();
String
direction
=
person
.
getDirection
();
//Long gateId = person.getGateId();
//Long gateId = person.getGateId();
Integer
bodyType
=
person
.
getBodyType
();
Integer
bodyType
=
person
.
getBodyType
();
Integer
personType
=
0
;
//person.getPersonType();
String
personChannelSerialNum
=
person
.
getChannelSerialNum
();
String
personChannelSerialNum
=
person
.
getChannelSerialNum
();
List
<
FaceFeature
>
faceFeatures
=
person
.
getFaceFeatures
();
List
<
FaceFeature
>
faceFeatures
=
person
.
getFaceFeatures
();
if
(
CollectionUtils
.
isNotEmpty
(
faceFeatures
))
{
if
(
CollectionUtils
.
isNotEmpty
(
faceFeatures
))
{
...
@@ -273,7 +274,7 @@ public class PersonService {
...
@@ -273,7 +274,7 @@ public class PersonService {
// "counttime", personCountTime == null ? null : Constant.DATE_FORMAT.get().format(personCountTime),
// "counttime", personCountTime == null ? null : Constant.DATE_FORMAT.get().format(personCountTime),
// "channelSerialNum", personChannelSerialNum, "gateId", gateId, "direction", direction);
// "channelSerialNum", personChannelSerialNum, "gateId", gateId, "direction", direction);
// bulkRequest.add(indexRequest);
// bulkRequest.add(indexRequest);
operationList
.
add
(
new
BulkOperation
.
Builder
().
index
(
new
IndexOperation
.
Builder
<
PersonInfo
>().
index
(
poolId
).
document
(
new
PersonInfo
(
unid
,
personId
,
feature
,
null
,
age
,
gender
,
bodyType
,
personCountTime
,
fid
,
personChannelSerialNum
,
gateId
,
direction
)).
build
()).
build
());
operationList
.
add
(
new
BulkOperation
.
Builder
().
index
(
new
IndexOperation
.
Builder
<
PersonInfo
>().
index
(
poolId
).
document
(
new
PersonInfo
(
unid
,
personId
,
feature
,
null
,
age
,
gender
,
bodyType
,
personCountTime
,
fid
,
personChannelSerialNum
,
gateId
,
direction
,
personType
)).
build
()).
build
());
}
}
}
}
}
}
...
@@ -303,7 +304,7 @@ public class PersonService {
...
@@ -303,7 +304,7 @@ public class PersonService {
// "counttime", counttime == null ? null : Constant.DATE_FORMAT.get().format(counttime)
// "counttime", counttime == null ? null : Constant.DATE_FORMAT.get().format(counttime)
// , "channelSerialNum", channelSerialNum, "gateId", gateId, "direction", direction);
// , "channelSerialNum", channelSerialNum, "gateId", gateId, "direction", direction);
// bulkRequest.add(indexRequest);
// bulkRequest.add(indexRequest);
operationList
.
add
(
new
BulkOperation
.
Builder
().
index
(
new
IndexOperation
.
Builder
<
PersonInfo
>().
index
(
poolId
).
document
(
new
PersonInfo
(
unid
,
personId
,
feature
,
null
,
age
,
gender
,
bodyType
,
personCountTime
,
fid
,
personChannelSerialNum
,
gateId
,
direction
)).
build
()).
build
());
operationList
.
add
(
new
BulkOperation
.
Builder
().
index
(
new
IndexOperation
.
Builder
<
PersonInfo
>().
index
(
poolId
).
document
(
new
PersonInfo
(
unid
,
personId
,
feature
,
null
,
age
,
gender
,
bodyType
,
personCountTime
,
fid
,
personChannelSerialNum
,
gateId
,
direction
,
personType
)).
build
()).
build
());
}
}
}
}
}
}
...
@@ -402,7 +403,6 @@ public class PersonService {
...
@@ -402,7 +403,6 @@ public class PersonService {
}
}
SearchRequest
searchRequest
=
getSearchRequest
(
rid
,
poolId
,
1
,
feature
,
person
,
1
,
agg
);
SearchRequest
searchRequest
=
getSearchRequest
(
rid
,
poolId
,
1
,
feature
,
person
,
1
,
agg
);
matchResult
.
addAll
(
match0
(
searchRequest
,
agg
));
matchResult
.
addAll
(
match0
(
searchRequest
,
agg
));
}
}
}
}
...
@@ -572,7 +572,7 @@ public class PersonService {
...
@@ -572,7 +572,7 @@ public class PersonService {
p
.
setAge
(
hit
.
getAge
());
p
.
setAge
(
hit
.
getAge
());
p
.
setGender
((
String
)
hit
.
getGender
());
p
.
setGender
((
String
)
hit
.
getGender
());
p
.
setChannelSerialNum
(
hit
.
getChannelSerialNum
());
p
.
setChannelSerialNum
(
hit
.
getChannelSerialNum
());
p
.
setBodyType
(
hit
.
getBody
T
ype
());
p
.
setBodyType
(
hit
.
getBody
_t
ype
());
p
.
setCaptureUnid
(
hit
.
getUnid
());
p
.
setCaptureUnid
(
hit
.
getUnid
());
p
.
setCounttime
(
Optional
.
ofNullable
((
String
)
hit
.
getCounttime
())
p
.
setCounttime
(
Optional
.
ofNullable
((
String
)
hit
.
getCounttime
())
...
@@ -593,5 +593,106 @@ public class PersonService {
...
@@ -593,5 +593,106 @@ public class PersonService {
return
persons
;
return
persons
;
}
}
public
ResponseVo
compare
(
List
<
String
>
poolId
,
String
unid
,
Long
mallId
,
List
<
Long
>
zoneId
,
List
<
Long
>
gateId
,
List
<
Integer
>
direction
,
Integer
size
){
String
customIndex
=
poolId
.
stream
().
filter
(
v
->
v
.
contains
(
"custompool"
)).
collect
(
Collectors
.
toList
()).
get
(
0
);
SearchRequest
getPerson
=
new
SearchRequest
.
Builder
()
.
index
(
poolId
)
.
query
(
q
->
q
.
term
(
t
->
t
.
field
(
"unid"
).
value
(
unid
)))
.
ignoreUnavailable
(
true
)
.
size
(
1
)
.
build
();
log
.
info
(
"request:{}"
,
getPerson
);
try
{
SearchResponse
<
PersonInfo
>
search
=
client
.
search
(
getPerson
,
PersonInfo
.
class
);
if
(
search
.
hits
().
total
().
value
()
<=
0
)
{
log
.
info
(
"未找到相应的人员:{}"
,
unid
);
return
ResponseVo
.
error
(
unid
,
"相关人员不存在"
);
}
PersonInfo
person
=
search
.
hits
().
hits
().
get
(
0
).
source
();
if
(
person
==
null
||
person
.
getBody
()
==
null
)
{
log
.
info
(
"相应的人员无特征:{}"
,
unid
);
return
ResponseVo
.
error
(
unid
,
"相关人员不存在!"
);
}
log
.
info
(
"获取人员特征"
);
List
<
Float
>
feature
=
getFeature
(
person
.
getBody
());
List
<
Query
>
queries
=
new
ArrayList
<>();
// if (mallId != null) {
// queries.add(Query.of(q -> q.term(t -> t.field("mallId").value(mallId))));
// }
if
(
zoneId
!=
null
)
{
// queries.add(Query.of(q -> q.term(t -> t.field("zoneId").value(zoneId))));
}
if
(
gateId
!=
null
&&
!
gateId
.
isEmpty
())
{
// queries.add(Query.of(q -> q.term(t -> t.field("gateId").value(gateId))));
BoolQuery
boolQuery
=
new
BoolQuery
.
Builder
()
.
should
(
Query
.
of
(
q
->
q
.
terms
(
t
->
t
.
field
(
"gateId"
).
terms
(
v
->
v
.
value
(
gateId
.
stream
().
map
(
FieldValue:
:
of
).
collect
(
Collectors
.
toList
()))))),
new
BoolQuery
.
Builder
().
mustNot
(
q
->
q
.
exists
(
e
->
e
.
field
(
"gateId"
))).
build
().
_toQuery
())
// .mustNot(Query.of(q -> q.exists(e -> e.field("gateId"))))
.
minimumShouldMatch
(
"1"
)
.
build
();
queries
.
add
(
boolQuery
.
_toQuery
());
}
if
(
direction
!=
null
&&
!
direction
.
equals
(
""
))
{
BoolQuery
boolQuery
=
new
BoolQuery
.
Builder
()
.
should
(
Query
.
of
(
q
->
q
.
terms
(
t
->
t
.
field
(
"direction"
).
terms
(
v
->
v
.
value
(
direction
.
stream
().
map
(
FieldValue:
:
of
).
collect
(
Collectors
.
toList
()))))),
new
BoolQuery
.
Builder
().
mustNot
(
q
->
q
.
exists
(
e
->
e
.
field
(
"direction"
))).
build
().
_toQuery
())
.
minimumShouldMatch
(
"1"
)
.
build
();
queries
.
add
(
boolQuery
.
_toQuery
());
// queries.add(Query.of(q -> q.terms(t -> t.field("direction").terms(v -> v.value(direction.stream().map(FieldValue::of).collect(Collectors.toList()))))));
}
KnnQuery
query
=
new
KnnQuery
.
Builder
()
.
filter
(
queries
)
.
field
(
"body"
).
queryVector
(
feature
)
.
build
();
String
[]
FETCH_SOURCE
=
new
String
[]{
"personId"
,
"unid"
};
List
<
Query
>
mustList
=
new
ArrayList
<>();
mustList
.
add
(
query
.
_toQuery
());
BoolQuery
boolQuery
=
new
BoolQuery
.
Builder
()
.
must
(
mustList
)
.
mustNot
(
Query
.
of
(
q
->
q
.
term
(
t
->
t
.
field
(
"unid"
).
value
(
unid
))))
.
build
();
SourceConfig
sourceConfig
=
new
SourceConfig
.
Builder
().
filter
(
s
->
s
.
includes
(
Arrays
.
asList
(
FETCH_SOURCE
))).
build
();
SearchRequest
request
=
new
SearchRequest
.
Builder
()
.
index
(
poolId
)
.
query
(
boolQuery
.
_toQuery
())
.
source
(
sourceConfig
)
.
ignoreUnavailable
(
true
)
.
size
(
size
).
build
();
log
.
info
(
"rid:{} poolId:{} 开始匹配"
,
unid
,
poolId
);
SearchResponse
<
SearchResultHit
>
response
=
client
.
search
(
request
,
SearchResultHit
.
class
);
log
.
info
(
"rid:{} poolId:{} 匹配结果:{}"
,
unid
,
poolId
,
response
.
hits
().
hits
().
size
());
List
<
Hit
<
SearchResultHit
>>
resultList
=
response
.
hits
().
hits
();
List
<
Person
>
persons
=
new
ArrayList
<>();
for
(
Hit
<
SearchResultHit
>
item
:
resultList
)
{
SearchResultHit
hit
=
item
.
source
();
Person
p
=
new
Person
();
p
.
setPersonId
((
String
)
hit
.
getPersonId
());
// p.setAge(hit.getAge());
// p.setGender((String) hit.getGender());
// p.setChannelSerialNum(hit.getChannelSerialNum());
// p.setBodyType(hit.getBody_type());
p
.
setCaptureUnid
(
hit
.
getUnid
());
p
.
setCounttime
(
Optional
.
ofNullable
((
String
)
hit
.
getCounttime
())
.
map
(
x
->
{
try
{
return
Constant
.
DATE_FORMAT
.
get
().
parse
(
x
);
}
catch
(
ParseException
e
)
{
return
null
;
}
})
.
orElse
(
null
));
p
.
setScore
(
item
.
score
().
floatValue
()
*
100
);
p
.
setPersonPoolId
(
item
.
index
());
persons
.
add
(
p
);
}
ResponseVo
success
=
ResponseVo
.
success
(
unid
,
"success"
);
success
.
setMatchBodies
(
persons
);
return
success
;
}
catch
(
IOException
e
)
{
log
.
error
(
"search exception"
,
e
);
return
ResponseVo
.
error
(
unid
,
"异常"
);
}
}
}
}
src/main/java/com/viontech/match/service/PoolService.java
View file @
525fd3c
...
@@ -59,9 +59,9 @@ public class PoolService {
...
@@ -59,9 +59,9 @@ public class PoolService {
// @Value("${vion.index.refresh_interval}")
// @Value("${vion.index.refresh_interval}")
// private String refreshInterval;
// private String refreshInterval;
@Value
(
"${vion.index.translog.sync_interval}"
)
@Value
(
"${vion.index.translog.sync_interval
:30s
}"
)
private
String
translogSyncInterval
;
private
String
translogSyncInterval
;
@Value
(
"${vion.index.merge.scheduler.max_thread_count}"
)
@Value
(
"${vion.index.merge.scheduler.max_thread_count
:50
}"
)
private
Integer
mergeThreadCount
;
private
Integer
mergeThreadCount
;
/**
/**
...
@@ -307,6 +307,7 @@ public class PoolService {
...
@@ -307,6 +307,7 @@ public class PoolService {
properties1
.
put
(
"gender"
,
new
Property
.
Builder
().
keyword
(
k
->
k
.
index
(
false
).
docValues
(
false
)).
build
());
properties1
.
put
(
"gender"
,
new
Property
.
Builder
().
keyword
(
k
->
k
.
index
(
false
).
docValues
(
false
)).
build
());
properties1
.
put
(
"counttime"
,
new
Property
.
Builder
().
date
(
d
->
d
.
format
(
"yyyy-MM-dd HH:mm:ss"
)).
build
());
properties1
.
put
(
"counttime"
,
new
Property
.
Builder
().
date
(
d
->
d
.
format
(
"yyyy-MM-dd HH:mm:ss"
)).
build
());
properties1
.
put
(
"unid"
,
new
Property
.
Builder
().
keyword
(
k
->
k
.
index
(
true
)).
build
());
properties1
.
put
(
"unid"
,
new
Property
.
Builder
().
keyword
(
k
->
k
.
index
(
true
)).
build
());
properties1
.
put
(
"personType"
,
new
Property
.
Builder
().
keyword
(
k
->
k
.
index
(
true
)).
build
());
// builder.properties(properties1);
// builder.properties(properties1);
TypeMapping
.
Builder
builder
=
new
TypeMapping
.
Builder
().
properties
(
properties1
);
TypeMapping
.
Builder
builder
=
new
TypeMapping
.
Builder
().
properties
(
properties1
);
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment