<?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.crm.ucard.dao.mapper.CardWalletRecordMapper">

    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.ucard.CardWalletRecordPageEntity">
        SELECT COUNT(*) FROM ucard_wallet_record uw
        left join ucard_merchant_user um
        ON uw.c_id = um.c_id
        <where>
            <if test="type != null and type > 0">
                and uw.`type` = #{type}
            </if>
            <if test="status != null and status > 0">
                and uw.`status` = #{status}
            </if>
            <if test="startDate != null">
                and uw.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and uw.add_time <![CDATA[ < ]]> #{endDate}
            </if>
            <if test="cId!=null and cId > 0">
                and uw.`c_id` = #{cId}
            </if>
            <if test="mobile != null and mobile != ''">
                and um.`mobile` like concat(#{mobile},'%')
            </if>
        </where>
    </select>

    <select id="pageList" resultType="com.crm.rely.backend.core.dto.ucard.CardWalletRecordDto"
            parameterType="com.crm.rely.backend.core.entity.ucard.CardWalletRecordPageEntity">
        SELECT
        uw.*,
        um.area_code,
        um.mobile,
        um.email,
        um.last_name,
        um.first_name,
        um.country
        FROM ucard_wallet_record uw
        left join ucard_merchant_user um
        ON uw.c_id = um.c_id
        <where>
            <if test="type != null and type > 0">
                and uw.`type` = #{type}
            </if>
            <if test="status != null and status > 0">
                and uw.`status` = #{status}
            </if>
            <if test="startDate != null">
                and uw.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and uw.add_time <![CDATA[ < ]]> #{endDate}
            </if>
            <if test="cId!=null and cId > 0">
                and uw.`c_id` = #{cId}
            </if>
            <if test="mobile != null and mobile != ''">
                and um.`mobile` like concat(#{mobile},'%')
            </if>
        </where>
        order by uw.id desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

</mapper> 