<?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.chushang.loan.mapper.LoanMapper">


    <select id="queryDataList" resultType="com.chushang.loan.domin.vo.LoanData"
            parameterType="com.chushang.loan.domin.vo.LoanData">
        select channel_name,
               author_name,
               author_phone,
               COUNT(if(status = 2, id, null))        as totalOpenFlux,
               SUM(if(status = 2, loan_amount, null)) as totalLoanAmount,
               sum(application_amount)                as totalTransactionAmount
        from loan l
        where l.del_state = false
        <if test="query.channelName != '' and query.channelName != null">
            AND l.channel_name like concat('%',#{query.channelName},'%')
        </if>
        <if test="query.formNumber != '' and query.formNumber != null ">
            AND l.form_number = #{query.formNumber}
        </if>
        <if test="query.authorPhone != '' and query.authorPhone != null">
            AND l.author_phone = #{query.authorPhone}
        </if>
        <if test="query.authorName != '' and query.authorName != null ">
            AND l.author_name like concat('%',#{query.authorName},'%')
        </if>
        <if test="query.status != null">
            AND l.status = #{query.status}
        </if>

        <if test="query.submissionTimes != null and query.submissionTimes.size() > 1 ">
            AND l.submission_time between #{query.submissionTimes[0]} and #{query.submissionTimes[1]}
        </if>
        ${query.sqlParam.dataScope}

        group by user_id,channel_name,author_name,author_phone
    </select>

</mapper>
