<?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.org.persistent.mapper.TablesMapper">
  <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.org.persistent.domain.Tables">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="shop_id" jdbcType="INTEGER" property="shopId" />
    <result column="table_name" jdbcType="VARCHAR" property="tableName" />
    <result column="comment" jdbcType="VARCHAR" property="comment" />
    <result column="seats" jdbcType="INTEGER" property="seats" />
    <result column="group_id" jdbcType="INTEGER" property="groupId" />
    <result column="order_id" jdbcType="VARCHAR" property="orderId" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="dishes" jdbcType="VARCHAR" property="dishes" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </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, shop_id, table_name, comment, seats, group_id, order_id, status, dishes, update_time
  </sql>
  <select id="selectByExample" parameterType="com.neusoft.smart.pos.org.persistent.domain.TablesExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from tables
    <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 tables
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from tables
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.neusoft.smart.pos.org.persistent.domain.TablesExample">
    delete from tables
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.neusoft.smart.pos.org.persistent.domain.Tables" useGeneratedKeys="true">
    insert into tables (shop_id, table_name, comment, 
      seats, group_id, order_id, 
      status, dishes, update_time
      )
    values (#{shopId,jdbcType=INTEGER}, #{tableName,jdbcType=VARCHAR}, #{comment,jdbcType=VARCHAR}, 
      #{seats,jdbcType=INTEGER}, #{groupId,jdbcType=INTEGER}, #{orderId,jdbcType=VARCHAR}, 
      #{status,jdbcType=INTEGER}, #{dishes,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.neusoft.smart.pos.org.persistent.domain.Tables" useGeneratedKeys="true">
    insert into tables
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="shopId != null">
        shop_id,
      </if>
      <if test="tableName != null">
        table_name,
      </if>
      <if test="comment != null">
        comment,
      </if>
      <if test="seats != null">
        seats,
      </if>
      <if test="groupId != null">
        group_id,
      </if>
      <if test="orderId != null">
        order_id,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="dishes != null">
        dishes,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="shopId != null">
        #{shopId,jdbcType=INTEGER},
      </if>
      <if test="tableName != null">
        #{tableName,jdbcType=VARCHAR},
      </if>
      <if test="comment != null">
        #{comment,jdbcType=VARCHAR},
      </if>
      <if test="seats != null">
        #{seats,jdbcType=INTEGER},
      </if>
      <if test="groupId != null">
        #{groupId,jdbcType=INTEGER},
      </if>
      <if test="orderId != null">
        #{orderId,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="dishes != null">
        #{dishes,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.neusoft.smart.pos.org.persistent.domain.TablesExample" resultType="java.lang.Integer">
    select count(*) from tables
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update tables
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.shopId != null">
        shop_id = #{record.shopId,jdbcType=INTEGER},
      </if>
      <if test="record.tableName != null">
        table_name = #{record.tableName,jdbcType=VARCHAR},
      </if>
      <if test="record.comment != null">
        comment = #{record.comment,jdbcType=VARCHAR},
      </if>
      <if test="record.seats != null">
        seats = #{record.seats,jdbcType=INTEGER},
      </if>
      <if test="record.groupId != null">
        group_id = #{record.groupId,jdbcType=INTEGER},
      </if>
      <if test="record.orderId != null">
        order_id = #{record.orderId,jdbcType=VARCHAR},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=INTEGER},
      </if>
      <if test="record.dishes != null">
        dishes = #{record.dishes,jdbcType=VARCHAR},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update tables
    set id = #{record.id,jdbcType=INTEGER},
      shop_id = #{record.shopId,jdbcType=INTEGER},
      table_name = #{record.tableName,jdbcType=VARCHAR},
      comment = #{record.comment,jdbcType=VARCHAR},
      seats = #{record.seats,jdbcType=INTEGER},
      group_id = #{record.groupId,jdbcType=INTEGER},
      order_id = #{record.orderId,jdbcType=VARCHAR},
      status = #{record.status,jdbcType=INTEGER},
      dishes = #{record.dishes,jdbcType=VARCHAR},
      update_time = #{record.updateTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.neusoft.smart.pos.org.persistent.domain.Tables">
    update tables
    <set>
      <if test="shopId != null">
        shop_id = #{shopId,jdbcType=INTEGER},
      </if>
      <if test="tableName != null">
        table_name = #{tableName,jdbcType=VARCHAR},
      </if>
      <if test="comment != null">
        comment = #{comment,jdbcType=VARCHAR},
      </if>
      <if test="seats != null">
        seats = #{seats,jdbcType=INTEGER},
      </if>
      <if test="groupId != null">
        group_id = #{groupId,jdbcType=INTEGER},
      </if>
      <if test="orderId != null">
        order_id = #{orderId,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="dishes != null">
        dishes = #{dishes,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.neusoft.smart.pos.org.persistent.domain.Tables">
    update tables
    set shop_id = #{shopId,jdbcType=INTEGER},
      table_name = #{tableName,jdbcType=VARCHAR},
      comment = #{comment,jdbcType=VARCHAR},
      seats = #{seats,jdbcType=INTEGER},
      group_id = #{groupId,jdbcType=INTEGER},
      order_id = #{orderId,jdbcType=VARCHAR},
      status = #{status,jdbcType=INTEGER},
      dishes = #{dishes,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <insert id="batchInsert">
    <if test="items.get(0) != null">
            insert into tables  (shop_id, table_name, comment, 
        seats, group_id, order_id, 
        status, dishes, update_time
        )
      values
      <foreach collection="items" item="item" index="index" separator=",">
      (#{item.shopId,jdbcType=INTEGER}, #{item.tableName,jdbcType=VARCHAR}, #{item.comment,jdbcType=VARCHAR}, 
        #{item.seats,jdbcType=INTEGER}, #{item.groupId,jdbcType=INTEGER}, #{item.orderId,jdbcType=VARCHAR}, 
        #{item.status,jdbcType=INTEGER}, #{item.dishes,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP}
        )
      </foreach>
    </if>
  </insert>

  <select id="countByTableName" resultType="java.lang.Integer">
        SELECT COUNT(1)
        FROM tables
        WHERE table_name = #{tableName,jdbcType=VARCHAR} and shop_id = #{shopId,jdbcType=INTEGER}
    </select>

  <select id="selectByShopId" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List" />
    FROM tables
    WHERE shop_id = #{shopId,jdbcType=INTEGER}
    ORDER BY id DESC
  </select>


  <select id="countByTableName2" resultType="java.lang.Integer">
    SELECT COUNT(1)
    FROM tables
    WHERE table_name = #{tableName,jdbcType=VARCHAR} AND shop_id = #{shopId,jdbcType=INTEGER} AND id &lt;&gt; #{id, jdbcType=INTEGER}
  </select>
  <select id="countByGroup" resultType="java.lang.Integer">
    SELECT COUNT(1)
    FROM tables
    WHERE group_id = #{groupId,jdbcType=INTEGER}
  </select>
</mapper>