<?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.cecep.talroad.mapper.BStatTableZxbgHdWaterPollutionMapper">

    <resultMap type="cn.cecep.talroad.domain.BStatTableZxbgHdWaterPollution" id="BStatTableZxbgHdWaterPollutionResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="zxbgType"    column="zxbg_type"    />
        <result property="zxbgPeriod"    column="zxbg_period"    />
        <result property="waterCategory"    column="water_category"    />
        <result property="governanceFacilityCode"    column="governance_facility_code"    />
        <result property="governanceFacilityName"    column="governance_facility_name"    />
        <result property="governanceFacilityTime"    column="governance_facility_time"    />
        <result property="pollutionFacilityTechnology"    column="pollution_facility_technology"    />
        <result property="contaminateFactor"    column="contaminate_factor"    />
        <result property="emissions"    column="emissions"    />
        <result property="receivingName"    column="receiving_name"    />
        <result property="electricityConsumption"    column="electricity_consumption"    />
        <result property="processingPower"    column="processing_power"    />
        <result property="actualProcessingVolume"    column="actual_processing_volume"    />
        <result property="willAmount"    column="will_amount"    />
        <result property="actualEmissions"    column="actual_emissions"    />
        <result property="designProcessingPower"    column="design_processing_power"    />
        <result property="waterTreatmentVolume"    column="water_treatment_volume"    />
        <result property="waterWillAmount"    column="water_will_amount"    />
        <result property="waterActualEmissions"    column="water_actual_emissions"    />
        <result property="sludgeGeneration"    column="sludge_generation"    />
        <result property="sludgeMoistureContent"    column="sludge_moisture_content"    />
        <result property="circulatingCooling"    column="circulating_cooling"    />
        <result property="coolingDischarge"    column="cooling_discharge"    />
        <result property="sludgeDisposalMethod"    column="sludge_disposal_method"    />
        <result property="facilityOperatingCosts"    column="facility_operating_costs"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>


    <sql id="selectBStatTableZxbgHdWaterPollutionVo">
        select id, factory_id, zxbg_type, zxbg_period, water_category, governance_facility_code, governance_facility_name, governance_facility_time, pollution_facility_technology, contaminate_factor, emissions, receiving_name, electricity_consumption, processing_power, actual_processing_volume, will_amount, actual_emissions, design_processing_power, water_treatment_volume, water_will_amount, water_actual_emissions, sludge_generation, sludge_moisture_content, circulating_cooling, cooling_discharge, sludge_disposal_method, facility_operating_costs, create_time from b_stat_table_zxbg_hd_water_pollution
    </sql>

    <select id="selectBStatTableZxbgHdWaterPollutionList" parameterType="cn.cecep.talroad.domain.BStatTableZxbgHdWaterPollution" resultMap="BStatTableZxbgHdWaterPollutionResult">
        <include refid="selectBStatTableZxbgHdWaterPollutionVo"/>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="zxbgType != null  and zxbgType != ''"> and zxbg_type = #{zxbgType}</if>
            <if test="zxbgPeriod != null  and zxbgPeriod != ''"> and zxbg_period = #{zxbgPeriod}</if>
            <if test="waterCategory != null  and waterCategory != ''"> and water_category = #{waterCategory}</if>
            <if test="governanceFacilityCode != null  and governanceFacilityCode != ''"> and governance_facility_code = #{governanceFacilityCode}</if>
            <if test="governanceFacilityName != null  and governanceFacilityName != ''"> and governance_facility_name like concat('%', #{governanceFacilityName}, '%')</if>
            <if test="governanceFacilityTime != null  and governanceFacilityTime != ''"> and governance_facility_time = #{governanceFacilityTime}</if>
            <if test="pollutionFacilityTechnology != null  and pollutionFacilityTechnology != ''"> and pollution_facility_technology = #{pollutionFacilityTechnology}</if>
            <if test="contaminateFactor != null  and contaminateFactor != ''"> and contaminate_factor = #{contaminateFactor}</if>
            <if test="emissions != null  and emissions != ''"> and emissions = #{emissions}</if>
            <if test="receivingName != null  and receivingName != ''"> and receiving_name like concat('%', #{receivingName}, '%')</if>
            <if test="electricityConsumption != null  and electricityConsumption != ''"> and electricity_consumption = #{electricityConsumption}</if>
            <if test="processingPower != null  and processingPower != ''"> and processing_power = #{processingPower}</if>
            <if test="actualProcessingVolume != null  and actualProcessingVolume != ''"> and actual_processing_volume = #{actualProcessingVolume}</if>
            <if test="willAmount != null  and willAmount != ''"> and will_amount = #{willAmount}</if>
            <if test="actualEmissions != null  and actualEmissions != ''"> and actual_emissions = #{actualEmissions}</if>
            <if test="designProcessingPower != null  and designProcessingPower != ''"> and design_processing_power = #{designProcessingPower}</if>
            <if test="waterTreatmentVolume != null  and waterTreatmentVolume != ''"> and water_treatment_volume = #{waterTreatmentVolume}</if>
            <if test="waterWillAmount != null  and waterWillAmount != ''"> and water_will_amount = #{waterWillAmount}</if>
            <if test="waterActualEmissions != null  and waterActualEmissions != ''"> and water_actual_emissions = #{waterActualEmissions}</if>
            <if test="sludgeGeneration != null  and sludgeGeneration != ''"> and sludge_generation = #{sludgeGeneration}</if>
            <if test="sludgeMoistureContent != null  and sludgeMoistureContent != ''"> and sludge_moisture_content = #{sludgeMoistureContent}</if>
            <if test="circulatingCooling != null  and circulatingCooling != ''"> and circulating_cooling = #{circulatingCooling}</if>
            <if test="coolingDischarge != null  and coolingDischarge != ''"> and cooling_discharge = #{coolingDischarge}</if>
            <if test="sludgeDisposalMethod != null  and sludgeDisposalMethod != ''"> and sludge_disposal_method = #{sludgeDisposalMethod}</if>
            <if test="facilityOperatingCosts != null  and facilityOperatingCosts != ''"> and facility_operating_costs = #{facilityOperatingCosts}</if>
        </where>
    </select>

    <select id="selectListAndFactory" resultMap="BStatTableZxbgHdWaterPollutionResult">
        SELECT
        zxbg.*,
        pf.factory_name,
        pf.country_name,
        pf.license_man_type,
        pf.poll_dis_license_code,
        pf.industrial_park_name,
        pf.industrial_park_code,
        pf.industry_permission_name,
        pf.river_basin
        FROM
        (select * from b_stat_table_zxbg_hd_water_pollution
        <where>
            <if test="zxbgType != null  and zxbgType != ''"> and zxbg_type = #{zxbgType}</if>
            <if test="zxbgPeriod != null  and zxbgPeriod != ''"> and zxbg_period  like concat('%', #{zxbgPeriod}, '%')</if>
        </where>
        )zxbg
        right JOIN pc_factory pf ON pf.ID = zxbg.factory_id
        <where>
            <if test="factoryIdList != null and factoryIdList.size() != 0">
                and pf.id
                <foreach collection="factoryIdList" close=")" open=" IN (" separator="," item="item">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        ORDER BY pf.order_num, pf.id
    </select>
</mapper>
