站点GEO
This commit is contained in:
parent
568af04dfb
commit
dcae17a0fc
@ -96,7 +96,7 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
|||||||
.set(EBIKE_SITE_IMAGES.SITE_REGION_ID, siteRegion.getSiteRegionId())
|
.set(EBIKE_SITE_IMAGES.SITE_REGION_ID, siteRegion.getSiteRegionId())
|
||||||
.where(EBIKE_SITE_IMAGES.IMAGE_ID.in(imageIds));
|
.where(EBIKE_SITE_IMAGES.IMAGE_ID.in(imageIds));
|
||||||
}
|
}
|
||||||
savePoints(points, operationRegionId, siteRegion.getSiteRegionId());
|
savePoints(points, operationRegionId, siteRegion.getSiteRegionId(), siteRegion.getSiteType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -105,7 +105,12 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
|||||||
EbikeSiteImages image = new EbikeSiteImages();
|
EbikeSiteImages image = new EbikeSiteImages();
|
||||||
InputStream inputStream = file.getInputStream();
|
InputStream inputStream = file.getInputStream();
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
String fileUniqueKey = UUID.randomUUID() + fileName.substring(fileName.lastIndexOf("."));
|
String fileUniqueKey;
|
||||||
|
if (fileName != null && !fileName.isEmpty()) {
|
||||||
|
fileUniqueKey = UUID.randomUUID() + fileName.substring(fileName.lastIndexOf("."));
|
||||||
|
} else {
|
||||||
|
fileUniqueKey = UUID.randomUUID() + ".jpg";
|
||||||
|
}
|
||||||
image.setImageName(fileUniqueKey);
|
image.setImageName(fileUniqueKey);
|
||||||
image.setImageBucket(MinioUtil.BUCKET_SIT);
|
image.setImageBucket(MinioUtil.BUCKET_SIT);
|
||||||
// image.setSiteRegionId(siteRegionId);
|
// image.setSiteRegionId(siteRegionId);
|
||||||
@ -134,14 +139,13 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
|||||||
}
|
}
|
||||||
StaffFeign staffFeign = getStaff();
|
StaffFeign staffFeign = getStaff();
|
||||||
EbikeSiteRegion ebikeSiteRegion = this.mapper.selectOneById(regionDto.getSiteRegionId());
|
EbikeSiteRegion ebikeSiteRegion = this.mapper.selectOneById(regionDto.getSiteRegionId());
|
||||||
|
Integer oldSiteType = ebikeSiteRegion.getSiteType();
|
||||||
BeanUtils.copyProperties(regionDto, ebikeSiteRegion);
|
BeanUtils.copyProperties(regionDto, ebikeSiteRegion);
|
||||||
ebikeSiteRegion.setUpdateStaff(staffFeign.getStaffId());
|
ebikeSiteRegion.setUpdateStaff(staffFeign.getStaffId());
|
||||||
ebikeSiteRegion.setUpdateTime(LocalDateTime.now());
|
ebikeSiteRegion.setUpdateTime(LocalDateTime.now());
|
||||||
this.mapper.update(ebikeSiteRegion);
|
this.mapper.update(ebikeSiteRegion);
|
||||||
List<ReqEbikePointDto> points = regionDto.getPoints();
|
List<ReqEbikePointDto> points = regionDto.getPoints();
|
||||||
if (points != null && !points.isEmpty()) {
|
updatePoints(points, operationRegionId, regionDto.getSiteRegionId(), regionDto.getSiteType(), oldSiteType);
|
||||||
updatePoints(points, operationRegionId, regionDto.getSiteRegionId());
|
|
||||||
}
|
|
||||||
delImages(regionDto.getSiteRegionId());
|
delImages(regionDto.getSiteRegionId());
|
||||||
List<Long> imageIds = regionDto.getImageIds();
|
List<Long> imageIds = regionDto.getImageIds();
|
||||||
if (imageIds != null && !imageIds.isEmpty()) {
|
if (imageIds != null && !imageIds.isEmpty()) {
|
||||||
@ -195,7 +199,7 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
|||||||
return this.mapper.paginateAs(pageParam.getPage(), queryWrapper, ResEbikeSiteRegionPageDto.class);
|
return this.mapper.paginateAs(pageParam.getPage(), queryWrapper, ResEbikeSiteRegionPageDto.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
void savePoints(List<ReqEbikePointDto> points, Long areaId, Long siteRegionId) {
|
void savePoints(List<ReqEbikePointDto> points, Long areaId, Long siteRegionId, int siteType) {
|
||||||
List<EbikePoint> list = new ArrayList<>();
|
List<EbikePoint> list = new ArrayList<>();
|
||||||
List<Coordinate> vertices = new ArrayList<>();
|
List<Coordinate> vertices = new ArrayList<>();
|
||||||
for (int i = 0; i < points.size(); i++) {
|
for (int i = 0; i < points.size(); i++) {
|
||||||
@ -210,13 +214,15 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
|||||||
Coordinate coordinate = new Coordinate(pointDto.getLongitude(), pointDto.getLatitude());
|
Coordinate coordinate = new Coordinate(pointDto.getLongitude(), pointDto.getLatitude());
|
||||||
vertices.add(coordinate);
|
vertices.add(coordinate);
|
||||||
}
|
}
|
||||||
//TODO:添加GEO
|
redisUtil.addSiteArea(areaId,siteRegionId,vertices);
|
||||||
// redisUtil.addParkingArea(areaId, siteRegionId, vertices);
|
if (siteType == 1) {
|
||||||
|
redisUtil.addParkingArea(areaId, siteRegionId, vertices);
|
||||||
|
}
|
||||||
pointMapper.insertBatch(list);
|
pointMapper.insertBatch(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void updatePoints(List<ReqEbikePointDto> points, Long areaId, Long siteRegionId) {
|
void updatePoints(List<ReqEbikePointDto> points, Long areaId, Long siteRegionId, int siteType, int oldSiteType) {
|
||||||
List<EbikePoint> list = new ArrayList<>();
|
List<EbikePoint> list = new ArrayList<>();
|
||||||
List<Coordinate> vertices = new ArrayList<>();
|
List<Coordinate> vertices = new ArrayList<>();
|
||||||
for (int i = 0; i < points.size(); i++) {
|
for (int i = 0; i < points.size(); i++) {
|
||||||
@ -231,7 +237,13 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
|||||||
Coordinate coordinate = new Coordinate(pointDto.getLongitude(), pointDto.getLatitude());
|
Coordinate coordinate = new Coordinate(pointDto.getLongitude(), pointDto.getLatitude());
|
||||||
vertices.add(coordinate);
|
vertices.add(coordinate);
|
||||||
}
|
}
|
||||||
// redisUtil.addOperationArea(orgId, operateRegionId, vertices);
|
redisUtil.addSiteArea(areaId,siteRegionId,vertices);
|
||||||
|
if (siteType == 1 && !list.isEmpty()) {
|
||||||
|
redisUtil.addParkingArea(areaId, siteRegionId, vertices);
|
||||||
|
}
|
||||||
|
if (oldSiteType == 1 && siteType != 1) {
|
||||||
|
redisUtil.delParkingArea(areaId, siteRegionId);
|
||||||
|
}
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
.where(EBIKE_POINT.REGION_ID.eq(siteRegionId));
|
.where(EBIKE_POINT.REGION_ID.eq(siteRegionId));
|
||||||
pointMapper.deleteByQuery(queryWrapper);
|
pointMapper.deleteByQuery(queryWrapper);
|
||||||
@ -242,7 +254,8 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
|||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
.where(EBIKE_POINT.REGION_ID.eq(siteRegionId));
|
.where(EBIKE_POINT.REGION_ID.eq(siteRegionId));
|
||||||
pointMapper.deleteByQuery(queryWrapper);
|
pointMapper.deleteByQuery(queryWrapper);
|
||||||
// redisUtil.addOperationArea(orgId, operateRegionId, vertices);
|
redisUtil.delSiteArea(areaId,siteRegionId);
|
||||||
|
redisUtil.delParkingArea(areaId, siteRegionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
StaffFeign getStaff() {
|
StaffFeign getStaff() {
|
||||||
|
|||||||
@ -32,6 +32,8 @@ public class RedisUtil {
|
|||||||
|
|
||||||
private final String parkingKey = "parking_geo";
|
private final String parkingKey = "parking_geo";
|
||||||
|
|
||||||
|
private final String siteKey = "site_geo";
|
||||||
|
|
||||||
private final String operationKey = "operation_geo";
|
private final String operationKey = "operation_geo";
|
||||||
|
|
||||||
private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();
|
private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();
|
||||||
@ -77,7 +79,7 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加停车区数据
|
* 删除停车区数据
|
||||||
* @param areaId 运营区Id
|
* @param areaId 运营区Id
|
||||||
* @param regionId 停车区Id
|
* @param regionId 停车区Id
|
||||||
*/
|
*/
|
||||||
@ -105,6 +107,48 @@ public class RedisUtil {
|
|||||||
delOperationAreaMeta(orgId,regionId);
|
delOperationAreaMeta(orgId,regionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加站点数据
|
||||||
|
* @param areaId 运营区Id
|
||||||
|
* @param regionId 停车区Id
|
||||||
|
* @param vertices 边缘点
|
||||||
|
*/
|
||||||
|
public void addSiteArea(Long areaId,Long regionId, List<Coordinate> vertices) {
|
||||||
|
Point point = calculateCentroid(vertices);
|
||||||
|
redisTemplate.opsForGeo().add(siteKey+areaId, point, regionId);
|
||||||
|
addSiteAreaMeta(areaId,regionId,vertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除站点
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void delSiteArea(Long orgId,Long regionId) {
|
||||||
|
redisTemplate.opsForGeo().remove(siteKey+orgId,regionId);
|
||||||
|
delSiteAreaMeta(orgId,regionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delSiteAreaMeta(Long orgId,Long regionId) {
|
||||||
|
redisTemplate.opsForHash().delete("site_area:meta:" + orgId, "vertices"+regionId);
|
||||||
|
redisTemplate.opsForHash().delete("site_area:meta:" + orgId, "mbr"+regionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSiteAreaMeta(Long areaId,Long regionId, List<Coordinate> vertices) {
|
||||||
|
|
||||||
|
// 计算 MBR
|
||||||
|
double[] mbr = calculateMBR(vertices);
|
||||||
|
String mbrStr = String.format("%f %f %f %f", mbr[0], mbr[1], mbr[2], mbr[3]);
|
||||||
|
|
||||||
|
// 序列化顶点
|
||||||
|
String verticesStr = vertices.stream()
|
||||||
|
.map(c -> c.x + " " + c.y)
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
|
||||||
|
// 存储到 Hash
|
||||||
|
redisTemplate.opsForHash().put("site_area:meta:" + areaId, "vertices"+regionId, verticesStr);
|
||||||
|
redisTemplate.opsForHash().put("site_area:meta:" + areaId, "mbr"+regionId, mbrStr);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加圆形停车区地理位置
|
* 添加圆形停车区地理位置
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user