<?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.fs.qw.mapper.QwExternalContactTransferLogMapper">

    <resultMap type="QwExternalContactTransferLog" id="QwExternalContactTransferLogResult">
        <result property="id"    column="id"    />
        <result property="corpId"    column="corp_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="externalUserId"    column="external_user_id"    />
        <result property="customerId"    column="customer_id"    />
        <result property="externalContactId"    column="external_contact_id"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="takeoverUserId"    column="takeover_user_id"    />
        <result property="handoverUserId"    column="handover_user_id"    />
        <result property="qwUserId"    column="qw_user_id"    />
        <result property="handoverQwUserId"    column="handover_qw_user_id"    />
    </resultMap>

    <sql id="selectQwExternalContactTransferLogVo">
        select id, corp_id, qw_user_id,handover_qw_user_id,company_id,takeover_user_id,handover_user_id, company_user_id, external_user_id, customer_id, external_contact_id, status, create_time from qw_external_contact_transfer_log
    </sql>

    <select id="selectQwExternalContactTransferLogList" parameterType="QwExternalContactTransferLog" resultMap="QwExternalContactTransferLogResult">
        <include refid="selectQwExternalContactTransferLogVo"/>
        <where>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="takeoverUserId != null  and takeoverUserId != ''"> and takeover_user_id = #{takeoverUserId}</if>
            <if test="externalUserId != null  and externalUserId != ''"> and external_user_id = #{externalUserId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="customerId != null "> and customer_id = #{customerId}</if>
            <if test="externalContactId != null "> and external_contact_id = #{externalContactId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectQwExternalContactTransferLogListByCheck" parameterType="QwExternalContactTransferLog" resultMap="QwExternalContactTransferLogResult">
        <include refid="selectQwExternalContactTransferLogVo"/>
        <where>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="takeoverUserId != null  and takeoverUserId != ''"> and takeover_user_id = #{takeoverUserId}</if>
            <if test="externalUserId != null  and externalUserId != ''"> and external_user_id = #{externalUserId}</if>
        </where>
        and status = '2'
        limit 1
    </select>

    <select id="selectQwExternalContactTransferLogById" parameterType="Long" resultMap="QwExternalContactTransferLogResult">
        <include refid="selectQwExternalContactTransferLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwExternalContactTransferLog" parameterType="QwExternalContactTransferLog">
        insert into qw_external_contact_transfer_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="externalUserId != null">external_user_id,</if>
            <if test="customerId != null">customer_id,</if>
            <if test="externalContactId != null">external_contact_id,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="takeoverUserId != null">takeover_user_id,</if>
            <if test="handoverUserId != null">handover_user_id,</if>
            <if test="qwUserId != null">qw_user_id,</if>
            <if test="handoverQwUserId != null">handover_qw_user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="externalUserId != null">#{externalUserId},</if>
            <if test="customerId != null">#{customerId},</if>
            <if test="externalContactId != null">#{externalContactId},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="takeoverUserId != null">#{takeoverUserId},</if>
            <if test="handoverUserId != null">#{handoverUserId},</if>
            <if test="qwUserId != null">#{qwUserId},</if>
            <if test="handoverQwUserId != null">#{handoverQwUserId},</if>
         </trim>
    </insert>

    <update id="updateQwExternalContactTransferLog" parameterType="QwExternalContactTransferLog">
        update qw_external_contact_transfer_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="externalUserId != null">external_user_id = #{externalUserId},</if>
            <if test="customerId != null">customer_id = #{customerId},</if>
            <if test="externalContactId != null">external_contact_id = #{externalContactId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="takeoverUserId != null">takeover_user_id = #{takeoverUserId},</if>
            <if test="handoverUserId != null">handover_user_id = #{handoverUserId},</if>
            <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
            <if test="handoverQwUserId != null">handover_qw_user_id = #{handoverQwUserId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwExternalContactTransferLogById" parameterType="Long">
        delete from qw_external_contact_transfer_log where id = #{id}
    </delete>

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