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

    <resultMap type="TMtAgenda" id="TMtAgendaResult">
        <result property="id"    column="id"    />
        <result property="meetingId"    column="meeting_id"    />
        <result property="agendaType"    column="agenda_type"    />
        <result property="agendaContent"    column="agenda_content"    />
        <result property="workType"    column="work_type"    />
        <result property="planType"    column="plan_type"    />
        <result property="responsible"    column="responsible"    />
        <result property="status"    column="status"    />
        <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="presided"    column="presided"    />
        <result property="isHis"    column="is_his"    />
        <result property="deadlineTime"    column="deadline_time"    />
        <result property="subject"    column="subject"    />
        <result property="meetingNo"    column="meeting_no"    />
        <result property="meetingDate"    column="meeting_date"    />
    </resultMap>

    <sql id="selectTMtAgendaVo">
        select deadline_time,id, meeting_id, agenda_type, agenda_content, work_type, plan_type, responsible, status, del_flag, creater_code, createdate, updater_code, updatedate, dept_id, remarks, presided,is_his from t_mt_agenda
    </sql>
    <select id="selectAgendaList" parameterType="TMtAgenda" resultMap="TMtAgendaResult">
        select a.deadline_time,
               a.id,
               a.meeting_id,
               a.agenda_type,
               a.agenda_content,
               a.work_type,
               a.plan_type,
               a.responsible,
               a.status,
               a.del_flag,
               a.creater_code,
               a.createdate,
               a.updater_code,
               a.updatedate,
               a.dept_id,
               a.remarks,
               a.presided,
               a.is_his,
               b.subject,
               b.meeting_no,
               b.meeting_date
        from t_mt_agenda a
                 left join t_mt_meeting b on a.meeting_id = b.id
        <where>
            <if test="isHis != null ">and a.is_his = #{isHis}</if>
            <if test="deadlineTime != null ">and a.deadline_time <![CDATA[ <= ]]> #{deadlineTime}</if>
            <if test="workType != null  and workType != ''">and a.work_type = #{workType}</if>
            <if test="status != null  and status != ''">and a.status = #{status}</if>
            <if test="responsible != null">and a.responsible like concat('%',#{responsible},'%')</if>
            and a.del_flag = 0
            and b.del_flag = 0
        </where>
    </select>

    <select id="selectTMtAgendaList" parameterType="TMtAgenda" resultMap="TMtAgendaResult">
        <include refid="selectTMtAgendaVo"/>
        <where>
            <if test="meetingId != null  and meetingId != ''"> and meeting_id = #{meetingId}</if>
            <if test="agendaType != null  and agendaType != ''"> and agenda_type = #{agendaType}</if>
            <if test="agendaContent != null  and agendaContent != ''"> and agenda_content = #{agendaContent}</if>
            <if test="workType != null  and workType != ''"> and work_type = #{workType}</if>
            <if test="planType != null  and planType != ''"> and plan_type = #{planType}</if>
            <if test="responsible != null  and responsible != ''"> and responsible = #{responsible}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="flag == 1"> and status != 'Finished'</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="deadlineTime != null "> and deadline_time <![CDATA[ <= ]]> #{deadlineTime}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="presided != null  and presided != ''"> and presided = #{presided}</if>
            <if test="isHis != null "> and is_his = #{isHis}</if>
        and del_flag = 0
        </where>
    </select>

    <select id="selectTMtAgendaById" parameterType="Long" resultMap="TMtAgendaResult">
        <include refid="selectTMtAgendaVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMtAgenda" parameterType="TMtAgenda" useGeneratedKeys="true" keyProperty="id">
        insert into t_mt_agenda
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="meetingId != null and meetingId != ''">meeting_id,</if>
            <if test="agendaType != null">agenda_type,</if>
            <if test="agendaContent != null">agenda_content,</if>
            <if test="workType != null">work_type,</if>
            <if test="planType != null">plan_type,</if>
            <if test="responsible != null">responsible,</if>
            <if test="status != null">status,</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="presided != null">presided,</if>
            <if test="isHis != null">is_his,</if>
            <if test="deadlineTime != null">deadline_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="meetingId != null and meetingId != ''">#{meetingId},</if>
            <if test="agendaType != null">#{agendaType},</if>
            <if test="agendaContent != null">#{agendaContent},</if>
            <if test="workType != null">#{workType},</if>
            <if test="planType != null">#{planType},</if>
            <if test="responsible != null">#{responsible},</if>
            <if test="status != null">#{status},</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="presided != null">#{presided},</if>
            <if test="isHis != null">#{isHis},</if>
            <if test="deadlineTime != null">#{deadlineTime},</if>
         </trim>
    </insert>

    <update id="updateTMtAgenda" parameterType="TMtAgenda">
        update t_mt_agenda
        <trim prefix="SET" suffixOverrides=",">
            <if test="meetingId != null and meetingId != ''">meeting_id = #{meetingId},</if>
            <if test="agendaType != null">agenda_type = #{agendaType},</if>
            <if test="agendaContent != null">agenda_content = #{agendaContent},</if>
            <if test="workType != null">work_type = #{workType},</if>
            <if test="planType != null">plan_type = #{planType},</if>
            <if test="responsible != null">responsible = #{responsible},</if>
            <if test="status != null">status = #{status},</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="presided != null">presided = #{presided},</if>
            <if test="isHis != null">is_his = #{isHis},</if>
            <if test="deadlineTime != null">deadline_time = #{deadlineTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTMtAgendaById" parameterType="Long">
        update t_mt_agenda set del_flag=1 where id = #{id}
    </delete>

    <delete id="deleteTMtAgendaByIds" parameterType="String">
        update t_mt_agenda set del_flag=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
