<?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.message.frequency.goeasymessage.mapper.GoeasyMessageMapper">

    <resultMap type="com.ruoyi.message.frequency.goeasymessage.entity.GoeasyMessage" id="GoeasyMessageResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="messageId"    column="message_id"    />
        <result property="type"    column="type"    />
        <result property="senderId"    column="sender_id"    />
        <result property="receiverId"    column="receiver_id"    />
        <result property="payload"    column="payload"    />
        <result property="goeasyTime"    column="goeasy_time"    />
        <result property="senderUserId"    column="sender_user_id"    />
        <result property="senderUserType"    column="sender_user_type"    />
        <result property="receiverUserId"    column="receiver_user_id"    />
        <result property="receiverUserType"    column="receiver_user_type"    />
    </resultMap>



    <sql id="selectGoeasyMessageVo">
        select
            t.id ,
            t.create_by ,
            t.create_time ,
            t.update_by ,
            t.update_time ,
            t.del_flag ,
            t.message_id ,
            t.type ,
            t.sender_id ,
            t.receiver_id ,
            t.payload ,
            t.goeasy_time ,
            t.sender_user_id ,
            t.sender_user_type ,
            t.receiver_user_id ,
            t.receiver_user_type
        from t_goeasy_message AS t

    </sql>

    <select id="selectGoeasyMessageList" parameterType="com.ruoyi.message.frequency.goeasymessage.entity.GoeasyMessage" resultMap="GoeasyMessageResult">
        <include refid="selectGoeasyMessageVo"/>
        <where>AND t.del_flag != 2
            <if test="messageId != null  and messageId != ''">and t.message_id = #{messageId}</if>
            <if test="type != null  and type != ''">and t.type = #{type}</if>
            <if test="senderId != null  and senderId != ''">and t.sender_id = #{senderId}</if>
            <if test="receiverId != null  and receiverId != ''">and t.receiver_id = #{receiverId}</if>
            <if test="payload != null  and payload != ''">and t.payload = #{payload}</if>
            <if test="goeasyTime != null ">and t.goeasy_time = #{goeasyTime}</if>
            <if test="delFlag != null and delFlag != ''">and t.del_flag = #{delFlag}</if>
            <if test="senderUserId != null and senderUserType != null and receiverUserId != null and receiverUserType != null">
                AND (
                ( t.sender_user_type = #{senderUserType} AND t.sender_user_id = #{senderUserId} AND t.receiver_user_type
                = #{receiverUserType} AND t.receiver_user_id = #{receiverUserId} )
                OR ( t.sender_user_type = #{receiverUserType} AND t.sender_user_id = #{receiverUserId} AND
                t.receiver_user_type = #{senderUserType} AND t.receiver_user_id = #{senderUserId} )
                )
            </if>
            <if test="lasttimestamp != null">and t.goeasy_time &lt;= #{lasttimestamp}</if>
        </where>
        order by t.goeasy_time desc
    </select>

    <select id="selectGoeasyMessageById" parameterType="Long" resultMap="GoeasyMessageResult">
        <include refid="selectGoeasyMessageVo"/>
        where t.id = #{id}
    </select>

    <insert id="insertGoeasyMessage" parameterType="com.ruoyi.message.frequency.goeasymessage.entity.GoeasyMessage">
        insert into t_goeasy_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="messageId != null">message_id,</if>
            <if test="type != null">type,</if>
            <if test="senderId != null">sender_id,</if>
            <if test="receiverId != null">receiver_id,</if>
            <if test="payload != null">payload,</if>
            <if test="goeasyTime != null">goeasy_time,</if>
            <if test="senderUserId != null">sender_user_id,</if>
            <if test="senderUserType != null">sender_user_type,</if>
            <if test="receiverUserId != null">receiver_user_id,</if>
            <if test="receiverUserType != null">receiver_user_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="messageId != null">#{messageId},</if>
            <if test="type != null">#{type},</if>
            <if test="senderId != null">#{senderId},</if>
            <if test="receiverId != null">#{receiverId},</if>
            <if test="payload != null">#{payload},</if>
            <if test="goeasyTime != null">#{goeasyTime},</if>
            <if test="senderUserId != null">#{senderUserId},</if>
            <if test="senderUserType != null">#{senderUserType},</if>
            <if test="receiverUserId != null">#{receiverUserId},</if>
            <if test="receiverUserType != null">#{receiverUserType},</if>
        </trim>
    </insert>

    <update id="updateGoeasyMessage" parameterType="com.ruoyi.message.frequency.goeasymessage.entity.GoeasyMessage">
        update t_goeasy_message
        <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="messageId != null">message_id = #{messageId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="senderId != null">sender_id = #{senderId},</if>
            <if test="receiverId != null">receiver_id = #{receiverId},</if>
            <if test="payload != null">payload = #{payload},</if>
            <if test="goeasyTime != null">goeasy_time = #{goeasyTime},</if>
            <if test="senderUserId != null">sender_user_id = #{senderUserId},</if>
            <if test="senderUserType != null">sender_user_type = #{senderUserType},</if>
            <if test="receiverUserId != null">receiver_user_id = #{receiverUserId},</if>
            <if test="receiverUserType != null">receiver_user_type = #{receiverUserType},</if>
        </trim>
        where id = #{id}
    </update>
</mapper>
