Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-performance
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
姜武杰
clx-performance
Commits
b2653fee
提交
b2653fee
authored
9月 20, 2023
作者:
liuhaiquan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提交获取车辆列表接口
上级
58b4d690
显示空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
432 行增加
和
41 行删除
+432
-41
PageTruckListParam.java
...java/com/clx/performance/param/pc/PageTruckListParam.java
+7
-2
PageTruckListVO.java
.../main/java/com/clx/performance/vo/pc/PageTruckListVO.java
+7
-5
PerformanceApplication.java
...main/java/com/clx/performance/PerformanceApplication.java
+1
-1
RedisConstants.java
...ain/java/com/clx/performance/constant/RedisConstants.java
+2
-0
TruckController.java
...va/com/clx/performance/controller/pc/TruckController.java
+26
-30
TruckTraceDTO.java
...main/java/com/clx/performance/dto/zjxl/TruckTraceDTO.java
+2
-0
TruckTraceJob.java
.../src/main/java/com/clx/performance/job/TruckTraceJob.java
+2
-3
TruckService.java
...c/main/java/com/clx/performance/service/TruckService.java
+20
-0
TruckServiceImpl.java
...va/com/clx/performance/service/impl/TruckServiceImpl.java
+217
-0
RedisGeoUntil.java
...rc/main/java/com/clx/performance/utils/RedisGeoUntil.java
+148
-0
没有找到文件。
performance-api/src/main/java/com/clx/performance/param/pc/PageTruckListParam.java
浏览文件 @
b2653fee
package
com
.
clx
.
performance
.
param
.
pc
;
import
com.msl.common.base.PageParam
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -15,12 +16,12 @@ import javax.validation.constraints.NotNull;
*/
@Getter
@Setter
public
class
PageTruckListParam
{
public
class
PageTruckListParam
extends
PageParam
{
@NotNull
(
message
=
"需要车数不能为空"
)
@ApiModelProperty
(
value
=
"需要车辆数量"
,
example
=
"5"
)
private
Integer
needTruckNum
;
@ApiModelProperty
(
value
=
"空重车状态 1
空车 2 运单-空车 3
运单-重车"
,
example
=
"1"
)
@ApiModelProperty
(
value
=
"空重车状态 1
:空车 2:运单-空车 3:
运单-重车"
,
example
=
"1"
)
private
Integer
truckUserStatus
;
@ApiModelProperty
(
value
=
"车辆等级"
,
example
=
"A"
)
private
String
truckLevel
;
...
...
@@ -28,5 +29,9 @@ public class PageTruckListParam {
private
Integer
maxDistance
;
@ApiModelProperty
(
value
=
"车牌号"
,
example
=
"冀F12345"
)
private
String
truckNo
;
@NotNull
(
message
=
"订单编号不能为空"
)
@ApiModelProperty
(
value
=
"订单编号"
,
example
=
"PT2023091600001"
)
private
String
orderNo
;
}
performance-api/src/main/java/com/clx/performance/vo/pc/PageTruckListVO.java
浏览文件 @
b2653fee
package
com
.
clx
.
performance
.
vo
.
pc
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.*
;
/**
* @ClassName SeniorLogisticsManagerVO
...
...
@@ -13,18 +12,21 @@ import lombok.Setter;
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public
class
PageTruckListVO
{
@ApiModelProperty
(
"车牌号"
)
private
String
truckNo
;
@ApiModelProperty
(
"状态
"
)
private
String
userName
;
@ApiModelProperty
(
value
=
"空重车状态 1:空车 2:运单-空车 3:运单-重车"
,
example
=
"1
"
)
private
Integer
truckUserStatus
;
@ApiModelProperty
(
value
=
"车辆等级"
,
example
=
"A"
)
private
String
truckLevel
;
@ApiModelProperty
(
value
=
"距货源地"
,
example
=
"20"
)
private
Integer
maxDistance
;
private
Double
maxDistance
;
}
performance-web/src/main/java/com/clx/performance/PerformanceApplication.java
浏览文件 @
b2653fee
...
...
@@ -16,7 +16,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
// @ComponentScan("com.msl.common.utils.*"),
//})
@ComponentScan
({
"com.clx.performance.*"
,
"com.msl.*"
})
@EnableFeignClients
(
basePackages
=
{
"com.msl.*"
,
"com.clx.performance.*"
,
"com.clx.order.*"
})
@EnableFeignClients
(
basePackages
=
{
"com.msl.*"
,
"com.clx.performance.*"
,
"com.clx.order.*"
,
"com.clx.user.*"
})
@ViewScan
(
basePackage
=
"com.clx.user.view"
)
public
class
PerformanceApplication
{
...
...
performance-web/src/main/java/com/clx/performance/constant/RedisConstants.java
浏览文件 @
b2653fee
...
...
@@ -10,4 +10,6 @@ public class RedisConstants {
public
static
final
String
ZJXL_TRUCK_TRACE_LIST
=
"performance:zjxl_truck_trace_list:"
;
public
static
final
String
TRUCK_LOCATION_KEY
=
"performance:truck_location_key:"
;
}
performance-web/src/main/java/com/clx/performance/controller/pc/TruckController.java
浏览文件 @
b2653fee
package
com
.
clx
.
performance
.
controller
.
pc
;
import
cn.hutool.json.JSONUtil
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.clx.order.feign.OrderFeign
;
import
com.clx.order.params.OrderGoodsChildParams
;
import
com.clx.order.params.OrderGoodsParams
;
import
com.clx.order.params.PageCarrierOrderListParam
;
import
com.clx.order.vo.feign.FeignOrderVO
;
import
com.clx.order.vo.feign.FeignPageOrderVO
;
import
com.clx.performance.component.OrderGoodsIdGenerate
;
import
com.clx.performance.constant.RedisConstants
;
import
com.clx.performance.mapper.OrderGoodsMapper
;
import
com.clx.performance.model.OrderGoods
;
import
com.clx.performance.param.pc.PageTruckListParam
;
import
com.clx.performance.service.
OrderGoods
Service
;
import
com.clx.performance.service.
Truck
Service
;
import
com.clx.performance.vo.pc.PageTruckListVO
;
import
com.msl.common.base.PageData
;
import
com.msl.common.convertor.aspect.UnitCovert
;
import
com.msl.common.result.Result
;
import
com.msl.common.utils.DateUtils
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.validation.annotation.Validated
;
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
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
org.springframework.web.bind.annotation.*
;
/**
* @ClassName GoodsOrderController
...
...
@@ -49,18 +24,39 @@ import java.util.concurrent.TimeUnit;
@RestController
@RequestMapping
(
"/pc/truck"
)
@Validated
@Api
(
tags
=
"PC-车辆"
)
@Api
(
tags
=
"PC-车辆
列表
"
)
public
class
TruckController
{
@Autowired
TruckService
truckService
;
@ApiOperation
(
value
=
"获取车辆列表"
,
notes
=
"<br>By:刘海泉"
)
@PostMapping
(
"/pageTruckList"
)
public
Result
<
PageData
<
PageTruckListVO
>>
pageTruckList
(
@RequestBody
@Validated
PageTruckListParam
param
)
{
IPage
<
PageTruckListVO
>
page
=
null
;
return
Result
.
page
(
page
.
getRecords
(),
page
.
getTotal
(),
page
.
getPages
()
);
PageData
<
PageTruckListVO
>
page
=
truckService
.
pageTruckList
(
param
)
;
return
Result
.
ok
(
page
);
}
@ApiOperation
(
value
=
"获取车辆列表"
,
notes
=
"<br>By:刘海泉"
)
@GetMapping
(
"/test"
)
public
Result
pageTruckList
()
{
truckService
.
test
();
return
Result
.
ok
();
}
@ApiOperation
(
value
=
"手动更新平台车辆定位信息"
,
notes
=
"<br>By:刘海泉"
)
@GetMapping
(
"/handExecTruckTrace"
)
public
Result
handExecTruckTrace
()
{
truckService
.
handExecTruckTrace
();
return
Result
.
ok
();
}
}
performance-web/src/main/java/com/clx/performance/dto/zjxl/TruckTraceDTO.java
浏览文件 @
b2653fee
...
...
@@ -14,6 +14,8 @@ import java.math.BigDecimal;
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public
class
TruckTraceDTO
{
private
String
truckNo
;
...
...
performance-web/src/main/java/com/clx/performance/job/TruckTraceJob.java
浏览文件 @
b2653fee
...
...
@@ -8,7 +8,6 @@ import com.clx.user.feign.UserClxFeign;
import
com.msl.common.enums.ResultCodeEnum
;
import
com.msl.common.job.JobLog
;
import
com.msl.common.result.Result
;
import
com.msl.user.feign.UserFeign
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
...
...
@@ -16,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.time.temporal.ChronoUnit
;
import
java.util.Comparator
;
...
...
@@ -27,7 +25,7 @@ import java.util.Objects;
@Component
public
class
TruckTraceJob
{
@
Resource
@
Autowired
(
required
=
false
)
UserClxFeign
userClxFeign
;
@Autowired
ZjxlGpsService
zjxlGpsService
;
...
...
@@ -69,6 +67,7 @@ public class TruckTraceJob {
//排序获取最新的定位位置
truckTrace
.
stream
().
sorted
(
Comparator
.
comparing
(
TruckTraceDTO:
:
getGpsTime
));
TruckTraceDTO
truckTraceDTO
=
truckTrace
.
get
(
0
);
truckTraceDTO
.
setTruckNo
(
truckNo
);
redisTemplate
.
opsForHash
().
put
(
RedisConstants
.
ZJXL_TRUCK_TRACE_LIST
,
truckNo
,
truckTraceDTO
);
}
}
...
...
performance-web/src/main/java/com/clx/performance/service/TruckService.java
0 → 100644
浏览文件 @
b2653fee
package
com
.
clx
.
performance
.
service
;
import
com.clx.performance.param.pc.PageTruckListParam
;
import
com.clx.performance.vo.pc.PageTruckListVO
;
import
com.msl.common.base.PageData
;
/**
* @Author: aiqinguo
* @Description: 运单表
* @Date: 2023/09/18 11:34:50
* @Version: 1.0
*/
public
interface
TruckService
{
PageData
<
PageTruckListVO
>
pageTruckList
(
PageTruckListParam
param
);
void
test
();
void
handExecTruckTrace
();
}
performance-web/src/main/java/com/clx/performance/service/impl/TruckServiceImpl.java
0 → 100644
浏览文件 @
b2653fee
package
com
.
clx
.
performance
.
service
.
impl
;
import
com.clx.order.enums.ResultEnum
;
import
com.clx.order.feign.OrderFeign
;
import
com.clx.order.vo.feign.FeignOrderVO
;
import
com.clx.performance.constant.RedisConstants
;
import
com.clx.performance.dto.zjxl.TruckTraceDTO
;
import
com.clx.performance.job.TruckTraceJob
;
import
com.clx.performance.param.pc.PageTruckListParam
;
import
com.clx.performance.service.TruckService
;
import
com.clx.performance.utils.RedisGeoUntil
;
import
com.clx.performance.vo.pc.PageTruckListVO
;
import
com.clx.user.feign.UserClxFeign
;
import
com.clx.user.vo.feign.TruckUseStatusVO
;
import
com.msl.common.base.PageData
;
import
com.msl.common.enums.ResultCodeEnum
;
import
com.msl.common.exception.ServiceSystemException
;
import
com.msl.common.result.Result
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.MapUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.geo.GeoResult
;
import
org.springframework.data.geo.GeoResults
;
import
org.springframework.data.geo.Point
;
import
org.springframework.data.redis.connection.RedisGeoCommands
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.math.BigDecimal
;
import
java.util.*
;
/**
* @ClassName TruckServiceImpl
* @Description
* @Author kavin
* @Date 2023/9/19 16:58
* @Version 1.0
*/
@Service
@Slf4j
public
class
TruckServiceImpl
implements
TruckService
{
@Resource
OrderFeign
orderFeign
;
@Autowired
(
required
=
false
)
UserClxFeign
userClxFeign
;
@Autowired
RedisTemplate
redisTemplate
;
@Autowired
RedisGeoUntil
redisGeoUntil
;
@Autowired
TruckTraceJob
truckTraceJob
;
/**
* @Author kavin
* @Description 获取车辆列表
* @Param [param]
* @return
**/
@Override
public
PageData
<
PageTruckListVO
>
pageTruckList
(
PageTruckListParam
param
)
{
//获取发货地经纬度
FeignOrderVO
orderInfoFeign
=
orderFeign
.
getOrderInfoFeign
(
param
.
getOrderNo
());
BigDecimal
sendLatitude
=
orderInfoFeign
.
getSendLatitude
();
//精度
BigDecimal
sendLongitude
=
orderInfoFeign
.
getSendLongitude
();
//维度
if
(
Objects
.
isNull
(
sendLatitude
)
||
Objects
.
isNull
(
sendLongitude
)){
throw
new
ServiceSystemException
(
ResultEnum
.
DATA_NOT_FIND
,
"获取订单发货地经纬度信息失败"
);
}
//获取缓存中所有车辆位置信息
Map
<
String
,
TruckTraceDTO
>
map
=
redisTemplate
.
opsForHash
().
entries
(
RedisConstants
.
ZJXL_TRUCK_TRACE_LIST
);
if
(
MapUtils
.
isEmpty
(
map
)){
log
.
warn
(
"缓存中车辆位置信息列表为空,缓存key:{}"
,
RedisConstants
.
ZJXL_TRUCK_TRACE_LIST
);
return
new
PageData
<>();
}
//查询平台所有车辆的出车状态信息
Result
<
List
<
TruckUseStatusVO
>>
result
=
userClxFeign
.
getPlatformTruckStatus
();
log
.
info
(
"通过clx-user服务获取平台认证成功车辆出车状态列表,返回结果:{}"
,
result
);
if
(!
Objects
.
equals
(
result
.
getCode
(),
ResultCodeEnum
.
SUCCESS
.
getCode
())){
throw
new
ServiceSystemException
(
ResultEnum
.
DATA_NOT_FIND
,
"查询车辆出车状态信息失败"
);
}
Map
<
String
,
Integer
>
truckStatusMap
=
new
HashMap
<>();
result
.
getData
().
stream
().
forEach
(
item
->{
truckStatusMap
.
put
(
item
.
getTruckNo
(),
item
.
getTruckOrderStatus
());
});
String
redisGeoKey
=
RedisConstants
.
TRUCK_LOCATION_KEY
+
UUID
.
randomUUID
();
//缓存中的车辆位置信息
//redis 进行空间位置排序
for
(
Map
.
Entry
<
String
,
TruckTraceDTO
>
entry
:
map
.
entrySet
()){
TruckTraceDTO
item
=
entry
.
getValue
();
BigDecimal
longitudeX
=
item
.
getLocation
()[
0
];
BigDecimal
latitudeY
=
item
.
getLocation
()[
1
];
redisGeoUntil
.
insertRedisGeo
(
redisGeoKey
,
longitudeX
.
doubleValue
(),
latitudeY
.
doubleValue
(),
item
.
getTruckNo
());
}
GeoResults
<
RedisGeoCommands
.
GeoLocation
<
String
>>
sortResult
=
redisGeoUntil
.
getRedisGeoMaxIntegerKm
(
redisGeoKey
,
sendLongitude
.
doubleValue
(),
sendLatitude
.
doubleValue
(),
param
.
getNeedTruckNum
()
*
4
);
//清除缓存geo数据
redisGeoUntil
.
deleteAllRedisGeo
(
redisGeoKey
);
List
<
GeoResult
<
RedisGeoCommands
.
GeoLocation
<
String
>>>
content
=
sortResult
.
getContent
();
List
<
PageTruckListVO
>
filterList
=
new
ArrayList
<>();
//车辆距离发货地由近及远的车辆列表信息
for
(
GeoResult
<
RedisGeoCommands
.
GeoLocation
<
String
>>
item
:
content
){
String
truckNo
=
item
.
getContent
().
getName
();
String
truckLevel
=
"A"
;
double
maxDistance
=
item
.
getDistance
().
getValue
();
//进行筛选
if
(
StringUtils
.
isNotBlank
(
param
.
getTruckNo
())
&&
!
StringUtils
.
equals
(
truckNo
,
param
.
getTruckNo
())){
continue
;
}
if
(
Objects
.
nonNull
(
param
.
getTruckUserStatus
())
&&
!
Objects
.
equals
(
param
.
getTruckUserStatus
(),
truckStatusMap
.
get
(
truckNo
))){
continue
;
}
if
(
StringUtils
.
isNotBlank
(
param
.
getTruckLevel
())
&&
!
StringUtils
.
equals
(
truckLevel
,
param
.
getTruckLevel
())){
continue
;
}
if
(
Objects
.
nonNull
(
param
.
getMaxDistance
())
&&
maxDistance
>
param
.
getMaxDistance
()){
continue
;
}
PageTruckListVO
vo
=
PageTruckListVO
.
builder
().
truckNo
(
truckNo
).
truckLevel
(
truckLevel
).
maxDistance
(
maxDistance
).
build
();
vo
.
setTruckUserStatus
(
truckStatusMap
.
get
(
truckNo
));
filterList
.
add
(
vo
);
}
//分页
PageData
<
PageTruckListVO
>
pageData
=
new
PageData
();
pageData
.
setPages
(
param
.
getPage
());
pageData
.
setTotal
(
filterList
.
size
());
pageData
.
setRecords
(
pageBySubList
(
filterList
,
param
.
getPageSize
(),
param
.
getPage
()));
return
pageData
;
}
@Override
public
void
test
()
{
//redisGeoUntil.deleteAllRedisGeo("station");
Point
redisGeo
=
redisGeoUntil
.
getRedisGeo
(
"station"
,
"游仙站点"
);
System
.
out
.
println
(
redisGeo
);
redisGeoUntil
.
updateRedisGeo
(
"station"
,
117.481011
,
40.996791
,
"kavin33站点"
);
redisGeoUntil
.
updateRedisGeo
(
"station"
,
116.514203
,
39.905409
,
"游仙站点"
);
redisGeoUntil
.
updateRedisGeo
(
"station"
,
116.514203
,
39.905409
,
"石桥铺站点"
);
redisGeoUntil
.
updateRedisGeo
(
"station"
,
116.562108
,
39.787602
,
"花荄站点"
);
redisGeoUntil
.
updateRedisGeo
(
"station"
,
116.334255
,
40.027400
,
"三台县站点"
);
GeoResults
<
RedisGeoCommands
.
GeoLocation
<
String
>>
sortResult
=
redisGeoUntil
.
getRedisGeoMaxIntegerKm
(
"station"
,
116.334212
,
39.992813
,
5
);
List
<
GeoResult
<
RedisGeoCommands
.
GeoLocation
<
String
>>>
content
=
sortResult
.
getContent
();
for
(
GeoResult
<
RedisGeoCommands
.
GeoLocation
<
String
>>
item
:
content
){
String
truckNo
=
item
.
getContent
().
getName
();
double
maxDistance
=
item
.
getDistance
().
getValue
();
System
.
out
.
println
(
item
);
/* GeoResult [content: RedisGeoCommands.GeoLocation(name=三台县站点, point=Point [x=116.334253, y=40.027400]), distance: 3.847 KILOMETERS, ]
GeoResult [content: RedisGeoCommands.GeoLocation(name=园艺山站点, point=Point [x=116.481050, y=39.996793]), distance: 12.52 KILOMETERS, ]
GeoResult [content: RedisGeoCommands.GeoLocation(name=游仙站点, point=Point [x=116.514202, y=39.905409]), distance: 18.1673 KILOMETERS, ]
GeoResult [content: RedisGeoCommands.GeoLocation(name=石桥铺站点, point=Point [x=116.514202, y=39.905409]), distance: 18.1673 KILOMETERS, ]
GeoResult [content: RedisGeoCommands.GeoLocation(name=花荄站点, point=Point [x=116.562106, y=39.787603]), distance: 29.987 KILOMETERS, ]*/
}
}
/**
* @Author kavin
* @Description 手动执行获取车辆定位信息
* @Param []
* @return
**/
public
void
handExecTruckTrace
(){
log
.
info
(
"手动执行获取平台车辆定位信息"
);
truckTraceJob
.
getPlatformTruckTrace
();
}
/**
* @Author kavin
* @Description 对给的list 进行分页
* @Param [list, pagesize, currentPage]
* @return
**/
public
static
List
<
PageTruckListVO
>
pageBySubList
(
List
<
PageTruckListVO
>
list
,
int
pagesize
,
int
currentPage
)
{
int
totalcount
=
list
.
size
();
int
pagecount
=
0
;
List
<
PageTruckListVO
>
subList
;
int
m
=
totalcount
%
pagesize
;
if
(
m
>
0
)
{
pagecount
=
totalcount
/
pagesize
+
1
;
}
else
{
pagecount
=
totalcount
/
pagesize
;
}
if
(
m
==
0
)
{
subList
=
list
.
subList
((
currentPage
-
1
)
*
pagesize
,
pagesize
*
(
currentPage
));
}
else
{
if
(
currentPage
==
pagecount
)
{
subList
=
list
.
subList
((
currentPage
-
1
)
*
pagesize
,
totalcount
);
}
else
{
subList
=
list
.
subList
((
currentPage
-
1
)
*
pagesize
,
pagesize
*
(
currentPage
));
}
}
return
subList
;
}
}
performance-web/src/main/java/com/clx/performance/utils/RedisGeoUntil.java
0 → 100644
浏览文件 @
b2653fee
package
com
.
clx
.
performance
.
utils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.geo.*
;
import
org.springframework.data.redis.connection.RedisGeoCommands
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
/*
*
*/
@Component
public
class
RedisGeoUntil
{
@Autowired
private
RedisTemplate
redisTemplate
;
/*
新增
*/
public
void
insertRedisGeo
(
String
redisKey
,
Double
longitudeX
,
Double
latitudeY
,
String
code
){
//增加(添加经纬度信息)
//Point的属性值,x轴是经度longitude,y轴是纬度latitude。
Point
point
=
new
Point
(
longitudeX
,
latitudeY
);
Long
addedNum
=
redisTemplate
.
opsForGeo
().
add
(
redisKey
,
point
,
code
);
System
.
out
.
println
(
addedNum
);
}
/**
* @Author kavin
* @Description 删除所有的geo数据
* @Param [redisKey]
* @return
**/
public
void
deleteAllRedisGeo
(
String
redisKey
){
//删除
redisTemplate
.
delete
(
redisKey
);
}
/*
删除
*/
public
void
deleteRedisGeo
(
String
redisKey
,
String
code
){
//删除
//redisTemplate.opsForZSet().remove(redisKey,"hangzhou5");
Long
remove
=
redisTemplate
.
boundZSetOps
(
redisKey
).
remove
(
code
);
System
.
out
.
println
(
remove
);
}
/*
修改
*/
public
void
updateRedisGeo
(
String
redisKey
,
Double
longitudeX
,
Double
latitudeY
,
String
code
){
//修改(先删除再新增)
deleteRedisGeo
(
redisKey
,
code
);
insertRedisGeo
(
redisKey
,
longitudeX
,
latitudeY
,
code
);
System
.
out
.
println
();
}
/*
查询多个
*/
public
List
<
Point
>
getRedisGeoList
(
String
redisKey
,
List
<
String
>
codeList
)
{
List
<
Point
>
pointList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
codeList
.
size
();
i
++){
Point
redisGeo
=
getRedisGeo
(
redisKey
,
codeList
.
get
(
i
));
if
(
redisGeo
!=
null
){
pointList
.
add
(
redisGeo
);
}
}
System
.
out
.
println
(
pointList
);
return
pointList
;
}
/*
查询单个
*/
public
Point
getRedisGeo
(
String
redisKey
,
String
code
)
{
//查询可以查询多个 经纬度
List
<
Point
>
pointsAll
=
redisTemplate
.
opsForGeo
().
position
(
redisKey
,
code
);
System
.
out
.
println
(
pointsAll
);
if
(!
CollectionUtils
.
isEmpty
(
pointsAll
)){
return
pointsAll
.
get
(
0
);
}
return
null
;
}
/**
* 计算指定点 5km内的(MaxInteger KM)
*/
public
GeoResults
<
RedisGeoCommands
.
GeoLocation
<
String
>>
getRedisGeoMaxIntegerKm
(
String
redisKey
,
String
code
)
{
Distance
disFiveKmFive
=
new
Distance
(
Integer
.
MAX_VALUE
,
Metrics
.
KILOMETERS
);
RedisGeoCommands
.
GeoRadiusCommandArgs
argsFiveKmFive
=
RedisGeoCommands
.
GeoRadiusCommandArgs
.
newGeoRadiusArgs
().
includeDistance
().
includeCoordinates
().
sortAscending
().
limit
(
5
);
GeoResults
<
RedisGeoCommands
.
GeoLocation
<
String
>>
resultsFiveKmFive
=
redisTemplate
.
opsForGeo
().
radius
(
redisKey
,
code
,
disFiveKmFive
,
argsFiveKmFive
);
System
.
out
.
println
(
resultsFiveKmFive
);
return
resultsFiveKmFive
;
}
/**
* //中心点设置 某个经纬度算距离
*/
public
GeoResults
<
RedisGeoCommands
.
GeoLocation
<
String
>>
getRedisGeoMaxIntegerKm
(
String
redisKey
,
Double
longitudeX
,
Double
latitudeY
,
Integer
limit
)
{
//longitude,latitude
//中心点设置 某个经纬度算距离
Point
pointCenter
=
new
Point
(
longitudeX
,
latitudeY
);
Distance
distanceCenter
=
new
Distance
(
Integer
.
MAX_VALUE
,
RedisGeoCommands
.
DistanceUnit
.
KILOMETERS
);
Circle
circleCenter
=
new
Circle
(
pointCenter
,
distanceCenter
);
RedisGeoCommands
.
GeoRadiusCommandArgs
argsCircle
=
RedisGeoCommands
.
GeoRadiusCommandArgs
.
newGeoRadiusArgs
().
includeDistance
().
includeCoordinates
().
sortAscending
().
limit
(
limit
);
GeoResults
<
RedisGeoCommands
.
GeoLocation
<
String
>>
resultsDis
=
redisTemplate
.
opsForGeo
().
radius
(
redisKey
,
circleCenter
,
argsCircle
);
System
.
out
.
println
(
resultsDis
);
return
resultsDis
;
}
/*
查询单个Hash
*/
public
List
<
String
>
getRedisGeoListHash
(
String
redisKey
,
String
code
)
{
List
<
String
>
resultsHash
=
redisTemplate
.
opsForGeo
().
hash
(
redisKey
,
code
);
System
.
out
.
println
(
resultsHash
);
return
resultsHash
;
}
/*
//计算2地之间距离(返回两个地方的距离,可以指定单位,比如米m,千米km,英里mi,英尺ft)
*/
public
Distance
getRedisGeoListTwoSpace
(
String
redisKey
,
String
codeOne
,
String
codeTwo
)
{
Distance
disTwoPlace
=
redisTemplate
.
opsForGeo
().
distance
(
redisKey
,
codeOne
,
codeTwo
,
RedisGeoCommands
.
DistanceUnit
.
KILOMETERS
);
System
.
out
.
println
(
disTwoPlace
);
return
disTwoPlace
;
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论