<?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.neusoft.smart.pos.inventory.persistent.mapper.InventoryGoodsLockInfoMapper">
  <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.inventory.persistent.domain.InventoryGoodsLockInfo">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="order_id" jdbcType="VARCHAR" property="orderId" />
    <result column="goods_id" jdbcType="INTEGER" property="goodsId" />
    <result column="goods_batch_id" jdbcType="INTEGER" property="goodsBatchId" />
    <result column="before_lock_count" jdbcType="INTEGER" property="beforeLockCount" />
    <result column="lock_count" jdbcType="INTEGER" property="lockCount" />
    <result column="lock_time" jdbcType="TIMESTAMP" property="lockTime" />
    <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="version" jdbcType="INTEGER" property="version" />
  </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, order_id, goods_id, goods_batch_id, before_lock_count, lock_count, lock_time, 
    expire_time, status, version
  </sql>
  <select id="selectByExample" parameterType="com.neusoft.smart.pos.inventory.persistent.domain.InventoryGoodsLockInfoExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from inventory_goods_lock_info
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    <if test="offset != null and limit != null">
      limit ${offset}, ${limit}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from inventory_goods_lock_info
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from inventory_goods_lock_info
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.neusoft.smart.pos.inventory.persistent.domain.InventoryGoodsLockInfoExample">
    delete from inventory_goods_lock_info
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.neusoft.smart.pos.inventory.persistent.domain.InventoryGoodsLockInfo" useGeneratedKeys="true">
    insert into inventory_goods_lock_info (order_id, goods_id, goods_batch_id, 
      before_lock_count, lock_count, lock_time, 
      expire_time, status, version
      )
    values (#{orderId,jdbcType=VARCHAR}, #{goodsId,jdbcType=INTEGER}, #{goodsBatchId,jdbcType=INTEGER}, 
      #{beforeLockCount,jdbcType=INTEGER}, #{lockCount,jdbcType=INTEGER}, #{lockTime,jdbcType=TIMESTAMP}, 
    #{expireTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, 0
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.neusoft.smart.pos.inventory.persistent.domain.InventoryGoodsLockInfo" useGeneratedKeys="true">
    insert into inventory_goods_lock_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="orderId != null">
        order_id,
      </if>
      <if test="goodsId != null">
        goods_id,
      </if>
      <if test="goodsBatchId != null">
        goods_batch_id,
      </if>
      <if test="beforeLockCount != null">
        before_lock_count,
      </if>
      <if test="lockCount != null">
        lock_count,
      </if>
      <if test="lockTime != null">
        lock_time,
      </if>
      <if test="expireTime != null">
        expire_time,
      </if>
      <if test="status != null">
        status,
      </if>
      version,
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="orderId != null">
        #{orderId,jdbcType=VARCHAR},
      </if>
      <if test="goodsId != null">
        #{goodsId,jdbcType=INTEGER},
      </if>
      <if test="goodsBatchId != null">
        #{goodsBatchId,jdbcType=INTEGER},
      </if>
      <if test="beforeLockCount != null">
        #{beforeLockCount,jdbcType=INTEGER},
      </if>
      <if test="lockCount != null">
        #{lockCount,jdbcType=INTEGER},
      </if>
      <if test="lockTime != null">
        #{lockTime,jdbcType=TIMESTAMP},
      </if>
      <if test="expireTime != null">
        #{expireTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      0,
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.neusoft.smart.pos.inventory.persistent.domain.InventoryGoodsLockInfoExample" resultType="java.lang.Integer">
    select count(*) from inventory_goods_lock_info
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update inventory_goods_lock_info
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.orderId != null">
        order_id = #{record.orderId,jdbcType=VARCHAR},
      </if>
      <if test="record.goodsId != null">
        goods_id = #{record.goodsId,jdbcType=INTEGER},
      </if>
      <if test="record.goodsBatchId != null">
        goods_batch_id = #{record.goodsBatchId,jdbcType=INTEGER},
      </if>
      <if test="record.beforeLockCount != null">
        before_lock_count = #{record.beforeLockCount,jdbcType=INTEGER},
      </if>
      <if test="record.lockCount != null">
        lock_count = #{record.lockCount,jdbcType=INTEGER},
      </if>
      <if test="record.lockTime != null">
        lock_time = #{record.lockTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.expireTime != null">
        expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=INTEGER},
      </if>
      version = version + 1,
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update inventory_goods_lock_info
    set id = #{record.id,jdbcType=INTEGER},
      order_id = #{record.orderId,jdbcType=VARCHAR},
      goods_id = #{record.goodsId,jdbcType=INTEGER},
      goods_batch_id = #{record.goodsBatchId,jdbcType=INTEGER},
      before_lock_count = #{record.beforeLockCount,jdbcType=INTEGER},
      lock_count = #{record.lockCount,jdbcType=INTEGER},
      lock_time = #{record.lockTime,jdbcType=TIMESTAMP},
      expire_time = #{record.expireTime,jdbcType=TIMESTAMP},
      status = #{record.status,jdbcType=INTEGER},
      version = version + 1
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.neusoft.smart.pos.inventory.persistent.domain.InventoryGoodsLockInfo">
    update inventory_goods_lock_info
    <set>
      <if test="orderId != null">
        order_id = #{orderId,jdbcType=VARCHAR},
      </if>
      <if test="goodsId != null">
        goods_id = #{goodsId,jdbcType=INTEGER},
      </if>
      <if test="goodsBatchId != null">
        goods_batch_id = #{goodsBatchId,jdbcType=INTEGER},
      </if>
      <if test="beforeLockCount != null">
        before_lock_count = #{beforeLockCount,jdbcType=INTEGER},
      </if>
      <if test="lockCount != null">
        lock_count = #{lockCount,jdbcType=INTEGER},
      </if>
      <if test="lockTime != null">
        lock_time = #{lockTime,jdbcType=TIMESTAMP},
      </if>
      <if test="expireTime != null">
        expire_time = #{expireTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      version = version + 1,
    </set>
    where id = #{id,jdbcType=INTEGER} and version = #{version,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.neusoft.smart.pos.inventory.persistent.domain.InventoryGoodsLockInfo">
    update inventory_goods_lock_info
    set order_id = #{orderId,jdbcType=VARCHAR},
      goods_id = #{goodsId,jdbcType=INTEGER},
      goods_batch_id = #{goodsBatchId,jdbcType=INTEGER},
      before_lock_count = #{beforeLockCount,jdbcType=INTEGER},
      lock_count = #{lockCount,jdbcType=INTEGER},
      lock_time = #{lockTime,jdbcType=TIMESTAMP},
      expire_time = #{expireTime,jdbcType=TIMESTAMP},
      status = #{status,jdbcType=INTEGER},
      version = version + 1
    where id = #{id,jdbcType=INTEGER} and version = #{version,jdbcType=INTEGER}
  </update>
  <insert id="batchInsert">
    <if test="items.get(0) != null">
            insert into inventory_goods_lock_info  (order_id, goods_id, goods_batch_id, 
        before_lock_count, lock_count, lock_time, 
        expire_time, status, version
        )
      values
      <foreach collection="items" item="item" index="index" separator=",">
      (#{item.orderId,jdbcType=VARCHAR}, #{item.goodsId,jdbcType=INTEGER}, #{item.goodsBatchId,jdbcType=INTEGER}, 
        #{item.beforeLockCount,jdbcType=INTEGER}, #{item.lockCount,jdbcType=INTEGER}, #{item.lockTime,jdbcType=TIMESTAMP}, 
      #{item.expireTime,jdbcType=TIMESTAMP}, #{item.status,jdbcType=INTEGER}, 0
        )
      </foreach>
    </if>
  </insert>
</mapper>