<?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="com.ruoyi.system.mapper.AisShipMapper">

    <delete id="deleteByDay">
        delete
        from ais_ship
        where DATE_SUB(CURDATE(), INTERVAL #{day} DAY) > receive
    </delete>

    <select id="queryDynamicShip" resultType="com.ruoyi.system.domain.AisShip">
        SELECT mmsi,
               lng,
               lat,
               head,
               speed,
               course,
               date_format(receive, '%Y-%m-%d %H:%i:%s') as receive
        FROM (
                 SELECT mmsi,
                        lng,
                        lat,
                        head,
                        speed,
                        course,
                        receive
                 FROM ais_ship
                 WHERE DATE_SUB(CURDATE(), INTERVAL #{day} DAY) &lt;= date (receive)
        ORDER BY receive DESC ) t
        GROUP BY t.mmsi
    </select>

    <select id="queryShipAddressList" resultType="com.ruoyi.system.domain.AisShip">
        SELECT mmsi,
               lng,
               lat,
               head
        FROM ais_ship
        WHERE DATE_SUB(CURDATE(), INTERVAL #{day} DAY) &lt;= date (receive)
        order BY receive
    </select>

</mapper>