<?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.CompanySmsMapper">
    
    <resultMap type="CompanySms" id="CompanySmsResult">
        <result property="smsId"    column="sms_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="remainSmsCount"    column="remain_sms_count"    />
        <result property="totalSmsCount"    column="total_sms_count"    />
    </resultMap>

    <sql id="selectCompanySmsVo">
        select sms_id, company_id, remain_sms_count, total_sms_count from company_sms
    </sql>


    
    <select id="selectCompanySmsById" parameterType="Long" resultMap="CompanySmsResult">
        <include refid="selectCompanySmsVo"/>
        where sms_id = #{smsId}
    </select>
        
    <insert id="insertCompanySms" parameterType="CompanySms" useGeneratedKeys="true" keyProperty="smsId">
        insert into company_sms
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="remainSmsCount != null">remain_sms_count,</if>
            <if test="totalSmsCount != null">total_sms_count,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="remainSmsCount != null">#{remainSmsCount},</if>
            <if test="totalSmsCount != null">#{totalSmsCount},</if>
         </trim>
    </insert>

    <update id="updateCompanySms" parameterType="CompanySms">
        update company_sms
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="remainSmsCount != null">remain_sms_count = #{remainSmsCount},</if>
            <if test="totalSmsCount != null">total_sms_count = #{totalSmsCount},</if>
        </trim>
        where sms_id = #{smsId}
    </update>

    <delete id="deleteCompanySmsById" parameterType="Long">
        delete from company_sms where sms_id = #{smsId}
    </delete>

    <delete id="deleteCompanySmsByIds" parameterType="String">
        delete from company_sms where sms_id in 
        <foreach item="smsId" collection="array" open="(" separator="," close=")">
            #{smsId}
        </foreach>
    </delete>
    
</mapper>