diff --git a/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeBikeInfoService.java b/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeBikeInfoService.java index edc132c..a5d8ba4 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeBikeInfoService.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeBikeInfoService.java @@ -3,6 +3,9 @@ package com.cdzy.operations.service; import com.cdzy.operations.model.vo.EbikeBikeBindVo; import com.mybatisflex.core.service.IService; import com.cdzy.operations.model.entity.EbikeBikeInfo; +import org.postgresql.geometric.PGpolygon; + +import java.util.List; /** * 服务层。 @@ -17,4 +20,11 @@ public interface EbikeBikeInfoService extends IService { * @param bindVo 绑定信息 */ void bind(EbikeBikeBindVo bindVo); + + /** + * 查询区域内车辆 + * @param polygon 区域 + * @return 列表 + */ + List list(PGpolygon polygon); } diff --git a/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeBikeInfoServiceImpl.java b/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeBikeInfoServiceImpl.java index 4997c42..b099b57 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeBikeInfoServiceImpl.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeBikeInfoServiceImpl.java @@ -16,6 +16,7 @@ import com.cdzy.operations.service.EbikeInventoryService; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.spring.service.impl.ServiceImpl; import jakarta.annotation.Resource; +import org.postgresql.geometric.PGpolygon; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -146,4 +147,14 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl list(PGpolygon polygon) { + QueryWrapper query = QueryWrapper.create() + .select(EBIKE_BIKE_INFO.ALL_COLUMNS) + .from(EBIKE_BIKE_INFO) + .where("ST_Within(location::geometry, ?::geometry)",polygon); + return this.mapper.selectListByQuery(query); + } + } diff --git a/ebike-operations/src/test/java/com/cdzy/operations/EbikeOperationsApplicationTests.java b/ebike-operations/src/test/java/com/cdzy/operations/EbikeOperationsApplicationTests.java index 19c0722..18c7905 100644 --- a/ebike-operations/src/test/java/com/cdzy/operations/EbikeOperationsApplicationTests.java +++ b/ebike-operations/src/test/java/com/cdzy/operations/EbikeOperationsApplicationTests.java @@ -1,7 +1,7 @@ package com.cdzy.operations; -import com.cdzy.operations.mapper.EbikeBikeInfoMapper; import com.cdzy.operations.model.entity.EbikeBikeInfo; +import com.cdzy.operations.service.EbikeBikeInfoService; import org.junit.jupiter.api.Test; import org.postgresql.geometric.PGpoint; import org.postgresql.geometric.PGpolygon; @@ -14,7 +14,7 @@ import java.util.List; class EbikeOperationsApplicationTests { @Autowired - private EbikeBikeInfoMapper bikeInfoMapper; + private EbikeBikeInfoService bikeInfoService; @Test void contextLoads(){ @@ -24,7 +24,7 @@ class EbikeOperationsApplicationTests { PGpoint gpoint4 = new PGpoint(103.943116,30.6327); PGpoint[] points = new PGpoint[]{gpoint1,gpoint2,gpoint3,gpoint4}; PGpolygon pgpolygon = new PGpolygon(points); - List bikeInfos = bikeInfoMapper.selectPolygonGeometry(pgpolygon); + List bikeInfos = bikeInfoService.list(pgpolygon); for (EbikeBikeInfo bikeInfo : bikeInfos) { System.out.println(bikeInfo); }