<?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.crm.mapper.CrmCustomerUserMapper">
    
    <resultMap type="CrmCustomerUser" id="CrmCustomerUserResult">
        <result property="customerUserId"    column="customer_user_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="customerId"    column="customer_id"    />
        <result property="status"    column="status"    />
        <result property="dealTime"    column="deal_time"    />
        <result property="startTime"    column="start_time"    />
        <result property="limitTime"    column="limit_time"    />
        <result property="poolTime"    column="pool_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="lastTime"    column="last_time"    />
        <result property="companyId"    column="company_id"    />
        <result property="isPool"    column="is_pool"    />
    </resultMap>

    <sql id="selectCrmCustomerUserVo">
        select customer_user_id, company_user_id, customer_id, status, deal_time, start_time, limit_time, pool_time, create_time, last_time, company_id,is_pool from crm_customer_user
    </sql>

    <select id="selectCrmCustomerUserList" parameterType="CrmCustomerUser" resultMap="CrmCustomerUserResult">
        <include refid="selectCrmCustomerUserVo"/>
        <where>  
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="customerId != null "> and customer_id = #{customerId}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="dealTime != null "> and deal_time = #{dealTime}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="limitTime != null "> and limit_time = #{limitTime}</if>
            <if test="poolTime != null "> and pool_time = #{poolTime}</if>
            <if test="lastTime != null "> and last_time = #{lastTime}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="isPool != null "> and is_pool = #{isPool}</if>
        </where>
    </select>
    
    <select id="selectCrmCustomerUserById" parameterType="Long" resultMap="CrmCustomerUserResult">
        <include refid="selectCrmCustomerUserVo"/>
        where customer_user_id = #{customerUserId}
    </select>
        
    <insert id="insertCrmCustomerUser" parameterType="CrmCustomerUser" useGeneratedKeys="true" keyProperty="customerUserId">
        insert into crm_customer_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyUserId != null">company_user_id,</if>
            <if test="customerId != null">customer_id,</if>
            <if test="status != null">status,</if>
            <if test="dealTime != null">deal_time,</if>
            <if test="startTime != null">start_time,</if>
            <if test="limitTime != null">limit_time,</if>
            <if test="poolTime != null">pool_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="lastTime != null">last_time,</if>
            <if test="companyId != null">company_id,</if>
            <if test="isPool != null">is_pool,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="customerId != null">#{customerId},</if>
            <if test="status != null">#{status},</if>
            <if test="dealTime != null">#{dealTime},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="limitTime != null">#{limitTime},</if>
            <if test="poolTime != null">#{poolTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="lastTime != null">#{lastTime},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="isPool != null">#{isPool},</if>
         </trim>
    </insert>

    <update id="updateCrmCustomerUser" parameterType="CrmCustomerUser">
        update crm_customer_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="customerId != null">customer_id = #{customerId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="dealTime != null">deal_time = #{dealTime},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="limitTime != null">limit_time = #{limitTime},</if>
            <if test="poolTime != null">pool_time = #{poolTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="lastTime != null">last_time = #{lastTime},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="isPool != null">is_pool = #{isPool},</if>
        </trim>
        where customer_user_id = #{customerUserId}
    </update>

    <delete id="deleteCrmCustomerUserById" parameterType="Long">
        delete from crm_customer_user where customer_user_id = #{customerUserId}
    </delete>

    <delete id="deleteCrmCustomerUserByIds" parameterType="String">
        delete from crm_customer_user where customer_user_id in 
        <foreach item="customerUserId" collection="array" open="(" separator="," close=")">
            #{customerUserId}
        </foreach>
    </delete>



    
</mapper>