Commit c05977bb authored by hanbing's avatar hanbing

[update] 辖区和子区返回坐标由多边形改为线

parent e66606fc
package net.wanji.web.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import net.wanji.web.po.RidInfoPO;
import net.wanji.databus.po.RidInfoPO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
......
......@@ -7,6 +7,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.dto.CrossIdDTO;
import net.wanji.common.enums.AreaEnum;
import net.wanji.common.enums.ControlModeEnum;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.common.gts.GeometryUtil;
......@@ -14,9 +15,11 @@ import net.wanji.common.utils.tool.CrossUtil;
import net.wanji.databus.bo.AreaDetailBO;
import net.wanji.databus.bo.AreaIdBO;
import net.wanji.databus.dao.entity.CrossSectionPO;
import net.wanji.databus.dao.entity.RidInfoEntity;
import net.wanji.databus.dao.mapper.BaseAreaInfoMapper;
import net.wanji.databus.dao.mapper.BaseCrossInfoMapper;
import net.wanji.databus.dao.mapper.BaseCrossSectionMapper;
import net.wanji.databus.dao.mapper.RidInfoMapper;
import net.wanji.databus.dto.RunningPlanDTO;
import net.wanji.databus.po.AreaDetailPOExt;
import net.wanji.databus.po.BaseAreaInfoPO;
......@@ -32,7 +35,10 @@ import net.wanji.web.bo.SpecialServiceRouteBO;
import net.wanji.web.mapper.TBaseAreaCrossMapper;
import net.wanji.web.service.CrossManageService;
import net.wanji.web.service.scheme.impl.RunningPlanServiceImpl;
import net.wanji.web.vo.*;
import net.wanji.web.vo.AreaTreeVO;
import net.wanji.web.vo.ControlModeVO;
import net.wanji.web.vo.ListAreaVO;
import net.wanji.web.vo.SelectCrossesByStartEndVO;
import net.wanji.web.vo.specialService.RouteElementVO;
import org.locationtech.jts.geom.Geometry;
import org.springframework.beans.BeanUtils;
......@@ -43,6 +49,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.time.OffsetDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Kent HAN
......@@ -58,11 +65,12 @@ public class CrossManageServiceImpl implements CrossManageService {
private final BaseCrossSectionMapper crossSectionMapper;
private final RunningPlanServiceImpl runningPlanServiceImpl;
private final UtcFeignClients utcFeignClients;
private final RidInfoMapper ridInfoMapper;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
public CrossManageServiceImpl(BaseCrossInfoMapper crossInfoMapper, BaseAreaInfoMapper baseAreaInfoMapper,
SpecialServiceServiceImpl specialServiceService, TBaseAreaCrossMapper areaCrossMapper, BaseCrossSectionMapper crossSectionMapper, RunningPlanServiceImpl runningPlanServiceImpl, @Qualifier("net.wanji.feign.service.UtcFeignClients") UtcFeignClients utcFeignClients) {
SpecialServiceServiceImpl specialServiceService, TBaseAreaCrossMapper areaCrossMapper, BaseCrossSectionMapper crossSectionMapper, RunningPlanServiceImpl runningPlanServiceImpl, @Qualifier("net.wanji.feign.service.UtcFeignClients") UtcFeignClients utcFeignClients, @Qualifier("ridInfoMapper") RidInfoMapper ridInfoMapper) {
this.crossInfoMapper = crossInfoMapper;
this.baseAreaInfoMapper = baseAreaInfoMapper;
this.specialServiceService = specialServiceService;
......@@ -70,6 +78,7 @@ public class CrossManageServiceImpl implements CrossManageService {
this.crossSectionMapper = crossSectionMapper;
this.runningPlanServiceImpl = runningPlanServiceImpl;
this.utcFeignClients = utcFeignClients;
this.ridInfoMapper = ridInfoMapper;
}
@Override
......@@ -110,8 +119,11 @@ public class CrossManageServiceImpl implements CrossManageService {
String wkt = addOrUpdateAreaBO.getWkt();
if (ObjectUtil.isNotEmpty(areaId) && 0 != areaId) {
// 修改
// 传ID为修改
// 修改区域基础信息
// 根据区域rid计算wkt
List<String> wktList = calcWkt(crossIdList);
wkt = wktList.toString();
baseAreaInfoMapper.updateAreaNameAndRemark(areaName, remark, areaId, roadName, parentCode, wkt);
// 修改区域关联路口
areaCrossMapper.deleteByAreaId(areaId);
......@@ -122,7 +134,7 @@ public class CrossManageServiceImpl implements CrossManageService {
areaIdBO.setAreaId(areaId);
return areaIdBO;
} else {
// 新增
// 不传ID为新增
if (2 == type) { // 交警辖区
BaseAreaInfoPO baseAreaInfoPO = new BaseAreaInfoPO();
if (parentCode != null) {
......@@ -131,6 +143,9 @@ public class CrossManageServiceImpl implements CrossManageService {
baseAreaInfoPO.setParentCode(0);
}
baseAreaInfoPO.setRoadName("");
// 根据区域rid计算wkt
List<String> wktList = calcWkt(crossIdList);
wkt = wktList.toString();
AreaIdBO areaIdBO = handleAreaInfoPO(type, areaName, remark, crossIdList, wkt, baseAreaInfoPO);
return areaIdBO;
} else if (6 == type) { // 道路
......@@ -143,6 +158,9 @@ public class CrossManageServiceImpl implements CrossManageService {
BaseAreaInfoPO baseAreaInfoPO = new BaseAreaInfoPO();
baseAreaInfoPO.setRoadName("");
baseAreaInfoPO.setParentCode(0);
// 根据区域rid计算wkt
List<String> wktList = calcWkt(crossIdList);
wkt = wktList.toString();
AreaIdBO areaIdBO = handleAreaInfoPO(type, areaName, remark, crossIdList, wkt, baseAreaInfoPO);
return areaIdBO;
}
......@@ -150,6 +168,65 @@ public class CrossManageServiceImpl implements CrossManageService {
return null;
}
private List<String> calcWkt(List<String> crossIdList) {
List<String> res = new ArrayList<>();
List<RidInfoEntity> ridInfoPOList = ridInfoMapper.selectByCrossList(crossIdList);
if (ridInfoPOList == null) {
throw new RuntimeException("路网数据未包含区域内所有路口");
}
// 去除多边形范围外的路段
List<RidInfoEntity> firstFilterRids = ridInfoPOList.stream()
.filter(rid -> validRid(rid, crossIdList))
.collect(Collectors.toList());
// 双向路段只保留一条RID
Iterator<RidInfoEntity> iterator = firstFilterRids.iterator();
while (iterator.hasNext()) {
RidInfoEntity next = iterator.next();
if (hasDuplicate(next, firstFilterRids)) {
iterator.remove();
}
}
// 验证路口数量
Set<String> ridCrossIds = new HashSet<>();
for (RidInfoEntity firstFilterRid : firstFilterRids) {
String startCrossId = firstFilterRid.getStartCrossId();
String endCrossId = firstFilterRid.getEndCrossId();
ridCrossIds.add(startCrossId);
ridCrossIds.add(endCrossId);
}
if (ridCrossIds.size() != crossIdList.size()) {
throw new RuntimeException("路网数据未包含区域内所有路口");
}
for (RidInfoEntity firstFilterRid : firstFilterRids) {
String wkt = firstFilterRid.getWkt();
res.add(wkt);
}
return res;
}
private boolean hasDuplicate(RidInfoEntity rid, List<RidInfoEntity> firstFilterRids) {
String startCrossId = rid.getStartCrossId();
String endCrossId = rid.getEndCrossId();
for (RidInfoEntity firstFilterRid : firstFilterRids) {
String startCrossId2 = firstFilterRid.getStartCrossId();
String endCrossId2 = firstFilterRid.getEndCrossId();
// 如果开始路口和结束路口对应另一个rid的结束路口和开始路口,则剔除
if (Objects.equals(startCrossId, endCrossId2) && Objects.equals(endCrossId, startCrossId2)) {
return true;
}
}
return false;
}
private boolean validRid(RidInfoEntity rid, List<String> crossIdList) {
String startCrossId = rid.getStartCrossId();
String endCrossId = rid.getEndCrossId();
return crossIdList.contains(startCrossId) && crossIdList.contains(endCrossId);
}
private AreaIdBO handleAreaInfoPO(Integer type, String areaName, String remark, List<String> crossIdList, String wkt,
BaseAreaInfoPO baseAreaInfoPO) {
baseAreaInfoPO.setCode(0);
......@@ -385,11 +462,24 @@ public class CrossManageServiceImpl implements CrossManageService {
// 查询区域路口ID
areaInfoVO.setCrossIdAndNameList(buildCrossIdAndNameList(areaId));
areaInfoVO.setWkt(baseAreaInfoPO.getPolylines());
String polylines = baseAreaInfoPO.getPolylines();
// 如果是道路,直接返回线
if (Objects.equals(AreaEnum.ROAD.getCode(), baseAreaInfoPO.getType())) {
areaInfoVO.setWkt(polylines);
} else {
List<String> wktList = buildWktList(polylines);
areaInfoVO.setWktList(wktList);
}
return areaInfoVO;
}
private List<String> buildWktList(String polylines) {
String[] strArray = polylines.substring(1, polylines.length() - 1).split(", ");
return Arrays.asList(strArray);
}
private List<CrossIdAndNameVO> buildCrossIdAndNameList(Integer areaId) {
List<CrossIdAndNameVO> res = new ArrayList<>();
......@@ -512,7 +602,14 @@ public class CrossManageServiceImpl implements CrossManageService {
areaTreeVO.setId(areaId.toString());
areaTreeVO.setName(baseAreaInfoPO.getName());
areaTreeVO.setType("1");
areaTreeVO.setPolylines(baseAreaInfoPO.getPolylines());
String polylines = baseAreaInfoPO.getPolylines();
// 如果是道路,直接返回线
if (Objects.equals(AreaEnum.ROAD.getCode(), baseAreaInfoPO.getType())) {
areaTreeVO.setPolylines(polylines);
} else {
List<String> wktList = buildWktList(polylines);
areaTreeVO.setWktList(wktList);
}
areaTreeVO.setPoint("");
areaTreeVO.setChildren(buildCrossList(areaId));
res.add(areaTreeVO);
......@@ -532,7 +629,14 @@ public class CrossManageServiceImpl implements CrossManageService {
areaTreeVO.setId(areaId.toString());
areaTreeVO.setName(baseAreaInfoPO.getName());
areaTreeVO.setType("1");
areaTreeVO.setPolylines(baseAreaInfoPO.getPolylines());
String polylines = baseAreaInfoPO.getPolylines();
// 如果是道路,直接返回线
if (Objects.equals(AreaEnum.ROAD.getCode(), baseAreaInfoPO.getType())) {
areaTreeVO.setPolylines(polylines);
} else {
List<String> wktList = buildWktList(polylines);
areaTreeVO.setWktList(wktList);
}
areaTreeVO.setPoint("");
areaTreeVO.setChildren(buildSubPoliceList(areaId));
......
......@@ -32,56 +32,17 @@ import net.wanji.web.entity.TBaseAreaCross;
import net.wanji.web.entity.TBaseAreaInfo;
import net.wanji.web.entity.TCrossControlHist;
import net.wanji.web.entity.TDeviceStatusInfo;
import net.wanji.web.mapper.AllDeviceStatusMapper;
import net.wanji.web.mapper.ControlHistMapper;
import net.wanji.web.mapper.CrossAlarmMapper;
import net.wanji.web.mapper.EventAlarmMapper;
import net.wanji.web.mapper.GreenwaveRealtimeMapperOld;
import net.wanji.web.mapper.OptRecordsMapper;
import net.wanji.web.mapper.TBaseAreaCrossMapper;
import net.wanji.web.mapper.TBaseAreaInfoMapper;
import net.wanji.web.mapper.TDeviceStatusLogMapper;
import net.wanji.web.mapper.VehicleTraceMapper;
import net.wanji.web.mapper.VideoDeviceInfoMapper;
import net.wanji.web.po.BaseAreaDataPO;
import net.wanji.web.po.ControlHistPO;
import net.wanji.web.po.CrossAlarmPO;
import net.wanji.web.po.EventAlarmPO;
import net.wanji.web.po.GreenwaveRealtimePO;
import net.wanji.web.po.VehicleTracePO;
import net.wanji.web.po.VideoDeviceInfoPO;
import net.wanji.web.mapper.*;
import net.wanji.web.po.*;
import net.wanji.web.service.SituationDetectionService;
import net.wanji.web.vo.situationDetection.AreaListVO;
import net.wanji.web.vo.situationDetection.ControlHistOutVO;
import net.wanji.web.vo.situationDetection.CrossAlarmOutVO;
import net.wanji.web.vo.situationDetection.DeviceFaultCountVO;
import net.wanji.web.vo.situationDetection.EventAlarmOutVO;
import net.wanji.web.vo.situationDetection.GreenwaveRealtimeOutVO;
import net.wanji.web.vo.situationDetection.JurisdictionAreaTreeVO;
import net.wanji.web.vo.situationDetection.OptRecordsOutVO;
import net.wanji.web.vo.situationDetection.SignalFaultInfoVO;
import net.wanji.web.vo.situationDetection.SignalManufacturerCountInfoVO;
import net.wanji.web.vo.situationDetection.SignalOperationModeCountVO;
import net.wanji.web.vo.situationDetection.SignalOperationModeVO;
import net.wanji.web.vo.situationDetection.VehicleTraceOutVO;
import net.wanji.web.vo.situationDetection.VideoDeviceInfoOutVO;
import net.wanji.web.vo.situationDetection.*;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -766,13 +727,24 @@ public class SituationDetectionServiceImpl implements SituationDetectionService
optAreaInfoVO.setAreaId(areaId);
optAreaInfoVO.setAreaName(baseAreaInfoPO.getName());
optAreaInfoVO.setCrossInfos(buildCrossIdAndNameList(areaId));
optAreaInfoVO.setPloyLines(baseAreaInfoPO.getPolylines());
String polylines = baseAreaInfoPO.getPolylines();
// 如果是道路,直接返回线
if (Objects.equals(AreaEnum.ROAD.getCode(), baseAreaInfoPO.getType())) {
optAreaInfoVO.setPloyLines(polylines);
} else {
List<String> wktList = buildWktList(polylines);
optAreaInfoVO.setWktList(wktList);
}
res.add(optAreaInfoVO);
}
return res;
}
private List<String> buildWktList(String polylines) {
String[] strArray = polylines.substring(1, polylines.length() - 1).split(", ");
return Arrays.asList(strArray);
}
private List<OptCrossIdAndNameVO> buildCrossIdAndNameList(Integer areaId) {
List<OptCrossIdAndNameVO> res = new ArrayList<>();
......
......@@ -15,8 +15,10 @@ public class AreaTreeVO {
private String name;
@ApiModelProperty(value = "类型:1-区域;2-路口")
private String type;
@ApiModelProperty(value = "区域边界")
@ApiModelProperty(value = "道路区域坐标")
private String polylines;
@ApiModelProperty(value = "其他区域坐标")
private List<String> wktList;
@ApiModelProperty(value = "路口经纬度")
private String point;
@ApiModelProperty(value = "子辖区")
......
......@@ -3,7 +3,7 @@
<mapper namespace="net.wanji.web.mapper.CustomRidInfoMapper">
<!-- 通用查询映射结果 -->
<resultMap type="net.wanji.web.po.RidInfoPO" id="BaseResultMap">
<resultMap type="net.wanji.databus.po.RidInfoPO" id="BaseResultMap">
<result property="rid" column="rid"/>
<result property="name" column="name"/>
<result property="roadId" column="road_id"/>
......
......@@ -39,4 +39,6 @@ public interface RidInfoMapper {
List<RidInfoEntity> selectByEndCross(String crossId);
List<RidInfoEntity> selectByStartCross(String crossId);
List<RidInfoEntity> selectByCrossList(List<String> crossIdList);
}
package net.wanji.web.po;
package net.wanji.databus.po;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Id;
import java.util.Date;
......@@ -13,7 +12,6 @@ import java.util.Date;
@Data
public class RidInfoPO {
/** 路段编号(开始路口编号+结束路口编号+顺序号0) */
@Id
@ApiModelProperty(name = "路段编号(开始路口编号+结束路口编号+顺序号0)",notes = "")
private String rid = "";
/** 路段名称 */
......
......@@ -38,7 +38,10 @@ public class AreaInfoVO {
@ApiModelProperty(value = "路口数组", required = true)
private List<CrossIdAndNameVO> crossIdAndNameList;
@ApiModelProperty(value = "坐标")
@ApiModelProperty(value = "道路区域坐标")
private String wkt;
@ApiModelProperty(value = "其他区域坐标")
private List<String> wktList;
}
......@@ -22,7 +22,10 @@ public class OptAreaInfoVO {
@ApiModelProperty(value = "路口数组", required = true)
private List<OptCrossIdAndNameVO> crossInfos;
@ApiModelProperty(value = "坐标")
@ApiModelProperty(value = "道路区域坐标线")
private String ployLines;
@ApiModelProperty(value = "其他区域坐标线")
private List<String> wktList;
}
......@@ -117,4 +117,15 @@
from t_base_rid_info
where start_cross_id = #{finalCrossId}
</select>
<select id="selectByCrossList" resultType="net.wanji.databus.dao.entity.RidInfoEntity">
select <include refid="Base_Column_List"/>
from t_base_rid_info
where
(start_cross_id in
<foreach collection="crossIdList" item="id" separator="," open="(" close=")">#{id}</foreach>)
or
(end_cross_id in
<foreach collection="crossIdList" item="id" separator="," open="(" close=")">#{id}</foreach>)
</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