<?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.project.business.mapper.businessMessage.BusinessMessageMapper">

    <select id="selectMessageList" resultMap="com.ruoyi.project.common.mapper.MessageMapper.MessageResult">
        select mu.id,mu.read_status,mu.user_id,m.message_type,m.message_content,m.create_time
        from device_message m
        inner join device_message_user mu on m.id = mu.message_id
        <where>
            m.del_flag = 0
            <if test="messageType != null  and messageType != ''">
                and m.message_type like concat('%', #{messageType}, '%')
            </if>
            <if test="createBy != null  and createBy != ''">
                and m.create_by like concat('%', #{createBy}, '%')
            </if>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                and m.create_time &gt;= #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                and m.create_time &lt; DATE_ADD(#{endTime}, INTERVAL 1 DAY)
            </if>
        </where>
        order by mu.read_status asc, m.create_time desc
    </select>

    <select id="selectMessageUserById" parameterType="com.ruoyi.project.business.dto.MessageDto"
            resultType="com.ruoyi.project.business.dto.MessageDto">
        select u.id,u.read_status,u.user_id,m.message_type,m.create_time,

        CASE #{lan}
        WHEN 'US' THEN m.message_contentUS
        WHEN 'RU' THEN m.message_contentRU
        WHEN 'ES' THEN m.message_contentES
        ELSE m.message_content
        END AS message_content

        from message_user u inner join message m on m.id = u.message_id
        where u.del_flag = 0 and m.del_flag = 0 and u.user_id = #{userId}
        <if test="messageType != null and messageType != '' ">
            and m.message_type = #{messageType}
        </if>
        <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
            and u.create_time &gt;= #{beginTime}
        </if>
        <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
            and u.create_time &lt; DATE_ADD(#{endTime}, INTERVAL 1 DAY)
        </if>
        <if test="readStatus !=null and readStatus !=''">
            and u.read_status =#{readStatus}
        </if>
        <if test="messageContent !=null and messageContent != ''">
            and m.message_content like concat('%',#{messageContent},'%')
        </if>
        order by u.read_status asc, m.create_time desc
        <if test="indexQuery">
            limit 3
        </if>
    </select>

</mapper>
