<?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.house365.ws.dao.mapper.OnlineLogMapper">

    <resultMap id="infoMap" type="com.house365.beans.entity.OnlineLogEntity">
        <result property="id" column="id"/>
        <result property="oldStatus" column="old_status"/>
        <result property="newStatus" column="new_status"/>
        <result property="userId" column="user_id"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <insert id="save" parameterType="com.house365.beans.entity.OnlineLogEntity">
        insert into online_log (old_status,new_status,user_id,create_time)
        values
        ( #{oldStatus},#{newStatus},#{userId},#{createTime} )
    </insert>

    <select id="queryByConditions" resultMap="infoMap" parameterType="map">
        SELECT *
        FROM online_log
        where old_status != new_status
        <if test="userId != null and userId >= 0 ">
            AND user_id = #{userId}
        </if>
        <if test="oldStatus != null and oldStatus >= 0 ">
            AND old_status = #{oldStatus}
        </if>
        <if test="newStatus != null and newStatus >= 0 ">
            AND new_status = #{newStatus}
        </if>
        <if test="startTime != null and startTime != ''">
            AND create_time BETWEEN #{startTime} AND #{endTime}
        </if>
        <if test="order != null and order > 0 ">
            ORDER BY id desc
        </if>
    </select>

</mapper>