<?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.CompanyVoicePackageOrderMapper">
    
    <resultMap type="CompanyVoicePackageOrder" id="CompanyVoicePackageOrderResult">
        <result property="orderId"    column="order_id"    />
        <result property="orderSn"    column="order_sn"    />
        <result property="companyId"    column="company_id"    />
        <result property="packageId"    column="package_id"    />
        <result property="price"    column="price"    />
        <result property="times"    column="times"    />
        <result property="remainTimes"    column="remain_times"    />
        <result property="isPay"    column="is_pay"    />
        <result property="createTime"    column="create_time"    />
        <result property="payTime"    column="pay_time"    />
        <result property="status"    column="status"    />
        <result property="payType"    column="pay_type"    />
        <result property="startTime"    column="start_time"    />
        <result property="limitTime"    column="limit_time"    />
    </resultMap>

    <sql id="selectCompanyVoicePackageOrderVo">
        select order_id, order_sn, company_id, package_id, price, times, remain_times, is_pay, create_time, pay_time, status, pay_type, start_time, limit_time from company_voice_package_order
    </sql>

    <select id="selectCompanyVoicePackageOrderList" parameterType="CompanyVoicePackageOrder" resultMap="CompanyVoicePackageOrderResult">
        <include refid="selectCompanyVoicePackageOrderVo"/>
        <where>  
            <if test="orderSn != null  and orderSn != ''"> and order_sn = #{orderSn}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="packageId != null "> and package_id = #{packageId}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="times != null "> and times = #{times}</if>
            <if test="remainTimes != null "> and remain_times = #{remainTimes}</if>
            <if test="isPay != null "> and is_pay = #{isPay}</if>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="payType != null "> and pay_type = #{payType}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="limitTime != null "> and limit_time = #{limitTime}</if>
        </where>
    </select>
    
    <select id="selectCompanyVoicePackageOrderById" parameterType="Long" resultMap="CompanyVoicePackageOrderResult">
        <include refid="selectCompanyVoicePackageOrderVo"/>
        where order_id = #{orderId}
    </select>
        
    <insert id="insertCompanyVoicePackageOrder" parameterType="CompanyVoicePackageOrder" useGeneratedKeys="true" keyProperty="orderId">
        insert into company_voice_package_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderSn != null">order_sn,</if>
            <if test="companyId != null">company_id,</if>
            <if test="packageId != null">package_id,</if>
            <if test="price != null">price,</if>
            <if test="times != null">times,</if>
            <if test="remainTimes != null">remain_times,</if>
            <if test="isPay != null">is_pay,</if>
            <if test="createTime != null">create_time,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="status != null">status,</if>
            <if test="payType != null">pay_type,</if>
            <if test="startTime != null">start_time,</if>
            <if test="limitTime != null">limit_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderSn != null">#{orderSn},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="packageId != null">#{packageId},</if>
            <if test="price != null">#{price},</if>
            <if test="times != null">#{times},</if>
            <if test="remainTimes != null">#{remainTimes},</if>
            <if test="isPay != null">#{isPay},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="status != null">#{status},</if>
            <if test="payType != null">#{payType},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="limitTime != null">#{limitTime},</if>
         </trim>
    </insert>

    <update id="updateCompanyVoicePackageOrder" parameterType="CompanyVoicePackageOrder">
        update company_voice_package_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderSn != null">order_sn = #{orderSn},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="packageId != null">package_id = #{packageId},</if>
            <if test="price != null">price = #{price},</if>
            <if test="times != null">times = #{times},</if>
            <if test="remainTimes != null">remain_times = #{remainTimes},</if>
            <if test="isPay != null">is_pay = #{isPay},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="limitTime != null">limit_time = #{limitTime},</if>
        </trim>
        where order_id = #{orderId}
    </update>

    <delete id="deleteCompanyVoicePackageOrderById" parameterType="Long">
        delete from company_voice_package_order where order_id = #{orderId}
    </delete>

    <delete id="deleteCompanyVoicePackageOrderByIds" parameterType="String">
        delete from company_voice_package_order where order_id in 
        <foreach item="orderId" collection="array" open="(" separator="," close=")">
            #{orderId}
        </foreach>
    </delete>
    
</mapper>