<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.access.dao.ReportDao">
    <insert id="insert" parameterType="com.cxyxiaomo.epp.common.pojo.Report">
        INSERT INTO report (`user_id`, `name`, `address`, `time`, `temperature`)
        VALUES (#{userId}, #{name}, #{address}, #{time}, #{temperature})
    </insert>
    <select id="getReportListByUserId" parameterType="java.lang.Integer" resultType="com.cxyxiaomo.epp.common.pojo.Report">
        SELECT * FROM report
        WHERE `user_id` = #{userId}
        order by time desc
    </select>
    <select id="getLatestReportByUserId" parameterType="java.lang.Integer" resultType="com.cxyxiaomo.epp.common.pojo.Report">
        SELECT * FROM report
        WHERE `user_id` = #{userId}
        order by time desc
        LIMIT 1
    </select>


    <select id="getReportList" resultType="com.cxyxiaomo.epp.common.pojo.Report">
        select *
        from report
        where 1 = 1
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="userId != null">
            AND user_id = #{userId}
        </if>
        <if test="name != null &amp;&amp; name != ''">
            AND name LIKE concat('%',#{name,jdbcType=VARCHAR},'%')
        </if>
        <!--<if test="timestamp != null">-->
        <!--    AND DATE_FORMAT(time, '%Y-%m-%d %H:%i:%s') = #{time, jdbcType=TIMESTAMP}-->
        <!--</if>-->
        <if test="startTime != null &amp;&amp; endTime != null">
            AND time BETWEEN from_unixtime(#{startTime}/1000) AND from_unixtime(#{endTime}/1000)
        </if>
        <if test="temperature != null">
            AND temperature = #{temperature}
        </if>
        <if test="address != null &amp;&amp; address != ''">
            AND address LIKE concat('%',#{address,jdbcType=VARCHAR},'%')
        </if>
        ORDER BY time desc
    </select>
    <delete id="remove">
        DELETE
        FROM report
        WHERE id = #{id}
    </delete>
</mapper>
