<?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.trade.persistent.mapper.BillMasterMapper">
  <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.trade.persistent.domain.BillMaster">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="bill_number" jdbcType="VARCHAR" property="billNumber" />
    <result column="bill_name" jdbcType="VARCHAR" property="billName" />
    <result column="org_id" jdbcType="INTEGER" property="orgId" />
    <result column="shop_id" jdbcType="INTEGER" property="shopId" />
    <result column="bill_amount" jdbcType="DECIMAL" property="billAmount" />
    <result column="accept_status" jdbcType="VARCHAR" property="acceptStatus" />
    <result column="version" jdbcType="INTEGER" property="version" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="accept_time" jdbcType="TIMESTAMP" property="acceptTime" />
    <result column="cycle_start_time" jdbcType="TIMESTAMP" property="cycleStartTime" />
    <result column="cycle_end_time" jdbcType="TIMESTAMP" property="cycleEndTime" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="VARCHAR" property="createdBy" />
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
    <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
  </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, bill_number, bill_name, org_id, shop_id, bill_amount, accept_status, version, 
    remark, accept_time, cycle_start_time, cycle_end_time, created_at, created_by, updated_by, 
    updated_at
  </sql>
  <select id="selectByExample" parameterType="com.neusoft.smart.pos.trade.persistent.domain.BillMasterExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from bill_master
    <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 bill_master
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from bill_master
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.neusoft.smart.pos.trade.persistent.domain.BillMasterExample">
    delete from bill_master
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.neusoft.smart.pos.trade.persistent.domain.BillMaster" useGeneratedKeys="true">
    insert into bill_master (bill_number, bill_name, org_id, 
      shop_id, bill_amount, accept_status, 
      version, remark, accept_time, 
      cycle_start_time, cycle_end_time, created_at, 
      created_by, updated_by, updated_at
      )
    values (#{billNumber,jdbcType=VARCHAR}, #{billName,jdbcType=VARCHAR}, #{orgId,jdbcType=INTEGER}, 
      #{shopId,jdbcType=INTEGER}, #{billAmount,jdbcType=DECIMAL}, #{acceptStatus,jdbcType=VARCHAR}, 
      #{version,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR}, #{acceptTime,jdbcType=TIMESTAMP}, 
      #{cycleStartTime,jdbcType=TIMESTAMP}, #{cycleEndTime,jdbcType=TIMESTAMP}, #{createdAt,jdbcType=TIMESTAMP}, 
      #{createdBy,jdbcType=VARCHAR}, #{updatedBy,jdbcType=VARCHAR}, #{updatedAt,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.neusoft.smart.pos.trade.persistent.domain.BillMaster" useGeneratedKeys="true">
    insert into bill_master
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="billNumber != null">
        bill_number,
      </if>
      <if test="billName != null">
        bill_name,
      </if>
      <if test="orgId != null">
        org_id,
      </if>
      <if test="shopId != null">
        shop_id,
      </if>
      <if test="billAmount != null">
        bill_amount,
      </if>
      <if test="acceptStatus != null">
        accept_status,
      </if>
      <if test="version != null">
        version,
      </if>
      <if test="remark != null">
        remark,
      </if>
      <if test="acceptTime != null">
        accept_time,
      </if>
      <if test="cycleStartTime != null">
        cycle_start_time,
      </if>
      <if test="cycleEndTime != null">
        cycle_end_time,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="updatedBy != null">
        updated_by,
      </if>
      <if test="updatedAt != null">
        updated_at,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="billNumber != null">
        #{billNumber,jdbcType=VARCHAR},
      </if>
      <if test="billName != null">
        #{billName,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null">
        #{orgId,jdbcType=INTEGER},
      </if>
      <if test="shopId != null">
        #{shopId,jdbcType=INTEGER},
      </if>
      <if test="billAmount != null">
        #{billAmount,jdbcType=DECIMAL},
      </if>
      <if test="acceptStatus != null">
        #{acceptStatus,jdbcType=VARCHAR},
      </if>
      <if test="version != null">
        #{version,jdbcType=INTEGER},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="acceptTime != null">
        #{acceptTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cycleStartTime != null">
        #{cycleStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cycleEndTime != null">
        #{cycleEndTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedBy != null">
        #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedAt != null">
        #{updatedAt,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.neusoft.smart.pos.trade.persistent.domain.BillMasterExample" resultType="java.lang.Integer">
    select count(*) from bill_master
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update bill_master
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.billNumber != null">
        bill_number = #{record.billNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.billName != null">
        bill_name = #{record.billName,jdbcType=VARCHAR},
      </if>
      <if test="record.orgId != null">
        org_id = #{record.orgId,jdbcType=INTEGER},
      </if>
      <if test="record.shopId != null">
        shop_id = #{record.shopId,jdbcType=INTEGER},
      </if>
      <if test="record.billAmount != null">
        bill_amount = #{record.billAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.acceptStatus != null">
        accept_status = #{record.acceptStatus,jdbcType=VARCHAR},
      </if>
      <if test="record.version != null">
        version = #{record.version,jdbcType=INTEGER},
      </if>
      <if test="record.remark != null">
        remark = #{record.remark,jdbcType=VARCHAR},
      </if>
      <if test="record.acceptTime != null">
        accept_time = #{record.acceptTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.cycleStartTime != null">
        cycle_start_time = #{record.cycleStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.cycleEndTime != null">
        cycle_end_time = #{record.cycleEndTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdBy != null">
        created_by = #{record.createdBy,jdbcType=VARCHAR},
      </if>
      <if test="record.updatedBy != null">
        updated_by = #{record.updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="record.updatedAt != null">
        updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update bill_master
    set id = #{record.id,jdbcType=INTEGER},
      bill_number = #{record.billNumber,jdbcType=VARCHAR},
      bill_name = #{record.billName,jdbcType=VARCHAR},
      org_id = #{record.orgId,jdbcType=INTEGER},
      shop_id = #{record.shopId,jdbcType=INTEGER},
      bill_amount = #{record.billAmount,jdbcType=DECIMAL},
      accept_status = #{record.acceptStatus,jdbcType=VARCHAR},
      version = #{record.version,jdbcType=INTEGER},
      remark = #{record.remark,jdbcType=VARCHAR},
      accept_time = #{record.acceptTime,jdbcType=TIMESTAMP},
      cycle_start_time = #{record.cycleStartTime,jdbcType=TIMESTAMP},
      cycle_end_time = #{record.cycleEndTime,jdbcType=TIMESTAMP},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=VARCHAR},
      updated_by = #{record.updatedBy,jdbcType=VARCHAR},
      updated_at = #{record.updatedAt,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.neusoft.smart.pos.trade.persistent.domain.BillMaster">
    update bill_master
    <set>
      <if test="billNumber != null">
        bill_number = #{billNumber,jdbcType=VARCHAR},
      </if>
      <if test="billName != null">
        bill_name = #{billName,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null">
        org_id = #{orgId,jdbcType=INTEGER},
      </if>
      <if test="shopId != null">
        shop_id = #{shopId,jdbcType=INTEGER},
      </if>
      <if test="billAmount != null">
        bill_amount = #{billAmount,jdbcType=DECIMAL},
      </if>
      <if test="acceptStatus != null">
        accept_status = #{acceptStatus,jdbcType=VARCHAR},
      </if>
      <if test="version != null">
        version = #{version,jdbcType=INTEGER},
      </if>
      <if test="remark != null">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="acceptTime != null">
        accept_time = #{acceptTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cycleStartTime != null">
        cycle_start_time = #{cycleStartTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cycleEndTime != null">
        cycle_end_time = #{cycleEndTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedBy != null">
        updated_by = #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedAt != null">
        updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.neusoft.smart.pos.trade.persistent.domain.BillMaster">
    update bill_master
    set bill_number = #{billNumber,jdbcType=VARCHAR},
      bill_name = #{billName,jdbcType=VARCHAR},
      org_id = #{orgId,jdbcType=INTEGER},
      shop_id = #{shopId,jdbcType=INTEGER},
      bill_amount = #{billAmount,jdbcType=DECIMAL},
      accept_status = #{acceptStatus,jdbcType=VARCHAR},
      version = #{version,jdbcType=INTEGER},
      remark = #{remark,jdbcType=VARCHAR},
      accept_time = #{acceptTime,jdbcType=TIMESTAMP},
      cycle_start_time = #{cycleStartTime,jdbcType=TIMESTAMP},
      cycle_end_time = #{cycleEndTime,jdbcType=TIMESTAMP},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=VARCHAR},
      updated_by = #{updatedBy,jdbcType=VARCHAR},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <insert id="batchInsert">
    <if test="items.get(0) != null">
            insert into bill_master  (bill_number, bill_name, org_id, 
        shop_id, bill_amount, accept_status, 
        version, remark, accept_time, 
        cycle_start_time, cycle_end_time, created_at, 
        created_by, updated_by, updated_at
        )
      values
      <foreach collection="items" item="item" index="index" separator=",">
      (#{item.billNumber,jdbcType=VARCHAR}, #{item.billName,jdbcType=VARCHAR}, #{item.orgId,jdbcType=INTEGER}, 
        #{item.shopId,jdbcType=INTEGER}, #{item.billAmount,jdbcType=DECIMAL}, #{item.acceptStatus,jdbcType=VARCHAR}, 
        #{item.version,jdbcType=INTEGER}, #{item.remark,jdbcType=VARCHAR}, #{item.acceptTime,jdbcType=TIMESTAMP}, 
        #{item.cycleStartTime,jdbcType=TIMESTAMP}, #{item.cycleEndTime,jdbcType=TIMESTAMP}, #{item.createdAt,jdbcType=TIMESTAMP}, 
        #{item.createdBy,jdbcType=VARCHAR}, #{item.updatedBy,jdbcType=VARCHAR}, #{item.updatedAt,jdbcType=TIMESTAMP}
        )
      </foreach>
    </if>
  </insert>
</mapper>