<?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.mall.coupon.mapper.CouponHistoryMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.mall.coupon.domain.entity.CouponHistory">
            <id column="id" property="id"/>
            <id column="coupon_id" property="couponId"/>
            <id column="member_id" property="memberId"/>
            <id column="member_nick_name" property="memberNickName"/>
            <id column="get_type" property="getType"/>
            <id column="create_time" property="createTime"/>
            <id column="use_type" property="useType"/>
            <id column="use_time" property="useTime"/>
            <id column="order_id" property="orderId"/>
            <id column="order_sn" property="orderSn"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,coupon_id,member_id,member_nick_name,get_type,create_time,use_type,use_time,order_id,order_sn
    </sql>

    <!-- 分页查询优惠券领取历史记录内容 -->
    <select id="selectListByPage" resultType="com.mall.coupon.domain.vo.CouponHistoryVo">
        select
        <include refid="Base_Column_List"/>
        from sms_coupon_history
        <where>
                <if test="dto.id != null and dto.id != ''">
                    and id like CONCAT('%',#{dto.id},'%')
                </if>
                <if test="dto.couponId != null and dto.couponId != ''">
                    and coupon_id like CONCAT('%',#{dto.couponId},'%')
                </if>
                <if test="dto.memberId != null and dto.memberId != ''">
                    and member_id like CONCAT('%',#{dto.memberId},'%')
                </if>
                <if test="dto.memberNickName != null and dto.memberNickName != ''">
                    and member_nick_name like CONCAT('%',#{dto.memberNickName},'%')
                </if>
                <if test="dto.getType != null and dto.getType != ''">
                    and get_type like CONCAT('%',#{dto.getType},'%')
                </if>
                <if test="dto.createTime != null and dto.createTime != ''">
                    and create_time like CONCAT('%',#{dto.createTime},'%')
                </if>
                <if test="dto.useType != null and dto.useType != ''">
                    and use_type like CONCAT('%',#{dto.useType},'%')
                </if>
                <if test="dto.useTime != null and dto.useTime != ''">
                    and use_time like CONCAT('%',#{dto.useTime},'%')
                </if>
                <if test="dto.orderId != null and dto.orderId != ''">
                    and order_id like CONCAT('%',#{dto.orderId},'%')
                </if>
                <if test="dto.orderSn != null and dto.orderSn != ''">
                    and order_sn like CONCAT('%',#{dto.orderSn},'%')
                </if>
        </where>
    </select>

</mapper>
