<?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.sop.mapper.QwSopTempVoiceMapper">

    <resultMap type="QwSopTempVoice" id="QwSopTempVoiceResult">
        <result property="id"    column="id"    />
        <result property="qwUserId"    column="qw_user_id"    />
        <result property="tempId"    column="temp_id"    />
        <result property="ruleId"    column="rule_id"    />
        <result property="contentId"    column="content_id"    />
        <result property="voiceTxt"    column="voice_txt"    />
        <result property="voiceUrl"    column="voice_url"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectQwSopTempVoiceVo">
        select id, qw_user_id, temp_id, rule_id, content_id, voice_txt, voice_url, create_time from qw_sop_temp_voice
    </sql>

    <select id="selectQwSopTempVoiceList" parameterType="QwSopTempVoice" resultMap="QwSopTempVoiceResult">
        <include refid="selectQwSopTempVoiceVo"/>
        <where>
            <if test="qwUserId != null  and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
            <if test="tempId != null  and tempId != ''"> and temp_id = #{tempId}</if>
            <if test="ruleId != null "> and rule_id = #{ruleId}</if>
            <if test="contentId != null "> and content_id = #{contentId}</if>
            <if test="voiceTxt != null  and voiceTxt != ''"> and voice_txt = #{voiceTxt}</if>
            <if test="voiceUrl != null  and voiceUrl != ''"> and voice_url = #{voiceUrl}</if>
        </where>
    </select>

    <select id="selectQwSopTempVoiceById" parameterType="Long" resultMap="QwSopTempVoiceResult">
        <include refid="selectQwSopTempVoiceVo"/>
        where id = #{id}
    </select>
    <select id="listVoice" resultType="com.fs.sop.domain.QwSopTempVoice">
        select * from qw_sop_temp_voice where temp_id = #{tempId} and company_user_id in
        <foreach collection="salesIds" item="item" separator="," open="(" close=")">#{item}</foreach>
    </select>
    <select id="getVoice" resultType="com.fs.sop.domain.QwSopTempVoice">
        select a.* from qw_sop_temp_voice a
        where a.company_user_id = #{companyUserId}
        and a.company_id = #{companyId}
        and a.temp_id = #{tempId}
        and a.rule_id = #{rulesId}
    </select>
    <select id="listVoiceTemp" resultType="com.fs.sop.domain.QwSopTempVoice">
        select * from qw_sop_temp_voice a where a.temp_id = #{tempId} and a.day_id =#{dayId}
    </select>
    <select id="getVoiceByText" resultType="com.fs.sop.domain.QwSopTempVoice">
        select a.* from qw_sop_temp_voice a
        where a.company_user_id = #{companyUserId}
        and a.voice_txt in <foreach collection="textList" item="txt" open="(" close=")" separator=",">#{txt}</foreach>
    </select>
    <select id="selectAllByUserIds" resultType="com.fs.sop.domain.QwSopTempVoice">
        select * from qw_sop_temp_voice a
        where a.company_user_id in <foreach collection="userIdList" open="(" separator="," close=")" item="item">#{item}</foreach>
    </select>

    <insert id="insertQwSopTempVoice" parameterType="QwSopTempVoice" useGeneratedKeys="true" keyProperty="id">
        insert into qw_sop_temp_voice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyUserId != null">company_user_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="tempId != null">temp_id,</if>
            <if test="ruleId != null">rule_id,</if>
            <if test="contentId != null">content_id,</if>
            <if test="voiceTxt != null">voice_txt,</if>
            <if test="voiceUrl != null">voice_url,</if>
            <if test="createTime != null">create_time,</if>
            <if test="duration != null">duration,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="tempId != null">#{tempId},</if>
            <if test="ruleId != null">#{ruleId},</if>
            <if test="contentId != null">#{contentId},</if>
            <if test="voiceTxt != null">#{voiceTxt},</if>
            <if test="voiceUrl != null">#{voiceUrl},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="duration != null">#{duration},</if>
         </trim>
    </insert>
    <insert id="insertBatch">
        INSERT INTO qw_sop_temp_voice (temp_id, company_user_id, day_id, company_id, content_id, rule_id, voice_txt, voice_url, duration)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.tempId}, #{item.companyUserId}, #{item.dayId}, #{item.companyId}, #{item.contentId}, #{item.ruleId}, #{item.voiceTxt}, #{item.voiceUrl}, #{item.duration})
        </foreach>
    </insert>

    <update id="updateQwSopTempVoice" parameterType="QwSopTempVoice">
        update qw_sop_temp_voice
        <trim prefix="SET" suffixOverrides=",">
            <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
            <if test="tempId != null">temp_id = #{tempId},</if>
            <if test="ruleId != null">rule_id = #{ruleId},</if>
            <if test="contentId != null">content_id = #{contentId},</if>
            <if test="voiceTxt != null">voice_txt = #{voiceTxt},</if>
            <if test="voiceUrl != null">voice_url = #{voiceUrl},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwSopTempVoiceById" parameterType="Long">
        delete from qw_sop_temp_voice where id = #{id}
    </delete>

    <delete id="deleteQwSopTempVoiceByIds" parameterType="String">
        delete from qw_sop_temp_voice where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="remove">
        delete from qw_sop_temp_voice a where a.temp_id = #{tempId} and a.day_id =#{dayId}
    </delete>
</mapper>
