<?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.rc.mapper.TMeetingMapper">
    
    <resultMap type="TMeeting" id="TMeetingResult">
        <result property="id"    column="id"    />
        <result property="year"    column="year"    />
        <result property="questionnaireId"    column="questionnaire_id"    />
        <result property="personInCharge"    column="person_in_charge"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="personInChargeName"    column="person_in_charge_name"    />
    </resultMap>

    <sql id="selectTMeetingVo">
        select d.id, year, questionnaire_id, person_in_charge, remarks, d.dept_id,
        u.nick_name as person_in_charge_name
        from t_meeting d
        left join sys_user u on d.person_in_charge = u.user_id
    </sql>

    <select id="selectTMeetingList" parameterType="TMeeting" resultMap="TMeetingResult">
        <include refid="selectTMeetingVo"/>
        <where>  
            <if test="year != null  and year != ''"> and year = #{year}</if>
            <if test="questionnaireId != null "> and questionnaire_id = #{questionnaireId}</if>
            <if test="personInCharge != null "> and person_in_charge = #{personInCharge}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="deptId != null  and deptId != ''"> and d.dept_id = #{deptId}</if>
            ${params.dataScope}
        </where>
    </select>
    
    <select id="selectTMeetingById" parameterType="Long" resultMap="TMeetingResult">
        <include refid="selectTMeetingVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMeeting" parameterType="TMeeting" useGeneratedKeys="true" keyProperty="id">
        insert into t_meeting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="year != null">year,</if>
            <if test="questionnaireId != null">questionnaire_id,</if>
            <if test="personInCharge != null">person_in_charge,</if>
            <if test="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="year != null">#{year},</if>
            <if test="questionnaireId != null">#{questionnaireId},</if>
            <if test="personInCharge != null">#{personInCharge},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTMeeting" parameterType="TMeeting">
        update t_meeting
        <trim prefix="SET" suffixOverrides=",">
            <if test="year != null">year = #{year},</if>
            <if test="questionnaireId != null">questionnaire_id = #{questionnaireId},</if>
            <if test="personInCharge != null">person_in_charge = #{personInCharge},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTMeetingById" parameterType="Long">
        delete from t_meeting where id = #{id}
    </delete>

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