<?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.company.mapper.CompanyVoiceCallerMapper">

    <resultMap type="CompanyVoiceCaller" id="CompanyVoiceCallerResult">
        <result property="callerId"    column="caller_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="callerNo"    column="caller_no"    />
        <result property="mobile"    column="mobile"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCompanyVoiceCallerVo">
        select caller_id, company_id, company_user_id, caller_no, mobile, status, remark from company_voice_caller
    </sql>

    <select id="selectCompanyVoiceCallerList" parameterType="CompanyVoiceCaller" resultMap="CompanyVoiceCallerResult">
        <include refid="selectCompanyVoiceCallerVo"/>
        <where>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="callerNo != null  and callerNo != ''"> and caller_no = #{callerNo}</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectCompanyVoiceCallerById" parameterType="Long" resultMap="CompanyVoiceCallerResult">
        <include refid="selectCompanyVoiceCallerVo"/>
        where caller_id = #{callerId}
    </select>

    <insert id="insertCompanyVoiceCaller" parameterType="CompanyVoiceCaller" useGeneratedKeys="true" keyProperty="callerId">
        insert into company_voice_caller
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="callerNo != null">caller_no,</if>
            <if test="mobile != null">mobile,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="callerNo != null">#{callerNo},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCompanyVoiceCaller" parameterType="CompanyVoiceCaller">
        update company_voice_caller
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="callerNo != null">caller_no = #{callerNo},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where caller_id = #{callerId}
    </update>

    <delete id="deleteCompanyVoiceCallerById" parameterType="Long">
        delete from company_voice_caller where caller_id = #{callerId}
    </delete>

    <delete id="deleteCompanyVoiceCallerByIds" parameterType="String">
        delete from company_voice_caller where caller_id in
        <foreach item="callerId" collection="array" open="(" separator="," close=")">
            #{callerId}
        </foreach>
    </delete>

</mapper>
