Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
c928122e
Commit
c928122e
authored
Nov 09, 2021
by
kongfm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改特种设备es 接口
parent
5079c387
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
235 additions
and
85 deletions
+235
-85
EsSpecialEquipmentDto.java
...n/amos/boot/module/tzs/api/dto/EsSpecialEquipmentDto.java
+1
-2
SpecialEquipmentController.java
...module/tzs/biz/controller/SpecialEquipmentController.java
+48
-22
ESElevatorServiceImpl.java
...ot/module/tzs/biz/service/impl/ESElevatorServiceImpl.java
+185
-60
application.properties
...boot-system-tzs/src/main/resources/application.properties
+1
-1
No files found.
amos-boot-module/amos-boot-module-api/amos-boot-module-tzs-api/src/main/java/com/yeejoin/amos/boot/module/tzs/api/dto/EsSpecialEquipmentDto.java
View file @
c928122e
...
@@ -4,8 +4,6 @@ import io.swagger.annotations.ApiModel;
...
@@ -4,8 +4,6 @@ import io.swagger.annotations.ApiModel;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.Data
;
import
java.util.Date
;
/**
/**
* 特种设备搜索DTO
* 特种设备搜索DTO
*/
*/
...
@@ -64,4 +62,5 @@ public class EsSpecialEquipmentDto {
...
@@ -64,4 +62,5 @@ public class EsSpecialEquipmentDto {
@ApiModelProperty
(
value
=
"聚合精确度1-12"
)
@ApiModelProperty
(
value
=
"聚合精确度1-12"
)
private
Integer
precision
;
private
Integer
precision
;
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/controller/SpecialEquipmentController.java
View file @
c928122e
...
@@ -8,6 +8,7 @@ import com.yeejoin.amos.boot.biz.common.controller.BaseController;
...
@@ -8,6 +8,7 @@ import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import
com.yeejoin.amos.boot.biz.common.feign.AmosFeignService
;
import
com.yeejoin.amos.boot.biz.common.feign.AmosFeignService
;
import
com.yeejoin.amos.boot.biz.common.utils.NameUtils
;
import
com.yeejoin.amos.boot.biz.common.utils.NameUtils
;
import
com.yeejoin.amos.boot.module.common.api.feign.EquipFeignClient
;
import
com.yeejoin.amos.boot.module.common.api.feign.EquipFeignClient
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ESAlertCalledDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorBaseInfoDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorBaseInfoDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorInfoDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorInfoDto
;
...
@@ -100,55 +101,52 @@ public class SpecialEquipmentController extends BaseController {
...
@@ -100,55 +101,52 @@ public class SpecialEquipmentController extends BaseController {
private
IElevatorRelationService
elevatorRelationService
;
private
IElevatorRelationService
elevatorRelationService
;
/**
/**
* ES查询
电梯信息
* ES查询
特种设备信息 带分页 加经纬度过滤 keyword 搜索
*
*
* @return 查询结果
* @return 查询结果
*/
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@RequestMapping
(
value
=
"/querySpecialEquipment"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/querySpecialEquipmentListPage"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"ES查询八大类信息"
,
notes
=
"ES查询八大类信息"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"ES查询特种设备信息带分页 "
,
notes
=
"ES查询特种设备信息带分页"
)
public
ResponseModel
<
Map
<
String
,
List
<
SpecialEquipmentDto
>>>
querySpecialEquipment
(
@RequestBody
EsSpecialEquipmentDto
esSpecialEquipmentDto
){
public
ResponseModel
<
Page
<
SpecialEquipmentDto
>>
querySpecialEquipmentListPage
(
@RequestBody
EsSpecialEquipmentDto
esSpecialEquipmentDto
Map
<
String
,
List
<
SpecialEquipmentDto
>>
result
=
new
HashMap
<>();
,
@RequestParam
(
value
=
"current"
)
int
current
,
@RequestParam
(
value
=
"size"
)
int
size
){
Page
<
SpecialEquipmentDto
>
result
=
null
;
if
(
ValidationUtil
.
isEmpty
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
throw
new
BadRequest
(
"参数校验失败."
);
}
if
(
StringUtils
.
isNotBlank
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
// 查找特定设备
if
(
StringUtils
.
isNotBlank
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
// 查找特定设备
if
(
"3000"
.
equals
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
if
(
"3000"
.
equals
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
List
<
SpecialEquipmentDto
>
elevatorList
=
esElevatorService
.
queryByDto
(
esSpecialEquipmentDto
,
true
);
result
=
esElevatorService
.
queryPageByDto
(
esSpecialEquipmentDto
,
current
,
size
);
result
.
put
(
"3000"
,
elevatorList
);
}
}
}
else
{
// 查找所有设备
// 查找电梯数据
List
<
SpecialEquipmentDto
>
elevatorList
=
esElevatorService
.
queryByDto
(
esSpecialEquipmentDto
,
false
);
result
.
put
(
"3000"
,
elevatorList
);
}
}
return
ResponseHelper
.
buildResponse
(
result
);
return
ResponseHelper
.
buildResponse
(
result
);
}
}
/**
/**
* ES查询
电梯信息
* ES查询
特种设备信息 不带分页 加经纬度过滤 keyword 搜索
*
*
* @return 查询结果
* @return 查询结果
*/
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@RequestMapping
(
value
=
"/querySpecialEquipmentList"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/querySpecialEquipmentList"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"ES查询
八大类列表信息"
,
notes
=
"ES查询八大类列表信息
"
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"ES查询
特种设备信息不带分页"
,
notes
=
"ES查询特种设备信息不带分页
"
)
public
ResponseModel
<
List
<
SpecialEquipmentDto
>>
querySpecialEquipmentList
(
@RequestBody
EsSpecialEquipment
ListDto
eSpecialEquipmentLis
tDto
){
public
ResponseModel
<
List
<
SpecialEquipmentDto
>>
querySpecialEquipmentList
(
@RequestBody
EsSpecialEquipment
Dto
esSpecialEquipmen
tDto
){
List
<
SpecialEquipmentDto
>
result
=
new
ArrayList
<>();
List
<
SpecialEquipmentDto
>
result
=
new
ArrayList
<>();
if
(
ValidationUtil
.
isEmpty
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
if
(
ValidationUtil
.
isEmpty
(
eSpecialEquipmentListDto
.
getCategoryCode
()))
{
throw
new
BadRequest
(
"参数校验失败."
);
throw
new
BadRequest
(
"参数校验失败."
);
}
}
if
(
"3000"
.
equals
(
eSpecialEquipmentListDto
.
getCategoryCode
()))
{
if
(
StringUtils
.
isNotBlank
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
// 查找特定设备
result
=
esElevatorService
.
queryListByDto
(
eSpecialEquipmentListDto
);
if
(
"3000"
.
equals
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
result
=
esElevatorService
.
queryByDto
(
esSpecialEquipmentDto
);
}
}
}
return
ResponseHelper
.
buildResponse
(
result
);
return
ResponseHelper
.
buildResponse
(
result
);
}
}
/**
/**
* ES查询
电梯
信息
* ES查询
特种设备聚合
信息
*
*
* @return 查询结果
* @return 查询结果
*/
*/
...
@@ -170,10 +168,38 @@ public class SpecialEquipmentController extends BaseController {
...
@@ -170,10 +168,38 @@ public class SpecialEquipmentController extends BaseController {
result
=
esElevatorService
.
queryTogetherByDto
(
esSpecialEquipmentDto
);
result
=
esElevatorService
.
queryTogetherByDto
(
esSpecialEquipmentDto
);
}
}
}
}
return
ResponseHelper
.
buildResponse
(
result
);
}
/***
* keyword 区域 查询八大类总数
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@RequestMapping
(
value
=
"/queryEquipNum"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"查询八大类总数"
,
notes
=
"查询八大类总数"
)
public
ResponseModel
<
Map
<
String
,
Long
>>
queryEquipNum
(
@RequestBody
EsSpecialEquipmentDto
esSpecialEquipmentDto
){
Map
<
String
,
Long
>
result
=
new
HashMap
<>();
// 锅炉
Long
boiler
=
0
l
;
result
.
put
(
"1000"
,
boiler
);
// 压力容器
Long
vessel
=
0
l
;
result
.
put
(
"2000"
,
vessel
);
// 电梯
Long
elevator
=
esElevatorService
.
queryNumberByDto
(
esSpecialEquipmentDto
);
result
.
put
(
"3000"
,
elevator
);
// 起重机械
Long
crane
=
0
l
;
result
.
put
(
"4000"
,
crane
);
// 大型游乐设施
Long
facility
=
0
l
;
result
.
put
(
"6000"
,
facility
);
// 大型游乐设施
return
ResponseHelper
.
buildResponse
(
result
);
return
ResponseHelper
.
buildResponse
(
result
);
}
}
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/service/impl/ESElevatorServiceImpl.java
View file @
c928122e
...
@@ -2,7 +2,9 @@ package com.yeejoin.amos.boot.module.tzs.biz.service.impl;
...
@@ -2,7 +2,9 @@ package com.yeejoin.amos.boot.module.tzs.biz.service.impl;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.yeejoin.amos.boot.biz.common.utils.DateUtils
;
import
com.yeejoin.amos.boot.biz.common.utils.DateUtils
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ESAlertCalledDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.EsElevatorDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.EsElevatorDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.EsSpecialEquipmentDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.EsSpecialEquipmentDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.EsSpecialEquipmentListDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.EsSpecialEquipmentListDto
;
...
@@ -36,6 +38,7 @@ import org.springframework.data.domain.PageRequest;
...
@@ -36,6 +38,7 @@ import org.springframework.data.domain.PageRequest;
import
org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
;
import
org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
;
import
org.springframework.data.elasticsearch.core.SearchHit
;
import
org.springframework.data.elasticsearch.core.SearchHit
;
import
org.springframework.data.elasticsearch.core.SearchHits
;
import
org.springframework.data.elasticsearch.core.SearchHits
;
import
org.springframework.data.elasticsearch.core.query.NativeSearchQuery
;
import
org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder
;
import
org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.typroject.tyboot.core.foundation.utils.Bean
;
import
org.typroject.tyboot.core.foundation.utils.Bean
;
...
@@ -235,10 +238,9 @@ public class ESElevatorServiceImpl {
...
@@ -235,10 +238,9 @@ public class ESElevatorServiceImpl {
/**
/**
* 根据特种设备搜索类查找电梯相关信息
* 根据特种设备搜索类查找电梯相关信息
* @param esSpecialEquipmentDto
* @param esSpecialEquipmentDto
* @param isSingle
* @return
* @return
*/
*/
public
List
<
SpecialEquipmentDto
>
queryByDto
(
EsSpecialEquipmentDto
esSpecialEquipmentDto
,
Boolean
isSingle
)
{
public
List
<
SpecialEquipmentDto
>
queryByDto
(
EsSpecialEquipmentDto
esSpecialEquipmentDto
)
{
Double
startLongitude
=
esSpecialEquipmentDto
.
getStartLongitude
();
Double
startLongitude
=
esSpecialEquipmentDto
.
getStartLongitude
();
Double
startLatitude
=
esSpecialEquipmentDto
.
getStartLatitude
();
Double
startLatitude
=
esSpecialEquipmentDto
.
getStartLatitude
();
...
@@ -278,37 +280,26 @@ public class ESElevatorServiceImpl {
...
@@ -278,37 +280,26 @@ public class ESElevatorServiceImpl {
boolMust
.
should
(
qb1
);
boolMust
.
should
(
qb1
);
boolMust
.
minimumShouldMatch
(
1
);
boolMust
.
minimumShouldMatch
(
1
);
}
}
int
size
=
3000
;
if
(
isSingle
)
{
size
=
400
;
}
// 创建查询构造器
// 创建查询构造器
NativeSearchQuery
Builder
queryBuilder
=
new
NativeSearchQueryBuilder
()
NativeSearchQuery
query
=
new
NativeSearchQueryBuilder
()
// 分页
// 分页
.
withPageable
(
PageRequest
.
of
(
0
,
size
))
//
.withPageable(PageRequest.of(0, size))
// 排序
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
//过滤条件
.
withQuery
(
boolMust
);
.
withQuery
(
boolMust
).
build
();
query
.
setTrackTotalHits
(
true
);
query
.
setMaxResults
(
10000
);
List
<
SpecialEquipmentDto
>
list
=
new
LinkedList
<>();
List
<
SpecialEquipmentDto
>
list
=
new
LinkedList
<>();
try
SearchHits
<
EsElevator
>
searchHits
=
elasticsearchTemplate
.
search
(
query
,
EsElevator
.
class
);
{
for
(
SearchHit
searchHit
:
searchHits
.
getSearchHits
())
SearchHits
<
EsElevator
>
searchHits
=
elasticsearchTemplate
.
search
(
queryBuilder
.
build
(),
EsElevator
.
class
);
for
(
SearchHit
searchHit
:
searchHits
.
getSearchHits
())
{
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
searchHit
.
getContent
());
SpecialEquipmentDto
esElevatorDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
SpecialEquipmentDto
.
class
);
esElevatorDto
.
setCategoryCode
(
"3000"
);
list
.
add
(
esElevatorDto
);
}
}
catch
(
Exception
e
)
{
{
// TODO: handle exception
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
searchHit
.
getContent
());
SpecialEquipmentDto
esElevatorDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
SpecialEquipmentDto
.
class
);
esElevatorDto
.
setCategoryCode
(
"3000"
);
list
.
add
(
esElevatorDto
);
}
}
return
list
;
return
list
;
...
@@ -333,29 +324,25 @@ public class ESElevatorServiceImpl {
...
@@ -333,29 +324,25 @@ public class ESElevatorServiceImpl {
}
}
// 创建查询构造器
// 创建查询构造器
NativeSearchQuery
Builder
queryBuilder
=
new
NativeSearchQueryBuilder
()
NativeSearchQuery
query
=
new
NativeSearchQueryBuilder
()
// 分页
// 分页
.
withPageable
(
PageRequest
.
of
(
0
,
number
))
.
withPageable
(
PageRequest
.
of
(
0
,
number
))
// 排序
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
//过滤条件
.
withQuery
(
boolMust
);
.
withQuery
(
boolMust
).
build
();
query
.
setTrackTotalHits
(
true
);
query
.
setMaxResults
(
10000
);
//queryBuilder.addAggregation()
//queryBuilder.addAggregation()
List
<
SpecialEquipmentDto
>
list
=
new
LinkedList
<>();
List
<
SpecialEquipmentDto
>
list
=
new
LinkedList
<>();
try
SearchHits
<
EsElevator
>
searchHits
=
elasticsearchTemplate
.
search
(
query
,
EsElevator
.
class
);
for
(
SearchHit
searchHit
:
searchHits
.
getSearchHits
())
{
{
SearchHits
<
EsElevator
>
searchHits
=
elasticsearchTemplate
.
search
(
queryBuilder
.
build
(),
EsElevator
.
class
);
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
searchHit
.
getContent
());
for
(
SearchHit
searchHit
:
searchHits
.
getSearchHits
())
SpecialEquipmentDto
esElevatorDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
SpecialEquipmentDto
.
class
);
{
esElevatorDto
.
setCategoryCode
(
"3000"
);
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
searchHit
.
getContent
());
list
.
add
(
esElevatorDto
);
SpecialEquipmentDto
esElevatorDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
SpecialEquipmentDto
.
class
);
esElevatorDto
.
setCategoryCode
(
"3000"
);
list
.
add
(
esElevatorDto
);
}
}
catch
(
Exception
e
)
{
// TODO: handle exception
}
}
return
list
;
return
list
;
}
}
...
@@ -392,32 +379,170 @@ public class ESElevatorServiceImpl {
...
@@ -392,32 +379,170 @@ public class ESElevatorServiceImpl {
boolMust
.
must
(
constantScore
);
boolMust
.
must
(
constantScore
);
// 创建查询构造器
// 创建查询构造器
NativeSearchQuery
Builder
queryBuilder
=
new
NativeSearchQueryBuilder
()
NativeSearchQuery
query
=
new
NativeSearchQueryBuilder
()
// 分页
// 分页
//.withPageable(PageRequest.of(0, number))
//.withPageable(PageRequest.of(0, number))
// 排序
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
//过滤条件
.
withQuery
(
boolMust
).
addAggregation
(
new
GeoHashGridAggregationBuilder
(
"96333"
).
precision
(
esSpecialEquipmentDto
.
getPrecision
()).
field
(
"location"
));
.
withQuery
(
boolMust
)
.
addAggregation
(
new
GeoHashGridAggregationBuilder
(
"96333"
)
SearchHits
<
EsElevator
>
searchHits
=
elasticsearchTemplate
.
search
(
queryBuilder
.
build
(),
EsElevator
.
class
);
.
precision
(
esSpecialEquipmentDto
.
getPrecision
()).
field
(
"location"
)).
build
();
Aggregations
aggregations
=
searchHits
.
getAggregations
();
query
.
setTrackTotalHits
(
true
);
ParsedGeoHashGrid
aggregation
=
aggregations
.
get
(
"96333"
);
query
.
setMaxResults
(
10000
);
List
<?
extends
Terms
.
Bucket
>
buckets
=
(
List
<?
extends
Terms
.
Bucket
>)
aggregation
.
getBuckets
();
SearchHits
<
EsElevator
>
searchHits
=
elasticsearchTemplate
.
search
(
query
,
EsElevator
.
class
);
// 通过debug能看到aggregation.getBuckets里就是我所需要的分组信息,但是直接.出不来,这里我是手动拼出来并强转一下(ParsedLongTerms)
Aggregations
aggregations
=
searchHits
.
getAggregations
();
for
(
int
i
=
0
;
i
<
buckets
.
size
();
i
++)
{
ParsedGeoHashGrid
aggregation
=
aggregations
.
get
(
"96333"
);
ParsedGeoHashGridBucket
bucket
=
(
ParsedGeoHashGridBucket
)
buckets
.
get
(
i
);
List
<?
extends
Terms
.
Bucket
>
buckets
=
(
List
<?
extends
Terms
.
Bucket
>)
aggregation
.
getBuckets
();
// 每组的key
// 通过debug能看到aggregation.getBuckets里就是我所需要的分组信息,但是直接.出不来,这里我是手动拼出来并强转一下(ParsedLongTerms)
String
key
=
bucket
.
getKeyAsString
();
// bucket key
for
(
int
i
=
0
;
i
<
buckets
.
size
();
i
++)
{
long
docCount
=
bucket
.
getDocCount
();
// Doc count
ParsedGeoHashGridBucket
bucket
=
(
ParsedGeoHashGridBucket
)
buckets
.
get
(
i
);
GeoPoint
point
=
GeoPoint
.
fromGeohash
(
key
);
// 每组的key
Map
<
String
,
String
>
tempMap
=
new
HashMap
<>();
String
key
=
bucket
.
getKeyAsString
();
// bucket key
tempMap
.
put
(
"lat"
,
point
.
getLat
()
+
""
);
long
docCount
=
bucket
.
getDocCount
();
// Doc count
tempMap
.
put
(
"lon"
,
point
.
getLon
()
+
""
);
GeoPoint
point
=
GeoPoint
.
fromGeohash
(
key
);
tempMap
.
put
(
"number"
,
docCount
+
""
);
Map
<
String
,
String
>
tempMap
=
new
HashMap
<>();
result
.
add
(
tempMap
);
tempMap
.
put
(
"lat"
,
point
.
getLat
()
+
""
);
}
tempMap
.
put
(
"lon"
,
point
.
getLon
()
+
""
);
tempMap
.
put
(
"number"
,
docCount
+
""
);
result
.
add
(
tempMap
);
}
return
result
;
}
public
Page
<
SpecialEquipmentDto
>
queryPageByDto
(
EsSpecialEquipmentDto
esSpecialEquipmentDto
,
int
current
,
int
size
)
{
Page
<
SpecialEquipmentDto
>
result
=
new
Page
<
SpecialEquipmentDto
>(
current
,
size
);
Double
startLongitude
=
esSpecialEquipmentDto
.
getStartLongitude
();
Double
startLatitude
=
esSpecialEquipmentDto
.
getStartLatitude
();
Double
endLongitude
=
esSpecialEquipmentDto
.
getEndLongitude
();
Double
endLatitude
=
esSpecialEquipmentDto
.
getEndLatitude
();
String
regionCode
=
esSpecialEquipmentDto
.
getRegionCode
();
String
keyword
=
esSpecialEquipmentDto
.
getKeyword
();
/**
* 通用匹配规则,条件构建
*/
BoolQueryBuilder
boolMust
=
QueryBuilders
.
boolQuery
();
// 经度比start 大比end 小 纬度比start 小 比end 大
if
(!
ValidationUtil
.
isEmpty
(
startLongitude
)
&&
!
ValidationUtil
.
isEmpty
(
startLatitude
)
&&
!
ValidationUtil
.
isEmpty
(
endLongitude
)
&&
!
ValidationUtil
.
isEmpty
(
endLatitude
))
{
BoolQueryBuilder
longLatMust
=
QueryBuilders
.
boolQuery
();
BoolQueryBuilder
qb1
=
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
rangeQuery
(
"longitude"
).
gte
(
startLongitude
).
lte
(
endLongitude
));
BoolQueryBuilder
qb2
=
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
rangeQuery
(
"latitude"
).
gte
(
endLatitude
).
lte
(
startLatitude
));
longLatMust
.
must
(
qb1
);
longLatMust
.
must
(
qb2
);
boolMust
.
must
(
longLatMust
);
}
if
(!
ValidationUtil
.
isEmpty
(
regionCode
))
{
BoolQueryBuilder
qb2
=
QueryBuilders
.
boolQuery
().
filter
(
QueryBuilders
.
matchPhraseQuery
(
"regionCode"
,
regionCode
));
boolMust
.
must
(
qb2
);
}
if
(!
ValidationUtil
.
isEmpty
(
keyword
))
{
BoolQueryBuilder
qb0
=
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
matchQuery
(
"rescueCode.keyword"
,
keyword
));
boolMust
.
should
(
qb0
);
BoolQueryBuilder
qb1
=
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
matchQuery
(
"address"
,
keyword
));
boolMust
.
should
(
qb1
);
boolMust
.
minimumShouldMatch
(
1
);
}
// 创建查询构造器
NativeSearchQuery
query
=
new
NativeSearchQueryBuilder
()
// 分页
.
withPageable
(
PageRequest
.
of
(
current
,
size
))
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
.
withQuery
(
boolMust
).
build
();
query
.
setTrackTotalHits
(
true
);
query
.
setMaxResults
(
size
);
List
<
SpecialEquipmentDto
>
list
=
new
LinkedList
<>();
long
total
=
0
;
try
{
SearchHits
<
EsElevator
>
searchHits
=
elasticsearchTemplate
.
search
(
query
,
EsElevator
.
class
);
for
(
SearchHit
searchHit
:
searchHits
.
getSearchHits
())
{
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
searchHit
.
getContent
());
SpecialEquipmentDto
esElevatorDto
=
JSONObject
.
toJavaObject
(
jsonObject
,
SpecialEquipmentDto
.
class
);
esElevatorDto
.
setCategoryCode
(
"3000"
);
list
.
add
(
esElevatorDto
);
}
total
=
searchHits
.
getTotalHits
();
}
catch
(
Exception
e
)
{
// TODO: handle exception
}
result
.
setRecords
(
list
);
result
.
setTotal
(
total
);
return
result
;
return
result
;
}
}
public
Long
queryNumberByDto
(
EsSpecialEquipmentDto
esSpecialEquipmentDto
)
{
Double
startLongitude
=
esSpecialEquipmentDto
.
getStartLongitude
();
Double
startLatitude
=
esSpecialEquipmentDto
.
getStartLatitude
();
Double
endLongitude
=
esSpecialEquipmentDto
.
getEndLongitude
();
Double
endLatitude
=
esSpecialEquipmentDto
.
getEndLatitude
();
String
regionCode
=
esSpecialEquipmentDto
.
getRegionCode
();
String
keyword
=
esSpecialEquipmentDto
.
getKeyword
();
/**
* 通用匹配规则,条件构建
*/
BoolQueryBuilder
boolMust
=
QueryBuilders
.
boolQuery
();
// 经度比start 大比end 小 纬度比start 小 比end 大
if
(!
ValidationUtil
.
isEmpty
(
startLongitude
)
&&
!
ValidationUtil
.
isEmpty
(
startLatitude
)
&&
!
ValidationUtil
.
isEmpty
(
endLongitude
)
&&
!
ValidationUtil
.
isEmpty
(
endLatitude
))
{
BoolQueryBuilder
longLatMust
=
QueryBuilders
.
boolQuery
();
BoolQueryBuilder
qb1
=
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
rangeQuery
(
"longitude"
).
gte
(
startLongitude
).
lte
(
endLongitude
));
BoolQueryBuilder
qb2
=
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
rangeQuery
(
"latitude"
).
gte
(
endLatitude
).
lte
(
startLatitude
));
longLatMust
.
must
(
qb1
);
longLatMust
.
must
(
qb2
);
boolMust
.
must
(
longLatMust
);
}
if
(!
ValidationUtil
.
isEmpty
(
regionCode
))
{
BoolQueryBuilder
qb2
=
QueryBuilders
.
boolQuery
().
filter
(
QueryBuilders
.
matchPhraseQuery
(
"regionCode"
,
regionCode
));
boolMust
.
must
(
qb2
);
}
if
(!
ValidationUtil
.
isEmpty
(
keyword
))
{
BoolQueryBuilder
qb0
=
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
matchQuery
(
"rescueCode.keyword"
,
keyword
));
boolMust
.
should
(
qb0
);
BoolQueryBuilder
qb1
=
QueryBuilders
.
boolQuery
().
must
(
QueryBuilders
.
matchQuery
(
"address"
,
keyword
));
boolMust
.
should
(
qb1
);
boolMust
.
minimumShouldMatch
(
1
);
}
// 创建查询构造器
NativeSearchQueryBuilder
queryBuilder
=
new
NativeSearchQueryBuilder
()
// 分页
// .withPageable(PageRequest.of(current, size))
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
.
withQuery
(
boolMust
);
List
<
SpecialEquipmentDto
>
list
=
new
LinkedList
<>();
long
total
=
0
;
try
{
SearchHits
<
EsElevator
>
searchHits
=
elasticsearchTemplate
.
search
(
queryBuilder
.
build
(),
EsElevator
.
class
);
total
=
searchHits
.
getTotalHits
();
}
catch
(
Exception
e
)
{
// TODO: handle exception
}
return
total
;
}
}
}
amos-boot-system-tzs/src/main/resources/application.properties
View file @
c928122e
spring.application.name
=
TZS
spring.application.name
=
TZS
-kfm
server.servlet.context-path
=
/tzs
server.servlet.context-path
=
/tzs
server.port
=
11000
server.port
=
11000
spring.profiles.active
=
dev
spring.profiles.active
=
dev
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment