<?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.ruoyi.aicall.mapper.CcInboundLlmAccountMapper">
    
    <resultMap type="CcInboundLlmAccount" id="CcInboundLlmAccountResult">
        <result property="id"    column="id"    />
        <result property="llmAccountId"    column="llm_account_id"    />
        <result property="inboundAlias"    column="inbound_alias"    />
        <result property="callee"    column="callee"    />
        <result property="voiceCode"    column="voice_code"    />
        <result property="voiceSource"    column="voice_source"    />
        <result property="serviceType"    column="service_type"    />
        <result property="asrProvider"    column="asr_provider"    />
        <result property="aiTransferType"    column="ai_transfer_type"    />
        <result property="aiTransferData"    column="ai_transfer_data"    />
        <result property="ivrId"    column="ivr_id"    />
        <result property="satisfSurveyIvrId"    column="satisf_survey_ivr_id"    />
        <result property="asrLanguageCode"    column="asr_language_code"    />
        <result property="ttsLanguageCode"    column="tts_language_code"    />
        <result property="asrModels"    column="asr_models"    />
        <result property="ttsModels"    column="tts_models"    />
    </resultMap>

    <sql id="selectCcInboundLlmAccountVo">
        select id, llm_account_id, callee, voice_code, voice_source,
               service_type, asr_provider, ai_transfer_type, ai_transfer_data,
               ivr_id, satisf_survey_ivr_id, inbound_alias,
               asr_language_code, tts_language_code, asr_models, tts_models from cc_inbound_llm_account
    </sql>

    <select id="selectCcInboundLlmAccountList" parameterType="CcInboundLlmAccount" resultMap="CcInboundLlmAccountResult">
        <include refid="selectCcInboundLlmAccountVo"/>
        <where>  
            <if test="llmAccountId != null "> and llm_account_id = #{llmAccountId}</if>
            <if test="callee != null  and callee != ''"> and callee = #{callee}</if>
            <if test="inboundAlias != null  and inboundAlias != ''"> and inbound_alias = #{inboundAlias}</if>
            <if test="voiceCode != null  and voiceCode != ''"> and voice_code = #{voiceCode}</if>
            <if test="voiceSource != null  and voiceSource != ''"> and voice_source = #{voiceSource}</if>
            <if test="serviceType != null  and serviceType != ''"> and service_type = #{serviceType}</if>
            <if test="asrProvider != null  and asrProvider != ''"> and asr_provider = #{asrProvider}</if>
            <if test="aiTransferType != null  and aiTransferType != ''"> and ai_transfer_type = #{aiTransferType}</if>
            <if test="aiTransferData != null  and aiTransferData != ''"> and ai_transfer_data = #{aiTransferData}</if>
            <if test="asrLanguageCode != null  and asrLanguageCode != ''"> and asr_language_code = #{asrLanguageCode}</if>
            <if test="ttsLanguageCode != null  and ttsLanguageCode != ''"> and tts_language_code = #{ttsLanguageCode}</if>
            <if test="asrModels != null  and asrModels != ''"> and asr_models = #{asrModels}</if>
            <if test="ttsModels != null  and ttsModels != ''"> and tts_models = #{ttsModels}</if>

        </where>
        order by id desc
    </select>
    
    <select id="selectCcInboundLlmAccountById" parameterType="Integer" resultMap="CcInboundLlmAccountResult">
        <include refid="selectCcInboundLlmAccountVo"/>
        where id = #{id}
    </select>

    <insert id="insertCcInboundLlmAccount" parameterType="CcInboundLlmAccount">
        insert into cc_inbound_llm_account
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="llmAccountId != null">llm_account_id,</if>
            <if test="callee != null and callee != ''">callee,</if>
            <if test="inboundAlias != null and inboundAlias != ''">inbound_alias,</if>
            voice_code,
            voice_source,
            <if test="serviceType != null and serviceType != ''">service_type,</if>
            <if test="asrProvider != null and asrProvider != ''">asr_provider,</if>
            <if test="aiTransferType != null and aiTransferType != ''">ai_transfer_type,</if>
            <if test="aiTransferData != null and aiTransferData != ''">ai_transfer_data,</if>
            <if test="ivrId != null">ivr_id,</if>
            <if test="satisfSurveyIvrId != null">satisf_survey_ivr_id,</if>
            asr_language_code,
            tts_language_code,
            asr_models,
            tts_models,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="llmAccountId != null">#{llmAccountId},</if>
            <if test="callee != null and callee != ''">#{callee},</if>
            <if test="inboundAlias != null and inboundAlias != ''">#{inboundAlias},</if>
            #{voiceCode},
            #{voiceSource},
            <if test="serviceType != null and serviceType != ''">#{serviceType},</if>
            <if test="asrProvider != null and asrProvider != ''">#{asrProvider},</if>
            <if test="aiTransferType != null and aiTransferType != ''">#{aiTransferType},</if>
            <if test="aiTransferData != null and aiTransferData != ''">#{aiTransferData},</if>
            <if test="ivrId != null">#{ivrId},</if>
            <if test="satisfSurveyIvrId != null">#{satisfSurveyIvrId},</if>
            #{asrLanguageCode},
            #{ttsLanguageCode},
            #{asrModels},
            #{ttsModels},
        </trim>
    </insert>

    <update id="updateCcInboundLlmAccount" parameterType="CcInboundLlmAccount">
        update cc_inbound_llm_account
        <set>
            <if test="llmAccountId != null">llm_account_id = #{llmAccountId},</if>
            <if test="callee != null and callee != ''">callee = #{callee},</if>
            <if test="inboundAlias != null and inboundAlias != ''">inbound_alias = #{inboundAlias},</if>
            voice_code = #{voiceCode},
            voice_source = #{voiceSource},
            <if test="serviceType != null and serviceType != ''">service_type = #{serviceType},</if>
            <if test="asrProvider != null and asrProvider != ''">asr_provider = #{asrProvider},</if>
            <if test="aiTransferType != null and aiTransferType != ''">ai_transfer_type = #{aiTransferType},</if>
            <if test="aiTransferData != null and aiTransferData != ''">ai_transfer_data = #{aiTransferData},</if>
            <if test="ivrId != null">ivr_id = #{ivrId},</if>
            <if test="satisfSurveyIvrId != null">satisf_survey_ivr_id = #{satisfSurveyIvrId},</if>
            asr_language_code = #{asrLanguageCode},
            tts_language_code = #{ttsLanguageCode},
            asr_models = #{asrModels},
            tts_models = #{ttsModels},

        </set>
        where id = #{id}
    </update>

    <delete id="deleteCcInboundLlmAccountById" parameterType="Integer">
        delete from cc_inbound_llm_account where id = #{id}
    </delete>

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

    <select id="selectCcInboundLlmAccountByCallee" parameterType="String" resultMap="CcInboundLlmAccountResult">
        <include refid="selectCcInboundLlmAccountVo"/>
           where callee = #{callee}
    </select>

</mapper>