<?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.supplier.SupplierInfoMapper">


    <select id="getById" resultType="com.sunxung.factoring.entity.supplier.SupplierInfo">
        select
            id,
            c_enterprise_id,
            construction_industry,
            sys_user_id,
            status statusStr,
            guarantee_enterprise_id,
            revenue_rating,
            credit_limit,
            admitted,
            score,
            gmt_modified
        from c_supplier_info where id = #{id}
    </select>
    <select id="findBySearch" resultType="com.sunxung.factoring.entity.supplier.SupplierInfo">
        select
            t1.id,
            t1.c_enterprise_id,
            t2.corporate_name supplierName,
            t1.construction_industry,
            t1.sys_user_id,
            t1.status statusStr,
            t3.name statusName,
            t1.guarantee_enterprise_id,
            t1.revenue_rating,
            t1.credit_limit,
            t1.admitted,
            t1.score,
            t1.gmt_modified
        from c_supplier_info t1
            left join c_enterprise t2 on t1.c_enterprise_id = t2.id
            left join t_dictionary t3 on t1.status = t3.code
            left join c_sys_user t4 on t4.id = t1.sys_user_id
        where
        exists (select * from business_processing_log l where l.business_type = 'SupplierInfo' and l.busness_key = t1.id)
            <if test="fastSearch != null and fastSearch !=''">
                AND t2.corporate_name like concat('%',#{fastSearch},'%')
            </if>
            <if test="status != null and status !=''">
                AND t1.status = #{status}
            </if>
            <if test="userIds != null and userIds.size()>0">
                AND  t4.risk_manager in
                <foreach collection="userIds" index="index" item="item"  open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
    </select>

  <select id="findByCUserId" resultType="com.sunxung.factoring.entity.supplier.SupplierInfo"
    parameterType="java.lang.Long">
        select * from  c_supplier_info  a where a.sys_user_id = #{userId}
  </select>

    <select id="getByEnterpriseId" resultType="com.sunxung.factoring.entity.supplier.SupplierInfo" parameterType="java.lang.Long">
        select a.* from c_supplier_info a where a.c_enterprise_id = #{enterpriseId}
    </select>
</mapper>
