<?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.districtReport.RdClosedBuildingProjectMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.districtReport.RdClosedBuildingProject">
                                    <id column="id" property="id" />
                                                <result column="district_code" property="districtCode" />
                                                <result column="project_code" property="projectCode" />
                                                <result column="project_name" property="projectName" />
                                                <result column="plan_place_area" property="planPlaceArea" />
                                                <result column="plan_build_area" property="planBuildArea" />
                                                <result column="manager_area" property="managerArea" />
                                                <result column="plan_car_area" property="planCarArea" />
                                                <result column="house_charges_area" property="houseChargesArea" />
                                                <result column="business_charges_area" property="businessChargesArea" />
                                                <result column="plan_households" property="planHouseholds" />
                                                <result column="manager_households" property="managerHouseholds" />
                                                <result column="manager_car_households" property="managerCarHouseholds" />
                                                <result column="industry_composition" property="industryComposition" />
                                                <result column="first_pay_date" property="firstPayDate" />
                                                <result column="property_price" property="propertyPrice" />
                                                <result column="car_price" property="carPrice" />
                                                <result column="property_collection_rate" property="propertyCollectionRate" />
                                                <result column="last_year_recovery_rate" property="lastYearRecoveryRate" />
                                                <result column="green_area" property="greenArea" />
                                                <result column="volume_ratio" property="volumeRatio" />
                                                <result column="building_density" property="buildingDensity" />
                                                <result column="project_place" property="projectPlace" />
                                                <result column="office_place" property="officePlace" />
                                                <result column="contact" property="contact" />
                                                <result column="project_responsibler" property="projectResponsibler" />
                                                <result column="elevator_count" property="elevatorCount" />
                                                <result column="committee_rate" property="committeeRate" />
                                                <result column="committee_project" property="committeeProject" />
                                                <result column="committee_unit" property="committeeUnit" />
                                                <result column="compiling_customer" property="compilingCustomer" />
                                                <result column="compiling_order" property="compilingOrder" />
                                                <result column="compiling_engineers" property="compilingEngineers" />
                                                <result column="compiling_cleaner" property="compilingCleaner" />
                                                <result column="compiling_case" property="compilingCase" />
                                                <result column="compiling_other" property="compilingOther" />
                                                <result column="descs" property="descs" />
                                                <result column="sync_date" property="syncDate" />
                                                <result column="sync_usercode" property="syncUsercode" />
                                                <result column="ENABLE" property="enable" />
                                                <result column="create_time" property="createTime" />
                                                <result column="create_by" property="createBy" />
                                                <result column="create_name" property="createName" />
                                                <result column="update_time" property="updateTime" />
                                                <result column="update_by" property="updateBy" />
                                                <result column="update_name" property="updateName" />
                        </resultMap>

    <select id="queryPageList" resultType="cn.com.countrygarden.bi.main.dto.districtReport.RdClosedBuildingProjectDTO">
                SELECT DISTINCT rc.id AS id,rd.region_code as regionCode,rd.region_name AS regionName,rd.district_code AS districtCode,rd.district_name AS districtName,rc.project_code AS projectCode,rc.project_name AS projectName,rc.plan_place_area AS planPlaceArea,rc.plan_build_area AS planBuildArea,
                rc.manager_area AS managerArea,rc.plan_car_area AS planCarArea,rc.house_charges_area AS houseChargesArea,
                rc.business_charges_area AS businessChargesArea,rc.plan_households AS planHouseholds,rc.manager_households AS managerHouseholds,rc.manager_car_households AS managerCarHouseholds,rc.industry_composition AS industryComposition,
                rc.first_pay_date AS firstPayDateString,rc.property_price AS propertyPrice,
                rc.car_price AS carPrice,rc.property_collection_rate AS propertyCollectionRate,rc.last_year_recovery_rate AS lastYearRecoveryRate,rc.green_area AS greenArea,rc.volume_ratio AS volumeRatio,
                rc.building_density AS buildingDensity,rc.project_place AS projectPlace,rc.office_place AS officePlace,
                rc.contact AS contact,rc.project_responsibler AS projectResponsibler,rc.elevator_count AS elevatorCount,rc.committee_rate AS committeeRate,rc.committee_project AS committeeProject,rc.committee_unit AS committeeUnit,
                rc.compiling_customer AS compilingCustomer,rc.compiling_order AS compilingOrder,
                rc.compiling_engineers AS compilingEngineers,rc.compiling_cleaner AS compilingCleaner,rc.compiling_case AS compilingCase,rc.compiling_other AS compilingOther,
                rc.sync_date AS syncDate,rc.sync_usercode AS syncUsercode,rc.create_name as createName,
                rc.create_time AS createTime,rc.create_by AS createBy,rc.descs as descs
                FROM rd_closed_building_project rc
                LEFT JOIN rd_district_info rd ON rd.district_code=rc.district_code
                LEFT JOIN rd_district_principal rdp ON rd.district_code=rdp.district_code
                 <where>
                     <if test="organCodeString!=null and organCodeString.size()!=0">
                         and rd.region_code in
                         <foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
                             #{organCodeString}
                         </foreach>
                     </if>
                     <if test="commIdString!=null and commIdString.size()!=0">
                         and rc.project_code in
                         <foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
                             #{commIdString}
                         </foreach>
                     </if>
                     <if test="principaString!=null and principaString.size()!=0">
                         and rdp.principal_code in
                         <foreach collection="principaString" item="principaString" index="index" open="(" close=")" separator=",">
                             #{principaString}
                         </foreach>
                         AND rdp.ENABLE=1
                     </if>
                    <if test="rdClosedBuildingProjectDTO.regionCode!=null and rdClosedBuildingProjectDTO.regionCode!=''">
                         and rd.region_code=#{rdClosedBuildingProjectDTO.regionCode}
                    </if>
                     <if test="rdClosedBuildingProjectDTO.projectCode!=null and rdClosedBuildingProjectDTO.projectCode!=''">
                         and rc.project_code=#{rdClosedBuildingProjectDTO.projectCode}
                     </if>
                     <if test="rdClosedBuildingProjectDTO.districtCode!=null and rdClosedBuildingProjectDTO.districtCode!=''">
                         and rd.district_code=#{rdClosedBuildingProjectDTO.districtCode}
                     </if>
                       <if test="rdClosedBuildingProjectDTO.firstPayDateList1!=null and rdClosedBuildingProjectDTO.firstPayDateList1!='' and rdClosedBuildingProjectDTO.firstPayDateList2!=null and rdClosedBuildingProjectDTO.firstPayDateList2!=''">
                           and rc.first_pay_date BETWEEN #{rdClosedBuildingProjectDTO.firstPayDateList1} and #{rdClosedBuildingProjectDTO.firstPayDateList2}
                       </if>
                     <if test="rdClosedBuildingProjectDTO.createBy!=null and rdClosedBuildingProjectDTO.createBy!=''">
                         and rc.create_by=#{rdClosedBuildingProjectDTO.createBy}
                     </if>
                    and rc.ENABLE=1
                 </where>
             ORDER BY rc.project_code,rd.district_code,rc.create_time
    </select>

    <select id="queryById" resultType="cn.com.countrygarden.bi.main.dto.districtReport.RdClosedBuildingProjectDTO">
             SELECT rc.id AS id,rd.region_name AS regionName,rd.district_code AS districtCode,rd.district_name AS districtName,rc.project_code AS projectCode,rc.project_name AS projectName,rc.plan_place_area AS planPlaceArea,rc.plan_build_area AS planBuildArea,
                rc.manager_area AS managerArea,rc.plan_car_area AS planCarArea,rc.house_charges_area AS houseChargesArea,
                rc.business_charges_area AS businessChargesArea,rc.plan_households AS planHouseholds,rc.manager_households AS managerHouseholds,rc.manager_car_households AS managerCarHouseholds,rc.industry_composition AS industryComposition,
                rc.first_pay_date AS firstPayDate,rc.property_price AS propertyPrice,
                rc.car_price AS carPrice,rc.property_collection_rate AS propertyCollectionRate,rc.last_year_recovery_rate AS lastYearRecoveryRate,rc.green_area AS greenArea,rc.volume_ratio AS volumeRatio,
                rc.building_density AS buildingDensity,rc.project_place AS projectPlace,rc.office_place AS officePlace,
                rc.contact AS contact,rc.project_responsibler AS projectResponsibler,rc.elevator_count AS elevatorCount,rc.committee_rate AS committeeRate,rc.committee_project AS committeeProject,rc.committee_unit AS committeeUnit,
                rc.compiling_customer AS compilingCustomer,rc.compiling_order AS compilingOrder,
                rc.compiling_engineers AS compilingEngineers,rc.compiling_cleaner AS compilingCleaner,rc.compiling_case AS compilingCase,rc.compiling_other AS compilingOther,
                rc.sync_date AS syncDate,rc.sync_usercode AS syncUsercode,
                rc.create_time AS createTime,rc.create_by AS createBy,rc.descs as descs
                FROM rd_closed_building_project rc
                LEFT JOIN rd_district_info rd ON rd.district_code=rc.district_code
                 <where>
                     <if test="id!=null">
                         and rc.id=#{id}
                     </if>
                     and rc.ENABLE=1
                 </where>
    </select>

    <select id="closedBuildingProjectAddOne" resultType="cn.com.countrygarden.bi.main.dto.districtReport.RdClosedBuildingProjectDTO">
        SELECT rc.id AS id,rd.region_code AS regionCode,rd.region_name AS regionName,rd.district_code AS districtCode,rd.district_name AS districtName,rc.project_code AS projectCode,rc.project_name AS projectName,rc.plan_place_area AS planPlaceArea,rc.plan_build_area AS planBuildArea,
        rc.manager_area AS managerArea,rc.plan_car_area AS planCarArea,rc.house_charges_area AS houseChargesArea,
        rc.business_charges_area AS businessChargesArea,rc.plan_households AS planHouseholds,rc.manager_households AS managerHouseholds,rc.manager_car_households AS managerCarHouseholds,rc.industry_composition AS industryComposition,
        rc.first_pay_date AS firstPayDate,rc.property_price AS propertyPrice,
        rc.car_price AS carPrice,rc.property_collection_rate AS propertyCollectionRate,rc.last_year_recovery_rate AS lastYearRecoveryRate,rc.green_area AS greenArea,rc.volume_ratio AS volumeRatio,
        rc.building_density AS buildingDensity,rc.project_place AS projectPlace,rc.office_place AS officePlace,
        rc.contact AS contact,rc.project_responsibler AS projectResponsibler,rc.elevator_count AS elevatorCount,rc.committee_rate AS committeeRate,rc.committee_project AS committeeProject,rc.committee_unit AS committeeUnit,
        rc.compiling_customer AS compilingCustomer,rc.compiling_order AS compilingOrder,
        rc.compiling_engineers AS compilingEngineers,rc.compiling_cleaner AS compilingCleaner,rc.compiling_case AS compilingCase,rc.compiling_other AS compilingOther,
        rc.sync_date AS syncDate,rc.sync_usercode AS syncUsercode,
        rc.create_time AS createTime,rc.create_by AS createBy,rc.descs as descs
        FROM rd_closed_building_project rc
        LEFT JOIN rd_district_info rd ON rd.district_code=rc.district_code
        <where>
            <if test="regionCode!=null and regionCode!=''">
                and rd.region_code=#{regionCode}
            </if>
            <if test="projectCode!=null and projectCode!=''">
                and rc.project_code=#{projectCode}
            </if>
            <if test="createdBy!=null and createdBy!=''">
                and rc.create_by=#{createdBy}
            </if>
            and rc.ENABLE=1
        </where>
    </select>

    <update id="update">
           UPDATE rd_closed_building_project
           <set>
                <if test="districtCode!=null and districtCode!=''">district_code = #{districtCode},</if>
               <if test="projectCode!=null and projectCode!=''">project_code = #{projectCode},</if>
               <if test="projectName!=null and projectName!=''">project_name = #{projectName},</if>
               <if test="planPlaceArea!=null">plan_place_area = #{planPlaceArea},</if>
               <if test="planBuildArea!=null">plan_build_area = #{planBuildArea},</if>
               <if test="managerArea!=null">manager_area = #{managerArea},</if>
               <if test="planCarArea!=null">plan_car_area = #{planCarArea},</if>
               <if test="houseChargesArea!=null">house_charges_area = #{houseChargesArea},</if>
               <if test="businessChargesArea!=null">business_charges_area = #{businessChargesArea},</if>
               <if test="planHouseholds!=null">plan_households = #{planHouseholds},</if>
               <if test="managerHouseholds!=null">manager_households = #{managerHouseholds},</if>
               <if test="managerCarHouseholds!=null">manager_car_households = #{managerCarHouseholds},</if>
               <if test="industryComposition!=null and industryComposition!=''">industry_composition = #{industryComposition},</if>
               <if test="firstPayDate!=null">first_pay_date = #{firstPayDate},</if>
               <if test="propertyPrice!=null and propertyPrice!=''">property_price = #{propertyPrice},</if>
               <if test="carPrice!=null and carPrice!=''">car_price = #{carPrice},</if>
               <if test="propertyCollectionRate!=null and propertyCollectionRate!=''">property_collection_rate = #{propertyCollectionRate},</if>
               <if test="lastYearRecoveryRate!=null and lastYearRecoveryRate!=''">last_year_recovery_rate = #{lastYearRecoveryRate},</if>
               <if test="greenArea!=null">green_area = #{greenArea},</if>
               <if test="volumeRatio!=null">volume_ratio = #{volumeRatio},</if>
               <if test="buildingDensity!=null">building_density = #{buildingDensity},</if>
               <if test="projectPlace!=null and projectPlace!=''">project_place = #{projectPlace},</if>
               <if test="officePlace!=null and officePlace!=''">office_place = #{officePlace},</if>
               <if test="contact!=null and contact!=''">contact = #{contact},</if>
               <if test="projectResponsibler!=null and projectResponsibler!=''">project_responsibler = #{projectResponsibler},</if>
               <if test="elevatorCount!=null">elevator_count = #{elevatorCount},</if>
               <if test="committeeRate!=null and committeeRate!=''">committee_rate = #{committeeRate},</if>
               <if test="committeeProject!=null and committeeProject!=''">committee_project = #{committeeProject},</if>
               <if test="committeeUnit!=null and committeeUnit!=''">committee_unit = #{committeeUnit},</if>
               <if test="compilingCustomer!=null">compiling_customer = #{compilingCustomer},</if>
               <if test="compilingOrder!=null">compiling_order = #{compilingOrder},</if>
               <if test="compilingEngineers!=null">compiling_engineers = #{compilingEngineers},</if>
               <if test="compilingCleaner!=null">compiling_cleaner = #{compilingCleaner},</if>
               <if test="compilingCase!=null">compiling_case = #{compilingCase},</if>
               <if test="compilingOther!=null">compiling_other = #{compilingOther},</if>
               <if test="descs!=null">descs = #{descs},</if>
               <if test="syncDate!=null">sync_date = #{syncDate},</if>
               <if test="syncUsercode!=null">sync_usercode = #{syncUsercode},</if>
               <if test="syncUsercode!=null and syncUsercode!=''">sync_usercode = #{syncUsercode},</if>
               <if test="createTime!=null">create_time = #{createTime},</if>
               <if test="createBy!=null and createBy!=''">create_by = #{createBy},</if>
               <if test="updateTime!=null">update_time = #{updateTime},</if>
               <if test="updateBy!=null and updateBy!=''">update_by = #{updateBy},</if>
           </set>
               WHERE id = #{id};
    </update>

    <update id="deleteUpdate">
                UPDATE rd_closed_building_project set ENABLE=0,update_time=NOW(),update_by=#{updateBy},update_name=#{updateName}
                where id=#{id}
    </update>

    <update id="delpingliangtag">
        UPDATE rd_closed_building_project SET ENABLE = 0,update_time=NOW(),update_by=#{updateBy},update_name=#{updateName}
        <where>
            <if test="rids!=null">
                id in
                <foreach collection="rids" item="rids" index="index" open="(" close=")" separator=",">
                    #{rids}
                </foreach>
            </if>
        </where>
    </update>

    <select id="evaluationrdClosedBuildingProject" resultType="cn.com.countrygarden.bi.main.dto.districtReport.RdClosedBuildingProjectVO">
        SELECT DISTINCT rc.id AS id,rd.region_name AS regionName,rd.district_code AS districtCode,rd.district_name AS districtName,rc.project_code AS projectCode,rc.project_name AS projectName,rc.plan_place_area AS planPlaceArea,rc.plan_build_area AS planBuildArea,
        rc.manager_area AS managerArea,rc.plan_car_area AS planCarArea,rc.house_charges_area AS houseChargesArea,
        rc.business_charges_area AS businessChargesArea,rc.plan_households AS planHouseholds,rc.manager_households AS managerHouseholds,rc.manager_car_households AS managerCarHouseholds,rc.industry_composition AS industryComposition,
        rc.first_pay_date AS firstPayDate,rc.property_price AS propertyPrice,
        rc.car_price AS carPrice,rc.property_collection_rate AS propertyCollectionRate,rc.last_year_recovery_rate AS lastYearRecoveryRate,rc.green_area AS greenArea,rc.volume_ratio AS volumeRatio,
        rc.building_density AS buildingDensity,rc.project_place AS projectPlace,rc.office_place AS officePlace,
        rc.contact AS contact,rc.project_responsibler AS projectResponsibler,rc.elevator_count AS elevatorCount,rc.committee_rate AS committeeRate,rc.committee_project AS committeeProject,rc.committee_unit AS committeeUnit,
        rc.compiling_customer AS compilingCustomer,rc.compiling_order AS compilingOrder,
        rc.compiling_engineers AS compilingEngineers,rc.compiling_cleaner AS compilingCleaner,rc.compiling_case AS compilingCase,rc.compiling_other AS compilingOther,
        rc.sync_date AS syncDate,rc.sync_usercode AS syncUsercode,
        rc.create_time AS createTime,rc.create_by AS createBy,rc.descs as descs
        FROM rd_closed_building_project rc
        LEFT JOIN rd_district_info rd ON rd.district_code=rc.district_code
        LEFT JOIN rd_district_principal rdp ON rd.district_code=rdp.district_code
        <where>
            <if test="organCodeString!=null and organCodeString.size()!=0">
                and rd.region_code in
                <foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
                    #{organCodeString}
                </foreach>
            </if>
            <if test="commIdString!=null and commIdString.size()!=0">
                and rc.project_code in
                <foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
                    #{commIdString}
                </foreach>
            </if>
            <if test="principaString!=null and principaString.size()!=0">
                and rdp.principal_code in
                <foreach collection="principaString" item="principaString" index="index" open="(" close=")" separator=",">
                    #{principaString}
                </foreach>
                AND rdp.ENABLE=1
            </if>
            <if test="rdClosedBuildingProjectDTO.regionCode!=null and rdClosedBuildingProjectDTO.regionCode!=''">
                and rd.region_code=#{rdClosedBuildingProjectDTO.regionCode}
            </if>
            <if test="rdClosedBuildingProjectDTO.projectCode!=null and rdClosedBuildingProjectDTO.projectCode!=''">
                and rc.project_code=#{rdClosedBuildingProjectDTO.projectCode}
            </if>
            <if test="rdClosedBuildingProjectDTO.districtCode!=null and rdClosedBuildingProjectDTO.districtCode!=''">
                and rd.district_code=#{rdClosedBuildingProjectDTO.districtCode}
            </if>
            <if test="rdClosedBuildingProjectDTO.firstPayDateList1!=null and rdClosedBuildingProjectDTO.firstPayDateList1!='' and rdClosedBuildingProjectDTO.firstPayDateList2!=null and rdClosedBuildingProjectDTO.firstPayDateList2!=''">
                and rc.first_pay_date BETWEEN #{rdClosedBuildingProjectDTO.firstPayDateList1} and #{rdClosedBuildingProjectDTO.firstPayDateList2}
            </if>
            and rc.ENABLE=1
        </where>
        ORDER BY rc.project_code,rd.district_code,rc.create_time
    </select>

    <select id="BuildingProjectsAddone" resultType="int">
        SELECT COUNT(DISTINCT rc.project_code) FROM rd_closed_building_project rc
        LEFT JOIN rd_district_info d ON d.district_code=rc.district_code
        <where>
            <if test="projectCode!=null and projectCode!=''">
                and rc.project_code=#{projectCode}
            </if>
            and rc.ENABLE=1
        </where>

    </select>

</mapper>