<?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.CompanyVoicePackageMapper">
    
    <resultMap type="CompanyVoicePackage" id="CompanyVoicePackageResult">
        <result property="packageId"    column="package_id"    />
        <result property="packageName"    column="package_name"    />
        <result property="price"    column="price"    />
        <result property="times"    column="times"    />
        <result property="status"    column="status"    />
        <result property="expirePrice"    column="expire_price"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCompanyVoicePackageVo">
        select package_id, package_name, price, times, status, expire_price, remark from company_voice_package
    </sql>

    <select id="selectCompanyVoicePackageList" parameterType="CompanyVoicePackage" resultMap="CompanyVoicePackageResult">
        <include refid="selectCompanyVoicePackageVo"/>
        <where>  
            <if test="packageName != null  and packageName != ''"> and package_name like concat('%', #{packageName}, '%')</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="times != null "> and times = #{times}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="expirePrice != null "> and expire_price = #{expirePrice}</if>
        </where>
    </select>
    
    <select id="selectCompanyVoicePackageById" parameterType="Long" resultMap="CompanyVoicePackageResult">
        <include refid="selectCompanyVoicePackageVo"/>
        where package_id = #{packageId}
    </select>
        
    <insert id="insertCompanyVoicePackage" parameterType="CompanyVoicePackage" useGeneratedKeys="true" keyProperty="packageId">
        insert into company_voice_package
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="packageName != null">package_name,</if>
            <if test="price != null">price,</if>
            <if test="times != null">times,</if>
            <if test="status != null">status,</if>
            <if test="expirePrice != null">expire_price,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="packageName != null">#{packageName},</if>
            <if test="price != null">#{price},</if>
            <if test="times != null">#{times},</if>
            <if test="status != null">#{status},</if>
            <if test="expirePrice != null">#{expirePrice},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCompanyVoicePackage" parameterType="CompanyVoicePackage">
        update company_voice_package
        <trim prefix="SET" suffixOverrides=",">
            <if test="packageName != null">package_name = #{packageName},</if>
            <if test="price != null">price = #{price},</if>
            <if test="times != null">times = #{times},</if>
            <if test="status != null">status = #{status},</if>
            <if test="expirePrice != null">expire_price = #{expirePrice},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where package_id = #{packageId}
    </update>

    <delete id="deleteCompanyVoicePackageById" parameterType="Long">
        delete from company_voice_package where package_id = #{packageId}
    </delete>

    <delete id="deleteCompanyVoicePackageByIds" parameterType="String">
        delete from company_voice_package where package_id in 
        <foreach item="packageId" collection="array" open="(" separator="," close=")">
            #{packageId}
        </foreach>
    </delete>
    
</mapper>