<?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.XiaoyuanNoticeMapper">
    
    <resultMap type="XiaoyuanNotice" id="XiaoyuanNoticeResult">
        <result property="noticeId"    column="notice_id"    />
        <result property="image"    column="image"    />
        <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="type"    column="type"    />
        <result property="senderId"    column="sender_id"    />
        <result property="senderName"    column="sender_name"    />
        <result property="senderDept"    column="sender_dept"    />
        <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="selectXiaoyuanNoticeVo">
        select notice_id, image, notice_title, notice_type, notice_content, status, type, sender_id, sender_name, sender_dept, create_by, create_time, update_by, update_time, remark from xiaoyuan_notice
    </sql>

    <select id="selectXiaoyuanNoticeList" parameterType="XiaoyuanNotice" resultMap="XiaoyuanNoticeResult">
SELECT
	notice_id,
	image,
	notice_title,
	notice_type,
	notice_content,
	STATUS,
	type,
	sender_id,
	sender_name,
	sender_dept,
	create_by,
	create_time,
	update_by,
	update_time,
	remark
FROM
	xiaoyuan_notice
WHERE
	type = '0'
	UNION
SELECT
	notice_id,
	image,
	notice_title,
	notice_type,
	notice_content,
	STATUS,
	type,
	sender_id,
	sender_name,
	sender_dept,
	create_by,
	create_time,
	update_by,
	update_time,
	remark
FROM
	xiaoyuan_notice
WHERE
	find_in_set( sender_dept, ${senderDept} )
	AND type = '1' UNION
SELECT
	notice_id,
	image,
	notice_title,
	notice_type,
	notice_content,
	STATUS,
	type,
	sender_id,
	sender_name,
	sender_dept,
	create_by,
	create_time,
	update_by,
	update_time,
	remark
FROM
	xiaoyuan_notice
WHERE
	sender_id = ${senderId}
	AND type = '2'
    </select>
    
    <select id="selectXiaoyuanNoticeByNoticeId" parameterType="Integer" resultMap="XiaoyuanNoticeResult">
        <include refid="selectXiaoyuanNoticeVo"/>
        where notice_id = #{noticeId}
    </select>
        
    <insert id="insertXiaoyuanNotice" parameterType="XiaoyuanNotice" useGeneratedKeys="true" keyProperty="noticeId">
        insert into xiaoyuan_notice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="image != null">image,</if>
            <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="type != null and type != ''">type,</if>
            <if test="senderId != null">sender_id,</if>
            <if test="senderName != null">sender_name,</if>
            <if test="senderDept != null">sender_dept,</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="image != null">#{image},</if>
            <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="type != null and type != ''">#{type},</if>
            <if test="senderId != null">#{senderId},</if>
            <if test="senderName != null">#{senderName},</if>
            <if test="senderDept != null">#{senderDept},</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="updateXiaoyuanNotice" parameterType="XiaoyuanNotice">
        update xiaoyuan_notice
        <trim prefix="SET" suffixOverrides=",">
            <if test="image != null">image = #{image},</if>
            <if test="noticeTitle != null and noticeTitle != ''">notice_title = #{noticeTitle},</if>
            <if test="noticeType != null and noticeType != ''">notice_type = #{noticeType},</if>
            <if test="noticeContent != null and noticeContent != ''">notice_content = #{noticeContent},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="senderId != null">sender_id = #{senderId},</if>
            <if test="senderName != null">sender_name = #{senderName},</if>
            <if test="senderDept != null">sender_dept = #{senderDept},</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="deleteXiaoyuanNoticeByNoticeId" parameterType="Integer">
        delete from xiaoyuan_notice where notice_id = #{noticeId}
    </delete>

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