package com.sysu.admin.controller.city;

import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
import org.locationtech.jts.geom.Geometry;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface DistrictRepository extends JpaPlusRepository<District, Integer> {

    District findByCode(String code);

    @Query(value = "SELECT * FROM \"p_district\" where St_within(?1, geom) limit 1", nativeQuery = true)
    District findByPoint(Geometry point);

    @Query(value = "Select new District(p.name,p.code,p.area,p.geom) from District p where p.code like ?1 ")
    List<District> findList(String likeCode);

    @Query(value = "Select new District(p.name,p.code,p.area) from District p where p.code like ?1 ")
    List<District> findInfoList(String cityCodeLike);

    @Query(value = "select st_astext(geom) from p_district where code = ?1" ,nativeQuery = true)
    String findWktByCode(String code);

}
