<?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.biddingManagement.CBiddingBasicInfoMapper">

    <resultMap id="resultMap" type="com.sunxung.factoring.entity.project.vo.BusinessProcessingTaskVo">
        <result column="id" property="id" />
        <result column="business_number" property="businessNumber" />
        <result column="customer_name" property="customerName" />
        <result column="supplier_name" property="supplierName" />
        <result column="platform_name" property="platformName" />
        <result column="stage" property="stage.code" />
        <result column="status" property="status.code" />
    </resultMap>

    <select id="getCreditProjectByBiddingId"
            resultType="com.sunxung.factoring.entity.biddingManagement.vo.BiddingBasicInfoResultVo">
        SELECT
            c.id,
            t1.business_number,
            t1.project_name,
            t3.corporate_name,
            t5.corporate_name AS main_enterprise,
            t8.platform_name AS platform_name,
            c.stage,
            c.status
        FROM c_bidding_basic_info c
                 LEFT JOIN c_project_information t1 ON t1.id = c.c_project_information_id
                 LEFT JOIN c_supplier_info t2 ON t2.id = t1.c_supplier_info_id
                 LEFT JOIN c_enterprise t3 ON t3.id = t2.c_enterprise_id
                 LEFT JOIN c_project_core_enterprise t4 ON  t4.c_project_information_id = t1.id
                 LEFT JOIN c_enterprise t5 ON t5.id = t4.c_enterprise_id
                 LEFT JOIN trading_platform t8 ON t8.id = c.trading_platform_id
        WHERE c.id = #{value}
    </select>
    <select id="findAllList" resultMap="resultMap">
        SELECT
        c.id,
        t1.business_number,
        t1.project_name,
        t3.corporate_name AS supplier_name,
        t5.corporate_name AS customer_name,
        -- 贸易平台
        t8.platform_name AS platform_name,
        c.stage,
        c.status,
        c.gmt_create,
        c.gmt_modified
        FROM c_bidding_basic_info c
        LEFT JOIN c_project_information t1 ON t1.id = c.c_project_information_id
        LEFT JOIN c_supplier_info t2 ON t2.id = t1.c_supplier_info_id
        LEFT JOIN c_enterprise t3 ON t3.id = t2.c_enterprise_id
        LEFT JOIN c_project_core_enterprise t4 ON t4.c_project_information_id = t1.id
        LEFT JOIN c_enterprise t5 ON t5.id = t4.c_enterprise_id
        LEFT JOIN trading_platform t8 ON t8.id = c.trading_platform_id
        LEFT JOIN c_sys_user t9 ON t9.id = t2.sys_user_id
        <where>
            <if test="businessNo != null and businessNo !=''  ">
                AND t1.business_number = #{businessNo}
            </if>
            <if test="status != null and status !='' ">
                AND c.status = #{status}
            </if>
            <if test="fastSearch != null and fastSearch !='' ">
                AND (t1.project_name LIKE CONCAT('%',#{fastSearch},'%') or t3.corporate_name LIKE
                CONCAT('%',#{fastSearch},'%')
                or t5.corporate_name LIKE CONCAT('%',#{fastSearch},'%'))
            </if>
            <if test="null != userIds and userIds.size()>0">
                AND t9.project_manager in
                <foreach item="item" collection="userIds" separator="," open="(" close=")"
                         index="">
                    #{item}
                </foreach>
            </if>

        </where>
        ORDER BY c.gmt_modified DESC
    </select>
    <select id="get" resultType="com.sunxung.factoring.entity.biddingManagement.CBiddingBasicInfo">
        SELECT
        c.id,
        t1.business_number,
        t1.project_name,
        t3.corporate_name AS owner_name,
        t5.corporate_name AS customer_name,
        -- 贸易平台
        t8.platform_name AS trading_platform_name,
        c.stage,
        c.status AS status_code,
        c.gmt_create,
        c.gmt_modified
        FROM c_bidding_basic_info c
        LEFT JOIN c_project_information t1 ON t1.id = c.c_project_information_id
        LEFT JOIN c_supplier_info t2 ON t2.id = t1.c_supplier_info_id
        LEFT JOIN c_enterprise t3 ON t3.id = t2.c_enterprise_id
        LEFT JOIN c_project_core_enterprise t4 ON t4.c_project_information_id = t1.id
        LEFT JOIN c_enterprise t5 ON t5.id = t4.c_enterprise_id
        LEFT JOIN trading_platform t8 ON t8.id = c.trading_platform_id
        WHERE  c.id = #{value}
        ORDER BY c.gmt_modified DESC
    </select>
    <select id="getByHisId"
            resultType="com.sunxung.factoring.entity.biddingManagement.vo.BiddingBasicInfoResultVo">
        SELECT
            c.id,
            t1.id AS project_information_id,
            t1.business_number,
            t1.project_name,
            t3.corporate_name AS main_enterprise,
            t5.corporate_name AS enterprise,
            t8.platform_name AS platform
        FROM bidding_basic_info_his c
                 LEFT JOIN c_project_information t1 ON t1.id = c.c_project_information_id
                 LEFT JOIN c_supplier_info t2 ON t2.id = t1.c_supplier_info_id
                 LEFT JOIN c_enterprise t3 ON t3.id = t2.c_enterprise_id
                 LEFT JOIN c_project_core_enterprise t4 ON  t4.c_project_information_id = t1.id
                 LEFT JOIN c_enterprise t5 ON t5.id = t4.c_enterprise_id
                 LEFT JOIN trading_platform t8 ON t8.id = c.trading_platform_id
        WHERE c.id = #{value}
    </select>

</mapper>
