<?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.member.persistent.mapper.MemberLevelMapper">
  <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.member.persistent.domain.MemberLevel">
    <id column="member_level_id" jdbcType="INTEGER" property="memberLevelId" />
    <result column="level_name" jdbcType="VARCHAR" property="levelName" />
    <result column="card_sales_amount" jdbcType="DECIMAL" property="cardSalesAmount" />
    <result column="init_amount" jdbcType="DECIMAL" property="initAmount" />
    <result column="sales_amount" jdbcType="DECIMAL" property="salesAmount" />
    <result column="give_integral" jdbcType="INTEGER" property="giveIntegral" />
    <result column="discount_proportion" jdbcType="DECIMAL" property="discountProportion" />
    <result column="recharge_convert_rate" jdbcType="DECIMAL" property="rechargeConvertRate" />
    <result column="member_time" jdbcType="INTEGER" property="memberTime" />
    <result column="member_time_unit" jdbcType="INTEGER" property="memberTimeUnit" />
    <result column="sign_integral" jdbcType="INTEGER" property="signIntegral" />
    <result column="member_image" jdbcType="VARCHAR" property="memberImage" />
    <result column="is_active" jdbcType="INTEGER" property="isActive" />
    <result column="content" jdbcType="VARCHAR" property="content" />
    <result column="version" jdbcType="INTEGER" property="version" />
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime" />
    <result column="created_by" jdbcType="VARCHAR" property="createdBy" />
    <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime" />
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
    <result column="org_id" jdbcType="INTEGER" property="orgId" />
    <result column="store_id" jdbcType="INTEGER" property="storeId" />
    <result column="level" jdbcType="TINYINT" property="level" />
    <result column="required_point" jdbcType="INTEGER" property="requiredPoint" />
    <result column="required_recharge_amount" jdbcType="DECIMAL" property="requiredRechargeAmount" />
  </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">
    member_level_id, level_name, card_sales_amount, init_amount, sales_amount, give_integral, 
    discount_proportion, recharge_convert_rate, member_time, member_time_unit, sign_integral, member_image,
    is_active, content, version, created_time, created_by, updated_time, updated_by, 
    org_id, store_id, level, required_point, required_recharge_amount
  </sql>
  <select id="selectByExample" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberLevelExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from member_level
    <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 member_level
    where member_level_id = #{memberLevelId,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from member_level
    where member_level_id = #{memberLevelId,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberLevelExample">
    delete from member_level
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" keyColumn="member_level_id" keyProperty="memberLevelId" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberLevel" useGeneratedKeys="true">
    insert into member_level (level_name, card_sales_amount, init_amount, 
      sales_amount, give_integral, discount_proportion, recharge_convert_rate,
      member_time, member_time_unit, sign_integral, 
      member_image, is_active, content, 
      version, created_time, created_by, 
      updated_time, updated_by, org_id, 
      store_id, level, required_point, 
      required_recharge_amount)
    values (#{levelName,jdbcType=VARCHAR}, #{cardSalesAmount,jdbcType=DECIMAL}, #{initAmount,jdbcType=DECIMAL}, 
      #{salesAmount,jdbcType=DECIMAL}, #{giveIntegral,jdbcType=INTEGER}, #{discountProportion,jdbcType=DECIMAL}, #{rechargeConvertRate,jdbcType=DECIMAL},
      #{memberTime,jdbcType=INTEGER}, #{memberTimeUnit,jdbcType=INTEGER}, #{signIntegral,jdbcType=INTEGER}, 
      #{memberImage,jdbcType=VARCHAR}, #{isActive,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, 
      #{version,jdbcType=INTEGER}, #{createdTime,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=VARCHAR}, 
      #{updatedTime,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=VARCHAR}, #{orgId,jdbcType=INTEGER}, 
      #{storeId,jdbcType=INTEGER}, #{level,jdbcType=TINYINT}, #{requiredPoint,jdbcType=INTEGER}, 
      #{requiredRechargeAmount,jdbcType=DECIMAL})
  </insert>
  <insert id="insertSelective" keyColumn="member_level_id" keyProperty="memberLevelId" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberLevel" useGeneratedKeys="true">
    insert into member_level
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="levelName != null">
        level_name,
      </if>
      <if test="cardSalesAmount != null">
        card_sales_amount,
      </if>
      <if test="initAmount != null">
        init_amount,
      </if>
      <if test="salesAmount != null">
        sales_amount,
      </if>
      <if test="giveIntegral != null">
        give_integral,
      </if>
      <if test="discountProportion != null">
        discount_proportion,
      </if>
      <if test="rechargeConvertRate != null">
        recharge_convert_rate,
      </if>
      <if test="memberTime != null">
        member_time,
      </if>
      <if test="memberTimeUnit != null">
        member_time_unit,
      </if>
      <if test="signIntegral != null">
        sign_integral,
      </if>
      <if test="memberImage != null">
        member_image,
      </if>
      <if test="isActive != null">
        is_active,
      </if>
      <if test="content != null">
        content,
      </if>
      <if test="version != null">
        version,
      </if>
      <if test="createdTime != null">
        created_time,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="updatedTime != null">
        updated_time,
      </if>
      <if test="updatedBy != null">
        updated_by,
      </if>
      <if test="orgId != null">
        org_id,
      </if>
      <if test="storeId != null">
        store_id,
      </if>
      <if test="level != null">
        level,
      </if>
      <if test="requiredPoint != null">
        required_point,
      </if>
      <if test="requiredRechargeAmount != null">
        required_recharge_amount,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="levelName != null">
        #{levelName,jdbcType=VARCHAR},
      </if>
      <if test="cardSalesAmount != null">
        #{cardSalesAmount,jdbcType=DECIMAL},
      </if>
      <if test="initAmount != null">
        #{initAmount,jdbcType=DECIMAL},
      </if>
      <if test="salesAmount != null">
        #{salesAmount,jdbcType=DECIMAL},
      </if>
      <if test="giveIntegral != null">
        #{giveIntegral,jdbcType=INTEGER},
      </if>
      <if test="discountProportion != null">
        #{discountProportion,jdbcType=DECIMAL},
      </if>
      <if test="rechargeConvertRate != null">
        #{rechargeConvertRate,jdbcType=DECIMAL},
      </if>
      <if test="memberTime != null">
        #{memberTime,jdbcType=INTEGER},
      </if>
      <if test="memberTimeUnit != null">
        #{memberTimeUnit,jdbcType=INTEGER},
      </if>
      <if test="signIntegral != null">
        #{signIntegral,jdbcType=INTEGER},
      </if>
      <if test="memberImage != null">
        #{memberImage,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="version != null">
        #{version,jdbcType=INTEGER},
      </if>
      <if test="createdTime != null">
        #{createdTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedTime != null">
        #{updatedTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null">
        #{orgId,jdbcType=INTEGER},
      </if>
      <if test="storeId != null">
        #{storeId,jdbcType=INTEGER},
      </if>
      <if test="level != null">
        #{level,jdbcType=TINYINT},
      </if>
      <if test="requiredPoint != null">
        #{requiredPoint,jdbcType=INTEGER},
      </if>
      <if test="requiredRechargeAmount != null">
        #{requiredRechargeAmount,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberLevelExample" resultType="java.lang.Integer">
    select count(*) from member_level
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update member_level
    <set>
      <if test="record.memberLevelId != null">
        member_level_id = #{record.memberLevelId,jdbcType=INTEGER},
      </if>
      <if test="record.levelName != null">
        level_name = #{record.levelName,jdbcType=VARCHAR},
      </if>
      <if test="record.cardSalesAmount != null">
        card_sales_amount = #{record.cardSalesAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.initAmount != null">
        init_amount = #{record.initAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.salesAmount != null">
        sales_amount = #{record.salesAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.giveIntegral != null">
        give_integral = #{record.giveIntegral,jdbcType=INTEGER},
      </if>
      <if test="record.discountProportion != null">
        discount_proportion = #{record.discountProportion,jdbcType=DECIMAL},
      </if>
      <if test="record.rechargeConvertRate != null">
        recharge_convert_rate = #{record.rechargeConvertRate,jdbcType=DECIMAL},
      </if>
      <if test="record.memberTime != null">
        member_time = #{record.memberTime,jdbcType=INTEGER},
      </if>
      <if test="record.memberTimeUnit != null">
        member_time_unit = #{record.memberTimeUnit,jdbcType=INTEGER},
      </if>
      <if test="record.signIntegral != null">
        sign_integral = #{record.signIntegral,jdbcType=INTEGER},
      </if>
      <if test="record.memberImage != null">
        member_image = #{record.memberImage,jdbcType=VARCHAR},
      </if>
      <if test="record.isActive != null">
        is_active = #{record.isActive,jdbcType=INTEGER},
      </if>
      <if test="record.content != null">
        content = #{record.content,jdbcType=VARCHAR},
      </if>
      <if test="record.version != null">
        version = #{record.version,jdbcType=INTEGER},
      </if>
      <if test="record.createdTime != null">
        created_time = #{record.createdTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdBy != null">
        created_by = #{record.createdBy,jdbcType=VARCHAR},
      </if>
      <if test="record.updatedTime != null">
        updated_time = #{record.updatedTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updatedBy != null">
        updated_by = #{record.updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="record.orgId != null">
        org_id = #{record.orgId,jdbcType=INTEGER},
      </if>
      <if test="record.storeId != null">
        store_id = #{record.storeId,jdbcType=INTEGER},
      </if>
      <if test="record.level != null">
        level = #{record.level,jdbcType=TINYINT},
      </if>
      <if test="record.requiredPoint != null">
        required_point = #{record.requiredPoint,jdbcType=INTEGER},
      </if>
      <if test="record.requiredRechargeAmount != null">
        required_recharge_amount = #{record.requiredRechargeAmount,jdbcType=DECIMAL},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update member_level
    set member_level_id = #{record.memberLevelId,jdbcType=INTEGER},
      level_name = #{record.levelName,jdbcType=VARCHAR},
      card_sales_amount = #{record.cardSalesAmount,jdbcType=DECIMAL},
      init_amount = #{record.initAmount,jdbcType=DECIMAL},
      sales_amount = #{record.salesAmount,jdbcType=DECIMAL},
      give_integral = #{record.giveIntegral,jdbcType=INTEGER},
      discount_proportion = #{record.discountProportion,jdbcType=DECIMAL},
      recharge_convert_rate = #{record.rechargeConvertRate,jdbcType=DECIMAL},
      member_time = #{record.memberTime,jdbcType=INTEGER},
      member_time_unit = #{record.memberTimeUnit,jdbcType=INTEGER},
      sign_integral = #{record.signIntegral,jdbcType=INTEGER},
      member_image = #{record.memberImage,jdbcType=VARCHAR},
      is_active = #{record.isActive,jdbcType=INTEGER},
      content = #{record.content,jdbcType=VARCHAR},
      version = #{record.version,jdbcType=INTEGER},
      created_time = #{record.createdTime,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=VARCHAR},
      updated_time = #{record.updatedTime,jdbcType=TIMESTAMP},
      updated_by = #{record.updatedBy,jdbcType=VARCHAR},
      org_id = #{record.orgId,jdbcType=INTEGER},
      store_id = #{record.storeId,jdbcType=INTEGER},
      level = #{record.level,jdbcType=TINYINT},
      required_point = #{record.requiredPoint,jdbcType=INTEGER},
      required_recharge_amount = #{record.requiredRechargeAmount,jdbcType=DECIMAL}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberLevel">
    update member_level
    <set>
      <if test="levelName != null">
        level_name = #{levelName,jdbcType=VARCHAR},
      </if>
      <if test="cardSalesAmount != null">
        card_sales_amount = #{cardSalesAmount,jdbcType=DECIMAL},
      </if>
      <if test="initAmount != null">
        init_amount = #{initAmount,jdbcType=DECIMAL},
      </if>
      <if test="salesAmount != null">
        sales_amount = #{salesAmount,jdbcType=DECIMAL},
      </if>
      <if test="giveIntegral != null">
        give_integral = #{giveIntegral,jdbcType=INTEGER},
      </if>
      <if test="discountProportion != null">
        discount_proportion = #{discountProportion,jdbcType=DECIMAL},
      </if>
      <if test="rechargeConvertRate != null">
        recharge_convert_rate = #{rechargeConvertRate,jdbcType=DECIMAL},
      </if>
      <if test="memberTime != null">
        member_time = #{memberTime,jdbcType=INTEGER},
      </if>
      <if test="memberTimeUnit != null">
        member_time_unit = #{memberTimeUnit,jdbcType=INTEGER},
      </if>
      <if test="signIntegral != null">
        sign_integral = #{signIntegral,jdbcType=INTEGER},
      </if>
      <if test="memberImage != null">
        member_image = #{memberImage,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        is_active = #{isActive,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="version != null">
        version = #{version,jdbcType=INTEGER},
      </if>
      <if test="createdTime != null">
        created_time = #{createdTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedTime != null">
        updated_time = #{updatedTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        updated_by = #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null">
        org_id = #{orgId,jdbcType=INTEGER},
      </if>
      <if test="storeId != null">
        store_id = #{storeId,jdbcType=INTEGER},
      </if>
      <if test="level != null">
        level = #{level,jdbcType=TINYINT},
      </if>
      <if test="requiredPoint != null">
        required_point = #{requiredPoint,jdbcType=INTEGER},
      </if>
      <if test="requiredRechargeAmount != null">
        required_recharge_amount = #{requiredRechargeAmount,jdbcType=DECIMAL},
      </if>
    </set>
    where member_level_id = #{memberLevelId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberLevel">
    update member_level
    set level_name = #{levelName,jdbcType=VARCHAR},
      card_sales_amount = #{cardSalesAmount,jdbcType=DECIMAL},
      init_amount = #{initAmount,jdbcType=DECIMAL},
      sales_amount = #{salesAmount,jdbcType=DECIMAL},
      give_integral = #{giveIntegral,jdbcType=INTEGER},
      discount_proportion = #{discountProportion,jdbcType=DECIMAL},
      recharge_convert_rate = #{rechargeConvertRate,jdbcType=DECIMAL},
      member_time = #{memberTime,jdbcType=INTEGER},
      member_time_unit = #{memberTimeUnit,jdbcType=INTEGER},
      sign_integral = #{signIntegral,jdbcType=INTEGER},
      member_image = #{memberImage,jdbcType=VARCHAR},
      is_active = #{isActive,jdbcType=INTEGER},
      content = #{content,jdbcType=VARCHAR},
      version = #{version,jdbcType=INTEGER},
      created_time = #{createdTime,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=VARCHAR},
      updated_time = #{updatedTime,jdbcType=TIMESTAMP},
      updated_by = #{updatedBy,jdbcType=VARCHAR},
      org_id = #{orgId,jdbcType=INTEGER},
      store_id = #{storeId,jdbcType=INTEGER},
      level = #{level,jdbcType=TINYINT},
      required_point = #{requiredPoint,jdbcType=INTEGER},
      required_recharge_amount = #{requiredRechargeAmount,jdbcType=DECIMAL}
    where member_level_id = #{memberLevelId,jdbcType=INTEGER}
  </update>
  <insert id="batchInsert">
    <if test="items.get(0) != null">
            insert into member_level  (level_name, card_sales_amount, init_amount, 
        sales_amount, give_integral, discount_proportion, recharge_convert_rate,
        member_time, member_time_unit, sign_integral, 
        member_image, is_active, content, 
        version, created_time, created_by, 
        updated_time, updated_by, org_id, 
        store_id, level, required_point, 
        required_recharge_amount)
      values
      <foreach collection="items" item="item" index="index" separator=",">
      (#{item.levelName,jdbcType=VARCHAR}, #{item.cardSalesAmount,jdbcType=DECIMAL}, #{item.initAmount,jdbcType=DECIMAL}, 
        #{item.salesAmount,jdbcType=DECIMAL}, #{item.giveIntegral,jdbcType=INTEGER}, #{item.discountProportion,jdbcType=DECIMAL}, #{item.rechargeConvertRate,jdbcType=DECIMAL},
        #{item.memberTime,jdbcType=INTEGER}, #{item.memberTimeUnit,jdbcType=INTEGER}, #{item.signIntegral,jdbcType=INTEGER}, 
        #{item.memberImage,jdbcType=VARCHAR}, #{item.isActive,jdbcType=INTEGER}, #{item.content,jdbcType=VARCHAR}, 
        #{item.version,jdbcType=INTEGER}, #{item.createdTime,jdbcType=TIMESTAMP}, #{item.createdBy,jdbcType=VARCHAR}, 
        #{item.updatedTime,jdbcType=TIMESTAMP}, #{item.updatedBy,jdbcType=VARCHAR}, #{item.orgId,jdbcType=INTEGER}, 
        #{item.storeId,jdbcType=INTEGER}, #{item.level,jdbcType=TINYINT}, #{item.requiredPoint,jdbcType=INTEGER}, 
        #{item.requiredRechargeAmount,jdbcType=DECIMAL})
      </foreach>
    </if>
  </insert>

  <update id="degradeLevel">
    update member_level
    set level = level - 1
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
</mapper>