车辆的区域内查询(未做状态筛选

This commit is contained in:
attiya 2025-10-22 16:32:12 +08:00
parent e17825be22
commit f8c322050a
3 changed files with 24 additions and 3 deletions

View File

@ -3,6 +3,9 @@ package com.cdzy.operations.service;
import com.cdzy.operations.model.vo.EbikeBikeBindVo; import com.cdzy.operations.model.vo.EbikeBikeBindVo;
import com.mybatisflex.core.service.IService; import com.mybatisflex.core.service.IService;
import com.cdzy.operations.model.entity.EbikeBikeInfo; 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<EbikeBikeInfo> {
* @param bindVo 绑定信息 * @param bindVo 绑定信息
*/ */
void bind(EbikeBikeBindVo bindVo); void bind(EbikeBikeBindVo bindVo);
/**
* 查询区域内车辆
* @param polygon 区域
* @return 列表
*/
List<EbikeBikeInfo> list(PGpolygon polygon);
} }

View File

@ -16,6 +16,7 @@ import com.cdzy.operations.service.EbikeInventoryService;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl; import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.postgresql.geometric.PGpolygon;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -146,4 +147,14 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
.build(); .build();
this.mapper.insert(bikeInfo); this.mapper.insert(bikeInfo);
} }
@Override
public List<EbikeBikeInfo> 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);
}
} }

View File

@ -1,7 +1,7 @@
package com.cdzy.operations; package com.cdzy.operations;
import com.cdzy.operations.mapper.EbikeBikeInfoMapper;
import com.cdzy.operations.model.entity.EbikeBikeInfo; import com.cdzy.operations.model.entity.EbikeBikeInfo;
import com.cdzy.operations.service.EbikeBikeInfoService;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.postgresql.geometric.PGpoint; import org.postgresql.geometric.PGpoint;
import org.postgresql.geometric.PGpolygon; import org.postgresql.geometric.PGpolygon;
@ -14,7 +14,7 @@ import java.util.List;
class EbikeOperationsApplicationTests { class EbikeOperationsApplicationTests {
@Autowired @Autowired
private EbikeBikeInfoMapper bikeInfoMapper; private EbikeBikeInfoService bikeInfoService;
@Test @Test
void contextLoads(){ void contextLoads(){
@ -24,7 +24,7 @@ class EbikeOperationsApplicationTests {
PGpoint gpoint4 = new PGpoint(103.943116,30.6327); PGpoint gpoint4 = new PGpoint(103.943116,30.6327);
PGpoint[] points = new PGpoint[]{gpoint1,gpoint2,gpoint3,gpoint4}; PGpoint[] points = new PGpoint[]{gpoint1,gpoint2,gpoint3,gpoint4};
PGpolygon pgpolygon = new PGpolygon(points); PGpolygon pgpolygon = new PGpolygon(points);
List<EbikeBikeInfo> bikeInfos = bikeInfoMapper.selectPolygonGeometry(pgpolygon); List<EbikeBikeInfo> bikeInfos = bikeInfoService.list(pgpolygon);
for (EbikeBikeInfo bikeInfo : bikeInfos) { for (EbikeBikeInfo bikeInfo : bikeInfos) {
System.out.println(bikeInfo); System.out.println(bikeInfo);
} }