<?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.GeoChinaMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into geo_china
        (`id`,`pid`,`deep`,`name`,`ext_name`,`geo`)
        values
        (#{id},#{pid},#{deep},#{name},#{extName},point(#{longitude},#{latitude}))
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert ignore into geo_china
        (`id`,`pid`,`deep`,`name`,`ext_name`,`geo`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
        (#{item.id},#{item.pid},#{item.deep},#{item.name},#{item.extName},point(#{item.longitude},#{item.latitude}))
        </foreach>
    </insert>

    <select id="findById" resultType="cn.reghao.tnb.content.app.geo.model.po.GeoChina">
        select *
        from geo_china
        where id=#{id}
    </select>
    <select id="findByDeep" resultType="cn.reghao.tnb.content.app.geo.model.vo.GeoMarker">
        select id,`name`,x(geo) as lng,y(geo) as lat
        from geo_china
        where deep=#{deep}
        limit 1000
    </select>
</mapper>
