<?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.CrmCustomerAssignMapper">
    
    <resultMap type="CrmCustomerAssign" id="CrmCustomerAssignResult">
        <result property="assignId"    column="assign_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="sourceUserId"    column="source_user_id"    />
        <result property="customerIds"    column="customer_ids"    />
        <result property="createTime"    column="create_time"    />
        <result property="sysUserId"    column="sys_user_id"    />
        <result property="assignType"    column="assign_type"    />
        <result property="remark"    column="remark"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectCrmCustomerAssignVo">
        select assign_id, company_id, company_user_id,source_user_id, customer_ids, create_time, sys_user_id, assign_type, remark,status from crm_customer_assign
    </sql>

    <select id="selectCrmCustomerAssignList" parameterType="CrmCustomerAssign" resultMap="CrmCustomerAssignResult">
        <include refid="selectCrmCustomerAssignVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="customerIds != null  and customerIds != ''"> and customer_ids = #{customerIds}</if>
            <if test="sysUserId != null "> and sys_user_id = #{sysUserId}</if>
            <if test="assignType != null "> and assign_type = #{assignType}</if>
        </where>
    </select>
    
    <select id="selectCrmCustomerAssignById" parameterType="Long" resultMap="CrmCustomerAssignResult">
        <include refid="selectCrmCustomerAssignVo"/>
        where assign_id = #{assignId}
    </select>
        
    <insert id="insertCrmCustomerAssign" parameterType="CrmCustomerAssign" useGeneratedKeys="true" keyProperty="assignId">
        insert into crm_customer_assign
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="sourceUserId != null">source_user_id,</if>
            <if test="customerIds != null">customer_ids,</if>
            <if test="createTime != null">create_time,</if>
            <if test="sysUserId != null">sys_user_id,</if>
            <if test="assignType != null">assign_type,</if>
            <if test="remark != null">remark,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="sourceUserId != null">#{sourceUserId},</if>
            <if test="customerIds != null">#{customerIds},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="sysUserId != null">#{sysUserId},</if>
            <if test="assignType != null">#{assignType},</if>
            <if test="remark != null">#{remark},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateCrmCustomerAssign" parameterType="CrmCustomerAssign">
        update crm_customer_assign
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="sourceUserId != null">source_user_id = #{sourceUserId},</if>
            <if test="customerIds != null">customer_ids = #{customerIds},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="sysUserId != null">sys_user_id = #{sysUserId},</if>
            <if test="assignType != null">assign_type = #{assignType},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where assign_id = #{assignId}
    </update>

    <delete id="deleteCrmCustomerAssignById" parameterType="Long">
        delete from crm_customer_assign where assign_id = #{assignId}
    </delete>

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