<?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.CompanyVoiceMapper">
    
    <resultMap type="CompanyVoice" id="CompanyVoiceResult">
        <result property="voiceId"    column="voice_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="times"    column="times"    />
        <result property="totalTimes"    column="total_times"    />
    </resultMap>

    <sql id="selectCompanyVoiceVo">
        select voice_id, company_id, times, total_times from company_voice
    </sql>

    <select id="selectCompanyVoiceList" parameterType="CompanyVoice" resultMap="CompanyVoiceResult">
        <include refid="selectCompanyVoiceVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="times != null "> and times = #{times}</if>
            <if test="totalTimes != null "> and total_times = #{totalTimes}</if>
        </where>
    </select>
    
    <select id="selectCompanyVoiceById" parameterType="Long" resultMap="CompanyVoiceResult">
        <include refid="selectCompanyVoiceVo"/>
        where voice_id = #{voiceId}
    </select>
        
    <insert id="insertCompanyVoice" parameterType="CompanyVoice" useGeneratedKeys="true" keyProperty="voiceId">
        insert into company_voice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="times != null">times,</if>
            <if test="totalTimes != null">total_times,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="times != null">#{times},</if>
            <if test="totalTimes != null">#{totalTimes},</if>
         </trim>
    </insert>

    <update id="updateCompanyVoice" parameterType="CompanyVoice">
        update company_voice
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="times != null">times = #{times},</if>
            <if test="totalTimes != null">total_times = #{totalTimes},</if>
        </trim>
        where voice_id = #{voiceId}
    </update>

    <delete id="deleteCompanyVoiceById" parameterType="Long">
        delete from company_voice where voice_id = #{voiceId}
    </delete>

    <delete id="deleteCompanyVoiceByIds" parameterType="String">
        delete from company_voice where voice_id in 
        <foreach item="voiceId" collection="array" open="(" separator="," close=")">
            #{voiceId}
        </foreach>
    </delete>
    
</mapper>