<?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.MemberCardMapper">
  <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.member.persistent.domain.MemberCard">
    <id column="card_id" jdbcType="INTEGER" property="cardId" />
    <result column="member_id" jdbcType="INTEGER" property="memberId" />
    <result column="card_num" jdbcType="VARCHAR" property="cardNum" />
    <result column="card_hid_code" jdbcType="VARCHAR" property="cardHidCode" />
    <result column="card_password" jdbcType="VARCHAR" property="cardPassword" />
    <result column="card_point" jdbcType="INTEGER" property="cardPoint" />
    <result column="card_balance" jdbcType="DECIMAL" property="cardBalance" />
    <result column="card_image" jdbcType="VARCHAR" property="cardImage" />
    <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="accumulative_point" jdbcType="INTEGER" property="accumulativePoint" />
    <result column="last_recharge_amount" jdbcType="DECIMAL" property="lastRechargeAmount" />
    <result column="need_password" jdbcType="CHAR" property="needPassword" />
  </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">
    card_id, member_id, card_num, card_hid_code, card_password, card_point, card_balance, 
    card_image, is_active, content, version, created_time, created_by, updated_time, 
    updated_by, accumulative_point, last_recharge_amount, need_password
  </sql>
  <select id="selectByExample" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberCardExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from member_card
    <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_card
    where card_id = #{cardId,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from member_card
    where card_id = #{cardId,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberCardExample">
    delete from member_card
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" keyColumn="card_id" keyProperty="cardId" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberCard" useGeneratedKeys="true">
    insert into member_card (member_id, card_num, card_hid_code, 
      card_password, card_point, card_balance, 
      card_image, is_active, content, 
      version, created_time, created_by, 
      updated_time, updated_by, accumulative_point, 
      last_recharge_amount, need_password)
    values (#{memberId,jdbcType=INTEGER}, #{cardNum,jdbcType=VARCHAR}, #{cardHidCode,jdbcType=VARCHAR}, 
      #{cardPassword,jdbcType=VARCHAR}, #{cardPoint,jdbcType=INTEGER}, #{cardBalance,jdbcType=DECIMAL}, 
      #{cardImage,jdbcType=VARCHAR}, #{isActive,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, 
     0, #{createdTime,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=VARCHAR},
      #{updatedTime,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=VARCHAR}, #{accumulativePoint,jdbcType=INTEGER}, 
      #{lastRechargeAmount,jdbcType=DECIMAL}, #{needPassword,jdbcType=CHAR})
  </insert>
  <insert id="insertSelective" keyColumn="card_id" keyProperty="cardId" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberCard" useGeneratedKeys="true">
    insert into member_card
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="memberId != null">
        member_id,
      </if>
      <if test="cardNum != null">
        card_num,
      </if>
      <if test="cardHidCode != null">
        card_hid_code,
      </if>
      <if test="cardPassword != null">
        card_password,
      </if>
      <if test="cardPoint != null">
        card_point,
      </if>
      <if test="cardBalance != null">
        card_balance,
      </if>
      <if test="cardImage != null">
        card_image,
      </if>
      <if test="isActive != null">
        is_active,
      </if>
      <if test="content != null">
        content,
      </if>
      version,
      <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="accumulativePoint != null">
        accumulative_point,
      </if>
      <if test="lastRechargeAmount != null">
        last_recharge_amount,
      </if>
      <if test="needPassword != null">
        need_password,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="memberId != null">
        #{memberId,jdbcType=INTEGER},
      </if>
      <if test="cardNum != null">
        #{cardNum,jdbcType=VARCHAR},
      </if>
      <if test="cardHidCode != null">
        #{cardHidCode,jdbcType=VARCHAR},
      </if>
      <if test="cardPassword != null">
        #{cardPassword,jdbcType=VARCHAR},
      </if>
      <if test="cardPoint != null">
        #{cardPoint,jdbcType=INTEGER},
      </if>
      <if test="cardBalance != null">
        #{cardBalance,jdbcType=DECIMAL},
      </if>
      <if test="cardImage != null">
        #{cardImage,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        #{content,jdbcType=VARCHAR},
      </if>
      0,
      <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="accumulativePoint != null">
        #{accumulativePoint,jdbcType=INTEGER},
      </if>
      <if test="lastRechargeAmount != null">
        #{lastRechargeAmount,jdbcType=DECIMAL},
      </if>
      <if test="needPassword != null">
        #{needPassword,jdbcType=CHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberCardExample" resultType="java.lang.Integer">
    select count(*) from member_card
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update member_card
    <set>
      <if test="record.cardId != null">
        card_id = #{record.cardId,jdbcType=INTEGER},
      </if>
      <if test="record.memberId != null">
        member_id = #{record.memberId,jdbcType=INTEGER},
      </if>
      <if test="record.cardNum != null">
        card_num = #{record.cardNum,jdbcType=VARCHAR},
      </if>
      <if test="record.cardHidCode != null">
        card_hid_code = #{record.cardHidCode,jdbcType=VARCHAR},
      </if>
      <if test="record.cardPassword != null">
        card_password = #{record.cardPassword,jdbcType=VARCHAR},
      </if>
      <if test="record.cardPoint != null">
        card_point = #{record.cardPoint,jdbcType=INTEGER},
      </if>
      <if test="record.cardBalance != null">
        card_balance = #{record.cardBalance,jdbcType=DECIMAL},
      </if>
      <if test="record.cardImage != null">
        card_image = #{record.cardImage,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>
      version = version + 1,
      <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.accumulativePoint != null">
        accumulative_point = #{record.accumulativePoint,jdbcType=INTEGER},
      </if>
      <if test="record.lastRechargeAmount != null">
        last_recharge_amount = #{record.lastRechargeAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.needPassword != null">
        need_password = #{record.needPassword,jdbcType=CHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update member_card
    set card_id = #{record.cardId,jdbcType=INTEGER},
      member_id = #{record.memberId,jdbcType=INTEGER},
      card_num = #{record.cardNum,jdbcType=VARCHAR},
      card_hid_code = #{record.cardHidCode,jdbcType=VARCHAR},
      card_password = #{record.cardPassword,jdbcType=VARCHAR},
      card_point = #{record.cardPoint,jdbcType=INTEGER},
      card_balance = #{record.cardBalance,jdbcType=DECIMAL},
      card_image = #{record.cardImage,jdbcType=VARCHAR},
      is_active = #{record.isActive,jdbcType=INTEGER},
      content = #{record.content,jdbcType=VARCHAR},
      version = version + 1,
      created_time = #{record.createdTime,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=VARCHAR},
      updated_time = #{record.updatedTime,jdbcType=TIMESTAMP},
      updated_by = #{record.updatedBy,jdbcType=VARCHAR},
      accumulative_point = #{record.accumulativePoint,jdbcType=INTEGER},
      last_recharge_amount = #{record.lastRechargeAmount,jdbcType=DECIMAL},
      need_password = #{record.needPassword,jdbcType=CHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberCard">
    update member_card
    <set>
      <if test="memberId != null">
        member_id = #{memberId,jdbcType=INTEGER},
      </if>
      <if test="cardNum != null">
        card_num = #{cardNum,jdbcType=VARCHAR},
      </if>
      <if test="cardHidCode != null">
        card_hid_code = #{cardHidCode,jdbcType=VARCHAR},
      </if>
      <if test="cardPassword != null">
        card_password = #{cardPassword,jdbcType=VARCHAR},
      </if>
      <if test="cardPoint != null">
        card_point = #{cardPoint,jdbcType=INTEGER},
      </if>
      <if test="cardBalance != null">
        card_balance = #{cardBalance,jdbcType=DECIMAL},
      </if>
      <if test="cardImage != null">
        card_image = #{cardImage,jdbcType=VARCHAR},
      </if>
      <if test="isActive != null">
        is_active = #{isActive,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
      version = version + 1,
      <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="accumulativePoint != null">
        accumulative_point = #{accumulativePoint,jdbcType=INTEGER},
      </if>
      <if test="lastRechargeAmount != null">
        last_recharge_amount = #{lastRechargeAmount,jdbcType=DECIMAL},
      </if>
      <if test="needPassword != null">
        need_password = #{needPassword,jdbcType=CHAR},
      </if>
    </set>
    where card_id = #{cardId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberCard">
    update member_card
    set member_id = #{memberId,jdbcType=INTEGER},
      card_num = #{cardNum,jdbcType=VARCHAR},
      card_hid_code = #{cardHidCode,jdbcType=VARCHAR},
      card_password = #{cardPassword,jdbcType=VARCHAR},
      card_point = #{cardPoint,jdbcType=INTEGER},
      card_balance = #{cardBalance,jdbcType=DECIMAL},
      card_image = #{cardImage,jdbcType=VARCHAR},
      is_active = #{isActive,jdbcType=INTEGER},
      content = #{content,jdbcType=VARCHAR},
      version = version + 1,
      created_time = #{createdTime,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=VARCHAR},
      updated_time = #{updatedTime,jdbcType=TIMESTAMP},
      updated_by = #{updatedBy,jdbcType=VARCHAR},
      accumulative_point = #{accumulativePoint,jdbcType=INTEGER},
      last_recharge_amount = #{lastRechargeAmount,jdbcType=DECIMAL},
      need_password = #{needPassword,jdbcType=CHAR}
    where card_id = #{cardId,jdbcType=INTEGER}
  </update>
  <insert id="batchInsert">
    <if test="items.get(0) != null">
            insert into member_card  (member_id, card_num, card_hid_code, 
        card_password, card_point, card_balance, 
        card_image, is_active, content, 
        version, created_time, created_by, 
        updated_time, updated_by, accumulative_point, 
        last_recharge_amount, need_password)
      values
      <foreach collection="items" item="item" index="index" separator=",">
      (#{item.memberId,jdbcType=INTEGER}, #{item.cardNum,jdbcType=VARCHAR}, #{item.cardHidCode,jdbcType=VARCHAR}, 
        #{item.cardPassword,jdbcType=VARCHAR}, #{item.cardPoint,jdbcType=INTEGER}, #{item.cardBalance,jdbcType=DECIMAL}, 
        #{item.cardImage,jdbcType=VARCHAR}, #{item.isActive,jdbcType=INTEGER}, #{item.content,jdbcType=VARCHAR}, 
        0, #{item.createdTime,jdbcType=TIMESTAMP}, #{item.createdBy,jdbcType=VARCHAR},
        #{item.updatedTime,jdbcType=TIMESTAMP}, #{item.updatedBy,jdbcType=VARCHAR}, #{item.accumulativePoint,jdbcType=INTEGER}, 
        #{item.lastRechargeAmount,jdbcType=DECIMAL}, #{item.needPassword,jdbcType=CHAR})
      </foreach>
    </if>
  </insert>
</mapper>