<?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.tmerclub.cloud.order.mapper.OrderPreSaleInfoMapper">
  <resultMap id="orderPreSaleInfoMap" type="com.tmerclub.cloud.order.model.OrderPreSaleInfo">
    <id column="order_pre_sale_info_id" property="orderPreSaleInfoId" />
    <result column="update_time" property="updateTime"/>
    <result column="create_time" property="createTime"/>
    <result column="order_id" property="orderId"/>
    <result column="user_id" property="userId"/>
    <result column="deposit_amount" property="depositAmount"/>
    <result column="deposit_reduce_amount" property="depositReduceAmount"/>
    <result column="deposit_expansion_amount" property="depositExpansionAmount"/>
    <result column="balance_amount" property="balanceAmount"/>
    <result column="pre_sale_type" property="preSaleType"/>
    <result column="pay_status" property="payStatus"/>
    <result column="balance_start_time" property="balanceStartTime"/>
    <result column="balance_end_time" property="balanceEndTime"/>
    <result column="balance_pay_time" property="balancePayTime"/>
    <result column="pre_sale_delivery_type" property="preSaleDeliveryType"/>
    <result column="pre_sale_delivery_time" property="preSaleDeliveryTime"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `order_pre_sale_info_id`,`update_time`,`create_time`,`order_id`,`deposit_amount`,`deposit_reduce_amount`,`pay_status`,`deposit_expansion_amount`,`balance_amount`,pre_sale_type,`balance_start_time`,`balance_end_time`, `balance_pay_time`, `pre_sale_delivery_type`,`pre_sale_delivery_time`
  </sql>

  <select id="getByOrderId" resultType="com.tmerclub.cloud.common.order.vo.OrderPreSaleInfoVO">
    select <include refid="Vo_Column_List"/> from order_pre_sale_info where order_id = #{orderId}
  </select>

  <select id="listByOrderIds" resultMap="orderPreSaleInfoMap">
    select <include refid="Vo_Column_List"/> from order_pre_sale_info where order_id in
    <foreach collection="orderIds" item="orderId" open="(" separator="," close=")">
        #{orderId}
    </foreach>
  </select>
  <insert id="save">
    insert into order_pre_sale_info (`order_pre_sale_info_id`,`order_id`,`deposit_amount`,`deposit_expansion_amount`,`deposit_reduce_amount`,`balance_amount`,`pre_sale_type`,`balance_start_time`,`balance_end_time`,`pre_sale_delivery_type`,`pre_sale_delivery_time`,`create_time`)
    values (#{orderPreSaleInfo.orderPreSaleInfoId},#{orderPreSaleInfo.orderId},#{orderPreSaleInfo.depositAmount},#{orderPreSaleInfo.depositExpansionAmount},#{orderPreSaleInfo.depositReduceAmount},#{orderPreSaleInfo.balanceAmount},#{orderPreSaleInfo.preSaleType},#{orderPreSaleInfo.balanceStartTime},#{orderPreSaleInfo.balanceEndTime},#{orderPreSaleInfo.preSaleDeliveryType},#{orderPreSaleInfo.preSaleDeliveryTime},#{orderPreSaleInfo.createTime});
  </insert>
  <insert id="saveBatch">
    insert into order_pre_sale_info (`order_pre_sale_info_id`,`order_id`,`deposit_amount`,`deposit_expansion_amount`,`deposit_reduce_amount`,`balance_amount`,`pre_sale_type`,`balance_start_time`,`balance_end_time`,`pre_sale_delivery_type`,`pre_sale_delivery_time`,`create_time`)
    values
    <foreach collection="orderPreSaleInfos" item="orderPreSaleInfo" separator=",">
        (#{orderPreSaleInfo.orderPreSaleInfoId},#{orderPreSaleInfo.orderId},#{orderPreSaleInfo.depositAmount},#{orderPreSaleInfo.depositExpansionAmount},#{orderPreSaleInfo.depositReduceAmount},#{orderPreSaleInfo.balanceAmount},#{orderPreSaleInfo.preSaleType},#{orderPreSaleInfo.balanceStartTime},#{orderPreSaleInfo.balanceEndTime},#{orderPreSaleInfo.preSaleDeliveryType},#{orderPreSaleInfo.preSaleDeliveryTime},#{orderPreSaleInfo.createTime})
    </foreach>
  </insert>

  <update id="update">
    update order_pre_sale_info
    <set>
      <if test="orderPreSaleInfo.depositAmount != null">
        `deposit_amount` = #{orderPreSaleInfo.depositAmount},
      </if>
      <if test="orderPreSaleInfo.depositExpansionAmount != null">
        `deposit_expansion_amount` = #{orderPreSaleInfo.depositExpansionAmount},
      </if>
      <if test="orderPreSaleInfo.balanceAmount != null">
        `balance_amount` = #{orderPreSaleInfo.balanceAmount},
      </if>
      <if test="orderPreSaleInfo.balanceStartTime != null">
        `balance_start_time` = #{orderPreSaleInfo.balanceStartTime},
      </if>
      <if test="orderPreSaleInfo.balanceEndTime != null">
        `balance_end_time` = #{orderPreSaleInfo.balanceEndTime},
      </if>
      <if test="orderPreSaleInfo.payStatus != null">
        `pay_status` = #{orderPreSaleInfo.payStatus},
      </if>
      <if test="orderPreSaleInfo.preSaleDeliveryType != null">
        `pre_sale_delivery_type` = #{orderPreSaleInfo.preSaleDeliveryType},
      </if>
      <if test="orderPreSaleInfo.preSaleDeliveryTime != null">
        `pre_sale_delivery_time` = #{orderPreSaleInfo.preSaleDeliveryTime},
      </if>
      <if test="orderPreSaleInfo.balancePayTime != null">
        `balance_pay_time` = #{orderPreSaleInfo.balancePayTime},
      </if>
    </set>
    where order_pre_sale_info_id = #{orderPreSaleInfo.orderPreSaleInfoId}
  </update>

</mapper>
