Compare commits
2 Commits
568af04dfb
...
810126cbd1
| Author | SHA1 | Date | |
|---|---|---|---|
| 810126cbd1 | |||
| dcae17a0fc |
@ -96,7 +96,7 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
||||
.set(EBIKE_SITE_IMAGES.SITE_REGION_ID, siteRegion.getSiteRegionId())
|
||||
.where(EBIKE_SITE_IMAGES.IMAGE_ID.in(imageIds));
|
||||
}
|
||||
savePoints(points, operationRegionId, siteRegion.getSiteRegionId());
|
||||
savePoints(points, operationRegionId, siteRegion.getSiteRegionId(), siteRegion.getSiteType());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -105,7 +105,12 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
||||
EbikeSiteImages image = new EbikeSiteImages();
|
||||
InputStream inputStream = file.getInputStream();
|
||||
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.setImageBucket(MinioUtil.BUCKET_SIT);
|
||||
// image.setSiteRegionId(siteRegionId);
|
||||
@ -134,14 +139,13 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
||||
}
|
||||
StaffFeign staffFeign = getStaff();
|
||||
EbikeSiteRegion ebikeSiteRegion = this.mapper.selectOneById(regionDto.getSiteRegionId());
|
||||
Integer oldSiteType = ebikeSiteRegion.getSiteType();
|
||||
BeanUtils.copyProperties(regionDto, ebikeSiteRegion);
|
||||
ebikeSiteRegion.setUpdateStaff(staffFeign.getStaffId());
|
||||
ebikeSiteRegion.setUpdateTime(LocalDateTime.now());
|
||||
this.mapper.update(ebikeSiteRegion);
|
||||
List<ReqEbikePointDto> points = regionDto.getPoints();
|
||||
if (points != null && !points.isEmpty()) {
|
||||
updatePoints(points, operationRegionId, regionDto.getSiteRegionId());
|
||||
}
|
||||
updatePoints(points, operationRegionId, regionDto.getSiteRegionId(), regionDto.getSiteType(), oldSiteType);
|
||||
delImages(regionDto.getSiteRegionId());
|
||||
List<Long> imageIds = regionDto.getImageIds();
|
||||
if (imageIds != null && !imageIds.isEmpty()) {
|
||||
@ -195,7 +199,7 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
||||
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<Coordinate> vertices = new ArrayList<>();
|
||||
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());
|
||||
vertices.add(coordinate);
|
||||
}
|
||||
//TODO:添加GEO
|
||||
// redisUtil.addParkingArea(areaId, siteRegionId, vertices);
|
||||
redisUtil.addSiteArea(areaId,siteRegionId,vertices);
|
||||
if (siteType == 1) {
|
||||
redisUtil.addParkingArea(areaId, siteRegionId, vertices);
|
||||
}
|
||||
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<Coordinate> vertices = new ArrayList<>();
|
||||
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());
|
||||
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()
|
||||
.where(EBIKE_POINT.REGION_ID.eq(siteRegionId));
|
||||
pointMapper.deleteByQuery(queryWrapper);
|
||||
@ -242,7 +254,8 @@ public class EbikeSiteRegionServiceImpl extends ServiceImpl<EbikeSiteRegionMappe
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(EBIKE_POINT.REGION_ID.eq(siteRegionId));
|
||||
pointMapper.deleteByQuery(queryWrapper);
|
||||
// redisUtil.addOperationArea(orgId, operateRegionId, vertices);
|
||||
redisUtil.delSiteArea(areaId,siteRegionId);
|
||||
redisUtil.delParkingArea(areaId, siteRegionId);
|
||||
}
|
||||
|
||||
StaffFeign getStaff() {
|
||||
|
||||
@ -32,6 +32,8 @@ public class RedisUtil {
|
||||
|
||||
private final String parkingKey = "parking_geo";
|
||||
|
||||
private final String siteKey = "site_geo";
|
||||
|
||||
private final String operationKey = "operation_geo";
|
||||
|
||||
private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();
|
||||
@ -77,7 +79,7 @@ public class RedisUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加停车区数据
|
||||
* 删除停车区数据
|
||||
* @param areaId 运营区Id
|
||||
* @param regionId 停车区Id
|
||||
*/
|
||||
@ -105,6 +107,48 @@ public class RedisUtil {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加圆形停车区地理位置
|
||||
*
|
||||
|
||||
@ -357,12 +357,33 @@ public class RedisUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定停车区的元数据(MBR 和顶点)
|
||||
* @param orgId 组织ID
|
||||
* 删除运营区
|
||||
*
|
||||
*/
|
||||
public void deleteParkingAreaMeta(Long orgId,Long regionId) {
|
||||
String hashKey = "parking_area:meta:" + orgId;
|
||||
redisTemplate.opsForHash().delete(hashKey,"vertices"+regionId,"mbr"+regionId);
|
||||
public void delOperationArea(Long orgId,Long regionId) {
|
||||
redisTemplate.opsForGeo().remove(operationKey+orgId,regionId);
|
||||
delOperationAreaMeta(orgId,regionId);
|
||||
}
|
||||
|
||||
public void delOperationAreaMeta(Long orgId,Long regionId) {
|
||||
redisTemplate.opsForHash().delete("operation_area:meta:" + orgId, "vertices"+regionId);
|
||||
redisTemplate.opsForHash().delete("operation_area:meta:" + orgId, "mbr"+regionId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除停车区数据
|
||||
* @param areaId 运营区Id
|
||||
* @param regionId 停车区Id
|
||||
*/
|
||||
public void delParkingArea(Long areaId,Long regionId) {
|
||||
redisTemplate.opsForGeo().remove(parkingKey+areaId, regionId);
|
||||
delParkingAreaMeta(areaId,regionId);
|
||||
}
|
||||
|
||||
public void delParkingAreaMeta(Long areaId,Long regionId) {
|
||||
redisTemplate.opsForHash().delete("parking_area:meta:" + areaId, "vertices"+regionId);
|
||||
redisTemplate.opsForHash().delete("parking_area:meta:" + areaId, "mbr"+regionId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user