<?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.CardOperateMapper">

    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.ucard.CardOperatePageEntity">
        SELECT COUNT(*)
        FROM ucard_operate a
        LEFT JOIN ucard_card b on a.card_no = b.card_no
        LEFT JOIN ucard_merchant_user c on a.unique_id = c.unique_id
        <where>
            <if test="cardNumber != null and cardNumber != ''">
                and b.`card_number` like concat(#{cardNumber},'%')
            </if>
            <if test="email != null and email != ''">
                and c.`email` like concat(#{email},'%')
            </if>
            <if test="mobile!=null and mobile!=''">
                and c.`mobile` like concat(#{mobile},'%')
            </if>
            <if test="cId != null and cId > 0">
                and c.`c_id` = #{cId}
            </if>
            <if test="operateType != null and operateType != ''">
                and a.`operate_type` = #{operateType}
            </if>
            <if test="operateUser != null and operateUser > 0">
                and a.`operate_user` = #{operateUser}
            </if>
            <if test="startDate != null">
                and a.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and a.add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>
    </select>

    <select id="pageList" resultType="com.crm.rely.backend.core.dto.ucard.CardOperateDto"
            parameterType="com.crm.rely.backend.core.entity.ucard.CardOperatePageEntity">
        SELECT a.*,b.card_number as card_number,c.c_id,c.area_code,c.mobile,c.last_name,c.first_name,c.email,c.country
        FROM ucard_operate a
        LEFT JOIN ucard_card b on a.card_no = b.card_no
        LEFT JOIN ucard_merchant_user c on a.unique_id = c.unique_id
        <where>
            <if test="cardNumber != null and cardNumber != ''">
                and b.`card_number` like concat(#{cardNumber},'%')
            </if>
            <if test="email != null and email != ''">
                and c.`email` like concat(#{email},'%')
            </if>
            <if test="mobile!=null and mobile!=''">
                and c.`mobile` like concat(#{mobile},'%')
            </if>
            <if test="cId != null and cId > 0">
                and c.`c_id` = #{cId}
            </if>
            <if test="operateType != null and operateType != ''">
                and a.`operate_type` = #{operateType}
            </if>
            <if test="operateUser != null and operateUser > 0">
                and a.`operate_user` = #{operateUser}
            </if>
            <if test="startDate != null">
                and a.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and a.add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>
        order by a.id desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

</mapper>