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

    <resultMap type="PostNotice" id="PostNoticeResult">
        <result property="noticeId"    column="notice_id"    />
        <result property="noticeTitle"    column="notice_title"    />
        <result property="noticeTime"    column="notice_time"    />
        <result property="noticeContent"  column="notice_content"  />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectPostNoticeVo">
        select notice_id, notice_title, notice_time, cast(notice_content as char) as notice_content, create_by, create_time, update_by, update_time from post_notice
    </sql>

    <select id="selectPostNoticeList" parameterType="PostNotice" resultMap="PostNoticeResult">
        <include refid="selectPostNoticeVo"/>
        <where>
            <if test="noticeTitle != null  and noticeTitle != ''"> and notice_title = #{noticeTitle}</if>
            <if test="noticeContent != null and noticeContent != ''">and notice_content = #{noticeContent} </if>
            and notice_time &lt; now()
        </where>
    </select>

    <select id="selectPostNoticeListByTitleOrNoticeTime" resultType="PostNotice" resultMap="PostNoticeResult">
        <include refid="selectPostNoticeVo"/>
        <where>
            <if test="noticeTitle != null  and noticeTitle != ''"> and notice_title LIKE '%${noticeTitle}%'</if>
            <if test="noticeTimeLeft != null and noticeTimeRight != null "> and notice_time between #{noticeTimeLeft} AND #{noticeTimeRight}</if>
        </where>
    </select>


    <select id="selectPostNoticeByNoticeId" parameterType="Long" resultMap="PostNoticeResult">
        <include refid="selectPostNoticeVo"/>
        where notice_id = #{noticeId}
    </select>
    <select id="selectDetailByNoticeId" resultType="String">
        select notice_content from post_notice
        where notice_id = #{noticeId}
    </select>



    <insert id="insertPostNotice" parameterType="PostNotice" useGeneratedKeys="true" keyProperty="noticeId">
        insert into post_notice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="noticeTitle != null">notice_title,</if>
            <if test="noticeTime != null">notice_time,</if>
            <if test="noticeContent != null and noticeContent != '' ">notice_content, </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>

        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="noticeTitle != null">#{noticeTitle},</if>
            <if test="noticeTime != null">#{noticeTime},</if>
            <if test="noticeContent != null and noticeContent != '' ">#{notice_content},</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>
        </trim>
    </insert>

    <update id="updatePostNotice" parameterType="PostNotice">
        update post_notice
        <trim prefix="SET" suffixOverrides=",">
            <if test="noticeTitle != null">notice_title = #{noticeTitle},</if>
            <if test="noticeTime != null">notice_time = #{noticeTime},</if>
            <if test="noticeContent != null">notice_content = #{noticeContent}, </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>
        </trim>
        where notice_id = #{noticeId}
    </update>

    <delete id="deletePostNoticeByNoticeId" parameterType="Long">
        delete from post_notice where notice_id = #{noticeId}
    </delete>

    <delete id="deletePostNoticeByNoticeIds" parameterType="String">
        delete from post_notice where notice_id in
        <foreach item="noticeId" collection="array" open="(" separator="," close=")">
            #{noticeId}
        </foreach>
    </delete>
</mapper>