<?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.MemberWithCardMapper">
  <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.member.persistent.domain.MemberWithCard">
    <id column="member_id" jdbcType="INTEGER" property="memberId" />
    <result column="member_store_id" jdbcType="INTEGER" property="memberStoreId" />
    <result column="member_org_id" jdbcType="INTEGER" property="memberOrgId" />
    <result column="member_name" jdbcType="VARCHAR" property="memberName" />
    <result column="member_mobile" jdbcType="INTEGER" property="memberMobile" />
    <result column="openid" jdbcType="VARCHAR" property="openid" />
    <result column="card_Id" jdbcType="INTEGER" property="cardId" />
    <result column="card_password" jdbcType="VARCHAR" property="cardPassword" />
    <result column="card_num" jdbcType="VARCHAR" property="cardNum" />
    <result column="card_hid_code" jdbcType="VARCHAR" property="cardOtherId" />
    <result column="card_active" jdbcType="INTEGER" property="cardActive" />
    <result column="member_birthday" jdbcType="DATE" property="memberBirthday" />
    <result column="member_email" jdbcType="VARCHAR" property="memberEmail" />
    <result column="member_code" jdbcType="VARCHAR" property="memberCode" />
    <result column="member_type" jdbcType="INTEGER" property="memberType" />
    <result column="gender" jdbcType="INTEGER" property="gender" />
    <result column="address" jdbcType="VARCHAR" property="address" />
    <result column="avatar" jdbcType="VARCHAR" property="avatar" />
    <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="card_balance" jdbcType="DECIMAL" property="cardBalance" />
    <result column="card_point" jdbcType="INTEGER" property="cardPoint" />
    <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="Base_Column_List">
    m.member_id as member_id, member_org_id, member_store_id, member_name, member_mobile,
    openid, member_birthday, gender, address, avatar, m.is_active as is_active, m.content,
    m.created_time as created_time, mc.card_id as card_id, card_num, mc.is_active as card_active,
    mc.last_recharge_amount as last_recharge_amount, mc.card_balance as card_balance,
    mc.card_point as card_point, last_recharge_amount,mc.card_another_id as card_hid_code,member_email,member_code,member_type, card_password, need_password
  </sql>
  <select id="selectByExample" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberWithCardExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from member as m
    inner join member_card_relation as mcr on m.member_id = mcr.member_id
    INNER JOIN card as mc on mc.card_id = mcr.card_id
    <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="countByExample" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberWithCardExample" resultType="java.lang.Integer">
    select count(*)
    from member as m
    inner join member_card_relation as mcr on m.member_id = mcr.member_id
    INNER JOIN card as mc on mc.card_id = mcr.card_id
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>

  <select id="selectByMemberId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from member as m
    inner join member_card_relation as mcr on m.member_id = mcr.member_id
    INNER JOIN card as mc on mc.card_id = mcr.card_id
    where m.member_id = #{memberId,jdbcType=INTEGER}
  </select>

  <select id="selectIdsByExample" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberWithCardExample" resultType="java.util.List">
    select m.member_id
    from member as m
    inner join member_card_relation as mcr on m.member_id = mcr.member_id
    INNER JOIN card as mc on mc.card_id = mcr.card_id
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>


  <select id="selectByExample4Canteen" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberWithCardExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from member as m
    inner join member_card_relation as mcr on m.member_id = mcr.member_id
    INNER JOIN card as mc on mc.card_id = mcr.card_id
    <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="countByExample4Canteen" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberWithCardExample" resultType="java.lang.Integer">
    select count(*)
    from member as m
    inner join member_card_relation as mcr on m.member_id = mcr.member_id
    INNER JOIN card as mc on mc.card_id = mcr.card_id
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>

  <select id="selectByMemberId4Canteen" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from member as m
    inner join member_card_relation as mcr on m.member_id = mcr.member_id
    INNER JOIN card as mc on mc.card_id = mcr.card_id
    where m.member_id = #{memberId,jdbcType=INTEGER}
    <if test="cardId != null">
     and   mc.card_id = #{cardId,jdbcType=INTEGER}
    </if>
    <if test="isActive == true">
      and mc.is_active =1 AND m.is_active=1
    </if>

  </select>

  <select id="selectIdsByExample4Canteen" parameterType="com.neusoft.smart.pos.member.persistent.domain.MemberWithCardExample" resultType="java.util.List">
    select m.member_id
    from member as m
    inner join member_card_relation as mcr on m.member_id = mcr.member_id
    INNER JOIN card as mc on mc.card_id = mcr.card_id
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
</mapper>