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

    <resultMap type="QwContactBatch" id="QwContactBatchResult">
        <result property="id"    column="id"    />
        <result property="phone"    column="phone"    />
        <result property="tagIds"    column="tag_ids"    />
        <result property="status"    column="status"    />
        <result property="userId"    column="user_id"    />
        <result property="num"    column="num"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
        <result property="qwUserId"    column="qw_user_id"    />
    </resultMap>

    <sql id="selectQwContactBatchVo">
        select id, phone, tag_ids, status,qw_user_id, user_id, num, company_user_id, company_id, create_time, remark from qw_contact_batch
    </sql>

    <select id="selectQwContactBatchList" parameterType="QwContactBatch" resultMap="QwContactBatchResult">
        <include refid="selectQwContactBatchVo"/>
        <where>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="tagIds != null  and tagIds != ''"> and tag_ids = #{tagIds}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="num != null "> and num = #{num}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>

    <select id="selectQwContactBatchById" parameterType="Long" resultMap="QwContactBatchResult">
        <include refid="selectQwContactBatchVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwContactBatch" parameterType="QwContactBatch" useGeneratedKeys="true" keyProperty="id">
        insert into qw_contact_batch
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="phone != null">phone,</if>
            <if test="tagIds != null">tag_ids,</if>
            <if test="status != null">status,</if>
            <if test="userId != null">user_id,</if>
            <if test="num != null">num,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
            <if test="qwUserId != null">qw_user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="phone != null">#{phone},</if>
            <if test="tagIds != null">#{tagIds},</if>
            <if test="status != null">#{status},</if>
            <if test="userId != null">#{userId},</if>
            <if test="num != null">#{num},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="qwUserId != null">#{qwUserId},</if>
         </trim>
    </insert>

    <update id="updateQwContactBatch" parameterType="QwContactBatch">
        update qw_contact_batch
        <trim prefix="SET" suffixOverrides=",">
            <if test="phone != null">phone = #{phone},</if>
            <if test="tagIds != null">tag_ids = #{tagIds},</if>
            <if test="status != null">status = #{status},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="num != null">num = #{num},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwContactBatchById" parameterType="Long">
        delete from qw_contact_batch where id = #{id}
    </delete>

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