<?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.TMtPersonMapper">

    <resultMap type="TMtPerson" id="TMtPersonResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="staffid"    column="staffid"    />
        <result property="name"    column="name"    />
        <result property="sex"    column="sex"    />
        <result property="unit"    column="unit"    />
        <result property="team"    column="team"    />
        <result property="actualpost"    column="actualpost"    />
        <result property="contact"    column="contact"    />
        <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="meetingId"    column="meeting_id"    />
        <result property="isHis"    column="is_his"    />
        <result property="isCc"    column="is_cc"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTMtPersonVo">
        select d.id, d.plant_code, d.staffid, d.name, d.sex, d.unit, d.team, d.actualpost, d.contact, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.meeting_id, d.is_his, d.is_cc ,s.dept_name from t_mt_person d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMtPersonList" parameterType="TMtPerson" resultMap="TMtPersonResult">
        <include refid="selectTMtPersonVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
            <if test="meetingId != null  and meetingId != ''"> and meeting_id = #{meetingId}</if>
            <if test="meetingId == null  or meetingId == ''"> and is_his = 0</if>
            <if test="isCc != null  and isCc != ''"> and is_cc = 1</if>
            <if test="isCc == null"> and is_cc IS NULL</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTMtPersonById" parameterType="Long" resultMap="TMtPersonResult">
        <include refid="selectTMtPersonVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMtPerson" parameterType="TMtPerson">

        insert into t_mt_person
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="staffid != null">staffid,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="sex != null and sex != ''">sex,</if>
            <if test="unit != null">unit,</if>
            <if test="team != null">team,</if>
            <if test="actualpost != null">actualpost,</if>
            <if test="contact != null">contact,</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="meetingId != null">meeting_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="isHis != null">is_his,</if>
            <if test="isCc != null">is_cc,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="staffid != null">#{staffid},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="sex != null and sex != ''">#{sex},</if>
            <if test="unit != null">#{unit},</if>
            <if test="team != null">#{team},</if>
            <if test="actualpost != null">#{actualpost},</if>
            <if test="contact != null">#{contact},</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="meetingId != null">#{meetingId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="isHis != null">#{isHis},</if>
            <if test="isCc != null">#{isCc},</if>
         </trim>
    </insert>

    <update id="updateTMtPerson" parameterType="TMtPerson">
        update t_mt_person
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="staffid != null">staffid = #{staffid},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="sex != null and sex != ''">sex = #{sex},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="team != null">team = #{team},</if>
            <if test="actualpost != null">actualpost = #{actualpost},</if>
            <if test="contact != null">contact = #{contact},</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="meetingId != null">meeting_id = #{meetingId},</if>
            <if test="isHis != null">is_his = #{isHis},</if>
            <if test="isCc != null">is_cc = #{isCc},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
