<?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.analysis.SRaEmissionsStandardMapper">

    <resultMap type="cn.cecep.talroad.domain.analysis.SRaEmissionsStandard" id="SRaEmissionsStandardResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="analyseYear"    column="analyse_year"    />
        <result property="pollutantName"    column="pollutant_name"    />
        <result property="regionRanking"    column="region_ranking"    />
        <result property="industryRanking"    column="industry_ranking"    />
        <result property="isEmissionsBigUser"    column="is_emissions_big_user"    />
        <result property="emissionsScale"    column="emissions_scale"    />
        <result property="unitEmissions"    column="unit_emissions"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>


    <sql id="selectSRaEmissionsStandardVo">
        select id, factory_id, factory_name,industry_category_name,district_name,analyse_year, pollutant_name, region_ranking, industry_ranking, is_emissions_big_user, emissions_scale, unit_emissions, create_by, create_time, update_by, update_time from s_ra_emissions_standard
    </sql>

    <select id="selectSRaEmissionsStandardList"  resultMap="SRaEmissionsStandardResult">
        <include refid="selectSRaEmissionsStandardVo"/>
        <where>
            <if test="sRaEmissionsStandard.factoryName != null  and sRaEmissionsStandard.factoryName != ''"> and factory_name like concat('%', #{sRaEmissionsStandard.factoryName}, '%') </if>
            <if test="sRaEmissionsStandard.analyseYear != null  and sRaEmissionsStandard.analyseYear != ''"> and analyse_year = #{sRaEmissionsStandard.analyseYear}</if>
            <if test="sRaEmissionsStandard.districtName != null  and sRaEmissionsStandard.districtName != ''"> and district_name = #{sRaEmissionsStandard.districtName}</if>
            <if test="sRaEmissionsStandard.districtCode != null  and sRaEmissionsStandard.districtCode != ''"> and district_code = #{sRaEmissionsStandard.districtCode}</if>
            <if test="sRaEmissionsStandard.industryCategoryName != null  and sRaEmissionsStandard.industryCategoryName != ''"> and industry_category_name = #{sRaEmissionsStandard.industryCategoryName}</if>
            <if test="sRaEmissionsStandard.pollutantName != null  and sRaEmissionsStandard.pollutantName != ''"> and pollutant_name like concat('%', #{sRaEmissionsStandard.pollutantName}, '%')</if>
            <if test="sRaEmissionsStandard.regionRanking != null  and sRaEmissionsStandard.regionRanking != ''"> and region_ranking = #{sRaEmissionsStandard.regionRanking}</if>
            <if test="sRaEmissionsStandard.industryRanking != null  and sRaEmissionsStandard.industryRanking != ''"> and industry_ranking = #{sRaEmissionsStandard.industryRanking}</if>
            <if test="sRaEmissionsStandard.isEmissionsBigUser != null  and sRaEmissionsStandard.isEmissionsBigUser != ''"> and is_emissions_big_user = #{sRaEmissionsStandard.isEmissionsBigUser}</if>
            <if test="start != null"> and emissions_scale::numeric >= #{start}</if>
            <if test="end != null"> and emissions_scale::numeric &lt;= #{end}</if>
            <if test="sRaEmissionsStandard.unitEmissions != null  and sRaEmissionsStandard.unitEmissions != ''"> and unit_emissions = #{sRaEmissionsStandard.unitEmissions}</if>
            <if test="sRaEmissionsStandard.regionCodes != null and sRaEmissionsStandard.regionCodes.size() != 0">
                and district_code IN
                <foreach collection="sRaEmissionsStandard.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
    </select>

    <select id="pullPollutantOptions" resultType="java.util.Map">
        select
            pollutant_name AS label,
            pollutant_name AS value
        from
            s_ra_emissions_standard
        group by pollutant_name
    </select>

    <select id="pullEmissionScaleOptions" resultType="java.util.Map">
        SELECT MAX(emissions_scale::numeric) AS maxvalue, MIN(emissions_scale::numeric) AS minvalue FROM s_ra_emissions_standard;
    </select>

</mapper>
