<?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.GeoPointMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into geo_point
        (`geo`,`device_id`,`create_by`,`create_at`)
        values 
        (point(#{longitude},#{latitude}),#{deviceId},#{createBy},#{createAt})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert ignore into geo_point
        (`geo`,`device_id`,`create_by`,`create_at`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (point(#{item.longitude},#{item.latitude}),#{item.deviceId},#{item.createBy},#{item.createAt})
        </foreach>
    </insert>

    <select id="findByUserId" resultType="cn.reghao.tnb.content.app.geo.model.po.GeoPoint">
        select id,create_time,x(geo) as longitude,y(geo) as latitude,device_id,create_by,create_at
        from geo_point
        where create_by=#{userId}
        order by create_at asc
    </select>
</mapper>