<?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.CompanySmsPackageMapper">
    
    <resultMap type="CompanySmsPackage" id="CompanySmsPackageResult">
        <result property="packageId"    column="package_id"    />
        <result property="title"    column="title"    />
        <result property="price"    column="price"    />
        <result property="smsCount"    column="sms_count"    />
        <result property="remark"    column="remark"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectCompanySmsPackageVo">
        select package_id, title, price, sms_count, remark, status from company_sms_package
    </sql>

    <select id="selectCompanySmsPackageList" parameterType="CompanySmsPackage" resultMap="CompanySmsPackageResult">
        <include refid="selectCompanySmsPackageVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="smsCount != null "> and sms_count = #{smsCount}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectCompanySmsPackageById" parameterType="Long" resultMap="CompanySmsPackageResult">
        <include refid="selectCompanySmsPackageVo"/>
        where package_id = #{packageId}
    </select>
        
    <insert id="insertCompanySmsPackage" parameterType="CompanySmsPackage" useGeneratedKeys="true" keyProperty="packageId">
        insert into company_sms_package
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="price != null">price,</if>
            <if test="smsCount != null">sms_count,</if>
            <if test="remark != null">remark,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="price != null">#{price},</if>
            <if test="smsCount != null">#{smsCount},</if>
            <if test="remark != null">#{remark},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateCompanySmsPackage" parameterType="CompanySmsPackage">
        update company_sms_package
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="price != null">price = #{price},</if>
            <if test="smsCount != null">sms_count = #{smsCount},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where package_id = #{packageId}
    </update>

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

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