xp-robotaxi-api/src/main/java/com/xiaopeng/api/dto/operation/ElectronicFenceUpdateDto.java
@@ -20,7 +20,6 @@ @NotNull(message = "id不能为空") private Long id; @ApiModelProperty(value = "围栏名称") @NotEmpty(message = "所属市区不能为空") private String cityCode; @ApiModelProperty(value = "围栏名称") @NotEmpty(message = "围栏名称不能为空") xp-robotaxi-itinerary-boot/src/main/java/com/xiaopeng/itinerary/constant/I18nKeyConstant.java
@@ -53,4 +53,10 @@ // 路径不存在 String PATH_NOT_FOUND = "path.not.found"; //未找到步行路线 String WALKING_ROUTE_NOT_FOUND = "walking.route.not.found"; //城市不存在 String CITY_NOT_FOUND = "city.not.found"; } xp-robotaxi-itinerary-boot/src/main/java/com/xiaopeng/itinerary/service/impl/XpPricingServiceImpl.java
@@ -37,6 +37,7 @@ import com.xiaopeng.itinerary.utils.XpPricingUtil; import com.xiaopeng.itinerary.utils.holiday.HolidayUtil; import com.xiaopeng.itinerary.utils.map.FastDistanceCalculator; import com.xiaopeng.itinerary.utils.map.GDMapGeocodingUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.geo.GeoJsonPoint; @@ -116,6 +117,9 @@ @Resource private XpPushMessageClient xpPushMessageClient; @Resource private GDMapGeocodingUtil gdMapGeocodingUtil; // 自定义线程池用于并行执行任务 private final ExecutorService executorService; @@ -174,8 +178,6 @@ @Override public RouteAndFareVo getRouteAndFare(RouteAndFareDto routeAndFareDto, String userId) { // 判断是否5分钟内进行了查询 相同站点的起始点 并且是同时段 String key = "xp-map-query-" + routeAndFareDto.getOpenCityId() + "-" + routeAndFareDto.getOrigin().getLongitude() + "-" + routeAndFareDto.getOrigin().getLatitude() @@ -188,12 +190,16 @@ } // 1. 基础数据查询 XpOpenCity xpOpenCity = xpOpenCityMapper.selectById(routeAndFareDto.getOpenCityId()); if (xpOpenCity == null) { throw new ServiceException("未找到步行路线", I18nKeyConstant.CITY_INFORMATION_DOES_NOT_EXIST); Map<String, String> geocode = gdMapGeocodingUtil.geocode(routeAndFareDto.getOrigin().getLongitude().toString(), routeAndFareDto.getOrigin().getLatitude().toString()); if(null == geocode){ throw new ServiceException("获取城市信息失败", I18nKeyConstant.CITY_NOT_FOUND); } String cityCode = xpOpenCity.getCityCode(); String cityCode = geocode.get("cityCode"); XpOpenCity xpOpenCity = xpOpenCityMapper.selectOne(new LambdaQueryWrapper<XpOpenCity>().eq(XpOpenCity::getCityCode, cityCode)); if (xpOpenCity == null) { throw new ServiceException("获取城市信息失败", I18nKeyConstant.CITY_NOT_FOUND); } routeAndFareDto.setOpenCityId(xpOpenCity.getId()); XpRoutePlan xpRoutePlan = xpRoutePlanMapper.selectOne(new LambdaQueryWrapper<XpRoutePlan>().eq(XpRoutePlan::getAuditStatus, 2).eq(XpRoutePlan::getCityCode, cityCode)); if (xpRoutePlan != null) { routeAndFareDto.setRoutePlanRule(xpRoutePlan.getRoutePlanRule()); @@ -208,7 +214,7 @@ // // 算距离 R<RouteVo> distanceAndDuration = xpMapClient.getDistanceAndDuration(routeAndFareDto); if (distanceAndDuration.getCode() != 200) { throw new ServiceException("未找到路径", I18nKeyConstant.PATH_NOT_FOUND); throw new ServiceException("获取导肮信息失败", I18nKeyConstant.PATH_NOT_FOUND); } xp-robotaxi-itinerary-boot/src/main/java/com/xiaopeng/itinerary/utils/map/GDMapGeocodingUtil.java
New file @@ -0,0 +1,56 @@ package com.xiaopeng.itinerary.utils.map; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.xiaopeng.common.core.utils.HttpUtils; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.Map; /** * 高德地图的地理编码工具类 */ @Component @Lazy public class GDMapGeocodingUtil { private String key = "66ae577f63898dae3016d599fda57221"; /** * 根据经纬度获取行政区域信息 * @param lon * @param lan * @return * @throws Exception */ public Map<String, String> geocode(String lon, String lan) { String url = "https://restapi.amap.com/v3/geocode/regeo?key=" + key + "&location=" + lon + "," + lan; String forObject = HttpUtils.sendGet(url); JSONObject jsonObject = JSON.parseObject(forObject); Map<String, String> map = new HashMap<>(); if(jsonObject.getString("status").equals("1")){ JSONObject regeocode = jsonObject.getJSONObject("regeocode"); JSONObject addressComponent = regeocode.getJSONObject("addressComponent"); String address = regeocode.getString("formatted_address"); map.put("address", address); String code = addressComponent.getString("adcode"); String province = addressComponent.getString("province"); String city = addressComponent.getString("city"); String district = addressComponent.getString("district"); map.put("province", province); map.put("provinceCode", code.substring(0, 2) + "0000"); map.put("city", city); map.put("cityCode", code.substring(0, 4) + "00"); map.put("district", district); map.put("districtCode", code); } return map; } } xp-robotaxi-itinerary-boot/src/main/resources/i18n/messages.properties
@@ -1,4 +1,7 @@ # 中文 path.not.found=路径不存在 city.not.found=获取城市信息失败 no.current.region=当前区域未开通服务 path.not.found=获取导航信息失败 to.work=当前的接送点距离过近。建议步行前往 walking.route.not.found=未找到步行路线 welcome.message=欢迎来到我们的应用程序! xp-robotaxi-itinerary-boot/src/main/resources/i18n/messages_en_US.properties
@@ -1,4 +1,7 @@ # English (US) path.not.found=Path does not exist city.not.found=city.not.found no.current.region=no.current.region path.not.found=Failed to obtain navigation information to.work=\ The current pick-up and drop-off points are too close to each other. It is recommended to walk there walking.route.not.found=walking.route.not.found welcome.message=Welcome to our application! xp-robotaxi-itinerary-boot/src/main/resources/i18n/messages_zh_CN.properties
@@ -1,4 +1,7 @@ # 中文 path.not.found=路径不存在 city.not.found=获取城市信息失败 no.current.region=当前区域未开通服务 path.not.found=获取导航信息失败 to.work=当前的接送点距离过近。建议步行前往 walking.route.not.found=未找到步行路线 welcome.message=欢迎来到我们的应用程序! xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/service/serviceimpl/XpElectronicFenceServiceImpl.java
@@ -25,6 +25,7 @@ import com.xiaopeng.map.mapper.XpElectronicFenceMapper; import com.xiaopeng.map.mapper.XpPointMapper; import com.xiaopeng.map.mapper.XpRegionMapper; import com.xiaopeng.map.service.XpElectronicFenceAreaService; import com.xiaopeng.map.service.XpElectronicFenceService; import com.xiaopeng.map.utils.GDMapGeocodingUtil; import com.xiaopeng.map.utils.PolygonOverlapService; @@ -69,6 +70,8 @@ private XpRegionMapper xpRegionMapper; @Autowired private GDMapGeocodingUtil gdMapGeocodingUtil; @Resource private XpElectronicFenceAreaService xpElectronicFenceAreaService; @Override public PageInfo<XpElectronicFence> pageList(ElectronicPageListQuery query) { @@ -389,10 +392,7 @@ this.updateById(xpElectronicFence); // 删除旧的区域数据,然后保存新的区域数据 xpElectronicFenceAreaMapper.delete(new LambdaQueryWrapper<XpElectronicFenceArea>() .eq(XpElectronicFenceArea::getElectronicId, dto.getId())); mongoTemplate.remove(new Query(Criteria.where("fenceId").is(String.valueOf(dto.getId()))), XpGeoFencingPolygon.class); if (xpElectronicFence.getStatus() == 2) { // 设置电子围栏ID并保存区域数据 for (XpElectronicFenceArea area : updatedElectronicFenceAreas) { @@ -400,7 +400,11 @@ area.setAreaStatus(1); area.setArea(area.getArea()); area.setCityCode(dto.getCityCode()); xpElectronicFenceAreaMapper.insert(area); if(null != area.getId()){ xpElectronicFenceAreaService.updateById(area); }else{ xpElectronicFenceAreaService.save(area); } } }else{ // 设置电子围栏ID并保存区域数据 @@ -409,7 +413,11 @@ area.setAreaStatus(2); area.setArea(area.getArea()); area.setCityCode(dto.getCityCode()); xpElectronicFenceAreaMapper.insert(area); if(null != area.getId()){ xpElectronicFenceAreaService.updateById(area); }else{ xpElectronicFenceAreaService.save(area); } } } if (dto.getStatus() == 1 || dto.getStatus() == 2) {