<?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.inkasso.factoring.creditmanagement.dao.ProjectInformationMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.inkasso.factoring.creditmanagement.entity.ProjectInformation">
        <id column="id" property="id"/>
        <result column="c_supplier_info_id" property="cSupplierInfoId"/>
        <result column="business_number" property="businessNumber"/>
        <result column="project_type" property="projectType"/>
        <result column="project_name" property="projectName"/>
        <result column="c_enterprise_id" property="cEnterpriseId"/>
        <result column="company_for_project" property="companyForProject"/>
        <result column="project_address" property="projectAddress"/>
        <result column="project_cycle" property="projectCycle"/>
        <result column="project_nature" property="projectNature"/>
        <result column="project_nature_detail" property="projectNatureDetail"/>
        <result column="goods_category" property="goodsCategory"/>
        <result column="goods_category_detail" property="goodsCategoryDetail"/>
        <result column="purpose" property="purpose"/>
        <result column="financial_funds" property="financialFunds"/>
        <result column="bank_loans" property="bankLoans"/>
        <result column="foreign_capital" property="foreignCapital"/>
        <result column="raise_independently" property="raiseIndependently"/>
        <result column="special_fund" property="specialFund"/>
        <result column="other_funds" property="otherFunds"/>
        <result column="unknown" property="unknown"/>
        <result column="bidding" property="bidding"/>
        <result column="cooperation_amount" property="cooperationAmount"/>
        <result column="peak_value" property="peakValue"/>
        <result column="estimated_accounting_period" property="estimatedAccountingPeriod"/>
        <result column="high_peak_usage" property="highPeakUsage"/>
        <result column="status" property="status"/>
        <result column="user_create" property="userCreate"/>
        <result column="user_modified" property="userModified"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id
        , c_supplier_info_id, business_number, project_type, project_name, c_enterprise_id, company_for_project, project_address, project_cycle, project_nature, project_nature_detail, goods_category, goods_category_detail, purpose, financial_funds, bank_loans, foreign_capital, raise_independently, special_fund, other_funds, unknown, bidding, cooperation_amount, peak_value, estimated_accounting_period, high_peak_usage, status, user_create, user_modified, gmt_create, gmt_modified
    </sql>
    <select id="getUserBiddingProjects"
            resultType="com.inkasso.factoring.creditmanagement.entity.vo.UserBiddingProjectsVo">
        SELECT c.id              AS project_information_id,
               c.project_name,
               c.business_number,
               t2.corporate_name AS main_enterprise, -- 主企业
               t4.corporate_name AS enterprise       -- 核心企业
        FROM c_project_information c
                 LEFT JOIN c_supplier_info t1 ON t1.id = c.c_supplier_info_id
                 LEFT JOIN c_enterprise t2 ON t2.id = t1.c_enterprise_id
                 LEFT JOIN c_project_core_enterprise t3 ON t3.c_project_information_id = c.id
                 LEFT JOIN c_enterprise t4 ON t4.id = t3.c_enterprise_id
                 LEFT JOIN credit_resolution t5 ON t5.c_project_information_id = c.id
        WHERE t1.sys_user_id = #{value}
          AND c.bidding = 1
          AND c.`status` = 'c_project_and_enterprise_status_4' -- 通过
          AND t5.`status` = 'project_init_completed'
          AND c.already_bidding = 0
        order by c.gmt_modified desc
    </select>
    <select id="getLocalPurchCompletedProject"
            resultType="com.inkasso.factoring.creditmanagement.entity.ProjectInformation">
        SELECT t2.*
        FROM c_purch_contract_management c
                 LEFT JOIN c_project_information t2 ON t2.business_number = c.business_number
                 LEFT JOIN c_supplier_info t3 ON t3.id = c.c_supplier_info_id
        WHERE c.contract_status = 'project_init_completed'
          AND t3.sys_user_id = #{userId}
    </select>

</mapper>
