<?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.effective.SEnvgasPollutantMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.effective.SEnvgasPollutant">
        <id column="pk_id" property="pkId" />
        <result column="fk_pollutant_type_id" property="fkPollutantTypeId" />
        <result column="pollutant_code" property="pollutantCode" />
        <result column="pollutant_name" property="pollutantName" />
        <result column="unit" property="unit" />
        <result column="serial" property="serial" />
        <result column="decimal_point" property="decimalPoint" />
        <result column="is_used" property="isUsed" />
        <result column="field" property="field" />
        <result column="is_pollutant" property="isPollutant" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        pk_id, fk_pollutant_type_id, pollutant_code, pollutant_name, unit, serial, decimal_point, is_used, is_pollutant,field
    </sql>

    <select id="queryPollutantMap" resultType="java.util.HashMap">
        SELECT
            pk_id,
            pollutant_name
        FROM
            `s_envgas_pollutant`
    </select>
    <select id="selectByDivisorData" resultType="java.util.Map">
        SELECT DISTINCT
            poll.pollutant_name pollutantName,
            poll.FIELD field
        FROM
            p_code_region_control p
            LEFT JOIN s_envgas_station_control s ON s.pk_id = p.control_level_id
            LEFT JOIN s_envgas_pollution_control c ON c.control_level_id = p.control_level_id
            INNER JOIN s_envgas_pollutant poll ON poll.pk_id = c.pollution_id
        WHERE
            1 = 1 and poll.is_used = '0' and p.type='2'
            AND region_code = #{regionCode}
            <if test="property != null and property != ''">
                AND c.property = #{property}
            </if>
            order by poll.serial
    </select>
    <select id="selectBySixApiParam" resultType="java.util.Map">
          SELECT DISTINCT
            poll.pollutant_name as "pollutantName",
            poll.FIELD as "field",serial
        FROM  s_envgas_pollutant poll WHERE   poll.is_used = '0'
        <if test="maps != null and maps.size > 0">
            AND poll.pollutant_code IN
            (
            <foreach collection="maps" item="item" separator=",">
                #{item}
            </foreach>
            )
        </if>
        ORDER BY serial
    </select>
    <select id="selectByWind" resultType="java.util.Map">
        SELECT DISTINCT
            GROUP_CONCAT( poll.pollutant_name ) pollutantName,
            GROUP_CONCAT( poll.FIELD ) field
        FROM
            s_envgas_pollutant poll
        WHERE
            1 = 1
            AND poll.is_used = '0'
            AND field = 'windd'
            OR field = 'winds'
    </select>
    <select id="findIdByName" resultType="java.lang.Integer">
        SELECT pk_id FROM s_envgas_pollutant WHERE `pollutant_name` = #{name}
    </select>
    <select id="findNameById" resultType="java.lang.String">
        SELECT `pollutant_name` FROM s_envgas_pollutant WHERE `pk_id` = #{id}
    </select>
    <select id="selectByParamData" resultType="java.util.Map">
        SELECT DISTINCT
        poll.pollutant_name pollutantName,
        poll.FIELD field
        FROM  s_envgas_pollutant poll
        WHERE   1 = 1 and poll.is_used = '0'
        <if test="maps != null and maps.size > 0">
            AND poll.FIELD IN
            (
            <foreach collection="maps" item="item" separator=",">
                #{item}
            </foreach>
            )
        </if>
        ORDER BY serial
    </select>

</mapper>
