<?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.slodon.b2b2c.dao.write.promotion.SeckillOrderExtendWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.promotion.pojo.SeckillOrderExtend">
    <id column="extern_id" property="externId" />
    <result column="order_sn" property="orderSn" />
    <result column="seckill_id" property="seckillId" />
    <result column="seckill_price" property="seckillPrice" />
    <result column="stage_id" property="stageId" />
    <result column="stage_productstage_product_id" property="stageProductstageProductId" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="externId != null">
        `extern_id`,
      </if>
      <if test="orderSn != null">
        `order_sn`,
      </if>
      <if test="seckillId != null">
        `seckill_id`,
      </if>
      <if test="seckillPrice != null">
        `seckill_price`,
      </if>
      <if test="stageId != null">
        `stage_id`,
      </if>
      <if test="stageProductstageProductId != null">
        `stage_productstage_product_id`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `extern_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.externIdNotEquals != null">
          AND `extern_id` != #{example.externIdNotEquals}
        </if>
        <if test="example.externIdIn != null">
          AND `extern_id` in (${example.externIdIn})
        </if>
        <if test="example.orderSn != null">
          AND `order_sn` = #{example.orderSn}
        </if>
        <if test="example.orderSnLike != null">
          AND `order_sn` like concat('%',#{example.orderSnLike},'%')
        </if>
        <if test="example.seckillId != null">
          AND `seckill_id` = #{example.seckillId}
        </if>
        <if test="example.seckillPrice != null">
          AND `seckill_price` = #{example.seckillPrice}
        </if>
        <if test="example.stageId != null">
          AND `stage_id` = #{example.stageId}
        </if>
        <if test="example.stageProductstageProductId != null">
          AND `stage_productstage_product_id` = #{example.stageProductstageProductId}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `extern_id` DESC
  </sql>
  <sql id="orderByOther">
    order by ${example.orderBy}
  </sql>
  <!--分组条件-->
  <sql id="groupBy">
    group by ${example.groupBy}
  </sql>
  <!--分页条件-->
  <sql id="limit">
    <if test="size != null and size &gt; 0">
      limit #{startRow},#{size}
    </if>
  </sql>
  <!--查询符合条件的记录数-->
  <select id="countByExample" parameterType="com.slodon.b2b2c.promotion.example.SeckillOrderExtendExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `promotion_seckill_order_extend`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_seckill_order_extend`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_seckill_order_extend`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(所有字段)-->
  <select id="listPageByExample" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_seckill_order_extend`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--查询符合条件的记录(指定字段)-->
  <select id="listFieldsByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `promotion_seckill_order_extend`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(指定字段)-->
  <select id="listFieldsPageByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `promotion_seckill_order_extend`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--根据条件删除记录，可多条删除-->
  <delete id="deleteByExample">
    DELETE FROM `promotion_seckill_order_extend`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `promotion_seckill_order_extend`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="extern_id" keyProperty="externId" parameterType="com.slodon.b2b2c.promotion.pojo.SeckillOrderExtend" useGeneratedKeys="true">
    INSERT INTO `promotion_seckill_order_extend`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="externId != null">
        #{externId},
      </if>
      <if test="orderSn != null">
        #{orderSn},
      </if>
      <if test="seckillId != null">
        #{seckillId},
      </if>
      <if test="seckillPrice != null">
        #{seckillPrice},
      </if>
      <if test="stageId != null">
        #{stageId},
      </if>
      <if test="stageProductstageProductId != null">
        #{stageProductstageProductId},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `promotion_seckill_order_extend`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.orderSn != null">
        `order_sn` = #{record.orderSn},
      </if>
      <if test="record.seckillId != null">
        `seckill_id` = #{record.seckillId},
      </if>
      <if test="record.seckillPrice != null">
        `seckill_price` = #{record.seckillPrice},
      </if>
      <if test="record.stageId != null">
        `stage_id` = #{record.stageId},
      </if>
      <if test="record.stageProductstageProductId != null">
        `stage_productstage_product_id` = #{record.stageProductstageProductId},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `promotion_seckill_order_extend`
    <trim prefix="SET" suffixOverrides=",">
      <if test="orderSn != null">
        `order_sn` = #{orderSn},
      </if>
      <if test="seckillId != null">
        `seckill_id` = #{seckillId},
      </if>
      <if test="seckillPrice != null">
        `seckill_price` = #{seckillPrice},
      </if>
      <if test="stageId != null">
        `stage_id` = #{stageId},
      </if>
      <if test="stageProductstageProductId != null">
        `stage_productstage_product_id` = #{stageProductstageProductId},
      </if>
    </trim>
    WHERE `extern_id` = #{externId}
  </update>
</mapper>