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
9b7f7b21
Commit
9b7f7b21
authored
Nov 08, 2021
by
kongfm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
特种设备ES 搜索优化
parent
35ee00c5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
612 additions
and
23 deletions
+612
-23
EsSpecialEquipmentDto.java
...n/amos/boot/module/tzs/api/dto/EsSpecialEquipmentDto.java
+67
-0
EsSpecialEquipmentListDto.java
...os/boot/module/tzs/api/dto/EsSpecialEquipmentListDto.java
+38
-0
SpecialEquipmentDto.java
...oin/amos/boot/module/tzs/api/dto/SpecialEquipmentDto.java
+54
-0
EsElevator.java
...m/yeejoin/amos/boot/module/tzs/api/entity/EsElevator.java
+13
-5
AlertCalledController.java
...boot/module/tzs/biz/controller/AlertCalledController.java
+26
-16
SpecialEquipmentController.java
...module/tzs/biz/controller/SpecialEquipmentController.java
+179
-0
ESElevatorServiceImpl.java
...ot/module/tzs/biz/service/impl/ESElevatorServiceImpl.java
+235
-2
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
0 → 100644
View file @
9b7f7b21
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
api
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.Date
;
/**
* 特种设备搜索DTO
*/
@Data
@ApiModel
(
value
=
"EsSpecialEquipmentDto"
,
description
=
"特种设备搜索DTO"
)
public
class
EsSpecialEquipmentDto
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
* 左上经度
*/
@ApiModelProperty
(
value
=
"左上经度"
)
private
Double
startLongitude
;
/**
* 左上纬度
*/
@ApiModelProperty
(
value
=
"左上纬度"
)
private
Double
startLatitude
;
/**
* 右下经度
*/
@ApiModelProperty
(
value
=
"右下经度"
)
private
Double
endLongitude
;
/**
* 右下纬度
*/
@ApiModelProperty
(
value
=
"右下纬度"
)
private
Double
endLatitude
;
/**
* 搜索关键字
*/
@ApiModelProperty
(
value
=
"搜索关键字"
)
private
String
keyword
;
/**
* 所属区域代码
*/
@ApiModelProperty
(
value
=
"所属区域代码"
)
private
String
regionCode
;
/**
* 设备类别编码
*/
@ApiModelProperty
(
value
=
"设备类别编码"
)
private
String
categoryCode
;
@ApiModelProperty
(
value
=
"聚合精确度1-12"
)
private
Integer
precision
;
}
amos-boot-module/amos-boot-module-api/amos-boot-module-tzs-api/src/main/java/com/yeejoin/amos/boot/module/tzs/api/dto/EsSpecialEquipmentListDto.java
0 → 100644
View file @
9b7f7b21
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
api
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* 特种设备搜索列表DTO
*/
@Data
@ApiModel
(
value
=
"EsSpecialEquipmentListDto"
,
description
=
"特种设备搜索列表DTO"
)
public
class
EsSpecialEquipmentListDto
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
* 所属区域代码
*/
@ApiModelProperty
(
value
=
"所属区域代码"
)
private
String
regionCode
;
/**
* 设备类别编码
*/
@ApiModelProperty
(
value
=
"设备类别编码"
)
private
String
categoryCode
;
/**
* 搜索数量
*/
@ApiModelProperty
(
value
=
"搜索数量"
)
private
Integer
equipmentNumber
;
}
amos-boot-module/amos-boot-module-api/amos-boot-module-tzs-api/src/main/java/com/yeejoin/amos/boot/module/tzs/api/dto/SpecialEquipmentDto.java
0 → 100644
View file @
9b7f7b21
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
api
.
dto
;
import
com.alibaba.excel.annotation.ExcelIgnore
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* 特种设备DTO
*/
@Data
@ApiModel
(
value
=
"SpecialEquipmentDto"
,
description
=
"特种设备DTO"
)
public
class
SpecialEquipmentDto
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@ExcelIgnore
@ApiModelProperty
(
value
=
"主键ID"
)
protected
Long
sequenceNbr
;
@ApiModelProperty
(
value
=
"电梯应急救援识别码"
)
private
Integer
rescueCode
;
@ApiModelProperty
(
value
=
"设备注册代码"
)
private
String
registerCode
;
@ApiModelProperty
(
value
=
"所属省"
)
private
String
province
;
@ApiModelProperty
(
value
=
"所属地市"
)
private
String
city
;
@ApiModelProperty
(
value
=
"所属区县"
)
private
String
district
;
@ApiModelProperty
(
value
=
"所属区域代码"
)
private
String
regionCode
;
@ApiModelProperty
(
value
=
"安装地址"
)
private
String
address
;
@ApiModelProperty
(
value
=
"经度"
)
private
Double
longitude
;
@ApiModelProperty
(
value
=
"纬度"
)
private
Double
latitude
;
@ApiModelProperty
(
value
=
"设备类别编码"
)
private
String
categoryCode
;
}
amos-boot-module/amos-boot-module-api/amos-boot-module-tzs-api/src/main/java/com/yeejoin/amos/boot/module/tzs/api/entity/EsElevator.java
View file @
9b7f7b21
...
...
@@ -2,10 +2,12 @@ package com.yeejoin.amos.boot.module.tzs.api.entity;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
org.elasticsearch.common.geo.GeoPoint
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.elasticsearch.annotations.Document
;
import
org.springframework.data.elasticsearch.annotations.Field
;
import
org.springframework.data.elasticsearch.annotations.FieldType
;
import
org.springframework.data.elasticsearch.annotations.GeoPointField
;
/**
* @author litw
...
...
@@ -55,19 +57,25 @@ public class EsElevator {
* 电梯识别码
*/
@Field
(
type
=
FieldType
.
Text
)
private
Integer
rescueCode
;
private
String
rescueCode
;
/**
* 电梯经度
*/
@Field
(
type
=
FieldType
.
Text
)
private
String
longitude
;
@Field
(
type
=
FieldType
.
Double
)
private
Double
longitude
;
/**
* 电梯纬度
*/
@Field
(
type
=
FieldType
.
Text
)
private
String
latitude
;
@Field
(
type
=
FieldType
.
Double
)
private
Double
latitude
;
/**
* 经纬度字段
*/
@GeoPointField
private
GeoPoint
location
;
/**
* 地址
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/controller/AlertCalledController.java
View file @
9b7f7b21
...
...
@@ -688,17 +688,22 @@ public class AlertCalledController extends BaseController {
while
(
regionIt
.
hasNext
())
{
String
tempCode
=
regionIt
.
next
();
String
districtCode
=
tempCode
.
substring
(
4
,
6
);
if
(
"00"
.
equals
(
districtCode
))
{
// 为市
if
(!
useRegionCode
.
contains
(
tempCode
))
{
// 不包含该市权限 需要移除市搜索条件 添加 该市下区搜索条件
for
(
String
tempUsercode
:
useRegionCode
)
{
if
(
tempUsercode
.
indexOf
(
tempCode
.
substring
(
0
,
4
))
!=
-
1
)
{
tempList
.
add
(
tempUsercode
);
String
provinceCode
=
tempCode
.
substring
(
2
,
6
);
if
(
"0000"
.
equals
(
provinceCode
))
{
// 为省则默认使用用户现有权限查询数据
regionCodes
=
useRegionCode
;
}
else
{
if
(
"00"
.
equals
(
districtCode
))
{
// 为市
if
(!
useRegionCode
.
contains
(
tempCode
))
{
// 不包含该市权限 需要移除市搜索条件 添加 该市下区搜索条件
for
(
String
tempUsercode
:
useRegionCode
)
{
if
(
tempUsercode
.
indexOf
(
tempCode
.
substring
(
0
,
4
))
!=
-
1
)
{
tempList
.
add
(
tempUsercode
);
}
}
regionIt
.
remove
();
}
regionIt
.
remove
();
}
}
else
{
// 为区 不会出现越权情况
}
else
{
// 为区 不会出现越权情况
}
}
}
for
(
String
t
:
tempList
)
{
...
...
@@ -727,17 +732,22 @@ public class AlertCalledController extends BaseController {
while
(
regionIt
.
hasNext
())
{
String
tempCode
=
regionIt
.
next
();
String
districtCode
=
tempCode
.
substring
(
4
,
6
);
if
(
"00"
.
equals
(
districtCode
))
{
// 为市
if
(!
useRegionCode
.
contains
(
tempCode
))
{
// 不包含该市权限 需要移除市搜索条件 添加 该市下区搜索条件
for
(
String
tempUsercode
:
useRegionCode
)
{
if
(
tempUsercode
.
indexOf
(
tempCode
.
substring
(
0
,
4
))
!=
-
1
)
{
tempList
.
add
(
tempUsercode
);
String
provinceCode
=
tempCode
.
substring
(
2
,
6
);
if
(
"0000"
.
equals
(
provinceCode
))
{
// 为省则默认使用用户现有权限查询数据
regionCodes
=
useRegionCode
;
}
else
{
if
(
"00"
.
equals
(
districtCode
))
{
// 为市
if
(!
useRegionCode
.
contains
(
tempCode
))
{
// 不包含该市权限 需要移除市搜索条件 添加 该市下区搜索条件
for
(
String
tempUsercode
:
useRegionCode
)
{
if
(
tempUsercode
.
indexOf
(
tempCode
.
substring
(
0
,
4
))
!=
-
1
)
{
tempList
.
add
(
tempUsercode
);
}
}
regionIt
.
remove
();
}
regionIt
.
remove
();
}
}
else
{
// 为区 不会出现越权情况
}
else
{
// 为区 不会出现越权情况
}
}
}
for
(
String
t
:
tempList
)
{
...
...
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
0 → 100644
View file @
9b7f7b21
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
biz
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
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.utils.NameUtils
;
import
com.yeejoin.amos.boot.module.common.api.feign.EquipFeignClient
;
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.ElevatorInfoDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorListDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorMaintenanceInfoDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorNewDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorTestInfoDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorWlInfoDto
;
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.EsSpecialEquipmentListDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.SpecialEquipmentDto
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.Elevator
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.MaintainInfo
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.TestInfo
;
import
com.yeejoin.amos.boot.module.tzs.api.service.IElevatorRelationService
;
import
com.yeejoin.amos.boot.module.tzs.api.service.IElevatorService
;
import
com.yeejoin.amos.boot.module.tzs.biz.service.impl.ESElevatorServiceImpl
;
import
com.yeejoin.amos.boot.module.tzs.biz.service.impl.ElevatorServiceImpl
;
import
com.yeejoin.amos.boot.module.tzs.biz.service.impl.MaintainInfoServiceImpl
;
import
com.yeejoin.amos.boot.module.tzs.biz.service.impl.TestInfoServiceImpl
;
import
com.yeejoin.amos.boot.module.tzs.biz.utils.BeanDtoVoUtils
;
import
com.yeejoin.amos.feign.privilege.model.AgencyUserModel
;
import
com.yeejoin.amos.feign.systemctl.model.DictionarieValueModel
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.eclipse.paho.client.mqttv3.MqttException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.typroject.tyboot.component.emq.EmqKeeper
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.foundation.utils.Bean
;
import
org.typroject.tyboot.core.foundation.utils.ValidationUtil
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
org.typroject.tyboot.core.restful.exception.instance.BadRequest
;
import
org.typroject.tyboot.core.restful.utils.ResponseHelper
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 特种设备API
*/
@RestController
@Api
(
tags
=
"特种设备API"
)
@RequestMapping
(
value
=
"/special-equipment"
)
public
class
SpecialEquipmentController
extends
BaseController
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SpecialEquipmentController
.
class
);
@Autowired
IElevatorService
iElevatorService
;
@Autowired
ElevatorServiceImpl
elevatorService
;
@Autowired
private
AmosFeignService
amosFeignService
;
@Autowired
private
MaintainInfoServiceImpl
maintainInfoService
;
@Autowired
private
EquipFeignClient
equipFeignClient
;
@Autowired
private
TestInfoServiceImpl
testInfoService
;
@Autowired
ESElevatorServiceImpl
esElevatorService
;
@Autowired
private
EmqKeeper
emqKeeper
;
@Value
(
"${mqtt.topic.elevator.push}"
)
private
String
elevatorpushTopic
;
@Autowired
private
IElevatorRelationService
elevatorRelationService
;
/**
* ES查询电梯信息
*
* @return 查询结果
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@RequestMapping
(
value
=
"/querySpecialEquipment"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"ES查询八大类信息"
,
notes
=
"ES查询八大类信息"
)
public
ResponseModel
<
Map
<
String
,
List
<
SpecialEquipmentDto
>>>
querySpecialEquipment
(
@RequestBody
EsSpecialEquipmentDto
esSpecialEquipmentDto
){
Map
<
String
,
List
<
SpecialEquipmentDto
>>
result
=
new
HashMap
<>();
if
(
StringUtils
.
isNotBlank
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
// 查找特定设备
if
(
"3000"
.
equals
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
List
<
SpecialEquipmentDto
>
elevatorList
=
esElevatorService
.
queryByDto
(
esSpecialEquipmentDto
,
true
);
result
.
put
(
"3000"
,
elevatorList
);
}
}
else
{
// 查找所有设备
// 查找电梯数据
List
<
SpecialEquipmentDto
>
elevatorList
=
esElevatorService
.
queryByDto
(
esSpecialEquipmentDto
,
false
);
result
.
put
(
"3000"
,
elevatorList
);
}
return
ResponseHelper
.
buildResponse
(
result
);
}
/**
* ES查询电梯信息
*
* @return 查询结果
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@RequestMapping
(
value
=
"/querySpecialEquipmentList"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"ES查询八大类列表信息"
,
notes
=
"ES查询八大类列表信息"
)
public
ResponseModel
<
List
<
SpecialEquipmentDto
>>
querySpecialEquipmentList
(
@RequestBody
EsSpecialEquipmentListDto
eSpecialEquipmentListDto
){
List
<
SpecialEquipmentDto
>
result
=
new
ArrayList
<>();
if
(
ValidationUtil
.
isEmpty
(
eSpecialEquipmentListDto
.
getCategoryCode
()))
{
throw
new
BadRequest
(
"参数校验失败."
);
}
if
(
"3000"
.
equals
(
eSpecialEquipmentListDto
.
getCategoryCode
()))
{
result
=
esElevatorService
.
queryListByDto
(
eSpecialEquipmentListDto
);
}
return
ResponseHelper
.
buildResponse
(
result
);
}
/**
* ES查询电梯信息
*
* @return 查询结果
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@RequestMapping
(
value
=
"/queryTogetherByDto"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
httpMethod
=
"POST"
,
value
=
"ES查询聚合信息"
,
notes
=
"ES查询聚合信息"
)
public
ResponseModel
<
List
<
Map
<
String
,
String
>>>
queryTogetherByDto
(
@RequestBody
EsSpecialEquipmentDto
esSpecialEquipmentDto
){
List
<
Map
<
String
,
String
>>
result
=
new
ArrayList
<>();
if
(
ValidationUtil
.
isEmpty
(
esSpecialEquipmentDto
.
getCategoryCode
())
||
ValidationUtil
.
isEmpty
(
esSpecialEquipmentDto
.
getPrecision
())
||
ValidationUtil
.
isEmpty
(
esSpecialEquipmentDto
.
getStartLatitude
())
||
ValidationUtil
.
isEmpty
(
esSpecialEquipmentDto
.
getStartLongitude
())
||
ValidationUtil
.
isEmpty
(
esSpecialEquipmentDto
.
getEndLatitude
())
||
ValidationUtil
.
isEmpty
(
esSpecialEquipmentDto
.
getEndLongitude
()))
{
throw
new
BadRequest
(
"参数校验失败."
);
}
if
(
StringUtils
.
isNotBlank
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
// 查找特定设备
if
(
"3000"
.
equals
(
esSpecialEquipmentDto
.
getCategoryCode
()))
{
result
=
esElevatorService
.
queryTogetherByDto
(
esSpecialEquipmentDto
);
}
}
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 @
9b7f7b21
...
...
@@ -4,14 +4,35 @@ import com.alibaba.fastjson.JSONObject;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.yeejoin.amos.boot.biz.common.utils.DateUtils
;
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.EsSpecialEquipmentListDto
;
import
com.yeejoin.amos.boot.module.tzs.api.dto.SpecialEquipmentDto
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.AlertCalled
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.Elevator
;
import
com.yeejoin.amos.boot.module.tzs.api.entity.EsElevator
;
import
com.yeejoin.amos.boot.module.tzs.biz.dao.ESElavtorRepository
;
import
io.swagger.annotations.ApiModelProperty
;
import
org.apache.commons.lang3.StringUtils
;
import
org.elasticsearch.common.geo.GeoBoundingBox
;
import
org.elasticsearch.common.geo.GeoPoint
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.ConstantScoreQueryBuilder
;
import
org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.search.aggregations.Aggregation
;
import
org.elasticsearch.search.aggregations.AggregationBuilder
;
import
org.elasticsearch.search.aggregations.AggregationBuilders
;
import
org.elasticsearch.search.aggregations.Aggregations
;
import
org.elasticsearch.search.aggregations.bucket.filter.Filters
;
import
org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridAggregationBuilder
;
import
org.elasticsearch.search.aggregations.bucket.geogrid.ParsedGeoHashGrid
;
import
org.elasticsearch.search.aggregations.bucket.geogrid.ParsedGeoHashGridBucket
;
import
org.elasticsearch.search.aggregations.bucket.terms.ParsedLongTerms
;
import
org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms
;
import
org.elasticsearch.search.aggregations.bucket.terms.Terms
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
;
import
org.springframework.data.elasticsearch.core.SearchHit
;
import
org.springframework.data.elasticsearch.core.SearchHits
;
...
...
@@ -22,8 +43,10 @@ import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -69,7 +92,25 @@ public class ESElevatorServiceImpl {
public
EsElevator
saveEsElevatorToES
(
Elevator
elevator
)
{
EsElevator
esElevator
=
new
EsElevator
();
Bean
.
toPo
(
elevator
,
esElevator
);
if
(
StringUtils
.
isNotEmpty
(
elevator
.
getLongitude
()))
{
esElevator
.
setLongitude
(
Double
.
parseDouble
(
elevator
.
getLongitude
()));
}
if
(
StringUtils
.
isNotEmpty
(
elevator
.
getLatitude
()))
{
esElevator
.
setLatitude
(
Double
.
parseDouble
(
elevator
.
getLatitude
()));
}
esElevator
.
setAddress
(
elevator
.
getAddress
());
esElevator
.
setCity
(
elevator
.
getCity
());
esElevator
.
setDistrict
(
elevator
.
getDistrict
());
esElevator
.
setProvince
(
elevator
.
getProvince
());
esElevator
.
setRegionCode
(
elevator
.
getRegionCode
());
esElevator
.
setRescueCode
(
elevator
.
getRescueCode
().
toString
());
esElevator
.
setRegisterCode
(
elevator
.
getRegisterCode
());
esElevator
.
setSequenceNbr
(
elevator
.
getSequenceNbr
());
if
(
StringUtils
.
isNotBlank
(
elevator
.
getLatitude
())
&&
StringUtils
.
isNotBlank
(
elevator
.
getLongitude
()))
{
Double
lat
=
Double
.
parseDouble
(
elevator
.
getLatitude
());
Double
lon
=
Double
.
parseDouble
(
elevator
.
getLongitude
());
esElevator
.
setLocation
(
new
GeoPoint
(
lat
,
lon
));
}
esElavtorRepository
.
save
(
esElevator
);
return
esElevator
;
}
...
...
@@ -150,12 +191,13 @@ public class ESElevatorServiceImpl {
// 创建查询构造器
NativeSearchQueryBuilder
queryBuilder
=
new
NativeSearchQueryBuilder
()
// 分页
// .withPageable(PageRequest.of(current, size
))
.
withPageable
(
PageRequest
.
of
(
0
,
3000
))
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
.
withQuery
(
boolMust
);
List
<
EsElevatorDto
>
list
=
new
LinkedList
<>();
try
{
...
...
@@ -189,4 +231,195 @@ public class ESElevatorServiceImpl {
return
list
;
}
/**
* 根据特种设备搜索类查找电梯相关信息
* @param esSpecialEquipmentDto
* @param isSingle
* @return
*/
public
List
<
SpecialEquipmentDto
>
queryByDto
(
EsSpecialEquipmentDto
esSpecialEquipmentDto
,
Boolean
isSingle
)
{
Double
startLongitude
=
esSpecialEquipmentDto
.
getStartLongitude
();
Double
startLatitude
=
esSpecialEquipmentDto
.
getStartLatitude
();
Double
endLongitude
=
esSpecialEquipmentDto
.
getEndLongitude
();
Double
endLatitude
=
esSpecialEquipmentDto
.
getEndLatitude
();
String
regionCode
=
esSpecialEquipmentDto
.
getRegionCode
();
String
keyword
=
esSpecialEquipmentDto
.
getKeyword
();
// 如果传入经纬度则根据经纬度过滤 如果传入regionCode 根据regionCode过滤 如果是 单独查电梯 则返回最多3000条 否则为 400条
/**
* 通用匹配规则,条件构建
*/
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
);
}
int
size
=
3000
;
if
(
isSingle
)
{
size
=
400
;
}
System
.
out
.
println
(
boolMust
.
toString
());
// 创建查询构造器
NativeSearchQueryBuilder
queryBuilder
=
new
NativeSearchQueryBuilder
()
// 分页
.
withPageable
(
PageRequest
.
of
(
0
,
size
))
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
.
withQuery
(
boolMust
);
List
<
SpecialEquipmentDto
>
list
=
new
LinkedList
<>();
try
{
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
}
return
list
;
}
public
List
<
SpecialEquipmentDto
>
queryListByDto
(
EsSpecialEquipmentListDto
eSpecialEquipmentListDto
)
{
Integer
number
=
eSpecialEquipmentListDto
.
getEquipmentNumber
();
String
regionCode
=
eSpecialEquipmentListDto
.
getRegionCode
();
// 如果传入经纬度则根据经纬度过滤 如果传入regionCode 根据regionCode过滤 如果是 单独查电梯 则返回最多3000条 否则为 400条
/**
* 通用匹配规则,条件构建
*/
BoolQueryBuilder
boolMust
=
QueryBuilders
.
boolQuery
();
if
(!
ValidationUtil
.
isEmpty
(
regionCode
))
{
BoolQueryBuilder
qb2
=
QueryBuilders
.
boolQuery
().
filter
(
QueryBuilders
.
matchPhraseQuery
(
"regionCode"
,
regionCode
));
boolMust
.
must
(
qb2
);
}
if
(
number
==
null
)
{
number
=
3000
;
}
// 创建查询构造器
NativeSearchQueryBuilder
queryBuilder
=
new
NativeSearchQueryBuilder
()
// 分页
.
withPageable
(
PageRequest
.
of
(
0
,
number
))
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
.
withQuery
(
boolMust
);
//queryBuilder.addAggregation()
List
<
SpecialEquipmentDto
>
list
=
new
LinkedList
<>();
try
{
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
}
return
list
;
}
public
List
<
Map
<
String
,
String
>>
queryTogetherByDto
(
EsSpecialEquipmentDto
esSpecialEquipmentDto
)
{
Double
startLongitude
=
esSpecialEquipmentDto
.
getStartLongitude
();
Double
startLatitude
=
esSpecialEquipmentDto
.
getStartLatitude
();
Double
endLongitude
=
esSpecialEquipmentDto
.
getEndLongitude
();
Double
endLatitude
=
esSpecialEquipmentDto
.
getEndLatitude
();
String
regionCode
=
esSpecialEquipmentDto
.
getRegionCode
();
/**
* 通用匹配规则,条件构建
*/
BoolQueryBuilder
boolMust
=
QueryBuilders
.
boolQuery
();
if
(!
ValidationUtil
.
isEmpty
(
regionCode
))
{
BoolQueryBuilder
qb2
=
QueryBuilders
.
boolQuery
().
filter
(
QueryBuilders
.
matchPhraseQuery
(
"regionCode"
,
regionCode
));
boolMust
.
must
(
qb2
);
}
/**
* 通用匹配规则,条件构建
*/
List
<
Map
<
String
,
String
>>
result
=
new
LinkedList
<>();
GeoPoint
left
=
new
GeoPoint
(
endLatitude
,
startLongitude
);
GeoPoint
right
=
new
GeoPoint
(
startLatitude
,
endLongitude
);
ConstantScoreQueryBuilder
constantScore
=
new
ConstantScoreQueryBuilder
(
new
GeoBoundingBoxQueryBuilder
(
"location"
).
setCornersOGC
(
left
,
right
));
boolMust
.
must
(
constantScore
);
// 创建查询构造器
NativeSearchQueryBuilder
queryBuilder
=
new
NativeSearchQueryBuilder
()
// 分页
//.withPageable(PageRequest.of(0, number))
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
.
withQuery
(
boolMust
).
addAggregation
(
new
GeoHashGridAggregationBuilder
(
"96333"
).
precision
(
esSpecialEquipmentDto
.
getPrecision
()).
field
(
"location"
));
System
.
out
.
println
(
constantScore
.
toString
());
SearchHits
<
EsElevator
>
searchHits
=
elasticsearchTemplate
.
search
(
queryBuilder
.
build
(),
EsElevator
.
class
);
Aggregations
aggregations
=
searchHits
.
getAggregations
();
ParsedGeoHashGrid
aggregation
=
aggregations
.
get
(
"96333"
);
List
<?
extends
Terms
.
Bucket
>
buckets
=
(
List
<?
extends
Terms
.
Bucket
>)
aggregation
.
getBuckets
();
// 通过debug能看到aggregation.getBuckets里就是我所需要的分组信息,但是直接.出不来,这里我是手动拼出来并强转一下(ParsedLongTerms)
for
(
int
i
=
0
;
i
<
buckets
.
size
();
i
++)
{
ParsedGeoHashGridBucket
bucket
=
(
ParsedGeoHashGridBucket
)
buckets
.
get
(
i
);
// 每组的key
String
key
=
bucket
.
getKeyAsString
();
// bucket key
long
docCount
=
bucket
.
getDocCount
();
// Doc count
GeoPoint
point
=
GeoPoint
.
fromGeohash
(
key
);
Map
<
String
,
String
>
tempMap
=
new
HashMap
<>();
tempMap
.
put
(
"lat"
,
point
.
getLat
()
+
""
);
tempMap
.
put
(
"lon"
,
point
.
getLon
()
+
""
);
tempMap
.
put
(
"number"
,
docCount
+
""
);
result
.
add
(
tempMap
);
}
return
result
;
}
}
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