<?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.oa.mapper.CmcContractMeetingMapper">

    <resultMap type="CmcContractMeeting" id="CmcContractMeetingResult">
        <result property="meetingId"    column="meeting_id"    />
        <result property="contractId"    column="contract_id"    />
        <result property="meetingTime"    column="meeting_time"    />
        <result property="hostId"    column="host_id"    />
        <result property="place"    column="place"    />
        <result property="users"    column="users"    />
        <result property="conclusion"    column="conclusion"    />
        <result property="document"    column="document"    />
        <result property="commentTime"    column="comment_time"    />
        <association property="hostUser"    javaType="SysUser"         resultMap="HostUserResult" />
    </resultMap>

    <resultMap type="SysUser" id="HostUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="nick_name"    />
    </resultMap>

    <sql id="selectCmcContractMeetingVo">
        select cm.meeting_id, cm.contract_id, cm.meeting_time, cm.host_id, u.nick_name as nick_name, cm.place, cm.users, cm.conclusion, cm.document, cm.comment_time from cmc_contract_meeting as cm
        left join sys_user as u on u.user_id = cm.host_id
    </sql>

    <select id="selectCmcContractMeetingList" parameterType="CmcContractMeeting" resultMap="CmcContractMeetingResult">
        <include refid="selectCmcContractMeetingVo"/>
        <where>
            <if test="contractId != null  and contractId != ''"> and cm.contract_id = #{contractId}</if>
            <if test="meetingTime != null "> and cm.meeting_time = #{meetingTime}</if>
            <if test="hostId != null "> and cm.host_id = #{hostId}</if>
            <if test="place != null  and place != ''"> and cm.place = #{place}</if>
            <if test="users != null  and users != ''"> and cm.users = #{users}</if>
            <if test="conclusion != null  and conclusion != ''"> and cm.conclusion = #{conclusion}</if>
            <if test="document != null  and document != ''"> and cm.document = #{document}</if>
            <if test="commentTime != null "> and cm.comment_time = #{commentTime}</if>
        </where>
    </select>

    <select id="selectCmcContractMeetingByContractId" parameterType="String" resultMap="CmcContractMeetingResult">
        <include refid="selectCmcContractMeetingVo"/>
        where cm.contract_id = #{contractId}
    </select>

    <insert id="insertCmcContractMeeting" parameterType="CmcContractMeeting">
        insert into cmc_contract_meeting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="meetingId != null">meeting_id,</if>
            <if test="contractId != null">contract_id,</if>
            <if test="meetingTime != null">meeting_time,</if>
            <if test="hostId != null">host_id,</if>
            <if test="place != null">place,</if>
            <if test="users != null">users,</if>
            <if test="conclusion != null">conclusion,</if>
            <if test="document != null">document,</if>
            <if test="commentTime != null">comment_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="meetingId != null">#{meetingId},</if>
            <if test="contractId != null">#{contractId},</if>
            <if test="meetingTime != null">#{meetingTime},</if>
            <if test="hostId != null">#{hostId},</if>
            <if test="place != null">#{place},</if>
            <if test="users != null">#{users},</if>
            <if test="conclusion != null">#{conclusion},</if>
            <if test="document != null">#{document},</if>
            <if test="commentTime != null">#{commentTime},</if>
        </trim>
    </insert>

    <update id="updateCmcContractMeeting" parameterType="CmcContractMeeting">
        update cmc_contract_meeting
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractId != null">contract_id = #{contractId},</if>
            <if test="meetingTime != null">meeting_time = #{meetingTime},</if>
            <if test="hostId != null">host_id = #{hostId},</if>
            <if test="place != null">place = #{place},</if>
            <if test="users != null">users = #{users},</if>
            <if test="conclusion != null">conclusion = #{conclusion},</if>
            <if test="document != null">document = #{document},</if>
            <if test="commentTime != null">comment_time = #{commentTime},</if>
        </trim>
        where meeting_id = #{meetingId}
    </update>

    <delete id="deleteCmcContractMeetingByContractId" parameterType="String">
        delete from cmc_contract_meeting where contract_id = #{contractId}
    </delete>

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