<?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.project.plant.mapper.TMtMeetingMapper">

    <resultMap type="TMtMeeting" id="TMtMeetingResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="recorder"    column="recorder"    />
        <result property="meetingNo"    column="meeting_no"    />
        <result property="meetingDate"    column="meeting_date"    />
        <result property="venue"    column="venue"    />
        <result property="subject"    column="subject"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
        <result property="wordUrl"    column="word_url"    />
        <result property="emailStatus"    column="email_status"    />
    </resultMap>

    <sql id="selectTMtMeetingVo">
        select d.id, d.plant_code, d.recorder,email_status,d.word_url, d.meeting_no, d.meeting_date, d.venue, d.subject
             , d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks
             ,s.dept_name from t_mt_meeting d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMtMeetingList" parameterType="TMtMeeting" resultMap="TMtMeetingResult">
        <include refid="selectTMtMeetingVo"/>
        <where>
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="meetingNo != null  and meetingNo != ''"> and meeting_no = #{meetingNo}</if>
            <if test="meetingDate != null "> and meeting_date = #{meetingDate}</if>
            <if test="venue != null  and venue != ''"> and venue = #{venue}</if>
            <if test="subject != null  and subject != ''"> and subject = #{subject}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by meeting_date desc
    </select>

    <select id="selectTMtMeetingById" parameterType="Long" resultMap="TMtMeetingResult">
        <include refid="selectTMtMeetingVo"/>
        where id = #{id}
    </select>


    <select id="selectTMtMeetingLast" parameterType="TMtMeeting" resultMap="TMtMeetingResult">
        <include refid="selectTMtMeetingVo"/>
        where d.DEL_FLAG = 0
        ORDER BY d.id DESC
        FETCH FIRST 1 ROW ONLY
    </select>

    <insert id="insertTMtMeeting" parameterType="TMtMeeting">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_mt_meeting.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_mt_meeting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="recorder != null">recorder,</if>
            <if test="meetingNo != null">meeting_no,</if>
            <if test="meetingDate != null">meeting_date,</if>
            <if test="venue != null">venue,</if>
            <if test="subject != null">subject,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="wordUrl != null">word_url,</if>
            <if test="emailStatus != null">email_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="recorder != null">#{recorder},</if>
            <if test="meetingNo != null">#{meetingNo},</if>
            <if test="meetingDate != null">#{meetingDate},</if>
            <if test="venue != null">#{venue},</if>
            <if test="subject != null">#{subject},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="wordUrl != null">#{wordUrl},</if>
            <if test="emailStatus != null">#{emailStatus},</if>
         </trim>
    </insert>

    <update id="updateTMtMeeting" parameterType="TMtMeeting">
        update t_mt_meeting
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="recorder != null">recorder = #{recorder},</if>
            <if test="meetingNo != null">meeting_no = #{meetingNo},</if>
            <if test="meetingDate != null">meeting_date = #{meetingDate},</if>
            <if test="venue != null">venue = #{venue},</if>
            <if test="subject != null">subject = #{subject},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="wordUrl != null">word_url = #{wordUrl},</if>
            <if test="emailStatus != null">email_status = #{emailStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTMtMeetingById" parameterType="Long">
        update t_mt_meeting set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTMtMeetingByIds" parameterType="String">
        update t_mt_meeting set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
