<?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.LcdInfoMapper">

    <resultMap type="LcdInfo" id="LcdInfoResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="sendTime"    column="send_time"    />
        <result property="detail"    column="detail"    />
        <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="image"    column="image"/>
    </resultMap>

    <sql id="selectLcdInfoVo">
        select id, title, send_time, detail, create_by, create_time, update_by, update_time, image from lcd_info
    </sql>
    <!--搜索消息列表,xml中>,
    <不能被正确解析，需要XML转义字符
     &gt；是大于
     &lt；是小于-->
    <select id="selectLcdListByTitleOrlcdTime" resultType="LcdInfo" resultMap="LcdInfoResult">
        <include refid="selectLcdInfoVo"/>
        <where>
            <if test="title != null  and title != ''"> and title LIKE CONCAT(CONCAT('%',#{title},'%'))</if>
            <if test="lcdTimeLeft !=null">
                and send_time &gt;=#{lcdTimeLeft}
            </if>
            <if test="lcdTimeRight != null">
                and send_time &lt;=#{lcdTimeRight}
            </if>

        </where>
    </select>

    <select id="selectLcdInfoList" parameterType="LcdInfo" resultMap="LcdInfoResult">
        <include refid="selectLcdInfoVo"/>
        <where>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="sendTime != null "> and send_time = #{sendTime}</if>
            <if test="detail != null  and detail != ''"> and detail = #{detail}</if>
            and send_time &lt; now()
        </where>
    </select>

    <select id="selectLcdInfoById" parameterType="Long" resultMap="LcdInfoResult">
        <include refid="selectLcdInfoVo"/>
        where id = #{id}
    </select>
    <select id="selectMobile" parameterType="Long" resultType="String">
        select u.mobile
        from lcd_info i
                 LEFT JOIN lcd_info_user_relation r
                           ON r.lcd_info_id=i.id
                 LEFT JOIN post_user u
                           ON r.lcd_receive_user_id = u.id
        where i.id = #{id}
    </select>

    <insert id="insertLcdInfo" useGeneratedKeys="true" keyProperty="id" parameterType="com.ruoyi.system.domain.vo.LcdInfoVo" >
        insert into lcd_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="sendTime != null">send_time,</if>
            <if test="detail != null">detail,</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="image != null">image,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="sendTime != null">#{sendTime},</if>
            <if test="detail != null">#{detail},</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="image != null">#{image},</if>
        </trim>
    </insert>

    <!--
    根据手机号查消息ID
    -->
    <select id="selectTitleById" resultType="Integer">
        SELECT id FROM lcd_info WHERE title = #{title}
    </select>

    <!--
    查寻手机号所对应注册表里的用户ID
    -->
    <select id="selectUserId"  resultType="Integer">
        select post_user.id from post_user where post_user.mobile = #{mobile}
    </select>
    <update id="updateLcdInfo" parameterType="LcdInfo">
        update lcd_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="detail != null">detail = #{detail},</if>
            <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="image != null">image = #{image},</if>

        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLcdInfoById" parameterType="Long">
        delete from lcd_info where id = #{id}
    </delete>

    <delete id="deleteLcdInfoByIds" parameterType="String">
        delete from lcd_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


</mapper>