<?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.cc.mapper.CcIvrMapper">
    
    <resultMap type="CcIvr" id="CcIvrResult">
        <result property="id"    column="id"    />
        <result property="rootId"    column="root_id"    />
        <result property="digit"    column="digit"    />
        <result property="ivrNodeName"    column="node_name"    />
        <result property="parentNodeId"    column="parent_node_id"    />
        <result property="ttsText"    column="tts_text"    />
        <result property="action"    column="action"    />
        <result property="waitKeyTimeout"    column="wait_key_timeout"    />
        <result property="maxPressKeyFailures"    column="max_press_key_failures"    />
        <result property="pressKeyInvalidTips"    column="press_key_invalid_tips"    />
        <result property="enabled"    column="enabled"    />
        <result property="failedAction"    column="failed_action"    />
        <result property="digitRange"    column="digit_range"    />
        <result property="ttsProvider"    column="tts_provider"    />
        <result property="voiceCode"    column="voice_code"    />
        <result property="aiTransferData"    column="ai_transfer_data"    />
        <result property="maxLen"    column="max_len"    />
        <result property="minLen"    column="min_len"    />
        <result property="userInputVarName"    column="user_input_var_name"    />
        <result property="hangupTips"    column="hangup_tips"    />
        <result property="ttsTextWav"    column="tts_text_wav"    />
        <result property="pressKeyInvalidTipsWav"    column="press_key_invalid_tips_wav"    />
        <result property="hangupTipsWav"    column="hangup_tips_wav"    />
    </resultMap>

    <sql id="selectCcIvrVo">
        select id, root_id, digit, node_name, parent_node_id, tts_text, action,
               wait_key_timeout, max_press_key_failures, press_key_invalid_tips,
               enabled, failed_action, digit_range, tts_provider, voice_code,
               ai_transfer_data, max_len, min_len, user_input_var_name,
               hangup_tips, tts_text_wav, press_key_invalid_tips_wav, hangup_tips_wav from cc_ivr
    </sql>

    <select id="selectCcIvrList" parameterType="CcIvr" resultMap="CcIvrResult">
        <include refid="selectCcIvrVo"/>
        <where>
            <if test="rootId != null and rootId != '' "> and root_id = #{rootId}</if>
            <if test="digit != null "> and digit = #{digit}</if>
            <if test="ivrNodeName != null  and ivrNodeName != ''"> and node_name like concat('%', #{ivrNodeName}, '%')</if>
            <if test="parentNodeId != null and parentNodeId != '' "> and parent_node_id = #{parentNodeId}</if>
            <if test="ttsText != null  and ttsText != ''"> and tts_text = #{ttsText}</if>
            <if test="action != null  and action != ''"> and action = #{action}</if>
            <if test="waitKeyTimeout != null "> and wait_key_timeout = #{waitKeyTimeout}</if>
            <if test="maxPressKeyFailures != null "> and max_press_key_failures = #{maxPressKeyFailures}</if>
            <if test="pressKeyInvalidTips != null  and pressKeyInvalidTips != ''"> and press_key_invalid_tips = #{pressKeyInvalidTips}</if>
            <if test="enabled != null "> and enabled = #{enabled}</if>
            <if test="failedAction != null  and failedAction != ''"> and failed_action = #{failedAction}</if>
            <if test="digitRange != null  and digitRange != ''"> and digit_range = #{digitRange}</if>
        </where>
    </select>
    
    <select id="selectCcIvrById" parameterType="String" resultMap="CcIvrResult">
        <include refid="selectCcIvrVo"/>
        where id = #{id}
    </select>

    <insert id="insertCcIvr" parameterType="CcIvr" useGeneratedKeys="true" keyProperty="id">
        insert into cc_ivr
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="rootId != null">root_id,</if>
            <if test="digit != null">digit,</if>
            <if test="ivrNodeName != null and ivrNodeName != ''">node_name,</if>
            <if test="parentNodeId != null">parent_node_id,</if>
            <if test="ttsText != null">tts_text,</if>
            <if test="action != null and action != ''">action,</if>
            <if test="waitKeyTimeout != null">wait_key_timeout,</if>
            <if test="maxPressKeyFailures != null">max_press_key_failures,</if>
            <if test="pressKeyInvalidTips != null and pressKeyInvalidTips != ''">press_key_invalid_tips,</if>
            <if test="enabled != null">enabled,</if>
            <if test="failedAction != null">failed_action,</if>
            <if test="digitRange != null">digit_range,</if>
            <if test="ttsProvider != null and ttsProvider != ''">tts_provider,</if>
            <if test="voiceCode != null and voiceCode != ''">voice_code,</if>
            <if test="aiTransferData != null and aiTransferData != ''">ai_transfer_data,</if>
            <if test="maxLen != null ">max_len,</if>
            <if test="minLen != null ">min_len,</if>
            <if test="userInputVarName != null and userInputVarName != ''">user_input_var_name,</if>
            <if test="hangupTips != null and hangupTips != ''">hangup_tips,</if>
            <if test="ttsTextWav != null and ttsTextWav != ''">tts_text_wav,</if>
            <if test="pressKeyInvalidTipsWav != null and pressKeyInvalidTipsWav != ''">press_key_invalid_tips_wav,</if>
            <if test="hangupTipsWav != null and hangupTipsWav != ''">hangup_tips_wav,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="rootId != null">#{rootId},</if>
            <if test="digit != null">#{digit},</if>
            <if test="ivrNodeName != null and ivrNodeName != ''">#{ivrNodeName},</if>
            <if test="parentNodeId != null">#{parentNodeId},</if>
            <if test="ttsText != null">#{ttsText},</if>
            <if test="action != null and action != ''">#{action},</if>
            <if test="waitKeyTimeout != null">#{waitKeyTimeout},</if>
            <if test="maxPressKeyFailures != null">#{maxPressKeyFailures},</if>
            <if test="pressKeyInvalidTips != null and pressKeyInvalidTips != ''">#{pressKeyInvalidTips},</if>
            <if test="enabled != null">#{enabled},</if>
            <if test="failedAction != null">#{failedAction},</if>
            <if test="digitRange != null">#{digitRange},</if>
            <if test="ttsProvider != null and ttsProvider != ''">#{ttsProvider},</if>
            <if test="voiceCode != null and voiceCode != ''">#{voiceCode},</if>
            <if test="aiTransferData != null and aiTransferData != ''">#{aiTransferData},</if>
            <if test="maxLen != null ">#{maxLen},</if>
            <if test="minLen != null ">#{minLen},</if>
            <if test="userInputVarName != null and userInputVarName != ''">#{userInputVarName},</if>
            <if test="hangupTips != null and hangupTips != ''">#{hangupTips},</if>
            <if test="ttsTextWav != null and ttsTextWav != ''">#{ttsTextWav},</if>
            <if test="pressKeyInvalidTipsWav != null and pressKeyInvalidTipsWav != ''">#{pressKeyInvalidTipsWav},</if>
            <if test="hangupTipsWav != null and hangupTipsWav != ''">#{hangupTipsWav},</if>
         </trim>
    </insert>

    <update id="updateCcIvr" parameterType="CcIvr">
        update cc_ivr
        <trim prefix="SET" suffixOverrides=",">
            <if test="rootId != null">root_id = #{rootId},</if>
            <if test="digit != null">digit = #{digit},</if>
            <if test="ivrNodeName != null and ivrNodeName != ''">node_name = #{ivrNodeName},</if>
            <if test="parentNodeId != null">parent_node_id = #{parentNodeId},</if>
            <if test="ttsText != null">tts_text = #{ttsText},</if>
            <if test="action != null and action != ''">action = #{action},</if>
            <if test="waitKeyTimeout != null">wait_key_timeout = #{waitKeyTimeout},</if>
            <if test="maxPressKeyFailures != null">max_press_key_failures = #{maxPressKeyFailures},</if>
            <if test="pressKeyInvalidTips != null and pressKeyInvalidTips != ''">press_key_invalid_tips = #{pressKeyInvalidTips},</if>
            <if test="enabled != null">enabled = #{enabled},</if>
            <if test="failedAction != null">failed_action = #{failedAction},</if>
            <if test="digitRange != null">digit_range = #{digitRange},</if>
            <if test="ttsProvider != null and ttsProvider != ''">tts_provider = #{ttsProvider},</if>
            <if test="voiceCode != null and voiceCode != ''">voice_code = #{voiceCode},</if>
            <if test="aiTransferData != null and aiTransferData != ''">ai_transfer_data = #{aiTransferData},</if>
            <if test="maxLen != null ">max_len = #{maxLen},</if>
            <if test="minLen != null ">min_len = #{minLen},</if>
            <if test="userInputVarName != null and userInputVarName != ''">user_input_var_name = #{userInputVarName},</if>
            <if test="hangupTips != null and hangupTips != ''">hangup_tips = #{hangupTips},</if>
            <if test="ttsTextWav != null and ttsTextWav != ''">tts_text_wav = #{ttsTextWav},</if>
            <if test="pressKeyInvalidTipsWav != null and pressKeyInvalidTipsWav != ''">press_key_invalid_tips_wav = #{pressKeyInvalidTipsWav},</if>
            <if test="hangupTipsWav != null and hangupTipsWav != ''">hangup_tips_wav = #{hangupTipsWav},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCcIvrById" parameterType="String">
        delete from cc_ivr where id = #{id}
    </delete>

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

    <select id="countByDigitAndParent" resultType="int">
        SELECT COUNT(*)
        FROM cc_ivr
        WHERE digit = #{digit}
        AND parent_node_id = #{parentNodeId}
        <if test="id != null">
            AND id != #{id}
        </if>
    </select>
</mapper>