<?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="cn.com.countrygarden.bi.main.dao.extension.ExtensionReportMapper">

    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.dto.extension.ExtensionReportDTO" >
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="committee_status" property="committeeStatus"           />
        <result column="extension_person" property="extensionPerson"           />
        <result column="extension_person_tel" property="extensionPersonTel"    />
        <result column="contract_property" property="contractProperty"         />
        <result column="contract_sing_date" property="contractSingDate"         />
        <result column="contract_commencement_date" property="contractCommencementDate" />
        <result column="contract_end_date" property="contractEndDate"                   />
        <result column="plan_number" property="planNumber"                               />
        <result column="contract_area" property="contractArea"                           />
        <result column="empty_room_fees_agreement" property="emptyRoomFeesAgreement"     />
        <result column="property_fees_price_agreement" property="propertyFeesPriceAgreement" />
        <result column="start_up_fees_agreement" property="startUpFeesAgreement"              />
        <result column="other_agreement" property="otherAgreement"                            />
        <result column="first_main_collection_rate" property="firstMainCollectionRate"       />
        <result column="first_sales_revenue" property="firstSalesRevenue" />
        <result column="first_subsidy" property="firstSubsidy"  />
        <result column="first_total_cost" property="firstTotalCost"  />
        <result column="first_net_profit" property="firstNetProfit"  />
        <result column="first_main_business_profit" property="firstMainBusinessProfit"  />
        <result column="second_main_collection_rate" property="secondMainCollectionRate" />
        <result column="second_sales_revenue" property="secondSalesRevenue" />
        <result column="second_subsidy" property="secondSubsidy" />
        <result column="second_total_cost" property="secondTotalCost"  />
        <result column="second_net_profit" property="secondNetProfit"  />
        <result column="second_main_business_profit" property="secondMainBusinessProfit"  />
        <result column="thirdly_main_collection_rate" property="thirdlyMainCollectionRate" />
        <result column="thirdly_sales_revenue" property="thirdlySalesRevenue" />
        <result column="thirdly_subsidy" property="thirdlySubsidy"  />
        <result column="thirdly_total_cost" property="thirdlyTotalCost"  />
        <result column="thirdly_net_profit" property="thirdlyNetProfit"  />
        <result column="thirdly_main_business_profit" property="thirdlyMainBusinessProfit"  />
        <result column="is_delete" property="isDelete" />
        <result column="erp_id" property="erpId"  />
        <result column="property_area" property="propertyArea" />
        <result column="area_number" property="areaNumber" />
        <result column="property_project" property="propertyProject"  />
        <result column="comm_kind" property="commKind" />
        <result column="project_number" property="projectNumber"/>
        <result column="project_type" property="projectType" />
        <result column="province" property="province"  />
        <result column="city" property="city" />
        <result column="borough" property="borough"  />
        <result column="region" property="region"  />
        <result column="conventional_charges" property="conventionalCharges"  />
        <result column="conventional_service" property="conventionalService"  />
        <result column="sales_field_charges" property="salesFieldCharges"  />
        <result column="sales_field_service" property="salesFieldService"  />
        <result column="property_form" property="propertyForm"  />
        <result column="development_state" property="developmentState"  />
        <result column="organ_name" property="organName"/>
        <result column="project_name" property="projectName"/>
        <result column="proposalOrganName" property="proposalOrganName"/>
        <result column="project_nature_name" property="projectNature"/>
        <result column="is_new" property="isNew"/>
        <result column="corp_type_name" property="corpType"/>
        <result column="sign_time" property="signTime"/>
        <result column="create_date" property="createDate"  />
        <result column="create_by" property="createBy"  />
        <result column="last_update_date" property="lastUpdateDate"  />
        <result column="last_update_by" property="lastUpdateBy"  />
        <result column="binding_Identifier" property="bindingIdentifier"  />
        <result column="dup_id" property="dupId" jdbcType="BIGINT" />
        <result column="property_name" property="propertyName"  />
        <result column="property_form" property="propertyForm"  />
        <result column="parent_company" property="parentCompany"  />
        <result column="nc_system_account" property="ncSystemAccount"  />
        <result column="nc_system_number" property="ncSystemNumber"  />
        <result column="nc_person_number" property="ncPersonNumber"  />
        <result column="fund_type" property="fundType"  />
        <result column="development_subject_names" property="developmentSubjectNames"  />
        <result column="development_subject" property="developmentSubject"  />
        <result column="takeover_state" property="takeoverState"  />
        <result column="manage_time" property="manageTime"  />
        <result column="actual_enter_time" property="actualEnterTime"  />
        <result column="state_property" property="stateProperty"  />
        <result column="actual_open" property="actualOpen"  />
        <result column="planned_open" property="plannedOpen"  />
        <result column="contract_property_date" property="contractPropertyDate"  />
        <result column="actual_property" property="actualProperty"  />
        <result column="end_case_date" property="endCaseDate"  />
        <result column="end_estate_management_date" property="endEstateManagementDate"  />
        <collection property="jointDTO" ofType="cn.com.countrygarden.bi.main.dto.extension.ExtensionJointInfoDTO"
                    resultMap="jointMap" >
        </collection>
        <collection property="leaderDTO" ofType="cn.com.countrygarden.bi.main.dto.extension.ExtensionProjectLeaderDTO"
                    resultMap="leaderMap" >
        </collection>
        <collection property="propertyCompositionDTOS" ofType="cn.com.countrygarden.bi.main.dto.extension.ExtensionPropertyCompositionDTO"
                    resultMap="propertyMap">
        </collection>
        <collection property="fileInfos" ofType="cn.com.countrygarden.bi.main.dto.extension.ExtensionUpFileInfo"
                    resultMap="fileInfoMap" >
        </collection>
    </resultMap>


    <resultMap id="selectResultMap" type="cn.com.countrygarden.bi.main.dto.extension.ExtensionReportDTO" >
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="committee_status" property="committeeStatus"           />
        <result column="extension_person" property="extensionPerson"           />
        <result column="extension_person_tel" property="extensionPersonTel"    />
        <result column="contract_property" property="contractProperty"         />
        <result column="contract_sing_date" property="contractSingDate"         />
        <result column="contract_commencement_date" property="contractCommencementDate" />
        <result column="contract_end_date" property="contractEndDate"                   />
        <result column="plan_number" property="planNumber"                               />
        <result column="contract_area" property="contractArea"                           />
        <result column="empty_room_fees_agreement" property="emptyRoomFeesAgreement"     />
        <result column="property_fees_price_agreement" property="propertyFeesPriceAgreement" />
        <result column="start_up_fees_agreement" property="startUpFeesAgreement"              />
        <result column="other_agreement" property="otherAgreement"                            />
        <result column="first_main_collection_rate" property="firstMainCollectionRate"       />
        <result column="first_sales_revenue" property="firstSalesRevenue" />
        <result column="first_subsidy" property="firstSubsidy"  />
        <result column="first_total_cost" property="firstTotalCost"  />
        <result column="first_net_profit" property="firstNetProfit"  />
        <result column="first_main_business_profit" property="firstMainBusinessProfit"  />
        <result column="second_main_collection_rate" property="secondMainCollectionRate" />
        <result column="second_sales_revenue" property="secondSalesRevenue" />
        <result column="second_subsidy" property="secondSubsidy" />
        <result column="second_total_cost" property="secondTotalCost"  />
        <result column="second_net_profit" property="secondNetProfit"  />
        <result column="second_main_business_profit" property="secondMainBusinessProfit"  />
        <result column="thirdly_main_collection_rate" property="thirdlyMainCollectionRate" />
        <result column="thirdly_sales_revenue" property="thirdlySalesRevenue" />
        <result column="thirdly_subsidy" property="thirdlySubsidy"  />
        <result column="thirdly_total_cost" property="thirdlyTotalCost"  />
        <result column="thirdly_net_profit" property="thirdlyNetProfit"  />
        <result column="thirdly_main_business_profit" property="thirdlyMainBusinessProfit"  />
        <result column="is_delete" property="isDelete" />
        <result column="erp_id" property="erpId"  />
        <result column="property_area" property="propertyArea" />
        <result column="area_number" property="areaNumber" />
        <result column="property_project" property="propertyProject"  />
        <result column="comm_kind" property="commKind" />
        <result column="project_number" property="projectNumber"/>
        <result column="project_type" property="projectType" />
        <result column="province" property="province"  />
        <result column="city" property="city" />
        <result column="borough" property="borough"  />
        <result column="region" property="region"  />
        <result column="conventional_charges" property="conventionalCharges"  />
        <result column="conventional_service" property="conventionalService"  />
        <result column="sales_field_charges" property="salesFieldCharges"  />
        <result column="sales_field_service" property="salesFieldService"  />
        <result column="property_form" property="propertyForm"  />
        <result column="development_state" property="developmentState"  />
        <result column="organ_name" property="organName"/>
        <result column="project_name" property="projectName"/>
        <result column="proposalOrganName" property="proposalOrganName"/>
        <result column="project_nature_name" property="projectNature"/>
        <result column="is_new" property="isNew"/>
        <result column="corp_type_name" property="corpType"/>
        <result column="sign_time" property="signTime"/>
        <result column="create_date" property="createDate"  />
        <result column="create_by" property="createBy"  />
        <result column="last_update_date" property="lastUpdateDate"  />
        <result column="last_update_by" property="lastUpdateBy"  />
        <result column="binding_Identifier" property="bindingIdentifier"  />
        <result column="dup_id" property="dupId" jdbcType="BIGINT" />
        <result column="property_name" property="propertyName"  />
        <result column="property_form" property="propertyForm"  />
        <result column="parent_company" property="parentCompany"  />
        <result column="nc_system_account" property="ncSystemAccount"  />
        <result column="nc_system_number" property="ncSystemNumber"  />
        <result column="nc_person_number" property="ncPersonNumber"  />
        <result column="fund_type" property="fundType"  />
        <result column="development_subject_names" property="developmentSubjectNames"  />
        <result column="development_subject" property="developmentSubject"  />
        <result column="takeover_state" property="takeoverState"  />
        <result column="manage_time" property="manageTime"  />
        <result column="actual_enter_time" property="actualEnterTime"  />
        <result column="state_property" property="stateProperty"  />
        <result column="actual_open" property="actualOpen"  />
        <result column="planned_open" property="plannedOpen"  />
        <result column="contract_property_date" property="contractPropertyDate"  />
        <result column="actual_property" property="actualProperty"  />
        <result column="end_case_date" property="endCaseDate"  />
        <result column="end_estate_management_date" property="endEstateManagementDate"  />
        <collection property="jointDTO" ofType="cn.com.countrygarden.bi.main.dto.extension.ExtensionJointInfoDTO"
                    select="getJointListById" column="id" >
        </collection>
        <collection property="leaderDTO" ofType="cn.com.countrygarden.bi.main.dto.extension.ExtensionProjectLeaderDTO"
                    select="getLeaderListById" column="id" >
        </collection>
        <collection property="propertyCompositionDTOS" ofType="cn.com.countrygarden.bi.main.dto.extension.ExtensionPropertyCompositionDTO"
                    select="getProperty" column="dup_id">
        </collection>
        <collection property="fileInfos" ofType="cn.com.countrygarden.bi.main.dto.extension.ExtensionUpFileInfo"
                    select="getFileInfo" column="id" >
        </collection>
    </resultMap>


    <resultMap id="jointMap" type="cn.com.countrygarden.bi.main.dto.extension.ExtensionJointInfoDTO" >
        <result column="joint_id" property="id"  />
        <result column="joint_name" property="jointName"  />
        <result column="extension_report_id" property="extensionReportId"  />
        <result column="joint_tel" property="jointTel"  />
        <result column="joint_create_date" property="createDate"  />
        <result column="joint_create_by" property="createBy"  />
        <result column="joint_last_update_date" property="lastUpdateDate"  />
        <result column="joint_last_update_by" property="lastUpdateBy"  />
        <result column="joint_is_delete" property="isDelete"  />
    </resultMap>

    <resultMap id="leaderMap" type="cn.com.countrygarden.bi.main.dto.extension.ExtensionProjectLeaderDTO">
        <result column="leader_id" property="id"  />
        <result column="leader_name" property="leaderName"  />
        <result column="leader_extension_report_id" property="extensionReportId"  />
        <result column="leader_tel" property="leaderTel"  />
        <result column="leader_create_date" property="createDate"  />
        <result column="leader_create_by" property="createBy"  />
        <result column="leader_last_update_date" property="lastUpdateDate"  />
        <result column="leader_last_update_by" property="lastUpdateBy"  />
        <result column="is_delete" property="isDelete"  />
    </resultMap>

    <resultMap id="propertyMap" type="cn.com.countrygarden.bi.main.dto.extension.ExtensionPropertyCompositionDTO">
        <result column="property_id" property="id"  />
        <result column="property_project_sign_id" property="projectSignId"  />
        <result column="property_business_type_name" property="businessTypeName"  />
        <result column="property_rates_area" property="ratesArea"  />
        <result column="property_price" property="price"  />
        <result column="property_month_income" property="monthIncome"  />
        <result column="property_year_income" property="yearIncome"  />
        <result column="property_gmt_create" property="createDate"  />
        <result column="property_create_by" property="createBy"  />
        <result column="property_gmt_modified" property="lastUpdateDate"  />
        <result column="property_modified_by" property="lastUpdateBy"  />
        <result column="property_is_delete" property="isDelete"  />
    </resultMap>

    <resultMap id="fileInfoMap" type="cn.com.countrygarden.bi.main.dto.extension.ExtensionUpFileInfo">
        <result column="file_id" property="id"  />
        <result column="file_extension_report_id" property="extensionReportId"  />
        <result column="file_name" property="fileName" />
        <result column="file_real_name" property="fileRealName" />
        <result column="file_url" property="fileUrl" />
        <result column="file_tab" property="fileTab" />
        <result column="file_create_date" property="createDate"  />
        <result column="file_create_by" property="createBy"  />
        <result column="file_last_update_date" property="lastUpdateDate"  />
        <result column="file_last_update_by" property="lastUpdateBy"  />
        <result column="file_is_delete" property="isDelete"  />
    </resultMap>

    <resultMap id="erpMap" type="cn.com.countrygarden.bi.main.dto.extension.ExtensionErpDTO">
        <result column="erp_id" property="id"/>
        <result column="property_area" property="propertyArea"/>
        <result column="area_number" property="areaNumber"/>
        <result column="property_project" property="propertyProject"/>
        <result column="comm_kind" property="commKind"/>
        <result column="project_number" property="projectNumber"/>
        <result column="project_type" property="projectType"/>
        <result column="province"  property="province" />
    </resultMap>

    <sql id="Base_Column_List" >
        jo.id AS joint_id,
        jo.joint_name,
        jo.joint_tel,
        jo.extension_report_id,
        jo.create_date AS joint_create_date,
        jo.create_by AS joint_create_by,
        jo.last_update_date AS joint_last_update_date,
        jo.last_update_by AS joint_last_update_by,
        jo.is_delete AS joint_is_delete,
        pl.id AS leader_id,
        pl.leader_name,
        pl.leader_tel,
        pl.extension_report_id AS leader_extension_report_id,
        pl.create_by AS leader_create_by,
        pl.create_date as leader_create_date,
        pl.last_update_date AS leader_last_update_date,
        pl.last_update_by AS leader_last_update_by,
        pl.is_delete as leader_is_delete,
        psi.id AS property_id,
        psi.project_sign_id AS property_project_sign_id,
        psi.business_type_name AS property_business_type_name,
        psi.rates_area AS property_rates_area,
        psi.price AS property_price,
        psi.month_income AS property_month_income,
        psi.year_income AS property_year_income,
        psi.gmt_create AS property_gmt_create,
        psi.create_by AS property_create_by,
        psi.gmt_modified AS property_gmt_modified,
        psi.modified_by AS property_modified_by,
        ps.is_delete as property_is_delete,
        uf.id AS file_id,
        uf.extension_report_id as file_extension_report_id,
        uf.file_name,
        uf.file_real_name,
        uf.file_url,
        uf.file_tab,
        uf.create_date as file_create_date,
        uf.create_by as file_create_by,
        uf.last_update_date as file_last_update_date,
        uf.last_update_by as file_last_update_by,
        uf.is_delete as file_is_delete,
        er.id,
        er.committee_status ,
        er.extension_person ,
        er.extension_person_tel ,
        DATE_FORMAT(er.contract_sing_date,'%Y-%m-%d') as contract_sing_date,
        DATE_FORMAT(er.contract_commencement_date,'%Y-%m-%d') as contract_commencement_date,
        er.contract_end_date,
        er.plan_number,
        er.empty_room_fees_agreement,
        er.property_fees_price_agreement,
        er.start_up_fees_agreement,
        er.other_agreement,
        er.first_main_collection_rate,
        er.first_sales_revenue,
        er.first_subsidy,
        er.first_total_cost,
        er.first_net_profit,
        er.first_main_business_profit,
        er.second_main_collection_rate,
        er.second_sales_revenue,
        er.second_subsidy,
        er.second_total_cost,
        er.second_net_profit,
        er.second_main_business_profit,
        er.thirdly_main_collection_rate,
        er.thirdly_sales_revenue,
        er.thirdly_subsidy,
        er.thirdly_total_cost,
        er.thirdly_net_profit,
        er.thirdly_main_business_profit,
        er.is_delete,
        er.erp_id,
        er.property_area,
        er.area_number,
        er.property_project,
        er.property_form,
        er.comm_kind,
        er.project_number,
        er.project_type,
        er.province,
        er.city,
        er.borough,
        er.region,
        er.conventional_charges,
        er.conventional_service,
        er.sales_field_charges,
        er.sales_field_service,
        er.development_state,
        er.dup_id,
        DATE_FORMAT(er.create_date,'%Y-%m-%d') as create_date,
        er.create_by,
        DATE_FORMAT(er.last_update_date,'%Y-%m-%d') as last_update_date,
        er.last_update_by,
        er.binding_Identifier,
        er.property_name,
        er.parent_company,
        er.nc_system_account,
        er.nc_system_number,
        er.nc_person_number,
        er.fund_type,
        er.development_subject_names,
        er.development_subject,
        er.takeover_state,
        er.contract_property,
        DATE_FORMAT(er.manage_time,'%Y-%m-%d') as manage_time,
        DATE_FORMAT(er.actual_enter_time,'%Y-%m-%d') as actual_enter_time,
        er.state_property,
        DATE_FORMAT(er.actual_open,'%Y-%m-%d') as actual_open,
        DATE_FORMAT(er.planned_open,'%Y-%m-%d') as planned_open,
        DATE_FORMAT(er.contract_property_date,'%Y-%m-%d') as contract_property_date,
        DATE_FORMAT(er.actual_property,'%Y-%m-%d') as actual_property,
        DATE_FORMAT(er.end_case_date,'%Y-%m-%d') as end_case_date,
        DATE_FORMAT(er.end_estate_management_date,'%Y-%m-%d') as end_estate_management_date
    </sql>

    <sql id="select_Column_List" >
        er.id,
        er.committee_status ,
        er.extension_person ,
        er.extension_person_tel ,
        DATE_FORMAT(er.contract_sing_date,'%Y-%m-%d') as contract_sing_date,
        DATE_FORMAT(er.contract_commencement_date,'%Y-%m-%d') as contract_commencement_date,
        er.contract_end_date,
        er.plan_number,
        er.empty_room_fees_agreement,
        er.property_fees_price_agreement,
        er.start_up_fees_agreement,
        er.other_agreement,
        er.first_main_collection_rate,
        er.first_sales_revenue,
        er.first_subsidy,
        er.first_total_cost,
        er.first_net_profit,
        er.first_main_business_profit,
        er.second_main_collection_rate,
        er.second_sales_revenue,
        er.second_subsidy,
        er.second_total_cost,
        er.second_net_profit,
        er.second_main_business_profit,
        er.thirdly_main_collection_rate,
        er.thirdly_sales_revenue,
        er.thirdly_subsidy,
        er.thirdly_total_cost,
        er.thirdly_net_profit,
        er.thirdly_main_business_profit,
        er.is_delete,
        er.erp_id,
        er.property_area,
        er.area_number,
        er.property_project,
        er.property_form,
        er.comm_kind,
        er.project_number,
        er.project_type,
        er.province,
        er.city,
        er.borough,
        er.region,
        er.conventional_charges,
        er.conventional_service,
        er.sales_field_charges,
        er.sales_field_service,
        er.development_state,
        er.dup_id,
        DATE_FORMAT(er.create_date,'%Y-%m-%d') as create_date,
        er.create_by,
        DATE_FORMAT(er.last_update_date,'%Y-%m-%d') as last_update_date,
        er.last_update_by,
        er.binding_Identifier,
        er.property_name,
        er.parent_company,
        er.nc_system_account,
        er.nc_system_number,
        er.nc_person_number,
        er.fund_type,
        er.development_subject_names,
        er.development_subject,
        er.takeover_state,
        er.contract_property,
        DATE_FORMAT(er.manage_time,'%Y-%m-%d') as manage_time,
        DATE_FORMAT(er.actual_enter_time,'%Y-%m-%d') as actual_enter_time,
        er.state_property,
        DATE_FORMAT(er.actual_open,'%Y-%m-%d') as actual_open,
        DATE_FORMAT(er.planned_open,'%Y-%m-%d') as planned_open,
        DATE_FORMAT(er.contract_property_date,'%Y-%m-%d') as contract_property_date,
        DATE_FORMAT(er.actual_property,'%Y-%m-%d') as actual_property,
        DATE_FORMAT(er.end_case_date,'%Y-%m-%d') as end_case_date,
        DATE_FORMAT(er.end_estate_management_date,'%Y-%m-%d') as end_estate_management_date
    </sql>

    <!-- 查询已绑定数据 -->
    <select id="selectAllByDTO" resultMap="BaseResultMap">
        SELECT
        er.id,
        er.erp_id,
        er.property_area,
        er.area_number,
        er.property_project,
        er.comm_kind,
        er.project_number,
        er.project_type,
        er.province,
        er.conventional_charges,
        er.conventional_service,
        er.property_form,
        er.development_state,
        er.dup_id,
        ps.project_name ,
        ps.organ_name ,
        ps.project_nature_name ,
        ps.is_new ,
        ps.corp_type_name ,
        DATE_FORMAT(er.contract_sing_date,'%Y-%m-%d') as contract_sing_date,
        DATE_FORMAT(er.create_date,'%Y-%m-%d') as create_date,
        er.create_by,
        er.binding_Identifier,
        DATE_FORMAT(er.last_update_date,'%Y-%m-%d') as last_update_date,
        er.last_update_by,
        org.name as 'proposalOrganName'
        FROM
        extension_report er
        LEFT JOIN project_sign ps ON ps.id = er.dup_id AND ps.is_delete = 0
        LEFT JOIN organ o ON o.name = ps.organ_name
        LEFT JOIN organ org ON org.organ_code = ps.proposal_organ_id
        <where>
            er.binding_Identifier = 1 AND er.is_delete = 0
            <if test="dto.propertyArea != null and dto.propertyArea != ''" > AND er.property_area in
                <foreach collection="dto.propertyArea.split(',')" item="item" index="index"   open="(" separator="," close=")">
                    '${item}'
                </foreach>
            </if>
            <if test="dto.propertyProject != null and dto.propertyProject != ''"> AND er.property_project LIKE CONCAT('%',#{dto.propertyProject},'%') </if>
            <if test="dto.developmentState != null and dto.developmentState != ''"> AND er.development_state = #{dto.developmentState} </if>
            <if test="dto.conventionalCharges != null and dto.conventionalCharges != ''"> AND er.conventional_charges = #{dto.conventionalCharges} </if>
            <if test="dto.conventionalService != null and dto.conventionalService != ''"> AND er.conventional_service = #{dto.conventionalService} </if>
            <if test="dto.propertyForm != null and dto.propertyForm != ''"> AND er.property_form  = #{dto.propertyForm}  </if>
            <if test="dto.projectType != null and dto.projectType != ''"> AND er.project_type = #{dto.projectType} </if>
            <if test="dto.projectName != null and dto.projectName != ''"> AND ps.project_name LIKE CONCAT('%',#{dto.projectName},'%') </if>
            <if test="dto.organName != null and dto.organName != ''"> AND ps.organ_name LIKE CONCAT('%',#{dto.organName},'%') </if>
            <if test="dto.proposalOrganName != null and dto.proposalOrganName != ''"> AND org.name = #{dto.proposalOrganName} </if>
            <if test="dto.signTime != null and dto.signTime != ''"> AND date_format(ps.sing_time_str,'%Y-%m-%d') &gt;= #{dto.signTime} </if>
            <if test="dto.signTimeEnd != null and dto.signTimeEnd != ''"> AND date_format(ps.sing_time_str,'%Y-%m-%d') &lt;=  #{dto.signTimeEnd} </if>
            <if test="organName != null and organName != ''" >
                AND org.name = #{organName}
            </if>
        </where>
        ORDER BY er.property_area DESC
    </select>
    <!-- 已绑定 导出 -->

    <!-- 查询 ERP 已绑定数据 ids -->
    <select id="selectErpBindingId" resultType="java.lang.Long" >
        SELECT
        er.erp_id
        FROM
        extension_report er
        LEFT JOIN project_sign ps ON ps.id = er.dup_id AND ps.is_delete = 0
        LEFT JOIN organ o ON o.name = ps.organ_name
        LEFT JOIN organ org ON org.organ_code = ps.proposal_organ_id
        WHERE
        er.binding_Identifier = 1 AND er.is_delete = 0
        <if test="organName != null and organName != ''" >
            AND org.name = #{organName}
        </if>
    </select>
    <!-- 查询 DUP 已绑定数据 ids -->
    <select id="selectDupBindingId" resultType="java.lang.Long" >
        SELECT
        er.dup_id
        FROM
        extension_report er
        LEFT JOIN project_sign ps ON ps.id = er.dup_id AND ps.is_delete = 0
        LEFT JOIN organ o ON o.name = ps.organ_name
        LEFT JOIN organ org ON org.organ_code = ps.proposal_organ_id
        WHERE
        er.binding_Identifier = 1 AND er.is_delete = 0
        <if test="organName != null and organName != ''" >
            AND org.name = #{organName}
        </if>
    </select>


    <!-- 查询 ERP 已绑定数据 -->
    <select id="selectErpBindingList" resultMap="BaseResultMap">
        SELECT
        er.erp_id,
        er.property_area,
        er.area_number,
        er.property_project,
        er.comm_kind,
        er.project_number,
        er.project_type,
        er.province
        FROM
        extension_report er
        LEFT JOIN project_sign ps ON ps.id = er.dup_id AND ps.is_delete = 0
        LEFT JOIN organ o ON o.name = ps.organ_name
        <where>
            er.binding_Identifier = 1 AND er.is_delete = 0
            <if test="dto.propertyArea != null and dto.propertyArea != ''" > AND er.property_area in
                <foreach collection="dto.propertyArea.split(',')" item="item" index="index"   open="(" separator="," close=")">
                    '${item}'
                </foreach>
            </if>
            <if test="dto.propertyProject != null and dto.propertyProject != ''"> AND er.property_project LIKE CONCAT('%',#{dto.propertyProject},'%') </if>
            <if test="dto.developmentState != null and dto.developmentState != ''"> AND er.development_state = #{dto.developmentState} </if>
            <if test="dto.conventionalCharges != null and dto.conventionalCharges != ''"> AND er.conventional_charges = #{dto.conventionalCharges} </if>
            <if test="dto.conventionalService != null and dto.conventionalService != ''"> AND er.conventional_service = #{dto.conventionalService} </if>
            <if test="dto.propertyForm != null and dto.propertyForm != ''"> AND er.property_form  = #{dto.propertyForm}  </if>
            <if test="dto.projectType != null and dto.projectType != ''"> AND er.project_type = #{dto.projectType} </if>
            <if test="organName != null and organName != ''" >
                AND o.name = #{organName}
            </if>
        </where>
        ORDER BY er.property_area DESC
    </select>

    <!-- 查询外拓报表信息 -->
    <select id="selectReportAll" resultMap="selectResultMap" >
        SELECT
        ps.project_name ,
        org.`name` AS 'proposalOrganName',
        ps.organ_name ,
        ps.project_nature_name ,
        ps.is_new ,
        ps.corp_type_name ,
        ps.contract_area,
        DATE_FORMAT(ps.sing_time_str,'%Y-%m-%d') as sign_time,
        <include refid="select_Column_List" />
        FROM
        extension_report er
        LEFT JOIN project_sign ps ON ps.id = er.dup_id AND ps.is_delete = 0
        LEFT JOIN organ o ON o.name = ps.organ_name
        LEFT JOIN organ org ON org.organ_code = ps.proposal_organ_id
        <where>
            er.binding_Identifier = 1 AND er.is_delete = 0
            <if test="dto.propertyArea != null and dto.propertyArea != ''" > AND er.property_area in
                <foreach collection="dto.propertyArea.split(',')" item="item" index="index"   open="(" separator="," close=")">
                    '${item}'
                </foreach>
            </if>
            <if test="dto.propertyProject != null and dto.propertyProject != ''"> AND er.property_project LIKE CONCAT('%',#{dto.propertyProject},'%') </if>
            <if test="dto.developmentState != null and dto.developmentState != ''"> AND er.development_state = #{dto.developmentState} </if>
            <if test="dto.conventionalCharges != null and dto.conventionalCharges != ''"> AND er.conventional_charges = #{dto.conventionalCharges} </if>
            <if test="dto.conventionalService != null and dto.conventionalService != ''"> AND er.conventional_service = #{dto.conventionalService} </if>
            <if test="dto.propertyForm != null and dto.propertyForm != ''"> AND er.property_form  = #{dto.propertyForm}  </if>
            <if test="dto.projectType != null and dto.projectType != ''"> AND er.project_type = #{dto.projectType} </if>
            <if test="dto.projectName != null and dto.projectName != ''"> AND ps.project_name LIKE CONCAT('%',#{dto.projectName},'%') </if>
            <if test="dto.organName != null and dto.organName != ''"> AND ps.organ_name LIKE CONCAT('%',#{dto.organName},'%') </if>
            <if test="dto.proposalOrganName != null and dto.proposalOrganName != ''"> AND org.name = #{dto.proposalOrganName} </if>
            <if test="dto.signTime != null and dto.signTime != ''"> AND date_format(ps.sing_time_str,'%Y-%m-%d') &gt;= #{dto.signTime} </if>
            <if test="dto.signTimeEnd != null and dto.signTimeEnd != ''"> AND date_format(ps.sing_time_str,'%Y-%m-%d') &lt;=  #{dto.signTimeEnd} </if>
            <if test="organName != null and organName != ''" >
                AND org.name = #{organName}
            </if>
        </where>
        ORDER BY er.property_area
    </select>

    <!-- 已绑定/ 报表 导出 -->
    <select id="selectExportByDto" resultMap="BaseResultMap" >
        SELECT
        ps.project_name ,
        org.`name` AS 'proposalOrganName',
        ps.organ_name ,
        ps.project_nature_name ,
        ps.is_new ,
        ps.corp_type_name ,
        ps.contract_area,
        DATE_FORMAT(ps.sing_time_str,'%Y-%m-%d') as sign_time,
        <include refid="Base_Column_List" />
        FROM
        extension_report er
        LEFT JOIN project_sign ps ON ps.id = er.dup_id AND ps.is_delete = 0
        LEFT JOIN organ o ON o.name = ps.organ_name
        LEFT JOIN organ org ON org.organ_code = ps.proposal_organ_id
        LEFT JOIN extension_joint jo ON jo.extension_report_id = er.id AND jo.is_delete = 0
        LEFT JOIN extension_project_leader pl ON pl.extension_report_id = er.id AND pl.is_delete = 0
        LEFT JOIN extension_upload_file uf ON uf.extension_report_id = er.id AND uf.is_delete = 0
        LEFT JOIN project_sign_item psi ON psi.project_sign_id = er.dup_id AND psi.is_delete = 0
        <where>
            er.binding_Identifier = 1 AND er.is_delete = 0
            <if test="dto.propertyArea != null and dto.propertyArea != ''" > AND er.property_area in
                <foreach collection="dto.propertyArea.split(',')" item="item" index="index"   open="(" separator="," close=")">
                    '${item}'
                </foreach>
            </if>
            <if test="dto.propertyProject != null and dto.propertyProject != ''"> AND er.property_project LIKE CONCAT('%',#{dto.propertyProject},'%') </if>
            <if test="dto.developmentState != null and dto.developmentState != ''"> AND er.development_state = #{dto.developmentState} </if>
            <if test="dto.conventionalCharges != null and dto.conventionalCharges != ''"> AND er.conventional_charges = #{dto.conventionalCharges} </if>
            <if test="dto.conventionalService != null and dto.conventionalService != ''"> AND er.conventional_service = #{dto.conventionalService} </if>
            <if test="dto.propertyForm != null and dto.propertyForm != ''"> AND er.property_form  = #{dto.propertyForm}  </if>
            <if test="dto.projectType != null and dto.projectType != ''"> AND er.project_type = #{dto.projectType} </if>
            <if test="dto.projectName != null and dto.projectName != ''"> AND ps.project_name LIKE CONCAT('%',#{dto.projectName},'%') </if>
            <if test="dto.organName != null and dto.organName != ''"> AND ps.organ_name LIKE CONCAT('%',#{dto.organName},'%') </if>
            <if test="dto.proposalOrganName != null and dto.proposalOrganName != ''"> AND org.name = #{dto.proposalOrganName} </if>
            <if test="dto.signTime != null and dto.signTime != ''"> AND date_format(ps.sing_time_str,'%Y-%m-%d') &gt;= #{dto.signTime} </if>
            <if test="dto.signTimeEnd != null and dto.signTimeEnd != ''"> AND date_format(ps.sing_time_str,'%Y-%m-%d') &lt;=  #{dto.signTimeEnd} </if>
            <if test="organName != null and organName != ''" >
                AND org.name = #{organName}
            </if>
        </where>
        ORDER BY er.property_area
    </select>

    <!-- 子对象 甲方对接人  -->
    <select id="getJointListById" resultMap="jointMap">
        SELECT
        id AS joint_id,
        joint_name,
        joint_tel,
        extension_report_id,
        create_date AS joint_create_date,
        create_by AS joint_create_by,
        last_update_date AS joint_last_update_date,
        last_update_by AS joint_last_update_by,
        is_delete
        FROM
        extension_joint
        WHERE extension_report_id = #{id} AND is_delete = 0
    </select>
    <!-- 子对象 项目负责人  -->
    <select id="getLeaderListById" resultMap="leaderMap">
        SELECT
        id AS leader_id,
        leader_name,
        leader_tel,
        extension_report_id AS leader_extension_report_id,
        create_by AS leader_create_by,
        create_date as leader_create_date,
        last_update_date AS leader_last_update_date,
        last_update_by AS leader_last_update_by,
        is_delete
        FROM
        extension_project_leader
        WHERE extension_report_id = #{id} AND is_delete = 0
    </select>
    <!-- 子对象 物业构成情况  -->
    <select id="getProperty" resultMap="propertyMap">
        SELECT
        psi.id AS property_id,
        psi.project_sign_id AS property_project_sign_id,
        psi.business_type_name AS property_business_type_name,
        psi.rates_area AS property_rates_area,
        psi.price AS property_price,
        psi.month_income AS property_month_income,
        psi.year_income AS property_year_income,
        psi.gmt_create AS property_gmt_create,
        psi.create_by AS property_create_by,
        psi.gmt_modified AS property_gmt_modified,
        psi.modified_by AS property_modified_by,
        ps.is_delete
        FROM
        project_sign_item psi, project_sign ps
        WHERE ps.id = psi.project_sign_id AND ps.id = #{dup_id} AND psi.is_delete = 0
    </select>
    <!-- 子对象 文件信息  -->
    <select id="getFileInfo" resultMap="fileInfoMap">
        SELECT
        id AS file_id,
        extension_report_id,
        file_name,
        file_real_name,
        file_url,
        file_tab,
        create_date,
        create_by,
        last_update_date,
        last_update_by,
        is_delete
        FROM extension_upload_file
        WHERE is_delete = 0 AND extension_report_id = #{id}
    </select>

    <!-- 条件插入 -->
    <insert id="insertSelectiveByDto" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionReportDTO" useGeneratedKeys="true" keyProperty="id">
        insert into extension_report
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="id != null" >
                id,
            </if>
            <if test="committeeStatus != null" >
                committee_status,
            </if>
            <if test="extensionPerson != null" >
                extension_person,
            </if>
            <if test="extensionPersonTel != null" >
                extension_person_tel,
            </if>
            <if test="contractProperty != null" >
                contract_property,
            </if>
            <if test="contractSingDate != null" >
                contract_sing_date,
            </if>
            <if test="contractCommencementDate != null" >
                contract_commencement_date,
            </if>
            <if test="contractEndDate != null and contractEndDate != ''" >
                contract_end_date,
            </if>
            <if test="planNumber != null" >
                plan_number,
            </if>
            <if test="contractArea != null" >
                contract_area,
            </if>
            <if test="emptyRoomFeesAgreement != null" >
                empty_room_fees_agreement,
            </if>
            <if test="propertyFeesPriceAgreement != null" >
                property_fees_price_agreement,
            </if>
            <if test="startUpFeesAgreement != null" >
                start_up_fees_agreement,
            </if>
            <if test="otherAgreement != null" >
                other_agreement,
            </if>
            <if test="firstMainCollectionRate != null" >
                first_main_collection_rate,
            </if>
            <if test="firstSalesRevenue != null" >
                first_sales_revenue,
            </if>
            <if test="firstSubsidy != null" >
                first_subsidy,
            </if>
            <if test="firstTotalCost != null" >
                first_total_cost,
            </if>
            <if test="firstNetProfit != null" >
                first_net_profit,
            </if>
            <if test="firstMainBusinessProfit != null" >
                first_main_business_profit,
            </if>
            <if test="secondMainCollectionRate != null" >
                second_main_collection_rate,
            </if>
            <if test="secondSalesRevenue != null" >
                second_sales_revenue,
            </if>
            <if test="secondSubsidy != null" >
                second_subsidy,
            </if>
            <if test="secondTotalCost != null" >
                second_total_cost,
            </if>
            <if test="secondNetProfit != null" >
                second_net_profit,
            </if>
            <if test="secondMainBusinessProfit != null" >
                second_main_business_profit,
            </if>
            <if test="thirdlyMainCollectionRate != null" >
                thirdly_main_collection_rate,
            </if>
            <if test="thirdlySalesRevenue != null" >
                thirdly_sales_revenue,
            </if>
            <if test="thirdlySubsidy != null" >
                thirdly_subsidy,
            </if>
            <if test="thirdlyTotalCost != null" >
                thirdly_total_cost,
            </if>
            <if test="thirdlyNetProfit != null" >
                thirdly_net_profit,
            </if>
            <if test="thirdlyMainBusinessProfit != null" >
                thirdly_main_business_profit,
            </if>
            <if test="erpId != null" >
                erp_id,
            </if>
            <if test="propertyArea != null" >
                property_area,
            </if>
            <if test="areaNumber != null" >
                area_number,
            </if>
            <if test="propertyProject != null" >
                property_project,
            </if>
            <if test="commKind != null" >
                comm_kind,
            </if>
            <if test="projectNumber != null" >
                project_number,
            </if>
            <if test="projectType != null" >
                project_type,
            </if>
            <if test="province != null" >
                province,
            </if>
            <if test="city != null" >
                city,
            </if>
            <if test="borough != null" >
                borough,
            </if>
            <if test="region != null" >
                region,
            </if>
            <if test="conventionalCharges != null" >
                conventional_charges,
            </if>
            <if test="conventionalService != null" >
                conventional_service,
            </if>
            <if test="salesFieldCharges != null" >
                sales_field_charges,
            </if>
            <if test="salesFieldService != null" >
                sales_field_service,
            </if>
            <if test="propertyForm != null" >
                property_form,
            </if>
            <if test="developmentState != null" >
                development_state,
            </if>
            <if test="dupId != null" >
                dup_id,
            </if>
            create_date,
            <if test="createBy != null" >
                create_by,
            </if>
            last_update_date,
            <if test="lastUpdateBy != null" >
                last_update_by,
            </if>
            <if test="bindingIdentifier != null" >
                binding_Identifier,
            </if>
            <if test="propertyName != null" >
                property_name,
            </if>
            <if test="parentCompany != null" >
                parent_company,
            </if>
            <if test="ncSystemAccount != null" >
                nc_system_account,
            </if>
            <if test="ncSystemNumber != null" >
                nc_system_number,
            </if>
            <if test="ncPersonNumber != null" >
                nc_person_number,
            </if>
            <if test="fundType != null" >
                fund_type,
            </if>
            <if test="developmentSubjectNames != null" >
                development_subject_names,
            </if>
            <if test="developmentSubject != null" >
                development_subject,
            </if>
            <if test="takeoverState != null" >
                takeover_state,
            </if>
            <if test="manageTime != null" >
                manage_time,
            </if>
            <if test="actualEnterTime != null" >
                actual_enter_time,
            </if>
            <if test="stateProperty != null" >
                state_property,
            </if>
            <if test="actualOpen != null" >
                actual_open,
            </if>
            <if test="plannedOpen != null" >
                planned_open,
            </if>
            <if test="contractPropertyDate != null" >
                contract_property_date,
            </if>
            <if test="actualProperty != null" >
                actual_property,
            </if>
            <if test="endCaseDate != null" >
                end_case_date,
            </if>
            <if test="endEstateManagementDate != null" >
                end_estate_management_date,
            </if>
            is_delete,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="id != null" >
                #{id},
            </if>
            <if test="committeeStatus != null" >
                #{committeeStatus},
            </if>
            <if test="extensionPerson != null" >
                #{extensionPerson},
            </if>
            <if test="extensionPersonTel != null" >
                #{extensionPersonTel},
            </if>
            <if test="contractProperty != null" >
                #{contractProperty},
            </if>
            <if test="contractSingDate != null" >
                #{contractSingDate},
            </if>
            <if test="contractCommencementDate != null" >
                #{contractCommencementDate},
            </if>
            <if test="contractEndDate != null and contractEndDate != ''" >
                #{contractEndDate},
            </if>
            <if test="planNumber != null" >
                #{planNumber},
            </if>
            <if test="contractArea != null" >
                #{contractArea},
            </if>
            <if test="emptyRoomFeesAgreement != null" >
                #{emptyRoomFeesAgreement},
            </if>
            <if test="propertyFeesPriceAgreement != null" >
                #{propertyFeesPriceAgreement},
            </if>
            <if test="startUpFeesAgreement != null" >
                #{startUpFeesAgreement},
            </if>
            <if test="otherAgreement != null" >
                #{otherAgreement},
            </if>
            <if test="firstMainCollectionRate != null" >
                #{firstMainCollectionRate},
            </if>
            <if test="firstSalesRevenue != null" >
                #{firstSalesRevenue},
            </if>
            <if test="firstSubsidy != null" >
                #{firstSubsidy},
            </if>
            <if test="firstTotalCost != null" >
                #{firstTotalCost},
            </if>
            <if test="firstNetProfit != null" >
                #{firstNetProfit},
            </if>
            <if test="firstMainBusinessProfit != null" >
                #{firstMainBusinessProfit},
            </if>
            <if test="secondMainCollectionRate != null" >
                #{secondMainCollectionRate},
            </if>
            <if test="secondSalesRevenue != null" >
                #{secondSalesRevenue},
            </if>
            <if test="secondSubsidy != null" >
                #{secondSubsidy},
            </if>
            <if test="secondTotalCost != null" >
                #{secondTotalCost},
            </if>
            <if test="secondNetProfit != null" >
                #{secondNetProfit},
            </if>
            <if test="secondMainBusinessProfit != null" >
                #{secondMainBusinessProfit},
            </if>
            <if test="thirdlyMainCollectionRate != null" >
                #{thirdlyMainCollectionRate},
            </if>
            <if test="thirdlySalesRevenue != null" >
                #{thirdlySalesRevenue},
            </if>
            <if test="thirdlySubsidy != null" >
                #{thirdlySubsidy},
            </if>
            <if test="thirdlyTotalCost != null" >
                #{thirdlyTotalCost},
            </if>
            <if test="thirdlyNetProfit != null" >
                #{thirdlyNetProfit},
            </if>
            <if test="thirdlyMainBusinessProfit != null" >
                #{thirdlyMainBusinessProfit},
            </if>
            <if test="erpId != null" >
                #{erpId},
            </if>
            <if test="propertyArea != null" >
                #{propertyArea},
            </if>
            <if test="areaNumber != null" >
                #{areaNumber},
            </if>
            <if test="propertyProject != null" >
                #{propertyProject},
            </if>
            <if test="commKind != null" >
                #{commKind},
            </if>
            <if test="projectNumber != null" >
                #{projectNumber},
            </if>
            <if test="projectType != null" >
                #{projectType},
            </if>
            <if test="province != null" >
                #{province},
            </if>
            <if test="city != null" >
                #{city},
            </if>
            <if test="borough != null" >
                #{borough},
            </if>
            <if test="region != null" >
                #{region},
            </if>
            <if test="conventionalCharges != null" >
                #{conventionalCharges},
            </if>
            <if test="conventionalService != null" >
                #{conventionalService},
            </if>
            <if test="salesFieldCharges != null" >
                #{salesFieldCharges},
            </if>
            <if test="salesFieldService != null" >
                #{salesFieldService},
            </if>
            <if test="propertyForm != null" >
                #{propertyForm},
            </if>
            <if test="developmentState != null" >
                #{developmentState},
            </if>
            <if test="dupId != null" >
                #{dupId},
            </if>
            NOW(),
            <if test="createBy != null" >
                #{createBy},
            </if>
            NOW(),
            <if test="lastUpdateBy != null" >
                #{lastUpdateBy},
            </if>
            <if test="bindingIdentifier != null" >
                #{bindingIdentifier},
            </if>
            <if test="propertyName != null" >
                #{propertyName},
            </if>
            <if test="parentCompany != null" >
                #{parentCompany},
            </if>
            <if test="ncSystemAccount != null" >
                #{ncSystemAccount},
            </if>
            <if test="ncSystemNumber != null" >
                #{ncSystemNumber},
            </if>
            <if test="ncPersonNumber != null" >
                #{ncPersonNumber},
            </if>
            <if test="fundType != null" >
                #{fundType},
            </if>
            <if test="developmentSubjectNames != null" >
                #{developmentSubjectNames},
            </if>
            <if test="developmentSubject != null" >
                #{developmentSubject},
            </if>
            <if test="takeoverState != null" >
                #{takeoverState},
            </if>
            <if test="manageTime != null" >
                #{manageTime},
            </if>
            <if test="actualEnterTime != null" >
                #{actualEnterTime},
            </if>
            <if test="stateProperty != null" >
                #{stateProperty},
            </if>
            <if test="actualOpen != null" >
                #{actualOpen},
            </if>
            <if test="plannedOpen != null" >
                #{plannedOpen},
            </if>
            <if test="contractPropertyDate != null" >
                #{contractPropertyDate},
            </if>
            <if test="actualProperty != null" >
                #{actualProperty},
            </if>
            <if test="endCaseDate != null" >
                #{endCaseDate},
            </if>
            <if test="endEstateManagementDate != null" >
                #{endEstateManagementDate},
            </if>
            0,
        </trim>
    </insert>

    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionReportDTO" >
        select 'false' as QUERYID,
        ps.project_name ,
        org.`name` AS 'proposalOrganName',
        ps.organ_name ,
        ps.project_nature_name ,
        ps.is_new ,
        ps.corp_type_name ,
        ps.contract_area,
        DATE_FORMAT(ps.sing_time_str,'%Y-%m-%d') as sign_time,
        <include refid="Base_Column_List" />
        FROM
        extension_report er
        LEFT JOIN project_sign ps ON ps.id = er.dup_id AND ps.is_delete = 0
        LEFT JOIN organ o ON o.name = ps.organ_name
        LEFT JOIN organ org ON org.organ_code = ps.proposal_organ_id
        LEFT JOIN extension_joint jo ON jo.extension_report_id = er.id AND jo.is_delete = 0
        LEFT JOIN extension_project_leader pl ON pl.extension_report_id = er.id AND pl.is_delete = 0
        LEFT JOIN extension_upload_file uf ON uf.extension_report_id = er.id AND uf.is_delete = 0
        LEFT JOIN project_sign_item psi ON psi.project_sign_id = er.dup_id AND psi.is_delete = 0
        WHERE er.id = #{id} AND er.is_delete = 0 AND er.binding_Identifier = 1
    </select>

    <update id="updateSelectiveByDto" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionReportDTO" >
        update extension_report
        <set >
            committee_status = #{committeeStatus},
            <if test="extensionPerson != null" >
                extension_person = #{extensionPerson},
            </if>
            <if test="extensionPersonTel != null" >
                extension_person_tel = #{extensionPersonTel},
            </if>
            contract_property = #{contractProperty},
            <if test="contractSingDate != null" >
                contract_sing_date = #{contractSingDate},
            </if>
            <if test="contractCommencementDate != null" >
                contract_commencement_date = #{contractCommencementDate},
            </if>
            <if test="contractEndDate != null and contractEndDate != ''" >
                contract_end_date = #{contractEndDate},
            </if>
            plan_number = #{planNumber},
            <if test="contractArea != null" >
                contract_area = #{contractArea},
            </if>
            <if test="emptyRoomFeesAgreement != null" >
                empty_room_fees_agreement = #{emptyRoomFeesAgreement},
            </if>
            <if test="propertyFeesPriceAgreement != null" >
                property_fees_price_agreement = #{propertyFeesPriceAgreement},
            </if>
            <if test="startUpFeesAgreement != null" >
                start_up_fees_agreement = #{startUpFeesAgreement},
            </if>
            <if test="otherAgreement != null" >
                other_agreement = #{otherAgreement},
            </if>
            first_main_collection_rate = #{firstMainCollectionRate},
            first_sales_revenue = #{firstSalesRevenue},
            first_subsidy = #{firstSubsidy},
            first_total_cost = #{firstTotalCost},
            first_net_profit = #{firstNetProfit},
            first_main_business_profit = #{firstMainBusinessProfit},
            second_main_collection_rate = #{secondMainCollectionRate},
            second_main_business_profit = #{secondMainBusinessProfit},
            second_sales_revenue = #{secondSalesRevenue},
            second_subsidy = #{secondSubsidy},
            second_total_cost = #{secondTotalCost},
            second_net_profit = #{secondNetProfit},
            thirdly_main_collection_rate = #{thirdlyMainCollectionRate},
            thirdly_main_business_profit = #{thirdlyMainBusinessProfit},
            thirdly_sales_revenue = #{thirdlySalesRevenue},
            thirdly_subsidy = #{thirdlySubsidy},
            thirdly_total_cost = #{thirdlyTotalCost},
            thirdly_net_profit = #{thirdlyNetProfit},
            <if test="isDelete != null" >
                is_delete = #{isDelete},
            </if>
            <if test="erpId != null" >
                erp_id = #{erpId},
            </if>
            <if test="propertyArea != null" >
                property_area = #{propertyArea},
            </if>
            <if test="areaNumber != null" >
                area_number = #{areaNumber},
            </if>
            <if test="propertyProject != null" >
                property_project = #{propertyProject},
            </if>
            <if test="commKind != null" >
                comm_kind = #{commKind},
            </if>
            <if test="projectNumber != null" >
                project_number = #{projectNumber},
            </if>
            <if test="projectType != null" >
                project_type = #{projectType},
            </if>
            <if test="province != null" >
                province = #{province},
            </if>
            <if test="city != null" >
                city = #{city},
            </if>
            <if test="borough != null" >
                borough = #{borough},
            </if>
            <if test="region != null" >
                region = #{region},
            </if>
            <if test="conventionalCharges != null" >
                conventional_charges = #{conventionalCharges},
            </if>
            <if test="conventionalService != null" >
                conventional_service = #{conventionalService},
            </if>
            <if test="salesFieldCharges != null" >
                sales_field_charges = #{salesFieldCharges},
            </if>
            <if test="salesFieldService != null" >
                sales_field_service = #{salesFieldService},
            </if>
            <if test="propertyForm != null" >
                property_form = #{propertyForm},
            </if>
            <if test="developmentState != null" >
                development_state = #{developmentState},
            </if>
            <if test="dupId != null" >
                dup_id = #{dupId},
            </if>
            <if test="createDate != null" >
                create_date = #{createDate},
            </if>
            <if test="createBy != null" >
                create_by = #{createBy},
            </if>
            <if test="lastUpdateDate != null" >
                last_update_date = #{lastUpdateDate},
            </if>
            <if test="lastUpdateBy != null" >
                last_update_by = #{lastUpdateBy},
            </if>
            <if test="bindingIdentifier != null" >
                binding_Identifier = #{bindingIdentifier},
            </if>
            <if test="propertyName != null" >
                property_name = #{propertyName},
            </if>
            <if test="parentCompany != null" >
                parent_company = #{parentCompany},
            </if>
            <if test="ncSystemAccount != null" >
                nc_system_account = #{ncSystemAccount},
            </if>
            <if test="ncSystemNumber != null" >
                nc_system_number = #{ncSystemNumber},
            </if>
            <if test="ncPersonNumber != null" >
                nc_person_number = #{ncPersonNumber},
            </if>
            <if test="fundType != null" >
                fund_type = #{fundType},
            </if>
            <if test="developmentSubjectNames != null" >
                development_subject_names = #{developmentSubjectNames},
            </if>
            <if test="developmentSubject != null" >
                development_subject = #{developmentSubject},
            </if>
            <if test="takeoverState != null" >
                takeover_state = #{takeoverState},
            </if>
            <if test="manageTime != null" >
                manage_time = #{manageTime},
            </if>
            <if test="actualEnterTime != null" >
                actual_enter_time = #{actualEnterTime},
            </if>
            <if test="stateProperty != null" >
                state_property = #{stateProperty},
            </if>
            <if test="actualOpen != null" >
                actual_open = #{actualOpen},
            </if>
            <if test="plannedOpen != null" >
                planned_open = #{plannedOpen},
            </if>
            <if test="contractPropertyDate != null" >
                contract_property_date = #{contractPropertyDate},
            </if>
            <if test="actualProperty != null" >
                actual_property = #{actualProperty},
            </if>
            <if test="endCaseDate != null" >
                end_case_date = #{endCaseDate},
            </if>
            <if test="endEstateManagementDate != null" >
                end_estate_management_date = #{endEstateManagementDate},
            </if>
        </set>
        where id = #{id}
    </update>

    <update id="updateByErpId" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionReportDTO" >
        update extension_report
        <set >
            <if test="contractArea != null" >
                contract_area = #{contractArea},
            </if>
            <if test="erpId != null" >
                erp_id = #{erpId},
            </if>
            <if test="propertyArea != null" >
                property_area = #{propertyArea},
            </if>
            <if test="areaNumber != null" >
                area_number = #{areaNumber},
            </if>
            <if test="propertyProject != null" >
                property_project = #{propertyProject},
            </if>
            <if test="commKind != null" >
                comm_kind = #{commKind},
            </if>
            <if test="projectNumber != null" >
                project_number = #{projectNumber},
            </if>
            <if test="projectType != null" >
                project_type = #{projectType},
            </if>
            <if test="province != null" >
                province = #{province},
            </if>
            <if test="city != null" >
                city = #{city},
            </if>
            <if test="borough != null" >
                borough = #{borough},
            </if>
            <if test="region != null" >
                region = #{region},
            </if>
            <if test="conventionalCharges != null" >
                conventional_charges = #{conventionalCharges},
            </if>
            <if test="conventionalService != null" >
                conventional_service = #{conventionalService},
            </if>
            <if test="salesFieldCharges != null" >
                sales_field_charges = #{salesFieldCharges},
            </if>
            <if test="salesFieldService != null" >
                sales_field_service = #{salesFieldService},
            </if>
            <if test="propertyForm != null" >
                property_form = #{propertyForm},
            </if>
            <if test="developmentState != null" >
                development_state = #{developmentState},
            </if>
            <if test="lastUpdateDate != null" >
                last_update_date = #{lastUpdateDate},
            </if>
            <if test="lastUpdateBy != null" >
                last_update_by = #{lastUpdateBy},
            </if>
            <if test="propertyName != null" >
                property_name = #{propertyName},
            </if>
            <if test="parentCompany != null" >
                parent_company = #{parentCompany},
            </if>
            <if test="ncSystemAccount != null" >
                nc_system_account = #{ncSystemAccount},
            </if>
            <if test="ncSystemNumber != null" >
                nc_system_number = #{ncSystemNumber},
            </if>
            <if test="ncPersonNumber != null" >
                nc_person_number = #{ncPersonNumber},
            </if>
            <if test="fundType != null" >
                fund_type = #{fundType},
            </if>
            <if test="developmentSubjectNames != null" >
                development_subject_names = #{developmentSubjectNames},
            </if>
            <if test="developmentSubject != null" >
                development_subject = #{developmentSubject},
            </if>
            <if test="takeoverState != null" >
                takeover_state = #{takeoverState},
            </if>
            <if test="manageTime != null" >
                manage_time = #{manageTime},
            </if>
            <if test="actualEnterTime != null" >
                actual_enter_time = #{actualEnterTime},
            </if>
            <if test="stateProperty != null" >
                state_property = #{stateProperty},
            </if>
            <if test="actualOpen != null" >
                actual_open = #{actualOpen},
            </if>
            <if test="plannedOpen != null" >
                planned_open = #{plannedOpen},
            </if>
            <if test="contractPropertyDate != null" >
                contract_property_date = #{contractPropertyDate},
            </if>
            <if test="actualProperty != null" >
                actual_property = #{actualProperty},
            </if>
            <if test="endCaseDate != null" >
                end_case_date = #{endCaseDate},
            </if>
            <if test="endEstateManagementDate != null" >
                end_estate_management_date = #{endEstateManagementDate},
            </if>
        </set>
        where erp_id = #{erpId}
    </update>

    <update id="deleteByPrimaryKey" >
        update extension_report
        set
        is_delete = 1,
        binding_Identifier = 0,
        last_update_date = NOW(),
        last_update_by = #{userCode}
        where id = #{id}
    </update>

    <select id="selectBindingCount" resultType="java.lang.Long" parameterType="String">
        SELECT COUNT(0) FROM extension_report er
        LEFT JOIN project_sign ps ON ps.id = er.dup_id AND ps.is_delete = 0
        LEFT JOIN organ o ON o.name = ps.organ_name
        LEFT JOIN organ org ON org.organ_code = ps.proposal_organ_id
        WHERE er.is_delete = 0 AND er.binding_Identifier = 1
        <if test="organName != null and organName != ''" >
            AND org.name = #{organName}
        </if>
    </select>

    <select id="selectRoleByUserCode" resultType="String" >
        SELECT role_code FROM user_roles WHERE user_code = #{userCode}
    </select>
</mapper>