<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="cn.reghao.tnb.content.app.geo.db.mapper.GeoPolygonMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into geo_polygon
        (`id`,`polygon`)
        values
        (#{id},GeomFromText('POLYGON((${polygon}))'))
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert ignore into geo_polygon
        (`id`,`polygon`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
        (#{item.id},GeomFromText('POLYGON((${item.polygon}))'))
        </foreach>
    </insert>

    <select id="findByPoint" resultType="java.lang.Integer">
        select id
        from geo_polygon
        where st_within(point(#{lng},#{lat}), polygon);
    </select>
</mapper>
