<?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.rwk.system.mapper.RwkMeetingMapper">

    <resultMap type="RwkMeeting" id="RwkMeetingResult">
        <result property="id"    column="id"    />
        <result property="meetingName"    column="meeting_name"    />
        <result property="meetingContent"    column="meeting_content"    />
        <result property="meetingDate"    column="meeting_date"    />
        <result property="meetingByCompany"    column="meeting_by_company"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <collection property="rwkMeetingStaffList" ofType="RwkMeetingStaff" column="id" select="selectRwkMeetingStaffList"/>
    </resultMap>

    <resultMap id="RwkMeetingRwkMeetingStaffResult" type="RwkMeeting" extends="RwkMeetingResult">
        <collection property="rwkMeetingStaffList" ofType="RwkMeetingStaff" column="id" select="selectRwkMeetingStaffList" />
    </resultMap>

    <resultMap type="RwkMeetingStaff" id="RwkMeetingStaffResult">
        <result property="id"    column="id"    />
        <result property="meetingId"    column="meeting_id"    />
        <result property="personnelName"    column="personnel_name"    />
        <result property="isSign"    column="is_sign"    />
        <result property="personnelId"    column="personnel_id"    />
        <result property="mobilePhone"    column="mobile_phone"    />
    </resultMap>

    <sql id="selectRwkMeetingVo">
        select id, meeting_name, meeting_content, meeting_date, meeting_by_company, create_time, create_by from rwk_meeting
    </sql>

    <select id="selectRwkMeetingList" parameterType="RwkMeeting" resultMap="RwkMeetingResult">
        <include refid="selectRwkMeetingVo"/>
        <where>
            <if test="meetingName != null  and meetingName != ''"> and meeting_name like concat('%', #{meetingName}, '%')</if>
            <if test="meetingContent != null  and meetingContent != ''"> and meeting_content = #{meetingContent}</if>
            <if test="meetingDate != null  and meetingDate != ''"> and meeting_date = #{meetingDate}</if>
            <if test="meetingByCompany != null  and meetingByCompany != ''"> and meeting_by_company = #{meetingByCompany}</if>
            <if test="startDate != null and startDate != ''"> and to_date(#{startDate},'yyyy-MM-dd') &lt;= meeting_date</if>
            <if test="endDate != null and endDate != ''"> and to_date(#{endDate},'yyyy-MM-dd') &gt;= meeting_date</if>
        </where>
    </select>

    <select id="selectRwkMeetingById" parameterType="Long" resultMap="RwkMeetingRwkMeetingStaffResult">
        select id, meeting_name, meeting_content, meeting_date, meeting_by_company, create_time, create_by
        from rwk_meeting
        where id = #{id}
    </select>

    <select id="selectRwkMeetingStaffList" resultMap="RwkMeetingStaffResult">
        select id, meeting_id, personnel_name, is_sign, personnel_id, mobile_phone
        from rwk_meeting_staff
        where meeting_id = #{meeting_id}
    </select>

    <insert id="insertRwkMeeting" parameterType="RwkMeeting" keyProperty="id">
        insert into rwk_meeting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="meetingName != null">meeting_name,</if>
            <if test="meetingContent != null">meeting_content,</if>
            <if test="meetingDate != null">meeting_date,</if>
            <if test="meetingByCompany != null">meeting_by_company,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="meetingName != null">#{meetingName},</if>
            <if test="meetingContent != null">#{meetingContent},</if>
            <if test="meetingDate != null">#{meetingDate},</if>
            <if test="meetingByCompany != null">#{meetingByCompany},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
         </trim>
    </insert>

    <update id="updateRwkMeeting" parameterType="RwkMeeting">
        update rwk_meeting
        <trim prefix="SET" suffixOverrides=",">
            <if test="meetingName != null">meeting_name = #{meetingName},</if>
            <if test="meetingContent != null">meeting_content = #{meetingContent},</if>
            <if test="meetingDate != null">meeting_date = #{meetingDate},</if>
            <if test="meetingByCompany != null">meeting_by_company = #{meetingByCompany},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRwkMeetingById" parameterType="Long">
        delete from rwk_meeting where id = #{id}
    </delete>

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

    <delete id="deleteRwkMeetingStaffByMeetingIds" parameterType="String">
        delete from rwk_meeting_staff where meeting_id in
        <foreach item="meetingId" collection="array" open="(" separator="," close=")">
            #{meetingId}
        </foreach>
    </delete>

    <delete id="deleteRwkMeetingStaffByMeetingId" parameterType="Long">
        delete from rwk_meeting_staff where meeting_id = #{meetingId}
    </delete>

    <insert id="batchRwkMeetingStaff">
        insert into rwk_meeting_staff( meeting_id, personnel_name, is_sign, personnel_id, mobile_phone) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.meetingId}, #{item.personnelName}, #{item.isSign}, #{item.personnelId}, #{item.mobilePhone})
        </foreach>
    </insert>

</mapper>