<?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.post.mapper.PostBulletinMapper">

    <resultMap type="PostBulletin" id="PostBulletinResult">
        <result property="noticeId" column="notice_id"/>
        <result property="noticeTitle" column="notice_title"/>
        <result property="noticeContent" column="notice_content"/>
        <result property="status" column="status"/>
        <result property="publisherId" column="publisher_id"/>
        <result property="publisherBy" column="publisher_by"/>
        <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="remark" column="remark"/>
    </resultMap>
    <sql id="selectPostBulletinVo">
        select notice_id,
               notice_title,
               cast(notice_content as char) as notice_content,
               status,
               publisher_id,
               publisher_by,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from post_bulletin
    </sql>
    <!--列表查询-->
    <select id="selectPostBulletinList" parameterType="PostBulletin" resultMap="PostBulletinResult">
        <include refid="selectPostBulletinVo"/>
        <where>
            <if test="noticeTitle != null and noticeTitle != ''">
                AND notice_title like concat('%', #{noticeTitle}, '%')
            </if>
            <if test="noticeContent != null and noticeTitle != ''">
                AND notice_content like concat('%', #{noticeContent}, '%')
            </if>
            <if test="createTime != null and noticeTitle != ''">
                AND create_time like concat('%', #{createTime}, '%')
            </if>
        </where>
    </select>
    <!--ID查询-->
    <select id="selectPostBulletinByNoticeId" parameterType="Integer" resultMap="PostBulletinResult">
        <include refid="selectPostBulletinVo"/>
        where notice_id = #{noticeId}
    </select>

    <!--插入-->
    <insert id="insertPostBulletin" parameterType="PostBulletin" useGeneratedKeys="true" keyProperty="noticeId">
        insert into post_bulletin
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="noticeTitle != null and noticeTitle != ''">notice_title,</if>
            <if test="noticeContent != null">notice_content,</if>
            <if test="status != null">status,</if>
            <if test="publisherId != null">publisher_id,</if>
            <if test="publisherBy != null">publisher_by,</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="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="noticeTitle != null and noticeTitle != ''">#{noticeTitle},</if>
            <if test="noticeContent != null">#{noticeContent},</if>
            <if test="status != null">#{status},</if>
            <if test="publisherId != null">#{publisherId},</if>
            <if test="publisherBy != null">#{publisherBy},</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="remark != null">#{remark},</if>
        </trim>
    </insert>
    <!--更新-->
    <update id="updatePostBulletin" parameterType="PostBulletin">
        update post_bulletin
        <trim prefix="SET" suffixOverrides=",">
            <if test="noticeTitle != null and noticeTitle != ''">notice_title = #{noticeTitle},</if>
            <if test="noticeContent != null">notice_content = #{noticeContent},</if>
            <if test="status != null">status = #{status},</if>
            <if test="publisherId != null">publisher_id = #{publisherId},</if>
            <if test="publisherBy != null">publisher_by = #{publisherBy},</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="remark != null">remark = #{remark},</if>
        </trim>
        where notice_id = #{noticeId}
    </update>
    <!--删除-->
    <delete id="deletePostBulletinByNoticeId" parameterType="Integer">
        delete
        from post_bulletin
        where notice_id = #{noticeId}
    </delete>
    <!--批量删除-->
    <delete id="deletePostBulletinByNoticeIds" parameterType="String">
        delete from post_bulletin where notice_id in
        <foreach item="noticeId" collection="array" open="(" separator="," close=")">
            #{noticeId}
        </foreach>
    </delete>

    <!-- 判断内容以及标题是否为空-->
    <select id="checkTitleAndContentIsExit" resultType="PostBulletin" resultMap="PostBulletinResult">
        <include refid="selectPostBulletinVo"></include>
        <where>
            <!--            <if test="@Ognl@isNotEmpty(noticeTitle)">and notice_title like concat('%', #{noticeTitle}, '%')</if>-->
            <if test="noticeTitle!= null and noticeTitle!=''">and notice_title like concat('%', #{noticeTitle}, '%')
            </if>
            <if test="noticeContent!= null and noticeContent!=''">and notice_content like concat('%', #{noticeContent},
                '%')
            </if>
        </where>
    </select>
    <!--    查看详情-->
    <select id="selectViewDetails" parameterType="Integer" resultMap="PostBulletinResult">
        select notice_title, create_time, notice_content
        from post_bulletin
        where notice_id = #{noticeId}
    </select>
    <!--     检验内容是否唯一-->
    <select id="checkContentUnique" parameterType="String" resultMap="PostBulletinResult">
        select notice_id, notice_content
        from post_bulletin
        where notice_content = #{noticeContent} limit 1
    </select>
    <!--    检验标题是否唯一-->
    <select id="checkTitleUnique" parameterType="String" resultMap="PostBulletinResult">
        select notice_id, notice_title
        from post_bulletin
        where notice_title = #{noticeTitle} limit 1
    </select>
</mapper>