Commit 6aae9be5 authored by hanbing's avatar hanbing

[add] 根据起始点获取第二条线路

parent a119931b
......@@ -10,7 +10,7 @@ import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.web.bo.SpecialServiceRouteBO;
import net.wanji.web.common.exception.CrossRelationException;
import net.wanji.web.service.SpecialServiceService;
import net.wanji.web.vo.SpecialServiceRouteVO;
import net.wanji.web.vo.RouteElementVO;
import net.wanji.web.vo.specialService.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -36,13 +36,13 @@ public class SpecialServiceController {
SpecialServiceService specialServiceService;
@AspectLog(description = "备选路线推送", operationType = BaseEnum.OperationTypeEnum.QUERY)
@ApiOperation(value = "备选路线推送", notes = "备选路线推送", response = SpecialServiceRouteVO.class,
@ApiOperation(value = "备选路线推送", notes = "备选路线推送", response = RouteElementVO.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/specialServiceRoute",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
public JsonViewObject specialServiceRoute(@RequestBody SpecialServiceRouteBO specialServiceRouteBO) {
specialServiceService.specialServiceRoute(specialServiceRouteBO);
return JsonViewObject.newInstance().success();
List<List<RouteElementVO>> res = specialServiceService.specialServiceRoute(specialServiceRouteBO);
return JsonViewObject.newInstance().success(res);
}
@AspectLog(description = "添加特勤", operationType = BaseEnum.OperationTypeEnum.QUERY)
......
package net.wanji.web.service;
import net.wanji.web.bo.SpecialServiceRouteBO;
import net.wanji.web.vo.RouteElementVO;
import net.wanji.web.vo.specialService.*;
import java.util.List;
......@@ -33,5 +34,5 @@ public interface SpecialServiceService {
Set<String> crossInList(String crossId);
void specialServiceRoute(SpecialServiceRouteBO specialServiceRouteBO);
List<List<RouteElementVO>> specialServiceRoute(SpecialServiceRouteBO specialServiceRouteBO);
}
......@@ -8,6 +8,7 @@ import net.wanji.common.gts.service.GtsService;
import net.wanji.common.utils.tool.CrossUtil;
import net.wanji.databus.dao.entity.RidInfoEntity;
import net.wanji.databus.dao.mapper.BaseCrossInfoMapper;
import net.wanji.databus.dao.mapper.CrossDirDataRealtimeMapper;
import net.wanji.databus.dao.mapper.RidInfoMapper;
import net.wanji.databus.po.BaseCrossInfoPO;
import net.wanji.databus.po.TBaseCrossInfo;
......@@ -22,7 +23,9 @@ import net.wanji.web.po.RidInfoPO;
import net.wanji.web.po.SpecialServiceCrossPO;
import net.wanji.web.po.SpecialServicePO;
import net.wanji.web.service.SpecialServiceService;
import net.wanji.web.vo.RouteElementVO;
import net.wanji.web.vo.specialService.*;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -56,6 +59,8 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
private Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
@Autowired
private GtsService gtsService;
@Autowired
private CrossDirDataRealtimeMapper crossDirDataRealtimeMapper;
@Override
public void addSpecialService(AddSpecialServiceInVO addSpecialServiceInVO) {
......@@ -335,7 +340,7 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
}
@Override
public void specialServiceRoute(SpecialServiceRouteBO specialServiceRouteBO) {
public List<List<RouteElementVO>> specialServiceRoute(SpecialServiceRouteBO specialServiceRouteBO) {
List<RidInfoEntity> ridInfoEntities = ridInfoMapper.selectAll();
// 获取起点经纬度与rid连线相交的路段
String startLonLat = specialServiceRouteBO.getStartLonLat();
......@@ -395,41 +400,103 @@ public class SpecialServiceServiceImpl implements SpecialServiceService {
}
}
// 构造第一条备选线路
if (ObjectUtil.isNotEmpty(startCross) && ObjectUtil.isNotEmpty(endCross)) {
String endLocation = endCross.getLocation();
double[] endCrossLonLat = CrossUtil.getLonLat(endLocation);
String endCrossLonLatStr = endCrossLonLat[0] + "," + endCrossLonLat[1];
// 获取起点路口所有上游路口
if (ObjectUtil.isNotEmpty(startCross) && ObjectUtil.isNotEmpty(endCross)
&& ObjectUtil.notEqual(startCross, endCross)) {
List<List<RouteElementVO>> res = new ArrayList<>();
// 构造第一条备选线路
List<BaseCrossInfoPO> routeList1 = getRouteList(startCross, endCross);
List<RouteElementVO> route1 = buildRoute(routeList1);
// 构造第二条备选线路
String startCrossId = startCross.getId();
String endCrossLonLatStr = getCrossLonLatStr(endCross);
List<RidInfoEntity> ridUpCrossList = ridInfoMapper.selectUpCross(startCrossId);
// 获取上有路口到终点距离最近的
BaseCrossInfoPO nextStartCross = startCross;
List<BaseCrossInfoPO> routeList = new ArrayList<>();
routeList.add(nextStartCross);
while (ObjectUtil.notEqual(endCross, nextStartCross)) {
double minDistance = Double.MAX_VALUE;
for (RidInfoEntity ridUpCross : ridUpCrossList) {
String upCrossId = ridUpCross.getStartCrossId();
BaseCrossInfoPO upCross = baseCrossInfoMapper.selectById(upCrossId);
String upCrossLocation = upCross.getLocation();
double[] upCrossLonLat = CrossUtil.getLonLat(upCrossLocation);
String upCrossLonLatStr = upCrossLonLat[0] + "," + upCrossLonLat[1];
double distance = gtsService.distance(endCrossLonLatStr, upCrossLonLatStr);
minDistance = Math.min(minDistance, distance);
if (minDistance == distance) {
nextStartCross = upCross;
}
}
if (ObjectUtil.notEqual(nextStartCross, startCross)) {
routeList.add(nextStartCross);
}
Map<Double, BaseCrossInfoPO> distanceMap = new HashMap<>();
List<Double> distanceList = new ArrayList<>();
for (RidInfoEntity ridUpCross : ridUpCrossList) {
String upCrossId = ridUpCross.getStartCrossId();
BaseCrossInfoPO upCross = baseCrossInfoMapper.selectById(upCrossId);
String upCrossLonLatStr = getCrossLonLatStr(upCross);
double distance = gtsService.distance(endCrossLonLatStr, upCrossLonLatStr);
distanceMap.put(distance, upCross);
distanceList.add(distance);
}
routeList.add(endCross);
// 构造返回结果
for (BaseCrossInfoPO baseCrossInfoPO : routeList) {
Collections.sort(distanceList);
BaseCrossInfoPO secondStartCross = distanceMap.get(distanceList.get(1));
List<BaseCrossInfoPO> routeList2 = getRouteList(secondStartCross, endCross);
routeList2.add(0, startCross);
List<RouteElementVO> route2 = buildRoute(routeList2);
res.add(route1);
res.add(route2);
return res;
}
return null;
}
@NotNull
private List<BaseCrossInfoPO> getRouteList(BaseCrossInfoPO startCross, BaseCrossInfoPO endCross) {
String endCrossLonLatStr = getCrossLonLatStr(endCross);
// 获取起点路口所有上游路口
String startCrossId = startCross.getId();
List<RidInfoEntity> ridUpCrossList = ridInfoMapper.selectUpCross(startCrossId);
// 获取上有路口到终点距离最近的
BaseCrossInfoPO nextStartCross = startCross;
List<BaseCrossInfoPO> routeList = new ArrayList<>();
routeList.add(nextStartCross);
while (ObjectUtil.notEqual(endCross, nextStartCross)) {
double minDistance = Double.MAX_VALUE;
for (RidInfoEntity ridUpCross : ridUpCrossList) {
String upCrossId = ridUpCross.getStartCrossId();
BaseCrossInfoPO upCross = baseCrossInfoMapper.selectById(upCrossId);
String upCrossLonLatStr = getCrossLonLatStr(upCross);
double distance = gtsService.distance(endCrossLonLatStr, upCrossLonLatStr);
minDistance = Math.min(minDistance, distance);
if (minDistance == distance && !routeList.contains(nextStartCross)) { // 已选过的路口不可再选
nextStartCross = upCross;
}
}
routeList.add(nextStartCross);
}
routeList.add(endCross);
return routeList;
}
private List<RouteElementVO> buildRoute(List<BaseCrossInfoPO> routeList) {
List<RouteElementVO> route = new ArrayList<>();
// 遍历到倒数第二个路口
for (int i = 0; i < routeList.size() - 1; i++) {
RouteElementVO routeElementVO = new RouteElementVO();
BaseCrossInfoPO firstCross = routeList.get(i);
BaseCrossInfoPO secondCross = routeList.get(i + 1);
String firstLonLatStr = getCrossLonLatStr(firstCross);
String secondLonLatStr = getCrossLonLatStr(secondCross);
routeElementVO.setStartLonLat(firstLonLatStr);
routeElementVO.setStartName(firstCross.getName());
routeElementVO.setEndLonLat(secondLonLatStr);
routeElementVO.setEndName(secondCross.getName());
// 获取路况,1为进口
Integer status = getRidStatus(firstCross, secondCross, 1);
routeElementVO.setStatus(status);
route.add(routeElementVO);
}
return route;
}
private Integer getRidStatus(BaseCrossInfoPO firstCross, BaseCrossInfoPO secondCross, int inOutType) {
String firstId = firstCross.getId();
String secondId = secondCross.getId();
RidInfoEntity ridInfoEntity = ridInfoMapper.selectByStartEnd(firstId, secondId);
Integer inDir = ridInfoEntity.getInDir();
Integer status = crossDirDataRealtimeMapper.selectStatus(secondId, inDir, inOutType);
return status;
}
private String getCrossLonLatStr(BaseCrossInfoPO firstCross) {
String firstLocation = firstCross.getLocation();
double[] firstLonLat = CrossUtil.getLonLat(firstLocation);
return firstLonLat[0] + "," + firstLonLat[1];
}
}
\ No newline at end of file
package net.wanji.web.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author Kent HAN
* @date 2023/5/16 14:27
*/
@Data
public class RouteElementVO {
@ApiModelProperty(value = "起点坐标")
private String startLonLat;
@ApiModelProperty(value = "起点路口名称")
private String startName;
@ApiModelProperty(value = "终点坐标")
private String endLonLat;
@ApiModelProperty(value = "终点路口名称")
private String endName;
@ApiModelProperty(value = "路况 1畅通;2缓行;3拥堵;4严重拥堵;5未知")
private Integer status;
}
package net.wanji.web.vo;
/**
* @author Kent HAN
* @date 2023/5/16 14:27
*/
public class SpecialServiceRouteVO {
}
......@@ -21,4 +21,5 @@ public interface CrossDirDataRealtimeMapper extends BaseMapper<CrossDirDataRealt
List<CrossDirDataRealtimePO> selectByCrossIdAndInOutType(String crossId, Integer inOutType);
Integer selectStatus(String secondId, Integer inDir, int inOutType);
}
......@@ -29,4 +29,6 @@ public interface RidInfoMapper {
List<RidInfoEntity> selectAll();
List<RidInfoEntity> selectUpCross(String startCrossId);
RidInfoEntity selectByStartEnd(String firstId, String secondId);
}
......@@ -60,4 +60,10 @@
where cross_id = #{crossId} and in_out_type = #{inOutType}
</select>
<select id="selectStatus" resultType="java.lang.Integer">
select status
from t_cross_dir_data_realtime
where dir_type = #{inDir} and in_out_type = #{inOutType} and cross_id = #{secondId}
</select>
</mapper>
\ No newline at end of file
......@@ -87,4 +87,10 @@
from t_base_rid_info
where end_cross_id = #{startCrossId}
</select>
<select id="selectByStartEnd" resultType="net.wanji.databus.dao.entity.RidInfoEntity">
select <include refid="Base_Column_List"/>
from t_base_rid_info
where start_cross_id = #{firstId} and end_cross_id = #{secondId}
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment