提交 429e8e37 authored 作者: liuhaiquan's avatar liuhaiquan

commit

上级 cecfafd5
package com.clx.performance.param.pc;
import com.msl.common.base.PageParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotNull;
/**
* @ClassName PageTruckListParam
* @Description
* @Author kavin
* @Date 2023/9/19 16:04
* @Version 1.0
*/
@Getter
@Setter
public class PageVicinityTruckListParam extends PageParam {
@NotNull(message = "订单编号不能为空")
@ApiModelProperty(value = "订单编号", example = "PT2023091600001")
private String orderNo;
}
package com.clx.performance.controller.pc;
import com.clx.performance.param.pc.PageTruckListParam;
import com.clx.performance.param.pc.PageVicinityTruckListParam;
import com.clx.performance.service.TruckService;
import com.clx.performance.vo.pc.PageTruckListVO;
import com.msl.common.base.PageData;
......@@ -47,5 +48,13 @@ public class TruckController {
@ApiOperation(value = "获取附近的车辆", notes = "<br>By:刘海泉")
@PostMapping("/getVicinityTruckList")
public Result<PageData<PageTruckListVO>> getVicinityTruckList(@RequestBody @Validated PageVicinityTruckListParam param) {
PageData<PageTruckListVO> page = truckService.getVicinityTruckList(param);
return Result.ok(page);
}
}
package com.clx.performance.service;
import com.clx.performance.param.pc.PageTruckListParam;
import com.clx.performance.param.pc.PageVicinityTruckListParam;
import com.clx.performance.vo.pc.PageTruckListVO;
import com.msl.common.base.PageData;
......@@ -17,4 +18,6 @@ public interface TruckService {
void test();
void handExecTruckTrace();
PageData<PageTruckListVO> getVicinityTruckList(PageVicinityTruckListParam param);
}
......@@ -7,6 +7,7 @@ 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.param.pc.PageVicinityTruckListParam;
import com.clx.performance.service.TruckService;
import com.clx.performance.utils.RedisGeoUntil;
import com.clx.performance.vo.pc.PageTruckListVO;
......@@ -58,16 +59,16 @@ public class TruckServiceImpl implements TruckService {
@Autowired
TruckTraceJob truckTraceJob;
/**
* @Author kavin
* @Description 获取车辆列表
* @Param [param]
* @Description geo 获取附近车辆
* @Param []
* @return
**/
@Override
public PageData<PageTruckListVO> pageTruckList(PageTruckListParam param) {
private GeoResults<RedisGeoCommands.GeoLocation<String>> vicinityTruckList(String orderNo,Integer maxShowTruckNum,double MaxDistance){
//获取发货地经纬度
FeignOrderVO orderInfoFeign = orderFeign.getOrderInfoFeign(param.getOrderNo());
FeignOrderVO orderInfoFeign = orderFeign.getOrderInfoFeign(orderNo);
BigDecimal sendLatitude = orderInfoFeign.getSendLatitude();//精度
BigDecimal sendLongitude = orderInfoFeign.getSendLongitude();//维度
if(Objects.isNull(sendLatitude) || Objects.isNull(sendLongitude)){
......@@ -79,22 +80,8 @@ public class TruckServiceImpl implements TruckService {
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,"查询车辆出车状态信息失败");
return null;
}
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();
......@@ -109,10 +96,28 @@ public class TruckServiceImpl implements TruckService {
GeoResults<RedisGeoCommands.GeoLocation<String>> sortResult = redisGeoUntil.getRedisGeoMaxIntegerKm(
redisGeoKey, sendLongitude.doubleValue(),sendLatitude.doubleValue(),
param.getNeedTruckNum() * 4);
maxShowTruckNum,MaxDistance);
//清除缓存geo数据
redisGeoUntil.deleteAllRedisGeo(redisGeoKey);
return sortResult;
}
/**
* @Author kavin
* @Description 获取车辆列表
* @Param [param]
* @return
**/
@Override
public PageData<PageTruckListVO> pageTruckList(PageTruckListParam param) {
GeoResults<RedisGeoCommands.GeoLocation<String>> sortResult = this.vicinityTruckList(param.getOrderNo(),param.getNeedTruckNum()*4,Integer.MAX_VALUE);
if(Objects.isNull(sortResult)){
return new PageData<>();
}
Map<String,Integer> truckStatusMap = this.getTruckStatusMap();
List<GeoResult<RedisGeoCommands.GeoLocation<String>>> content = sortResult.getContent();
List<PageTruckListVO> filterList = new ArrayList<>();
//车辆距离发货地由近及远的车辆列表信息
......@@ -148,6 +153,58 @@ public class TruckServiceImpl implements TruckService {
return pageData;
}
/**
* @Author kavin
* @Description 查询附近10公里内的车辆
* @Param [param]
* @return
**/
@Override
public PageData<PageTruckListVO> getVicinityTruckList(PageVicinityTruckListParam param) {
GeoResults<RedisGeoCommands.GeoLocation<String>> sortResult = this.vicinityTruckList(param.getOrderNo(),100000,10);
Map<String,Integer> truckStatusMap = this.getTruckStatusMap();
List<PageTruckListVO> list = new ArrayList<>();
List<GeoResult<RedisGeoCommands.GeoLocation<String>>> content = sortResult.getContent();
for(GeoResult<RedisGeoCommands.GeoLocation<String>> item : content){
String truckLevel = "A";
String truckNo = item.getContent().getName();
double maxDistance = item.getDistance().getValue();
PageTruckListVO vo = PageTruckListVO.builder().truckNo(truckNo).truckLevel(truckLevel).maxDistance(maxDistance).truckUserStatus(truckStatusMap.get(truckNo)).build();
list.add(vo);
}
//分页
PageData<PageTruckListVO> pageData = new PageData();
pageData.setPages(param.getPage());
pageData.setTotal(list.size());
pageData.setRecords(pageBySubList(list,param.getPageSize(),param.getPage()));
return pageData;
}
/**
* @Author kavin
* @Description 获取平台用车状态信息
* @Param []
* @return
**/
private Map<String,Integer> getTruckStatusMap(){
//查询平台所有车辆的出车状态信息
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());
});
return truckStatusMap;
}
@Override
public void test() {
......@@ -161,7 +218,7 @@ public class TruckServiceImpl implements TruckService {
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);
"station", 116.334212, 39.992813, 5,Integer.MAX_VALUE);
List<GeoResult<RedisGeoCommands.GeoLocation<String>>> content = sortResult.getContent();
......@@ -176,6 +233,8 @@ public class TruckServiceImpl implements TruckService {
GeoResult [content: RedisGeoCommands.GeoLocation(name=花荄站点, point=Point [x=116.562106, y=39.787603]), distance: 29.987 KILOMETERS, ]*/
}
}
/**
* @Author kavin
* @Description 手动执行获取车辆定位信息
......
......@@ -111,11 +111,11 @@ public class RedisGeoUntil {
/**
* //中心点设置 某个经纬度算距离
*/
public GeoResults<RedisGeoCommands.GeoLocation<String>> getRedisGeoMaxIntegerKm(String redisKey , Double longitudeX,Double latitudeY,Integer limit) {
public GeoResults<RedisGeoCommands.GeoLocation<String>> getRedisGeoMaxIntegerKm(String redisKey , Double longitudeX,Double latitudeY,Integer limit,double maxDistance) {
//longitude,latitude
//中心点设置 某个经纬度算距离
Point pointCenter = new Point(longitudeX,latitudeY);
Distance distanceCenter = new Distance(Integer.MAX_VALUE, RedisGeoCommands.DistanceUnit.KILOMETERS);
Distance distanceCenter = new Distance(maxDistance, 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);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论