<?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.manager.dao.mapper.CustomKycApproveMapper">

    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.custom.kyc.CustomKycApproveSearchEntity">
        select count(*) from custom_kyc_approve kyc
            left join custom_info cus on kyc.custom_id = cus.id
        <where>
            <if test="cId!=null">
                and kyc.`c_id` = #{cId}
            </if>
            <if test="status!=null">
                and kyc.`status` = #{status}
            </if>
            <if test="email!=null and email!=''">
                and cus.`email` like concat(#{email},"%")
            </if>
            <if test="ibNo!=null and ibNo!=''">
                and agent.`ib_no` = #{ibNo}
            </if>
        </where>
    </select>

    <select id="pageList" resultType="com.crm.rely.backend.core.dto.custom.CustomKycApproveListDto"
            parameterType="com.crm.rely.backend.core.entity.custom.kyc.CustomKycApproveSearchEntity">
        select kyc.*,cus.first_name,cus.last_name,cus.email,agent.ib_no,cus.phone,cus.country,cus.identity,cus.middle
        from custom_kyc_approve kyc
        left join custom_info cus on kyc.custom_id = cus.id
        left join user_info agent on cus.agent_id = agent.id
        <where>
            <if test="cId!=null">
                and kyc.`c_id` = #{cId}
            </if>
            <if test="status!=null">
                and kyc.`status` = #{status}
            </if>
            <if test="email!=null and email!=''">
                and cus.`email` like concat(#{email},"%")
            </if>
            <if test="ibNo!=null and ibNo!=''">
                and agent.`ib_no` = #{ibNo}
            </if>
        </where>
        order by id desc
        limit #{page.offset},#{page.row}
    </select>

    <select id="getKycApproveById" resultType="com.crm.rely.backend.core.dto.custom.CustomKycApproveListDto">
        select kyc.*,cus.first_name,cus.last_name,cus.email,cus.ib_no,cus.phone,cus.country,cus.identity
        from custom_kyc_approve kyc
        left join custom_info cus on kyc.custom_id = cus.id
        where kyc.id = #{id}
    </select>

</mapper>