<?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.buy507.mall.mapper.UmsMemberOrderQueueMapper">
  <resultMap id="BaseResultMap" type="com.buy507.mall.model.UmsMemberOrderQueue">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="member_id" jdbcType="BIGINT" property="memberId" />
    <result column="order_id" jdbcType="BIGINT" property="orderId" />
    <result column="order_amount" jdbcType="DECIMAL" property="orderAmount" />
    <result column="queue_index" jdbcType="BIGINT" property="queueIndex" />
    <result column="quit_queue_mark" jdbcType="INTEGER" property="quitQueueMark" />
    <result column="queue_type" jdbcType="INTEGER" property="queueType" />
    <result column="accelerate_switch" jdbcType="INTEGER" property="accelerateSwitch" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="nick" jdbcType="VARCHAR" property="nick" />
    <result column="accelerate_order_id" jdbcType="BIGINT" property="accelerateOrderId" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="high_member_id" jdbcType="BIGINT" property="highMemberId" />
    <result column="avatar" jdbcType="VARCHAR" property="avatar" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, member_id, order_id, order_amount, queue_index, quit_queue_mark, queue_type, 
    accelerate_switch, create_time, nick, accelerate_order_id, phone, high_member_id, avatar
  </sql>
  <select id="selectByExample" parameterType="com.buy507.mall.model.UmsMemberOrderQueueExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from ums_member_order_queue
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from ums_member_order_queue
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ums_member_order_queue
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.buy507.mall.model.UmsMemberOrderQueueExample">
    delete from ums_member_order_queue
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.buy507.mall.model.UmsMemberOrderQueue">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into ums_member_order_queue (member_id, order_id, order_amount, 
      queue_index, quit_queue_mark, queue_type,
      accelerate_switch, create_time, nick,accelerate_order_id, phone, high_member_id, avatar)
    values (#{memberId,jdbcType=BIGINT}, #{orderId,jdbcType=BIGINT}, #{orderAmount,jdbcType=DECIMAL}, 
      #{queueIndex,jdbcType=BIGINT}, #{quitQueueMark,jdbcType=INTEGER}, #{queueType,jdbcType=INTEGER}, 
      #{accelerateSwitch,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},#{nick,jdbcType=VARCHAR},#{accelerateOrderId,jdbcType=BIGINT},#{phone,jdbcType=VARCHAR},#{highMemberId,jdbcType=BIGINT},#{avatar,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.buy507.mall.model.UmsMemberOrderQueue">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into ums_member_order_queue
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="memberId != null">
        member_id,
      </if>
      <if test="orderId != null">
        order_id,
      </if>
      <if test="orderAmount != null">
        order_amount,
      </if>
      <if test="queueIndex != null">
        queue_index,
      </if>
      <if test="quitQueueMark != null">
        quit_queue_mark,
      </if>
      <if test="queueType != null">
        queue_type,
      </if>
      <if test="accelerateSwitch != null">
        accelerate_switch,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="memberId != null">
        #{memberId,jdbcType=BIGINT},
      </if>
      <if test="orderId != null">
        #{orderId,jdbcType=BIGINT},
      </if>
      <if test="orderAmount != null">
        #{orderAmount,jdbcType=DECIMAL},
      </if>
      <if test="queueIndex != null">
        #{queueIndex,jdbcType=BIGINT},
      </if>
      <if test="quitQueueMark != null">
        #{quitQueueMark,jdbcType=INTEGER},
      </if>
      <if test="queueType != null">
        #{queueType,jdbcType=INTEGER},
      </if>
      <if test="accelerateSwitch != null">
        #{accelerateSwitch,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.buy507.mall.model.UmsMemberOrderQueueExample" resultType="java.lang.Long">
    select count(*) from ums_member_order_queue
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update ums_member_order_queue
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.memberId != null">
        member_id = #{record.memberId,jdbcType=BIGINT},
      </if>
      <if test="record.orderId != null">
        order_id = #{record.orderId,jdbcType=BIGINT},
      </if>
      <if test="record.orderAmount != null">
        order_amount = #{record.orderAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.queueIndex != null">
        queue_index = #{record.queueIndex,jdbcType=BIGINT},
      </if>
      <if test="record.quitQueueMark != null">
        quit_queue_mark = #{record.quitQueueMark,jdbcType=INTEGER},
      </if>
      <if test="record.queueType != null">
        queue_type = #{record.queueType,jdbcType=INTEGER},
      </if>
      <if test="record.accelerateSwitch != null">
        accelerate_switch = #{record.accelerateSwitch,jdbcType=INTEGER},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update ums_member_order_queue
    set id = #{record.id,jdbcType=BIGINT},
      member_id = #{record.memberId,jdbcType=BIGINT},
      order_id = #{record.orderId,jdbcType=BIGINT},
      order_amount = #{record.orderAmount,jdbcType=DECIMAL},
      queue_index = #{record.queueIndex,jdbcType=BIGINT},
      quit_queue_mark = #{record.quitQueueMark,jdbcType=INTEGER},
      queue_type = #{record.queueType,jdbcType=INTEGER},
      accelerate_switch = #{record.accelerateSwitch,jdbcType=INTEGER},
      create_time = #{record.createTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.buy507.mall.model.UmsMemberOrderQueue">
    update ums_member_order_queue
    <set>
      <if test="memberId != null">
        member_id = #{memberId,jdbcType=BIGINT},
      </if>
      <if test="orderId != null">
        order_id = #{orderId,jdbcType=BIGINT},
      </if>
      <if test="orderAmount != null">
        order_amount = #{orderAmount,jdbcType=DECIMAL},
      </if>
      <if test="queueIndex != null">
        queue_index = #{queueIndex,jdbcType=BIGINT},
      </if>
      <if test="quitQueueMark != null">
        quit_queue_mark = #{quitQueueMark,jdbcType=INTEGER},
      </if>
      <if test="queueType != null">
        queue_type = #{queueType,jdbcType=INTEGER},
      </if>
      <if test="accelerateSwitch != null">
        accelerate_switch = #{accelerateSwitch,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.buy507.mall.model.UmsMemberOrderQueue">
    update ums_member_order_queue
    set member_id = #{memberId,jdbcType=BIGINT},
      order_id = #{orderId,jdbcType=BIGINT},
      order_amount = #{orderAmount,jdbcType=DECIMAL},
      queue_index = #{queueIndex,jdbcType=BIGINT},
      quit_queue_mark = #{quitQueueMark,jdbcType=INTEGER},
      queue_type = #{queueType,jdbcType=INTEGER},
      accelerate_switch = #{accelerateSwitch,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>

  <select id="getNextOrderQueueInfo" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ums_member_order_queue
    where quit_queue_mark = #{state,jdbcType=INTEGER}
    ORDER BY `create_time` ASC LIMIT 1
  </select>
</mapper>