<?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.ics.system.mapper.NoticeMapper">

    <resultMap type="com.ics.system.domain.Notice" id="NoticeResult">
        <result property="id"               column="id"             />
        <result property="noticeTitle"      column="notice_title"   />
        <result property="noticeType"       column="notice_type"    />
        <result property="noticeContent"    column="notice_content" />
        <result property="status"           column="status"         />
        <result property="version"          column="version"        />
        <result property="deleteFlag"       column="delete_flag"    />
        <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"         />
        <result property="tenantId"         column="tenant_id"      />
    </resultMap>

    <sql id="selectNoticeVo">
       SELECT
           id,
           notice_title,
           notice_type,
           notice_content,
           status,
           create_by,
           create_time,
           update_by,
           update_time,
           remark
       FROM sys_notice n
    </sql>

    <select id="selectNoticeById" parameterType="Long" resultMap="NoticeResult">
        <include refid="selectNoticeVo"/>
        WHERE id = #{id}
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectNoticeList" parameterType="com.ics.system.domain.Notice" resultMap="NoticeResult">
        <include refid="selectNoticeVo"/>
        <where>
            <if test="noticeTitle != null and noticeTitle != ''">
                AND notice_title like concat('%', #{noticeTitle}, '%')
            </if>
            <if test="noticeType != null and noticeType != ''">
                AND notice_type = #{noticeType}
            </if>
            <if test="createBy != null and createBy != ''">
                AND create_by like concat('%', #{createBy}, '%')
            </if>
            <!-- 数据范围过滤 -->
            ${params.dataScope}
        </where>

    </select>

    <insert id="insertNotice" parameterType="com.ics.system.domain.Notice">
        INSERT INTO sys_notice (
            <if test="noticeTitle != null and noticeTitle != '' ">notice_title,</if>
            <if test="noticeType != null and noticeType != '' ">notice_type,</if>
            <if test="noticeContent != null and noticeContent != '' ">notice_content,</if>
            <if test="status != null and status != '' ">status,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            create_time
        )VALUES(
            <if test="noticeTitle != null and noticeTitle != ''">#{noticeTitle},</if>
            <if test="noticeType != null and noticeType != ''">#{noticeType},</if>
            <if test="noticeContent != null and noticeContent != ''">#{noticeContent},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            sysdate()
        )
    </insert>

    <update id="updateNotice" parameterType="com.ics.system.domain.Notice">
        UPDATE sys_notice
        <set>
            <if test="noticeTitle != null and noticeTitle != ''">notice_title = #{noticeTitle},</if>
            <if test="noticeType != null and noticeType != ''">notice_type = #{noticeType},</if>
            <if test="noticeContent != null">notice_content = #{noticeContent},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            update_time = sysdate()
        </set>
        WHERE id = #{id}
    </update>

    <delete id="deleteNoticeByIds" parameterType="String">
        DELETE FROM sys_notice WHERE id IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>