<?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.CompanyVoiceConfigMapper">
    
    <resultMap type="CompanyVoiceConfig" id="CompanyVoiceConfigResult">
        <result property="configId"    column="config_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="callerJson"    column="caller_json"    />
        <result property="calleeJson"    column="callee_json"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectCompanyVoiceConfigVo">
        select config_id, company_id, caller_json, callee_json, create_time from company_voice_config
    </sql>

    <select id="selectCompanyVoiceConfigList" parameterType="CompanyVoiceConfig" resultMap="CompanyVoiceConfigResult">
        <include refid="selectCompanyVoiceConfigVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="callerJson != null  and callerJson != ''"> and caller_json = #{callerJson}</if>
            <if test="calleeJson != null  and calleeJson != ''"> and callee_json = #{calleeJson}</if>
        </where>
    </select>
    
    <select id="selectCompanyVoiceConfigById" parameterType="Long" resultMap="CompanyVoiceConfigResult">
        <include refid="selectCompanyVoiceConfigVo"/>
        where config_id = #{configId}
    </select>
        
    <insert id="insertCompanyVoiceConfig" parameterType="CompanyVoiceConfig" useGeneratedKeys="true" keyProperty="configId">
        insert into company_voice_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="callerJson != null">caller_json,</if>
            <if test="calleeJson != null">callee_json,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="callerJson != null">#{callerJson},</if>
            <if test="calleeJson != null">#{calleeJson},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateCompanyVoiceConfig" parameterType="CompanyVoiceConfig">
        update company_voice_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="callerJson != null">caller_json = #{callerJson},</if>
            <if test="calleeJson != null">callee_json = #{calleeJson},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where config_id = #{configId}
    </update>

    <delete id="deleteCompanyVoiceConfigById" parameterType="Long">
        delete from company_voice_config where config_id = #{configId}
    </delete>

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