<?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.mall.mapper.MallCmsNoticeMapper">
    
    <resultMap type="MallCmsNotice" id="MallCmsNoticeResult">
        <result property="id"    column="id"    />
        <result property="noticeTitle"    column="notice_title"    />
        <result property="noticeImg"    column="notice_img"    />
        <result property="noticeContent"    column="notice_content"    />
        <result property="noticeStatus"    column="notice_status"    />
        <result property="noticeAuthor"    column="notice_author"    />
        <result property="createAt"    column="create_at"    />
        <result property="updateAt"    column="update_at"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <resultMap type="com.ruoyi.mall.domain.vo.IndexNoticeVO" id="IndexNoticeVOResult">
        <result property="id"    column="id"    />
        <result property="noticeTitle"    column="notice_title"    />
        <result property="noticeImg"    column="notice_img"    />
        <result property="noticeContent"    column="notice_content"    />
        <result property="createAt"    column="create_at"    />
    </resultMap>

    <sql id="selectMallCmsNoticeVo">
        select id, notice_title, notice_img, notice_content, notice_status, notice_author, create_at, update_at, del_flag from mall_cms_notice
    </sql>

    <select id="selectMallCmsNoticeList" parameterType="MallCmsNotice" resultMap="MallCmsNoticeResult">
        <include refid="selectMallCmsNoticeVo"/>
        <where>  
            <if test="noticeTitle != null  and noticeTitle != ''"> and notice_title like concat('%', #{noticeTitle}, '%')</if>
            <if test="noticeStatus != null  and noticeStatus != ''"> and notice_status = #{noticeStatus}</if>
        </where>
    </select>
    
    <select id="selectMallCmsNoticeById" parameterType="Long" resultMap="MallCmsNoticeResult">
        <include refid="selectMallCmsNoticeVo"/>
        where id = #{id}
    </select>
    <select id="indexSelectMallCmsNoticeList" resultMap="IndexNoticeVOResult">
        select id, notice_title, notice_img, notice_content, create_at
        from mall_cms_notice
        where del_flag = '0'
        and notice_status = '0'
    </select>

    <insert id="insertMallCmsNotice" parameterType="MallCmsNotice" useGeneratedKeys="true" keyProperty="id">
        insert into mall_cms_notice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="noticeTitle != null">notice_title,</if>
            <if test="noticeImg != null">notice_img,</if>
            <if test="noticeContent != null">notice_content,</if>
            <if test="noticeStatus != null">notice_status,</if>
            <if test="noticeAuthor != null">notice_author,</if>
            <if test="createAt != null">create_at,</if>
            <if test="updateAt != null">update_at,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="noticeTitle != null">#{noticeTitle},</if>
            <if test="noticeImg != null">#{noticeImg},</if>
            <if test="noticeContent != null">#{noticeContent},</if>
            <if test="noticeStatus != null">#{noticeStatus},</if>
            <if test="noticeAuthor != null">#{noticeAuthor},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="updateAt != null">#{updateAt},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateMallCmsNotice" parameterType="MallCmsNotice">
        update mall_cms_notice
        <trim prefix="SET" suffixOverrides=",">
            <if test="noticeTitle != null">notice_title = #{noticeTitle},</if>
            <if test="noticeImg != null">notice_img = #{noticeImg},</if>
            <if test="noticeContent != null">notice_content = #{noticeContent},</if>
            <if test="noticeStatus != null">notice_status = #{noticeStatus},</if>
            <if test="noticeAuthor != null">notice_author = #{noticeAuthor},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="updateAt != null">update_at = #{updateAt},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallCmsNoticeById" parameterType="Long">
        delete from mall_cms_notice where id = #{id}
    </delete>

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