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 24f11a6b
authored
Jun 10, 2022
by
李乾广
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[add]添加gateId,direction,添加比对符合条件的数量
1 parent
fea2fd70
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
5 deletions
src/main/java/com/viontech/match/controller/MainController.java
src/main/java/com/viontech/match/entity/vo/ResponseVo.java
src/main/java/com/viontech/match/enumeration/CommandEnum.java
src/main/java/com/viontech/match/service/PersonService.java
src/main/java/com/viontech/match/service/PoolService.java
src/main/java/com/viontech/match/controller/MainController.java
View file @
24f11a6
...
...
@@ -5,7 +5,11 @@ import com.viontech.match.entity.vo.ResponseVo;
import
com.viontech.match.service.PersonService
;
import
com.viontech.match.service.PoolService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.GetMapping
;
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
java.io.IOException
;
...
...
@@ -43,6 +47,8 @@ public class MainController {
return
personService
.
matchPerson
(
requestVo
);
case
UpdatePerson:
return
personService
.
updatePerson
(
requestVo
);
case
CountMatchPerson:
return
personService
.
countMatchPerson
(
requestVo
);
default
:
return
ResponseVo
.
commandNotFound
(
rid
);
}
...
...
src/main/java/com/viontech/match/entity/vo/ResponseVo.java
View file @
24f11a6
...
...
@@ -34,6 +34,9 @@ public class ResponseVo {
private
List
<
Person
>
matchPersons
;
private
List
<
Person
>
matchBodies
;
//获取满足条件的数量 CountMatchPerson时有效
private
long
count
;
public
ResponseVo
(
String
rid
)
{
this
.
rid
=
rid
;
}
...
...
src/main/java/com/viontech/match/enumeration/CommandEnum.java
View file @
24f11a6
...
...
@@ -13,5 +13,6 @@ public enum CommandEnum {
ModifyPersonPool
,
QueryPersonPool
,
MatchPerson
,
UpdatePerson
UpdatePerson
,
CountMatchPerson
}
src/main/java/com/viontech/match/service/PersonService.java
View file @
24f11a6
...
...
@@ -17,6 +17,7 @@ import org.elasticsearch.action.bulk.BulkResponse;
import
org.elasticsearch.action.index.IndexRequest
;
import
org.elasticsearch.action.search.SearchRequest
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.action.support.IndicesOptions
;
import
org.elasticsearch.client.RequestOptions
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.common.xcontent.XContentType
;
...
...
@@ -39,6 +40,8 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import
org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder
;
import
org.elasticsearch.search.aggregations.metrics.Max
;
import
org.elasticsearch.search.aggregations.metrics.MaxAggregationBuilder
;
import
org.elasticsearch.search.aggregations.metrics.ParsedValueCount
;
import
org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.springframework.stereotype.Service
;
...
...
@@ -50,6 +53,7 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.EnumSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
...
...
@@ -73,6 +77,65 @@ public class PersonService {
private
PoolService
poolService
;
/**
* 符合条件的数量
* @param requestVo
* @return
* @throws Exception
*/
public
ResponseVo
countMatchPerson
(
RequestVo
requestVo
)
throws
Exception
{
String
rid
=
requestVo
.
getRid
();
String
poolId
=
requestVo
.
getPersonPoolId
();
List
<
String
>
unionPersonPoolId
=
requestVo
.
getUnionPersonPoolId
();
Person
person
=
requestVo
.
getPerson
();
List
<
String
>
poolIds
=
new
ArrayList
<>();
if
(
unionPersonPoolId
!=
null
&&
unionPersonPoolId
.
size
()
>
0
)
{
poolIds
.
addAll
(
unionPersonPoolId
);
}
if
(
poolId
!=
null
)
{
poolIds
.
add
(
poolId
);
}
log
.
info
(
"人员匹配操作开始,PoolIds:[{}]"
,
poolIds
);
try
{
String
[]
indices
=
poolIds
.
toArray
(
new
String
[
poolIds
.
size
()]);
SearchRequest
request
=
new
SearchRequest
(
indices
);
IndicesOptions
defaultIndicesOptions
=
request
.
indicesOptions
();
EnumSet
<
IndicesOptions
.
Option
>
options
=
defaultIndicesOptions
.
getOptions
();
options
.
add
(
IndicesOptions
.
Option
.
IGNORE_UNAVAILABLE
);
EnumSet
<
IndicesOptions
.
WildcardStates
>
expandWildcards
=
defaultIndicesOptions
.
getExpandWildcards
();
IndicesOptions
newIndicesOptions
=
new
IndicesOptions
(
options
,
expandWildcards
);
request
.
indicesOptions
(
newIndicesOptions
);
long
count
=
0
;
List
<
BodyFeature
>
bodyFeatures
=
person
.
getBodyFeatures
();
if
(
CollectionUtils
.
isEmpty
(
bodyFeatures
))
{
log
.
info
(
"CountMatchPerson人体特征为空,PoolIds:[{}],count:{}"
,
poolIds
,
count
);
}
else
{
Double
[]
feature
=
bodyFeatures
.
get
(
0
).
getFeature
();
SearchSourceBuilder
builder
=
getSearchSourceBuilder
(
feature
,
person
,
1
);
ValueCountAggregationBuilder
countAggregationBuilder
=
AggregationBuilders
.
count
(
"countId"
).
field
(
"_id"
);
builder
.
aggregation
(
countAggregationBuilder
);
request
.
source
(
builder
);
log
.
debug
(
"CountMatchPerson条件{}:{}"
,
indices
,
builder
.
toString
());
SearchResponse
response
=
client
.
search
(
request
,
RequestOptions
.
DEFAULT
);
ParsedValueCount
countId
=
response
.
getAggregations
().
get
(
"countId"
);
count
=
countId
.
getValue
();
}
ResponseVo
result
=
ResponseVo
.
success
(
rid
,
"success"
);
result
.
setCount
(
count
);
log
.
info
(
"CountMatchPerson完成,PoolIds:[{}],count:{}"
,
poolIds
,
count
);
return
result
;
}
catch
(
ElasticsearchStatusException
e
)
{
ResponseVo
error
=
ResponseVo
.
error
(
rid
,
e
.
getDetailedMessage
());
error
.
setCount
(
0
);
return
error
;
}
}
/**
* 人员比对
*
* @param requestVo rid,personPoolId,unionPersonPoolId,person
...
...
@@ -188,6 +251,8 @@ public class PersonService {
String
gender
=
person
.
getGender
();
String
personId
=
person
.
getPersonId
();
Date
personCountTime
=
person
.
getCounttime
();
String
direction
=
person
.
getDirection
();
//Long gateId = person.getGateId();
Integer
bodyType
=
person
.
getBodyType
();
String
personChannelSerialNum
=
person
.
getChannelSerialNum
();
List
<
FaceFeature
>
faceFeatures
=
person
.
getFaceFeatures
();
...
...
@@ -202,7 +267,7 @@ public class PersonService {
.
source
(
XContentType
.
JSON
,
"personId"
,
personId
,
"unid"
,
unid
,
"data"
,
feature
,
"fid"
,
fid
,
"age"
,
age
,
"gender"
,
gender
,
"body_type"
,
bodyType
,
"counttime"
,
personCountTime
==
null
?
null
:
Constant
.
DATE_FORMAT
.
get
().
format
(
personCountTime
),
"channelSerialNum"
,
personChannelSerialNum
,
"gateId"
,
gateId
);
"channelSerialNum"
,
personChannelSerialNum
,
"gateId"
,
gateId
,
"direction"
,
direction
);
bulkRequest
.
add
(
indexRequest
);
}
}
...
...
@@ -230,7 +295,7 @@ public class PersonService {
.
source
(
XContentType
.
JSON
,
"personId"
,
personId
,
"unid"
,
unid
,
"body"
,
feature
,
"fid"
,
fid
,
"age"
,
age
,
"gender"
,
gender
,
"body_type"
,
bodyType
,
"counttime"
,
counttime
==
null
?
null
:
Constant
.
DATE_FORMAT
.
get
().
format
(
counttime
)
,
"channelSerialNum"
,
channelSerialNum
,
"gateId"
,
gateId
);
,
"channelSerialNum"
,
channelSerialNum
,
"gateId"
,
gateId
,
"direction"
,
direction
);
bulkRequest
.
add
(
indexRequest
);
}
}
...
...
@@ -334,7 +399,14 @@ public class PersonService {
}
}
private
SearchRequest
getSearchRequest
(
String
poolId
,
Integer
matchResultSize
,
Double
[]
feature
,
Person
person
,
int
type
,
Boolean
agg
)
{
/**
*
* @param feature
* @param person
* @param type 0,人脸,1人体
* @return
*/
private
SearchSourceBuilder
getSearchSourceBuilder
(
Double
[]
feature
,
Person
person
,
int
type
)
{
Script
script
;
BoolQueryBuilder
boolQuery
=
QueryBuilders
.
boolQuery
();
if
(
type
==
0
)
{
...
...
@@ -366,6 +438,10 @@ public class PersonService {
boolQuery
.
filter
(
QueryBuilders
.
termQuery
(
"personId"
,
person
.
getPersonUnid
()));
}
if
(
StringUtils
.
isNotBlank
(
person
.
getCompareDirection
()))
{
boolQuery
.
filter
(
QueryBuilders
.
termQuery
(
"direction"
,
person
.
getCompareDirection
()));
}
// 根据时间过滤
RangeQueryBuilder
rangeQueryBuilder
=
QueryBuilders
.
rangeQuery
(
"counttime"
);
Date
counttimeGTE
=
person
.
getCounttimeGTE
();
...
...
@@ -382,6 +458,17 @@ public class PersonService {
ScriptScoreQueryBuilder
queryBuilder
=
QueryBuilders
.
scriptScoreQuery
(
boolQuery
,
script
);
SearchSourceBuilder
builder
=
new
SearchSourceBuilder
().
query
(
queryBuilder
);
//控制最小分数
if
(
0
==
type
&&
null
!=
person
.
getFaceMinScore
())
{
builder
.
minScore
(
person
.
getFaceMinScore
());
}
else
if
(
1
==
type
&&
null
!=
person
.
getBodyMinScore
())
{
builder
.
minScore
(
person
.
getBodyMinScore
());
}
return
builder
;
}
private
SearchRequest
getSearchRequest
(
String
poolId
,
Integer
matchResultSize
,
Double
[]
feature
,
Person
person
,
int
type
,
Boolean
agg
)
{
SearchSourceBuilder
builder
=
getSearchSourceBuilder
(
feature
,
person
,
type
);
if
(
agg
)
{
MaxAggregationBuilder
maxScoreAgg
=
AggregationBuilders
.
max
(
"max_score"
).
script
(
new
Script
(
"_score"
));
TermsAggregationBuilder
personIdAgg
=
AggregationBuilders
.
terms
(
"by_personId"
).
field
(
"personId"
);
...
...
@@ -394,6 +481,8 @@ public class PersonService {
.
size
(
matchResultSize
);
}
log
.
debug
(
"poolId:{} 匹配时参数:{}"
,
poolId
,
builder
.
toString
());
return
new
SearchRequest
(
poolId
).
source
(
builder
);
}
...
...
src/main/java/com/viontech/match/service/PoolService.java
View file @
24f11a6
...
...
@@ -312,6 +312,13 @@ public class PoolService {
}
builder
.
endObject
();
// 方向 direction
builder
.
startObject
(
"direction"
);
{
builder
.
field
(
"type"
,
"keyword"
);
}
builder
.
endObject
();
}
builder
.
endObject
();
}
...
...
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