<?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.card.persistent.mapper.CardCapitalChangeExtMapper">
    <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.card.persistent.domain.CardCapitalChangeExt">
        <id column="amount_change_id" jdbcType="INTEGER" property="amountChangeId"/>
        <result column="card_id" jdbcType="INTEGER" property="cardId"/>
        <result column="member_name" jdbcType="VARCHAR" property="memberName"/>
        <result column="member_mobile" jdbcType="VARCHAR" property="memberMobile"/>
        <result column="change_order_id" jdbcType="VARCHAR" property="changeOrderId"/>
        <result column="amount_change" jdbcType="DECIMAL" property="amountChange"/>
        <result column="amount_before" jdbcType="DECIMAL" property="amountBefore"/>
        <result column="amount_after" jdbcType="DECIMAL" property="amountAfter"/>
        <result column="point_change" jdbcType="INTEGER" property="pointChange"/>
        <result column="point_before" jdbcType="INTEGER" property="pointBefore"/>
        <result column="point_after" jdbcType="INTEGER" property="pointAfter"/>
        <result column="change_type" jdbcType="INTEGER" property="changeType"/>
        <result column="change_time" jdbcType="TIMESTAMP" property="changeTime"/>
        <result column="is_active" jdbcType="INTEGER" property="isActive"/>
        <result column="content" jdbcType="VARCHAR" property="content"/>
        <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
    </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">
    ccc.amount_change_id, ccc.card_id, ccc.change_order_id, ccc.amount_change, ccc.amount_before,
    ccc.amount_after, ccc.point_change, ccc.point_before, ccc.point_after, ccc.change_type, ccc.change_time,
    ccc.is_active, ccc.content, ccc.created_time, ccc.created_by, m.member_name, m.member_mobile
  </sql>

    <select id="selectByExample"
            parameterType="com.neusoft.smart.pos.card.persistent.domain.CardCapitalChangeExtExample"
            resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from card_capital_change ccc left join member_card_relation mcr on mcr.card_id= ccc.card_id left join
        member m on m.member_id=mcr.member_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.card.persistent.domain.CardCapitalChangeExtExample"
            resultType="java.lang.Integer">
        select count(*) from card_capital_change ccc left join member_card_relation mcr on mcr.card_id=
        ccc.card_id left join member m on m.member_id=mcr.member_id
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>

    <select id="selectByExample4Canteen"
            parameterType="com.neusoft.smart.pos.card.persistent.domain.CardCapitalChangeExtExample"
            resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        FROM card_capital_change ccc
        LEFT JOIN member_card mc on mc.card_id=ccc.card_id
        LEFT JOIN member m ON m.member_id=mc.member_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.card.persistent.domain.CardCapitalChangeExtExample"
            resultType="java.lang.Integer">
        select count(*) FROM card_capital_change ccc
        LEFT JOIN member_card mc on mc.card_id=ccc.card_id
        LEFT JOIN member m ON m.member_id=mc.member_id
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
</mapper>

