<?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.seckill.mapper.SeckillStockPointSkuMapper">
  <resultMap id="seckillStockPointSkuMap" type="com.tmerclub.cloud.seckill.model.SeckillStockPointSku">
    <id column="seckill_stock_point_sku_id" property="seckillStockPointSkuId" />
    <result column="stock_point_id" property="stockPointId"/>
    <result column="stock_point_type" property="stockPointType"/>
    <result column="sku_id" property="skuId"/>
    <result column="seckill_sku_id" property="seckillSkuId"/>
    <result column="status" property="status"/>
    <result column="create_time" property="createTime"/>
    <result column="update_time" property="updateTime"/>
    <result column="type" property="type"/>
    <result column="seckill_origin_stocks" property="seckillOriginStocks"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `seckill_stock_point_sku_id`,`stock_point_id`,`stock_point_type`,`sku_id`,`seckill_sku_id`,`status`,`create_time`,`update_time`,`type`
  </sql>
  <select id="list" resultMap="seckillStockPointSkuMap">
    select <include refid="Vo_Column_List"/> from seckill_stock_point_sku order by seckill_stock_point_sku_id desc
  </select>
  <select id="getBySeckillStockPointSkuId" resultMap="seckillStockPointSkuMap">
    select <include refid="Vo_Column_List"/> from seckill_stock_point_sku where seckill_stock_point_sku_id = #{seckillStockPointSkuId}
  </select>
  <insert id="save">
    insert into seckill_stock_point_sku (`stock_point_id`,`stock_point_type`,`sku_id`,`seckill_sku_id`,`status`,`type`)
    values (#{seckillStockPointSku.stockPointId},#{seckillStockPointSku.stockPointType},#{seckillStockPointSku.skuId},#{seckillStockPointSku.seckillSkuId},#{seckillStockPointSku.status},#{seckillStockPointSku.type});
  </insert>
  <update id="update">
    update seckill_stock_point_sku
    <set>
      <if test="seckillStockPointSku.stockPointId != null">
        `stock_point_id` = #{seckillStockPointSku.stockPointId},
      </if>
      <if test="seckillStockPointSku.stockPointType != null">
        `stock_point_type` = #{seckillStockPointSku.stockPointType},
      </if>
      <if test="seckillStockPointSku.skuId != null">
        `sku_id` = #{seckillStockPointSku.skuId},
      </if>
      <if test="seckillStockPointSku.seckillSkuId != null">
        `seckill_sku_id` = #{seckillStockPointSku.seckillSkuId},
      </if>
      <if test="seckillStockPointSku.status != null">
        `status` = #{seckillStockPointSku.status},
      </if>
      <if test="seckillStockPointSku.type != null">
        `type` = #{seckillStockPointSku.type},
      </if>
    </set>
    where seckill_stock_point_sku_id = #{seckillStockPointSku.seckillStockPointSkuId}
  </update>
  <delete id="deleteById">
    delete from seckill_stock_point_sku where seckill_stock_point_sku_id = #{seckillStockPointSkuId}
  </delete>

  <select id="batchSave">
    insert into seckill_stock_point_sku (`stock_point_id`,`stock_point_type`,`sku_id`,`seckill_sku_id`,`status`,`type`,`seckill_origin_stocks`) values
    <foreach collection="seckillStockPointSkuList" item="stockPointSku" separator=",">
      (#{stockPointSku.stockPointId},#{stockPointSku.stockPointType},#{stockPointSku.skuId},#{stockPointSku.seckillSkuId},#{stockPointSku.status}, #{stockPointSku.type}, #{stockPointSku.stock})
    </foreach>
  </select>
</mapper>
