<?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.SRaRealTimeAnalysisKwhMapper">

    <resultMap type="cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisKwh" id="SRaRealTimeAnalysisKwhResult">
        <result property="dataId"    column="data_id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="factoryName"    column="factory_name"    />
        <result property="industryCategoryName"    column="industry_category_name"    />
        <result property="industryCategoryCode"    column="industry_category_code"    />
        <result property="districtName"    column="district_name"    />
        <result property="districtCode"    column="district_code"    />
        <result property="paramName"    column="param_name"    />
        <result property="areaRank"    column="area_rank"    />
        <result property="industryRank"    column="industry_rank"    />
        <result property="largeHouse"    column="large_house"    />
        <result property="scale"    column="scale"    />
        <result property="vol"    column="vol"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="year"    column="year"    />
        <result property="paramCode"    column="param_code"    />
        <result property="paramUnit"    column="param_unit"    />
    </resultMap>


    <sql id="selectSRaRealTimeAnalysisKwhVo">
        select data_id, factory_id, factory_name, industry_category_name, industry_category_code, district_name, district_code, param_name, area_rank, industry_rank, large_house, scale, vol, update_time, create_time, year, param_code, param_unit from s_ra_real_time_analysis_kwh
    </sql>

    <select id="selectSRaRealTimeAnalysisKwhList" resultMap="SRaRealTimeAnalysisKwhResult">
        <include refid="selectSRaRealTimeAnalysisKwhVo"/>
        <where>
            <if test="sRaRealTimeAnalysisKwh.factoryName != null  and sRaRealTimeAnalysisKwh.factoryName != ''"> and factory_name like concat('%', #{sRaRealTimeAnalysisKwh.factoryName}, '%')</if>
            <if test="sRaRealTimeAnalysisKwh.industryCategoryName != null  and sRaRealTimeAnalysisKwh.industryCategoryName != ''"> and industry_category_name like concat('%', #{sRaRealTimeAnalysisKwh.industryCategoryName}, '%')</if>
            <if test="sRaRealTimeAnalysisKwh.industryCategoryCode != null  and sRaRealTimeAnalysisKwh.industryCategoryCode != ''"> and industry_category_code = #{sRaRealTimeAnalysisKwh.industryCategoryCode}</if>
            <if test="sRaRealTimeAnalysisKwh.districtName != null  and sRaRealTimeAnalysisKwh.districtName != ''"> and district_name like concat('%', #{sRaRealTimeAnalysisKwh.districtName}, '%')</if>
            <if test="sRaRealTimeAnalysisKwh.districtCode != null  and sRaRealTimeAnalysisKwh.districtCode != ''"> and district_code = #{sRaRealTimeAnalysisKwh.districtCode}</if>
            <if test="sRaRealTimeAnalysisKwh.paramName != null  and sRaRealTimeAnalysisKwh.paramName != ''"> and param_name like concat('%', #{sRaRealTimeAnalysisKwh.paramName}, '%')</if>
            <if test="sRaRealTimeAnalysisKwh.areaRank != null "> and area_rank = #{sRaRealTimeAnalysisKwh.areaRank}</if>
            <if test="sRaRealTimeAnalysisKwh.industryRank != null "> and industry_rank = #{sRaRealTimeAnalysisKwh.industryRank}</if>
            <if test="sRaRealTimeAnalysisKwh.largeHouse != null  and sRaRealTimeAnalysisKwh.largeHouse != ''"> and large_house = #{sRaRealTimeAnalysisKwh.largeHouse}</if>
            <if test="start != null  "> and scale::numeric >= #{start}</if>
            <if test="end != null  "> and scale::numeric &lt;= #{end}</if>
            <if test="sRaRealTimeAnalysisKwh.vol != null  and sRaRealTimeAnalysisKwh.vol != ''"> and vol = #{sRaRealTimeAnalysisKwh.vol}</if>
            <if test="sRaRealTimeAnalysisKwh.year != null  and sRaRealTimeAnalysisKwh.year != ''"> and year = #{sRaRealTimeAnalysisKwh.year}</if>
            <if test="sRaRealTimeAnalysisKwh.paramCode != null  and sRaRealTimeAnalysisKwh.paramCode != ''"> and param_code = #{sRaRealTimeAnalysisKwh.paramCode}</if>
            <if test="sRaRealTimeAnalysisKwh.paramUnit != null  and sRaRealTimeAnalysisKwh.paramUnit != ''"> and param_unit = #{sRaRealTimeAnalysisKwh.paramUnit}</if>
            <if test="sRaRealTimeAnalysisKwh.regionCodes != null and sRaRealTimeAnalysisKwh.regionCodes.size() != 0">
                and district_code IN
                <foreach collection="sRaRealTimeAnalysisKwh.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
    </select>

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

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