<?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.gxwebsoft.apps.mapper.HualalaCardMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM apps_hualala_card a
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.groupId != null">
                AND a.group_id LIKE CONCAT('%', #{param.groupId}, '%')
            </if>
            <if test="param.shopId != null">
                AND a.shop_id LIKE CONCAT('%', #{param.shopId}, '%')
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.cardId != null">
                AND a.card_id LIKE CONCAT('%', #{param.cardId}, '%')
            </if>
            <if test="param.cardTypeId != null">
                AND a.card_type_id LIKE CONCAT('%', #{param.cardTypeId}, '%')
            </if>
            <if test="param.cardLevelId != null">
                AND a.card_level_id LIKE CONCAT('%', #{param.cardLevelId}, '%')
            </if>
            <if test="param.cardLevelName != null">
                AND a.card_level_name LIKE CONCAT('%', #{param.cardLevelName}, '%')
            </if>
            <if test="param.cardStatus != null">
                AND a.card_status LIKE CONCAT('%', #{param.cardStatus}, '%')
            </if>
            <if test="param.customerId != null">
                AND a.customer_id LIKE CONCAT('%', #{param.customerId}, '%')
            </if>
            <if test="param.createShopId != null">
                AND a.create_shop_id LIKE CONCAT('%', #{param.createShopId}, '%')
            </if>
            <if test="param.createShopName != null">
                AND a.create_shop_name LIKE CONCAT('%', #{param.createShopName}, '%')
            </if>
            <if test="param.cardNo != null">
                AND a.card_no LIKE CONCAT('%', #{param.cardNo}, '%')
            </if>
            <if test="param.customerName != null">
                AND a.customer_name LIKE CONCAT('%', #{param.customerName}, '%')
            </if>
            <if test="param.customerMobile != null">
                AND a.customer_mobile LIKE CONCAT('%', #{param.customerMobile}, '%')
            </if>
            <if test="param.customerSex != null">
                AND a.customer_sex = #{param.customerSex}
            </if>
            <if test="param.customerBirthday != null">
                AND a.customer_birthday LIKE CONCAT('%', #{param.customerBirthday}, '%')
            </if>
            <if test="param.cardBalance != null">
                AND a.card_balance = #{param.cardBalance}
            </if>
            <if test="param.pointBalance != null">
                AND a.point_balance = #{param.pointBalance}
            </if>
            <if test="param.saveMoneyTotal != null">
                AND a.save_money_total = #{param.saveMoneyTotal}
            </if>
            <if test="param.consumptionTotal != null">
                AND a.consumption_total = #{param.consumptionTotal}
            </if>
            <if test="param.consumptionCount != null">
                AND a.consumption_count = #{param.consumptionCount}
            </if>
            <if test="param.grade != null">
                AND a.grade = #{param.grade}
            </if>
            <if test="param.nextLevelGrade != null">
                AND a.next_level_grade = #{param.nextLevelGrade}
            </if>
            <if test="param.expireTime != null">
                AND a.expire_time LIKE CONCAT('%', #{param.expireTime}, '%')
            </if>
            <if test="param.lastTransTime != null">
                AND a.last_trans_time LIKE CONCAT('%', #{param.lastTransTime}, '%')
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.merchantCode != null">
                AND a.merchant_code LIKE CONCAT('%', #{param.merchantCode}, '%')
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.apps.entity.HualalaCard">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.apps.entity.HualalaCard">
        <include refid="selectSql"></include>
    </select>

</mapper>
