<?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.sunxung.factoring.mapper.fundmanagement.FinancialInstitutionMapper">
    <resultMap type="com.sunxung.factoring.entity.fundmanagement.FinancialInstitutionInfo"
               id="financialInstitutionInfoResult">
        <result property="id" column="id"/>
        <result property="institutionId" column="institution_id"/>
        <result property="institutionName" column="institution_name"/>
        <result property="customerManager" column="customer_manager"/>
        <result property="loginName" column="login_name" />
    </resultMap>

    <resultMap type="com.sunxung.factoring.entity.fundmanagement.vo.FinancialInstitutionDetailVo"
               id="financialInstitutionDetailVoResult">
        <result property="institutionId" column="institution_id"/>
        <result property="institutionName" column="institution_name"/>
        <result property="customerManager" column="customer_manager"/>
        <result property="creditSubjectName" column="credit_subject_name"/>
        <result property="projectManager" column="project_manager"/>
        <result property="businessNo" column="business_no"/>
        <result property="contractNo" column="contract_no"/>
        <result property="quotaDisburseBatch" column="quota_disburse_batch"/>
        <result property="relationCustomerId" column="relation_customer_id"/>
        <result property="relationCustomerDisburseId" column="relation_customer_disburse_id"/>
    </resultMap>

    <select id="findBySearch" parameterType="com.sunxung.factoring.entity.BaseSearch"
            resultMap="financialInstitutionInfoResult">
        SELECT
        f.id,
        f.institution_id,
        f.institution_name,
        f.customer_manager,
        s.login_name
        FROM financial_institution_info f
        left join sys_user s on f.institution_name = s.name
        left join sys_user s1 on s1.name = f.customer_manager
        <where>
            <if test="fastSearch != null  and fastSearch !=''">
                AND f.institution_name LIKE concat('%', #{fastSearch}, '%')
            </if>
            <if test="userIds != null and userIds.size() > 0">
                AND s1.id in
                <foreach item="item" collection="userIds" separator="," open="(" close=")"
                         index="">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
    <select id="getDetailList" parameterType="com.sunxung.factoring.entity.fundmanagement.vo.FinancialInstitutionSearch"
            resultMap="financialInstitutionDetailVoResult">
            SELECT
            t1.institution_id,
            t1.institution_name,
            t1.customer_manager,
            t2.credit_subject_name,
            t2.project_manager,
            t3.business_no,
            t3.contract_no,
            t3.quota_disburse_batch,
            t2.id relation_customer_id,
            t3.id relation_customer_disburse_id
        FROM
            financial_relation_customer t2
                LEFT JOIN financial_institution_info t1 ON t1.id = t2.financial_institution_info_id
                LEFT JOIN financial_relation_customer_disburse t3 ON t2.id = t3.financial_relation_customer_id
         WHERE t1.id = #{institutionId}
         order by t2.gmt_create desc
    </select>
</mapper>
