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

    <resultMap type="cn.cecep.talroad.vo.AmProblemFiRatioVo" id="AmProblemFiRatioResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="stationId"    column="station_id"    />
        <result property="pollId"    column="poll_id"    />
        <result property="problemRatio"    column="problem_ratio"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="factoryName"    column="factory_name"    />
        <result property="monitoringPointName"    column="monitoring_point_name"    />
        <result property="pollName"    column="poll_name"    />
        <result property="executiveStandard"    column="executive_standard"    />
    </resultMap>

    <sql id="selectAmProblemFiRatioVo">
        SELECT
            A.ID,
            A.factory_id,
            A.station_id,
            A.poll_id,
            A.problem_ratio,
            A.create_time,
            A.update_time,
            B.factory_name,
            C.monitoring_point_name,
            D.poll_name,
            D.executive_standard
        FROM
            m_am_problem_fi_ratio A
                LEFT JOIN pc_factory b ON A.factory_id = b.ID
                LEFT JOIN pc_outlet C ON A.station_id = C.ID
                LEFT JOIN pc_pollutant d ON A.poll_id = d.ID
    </sql>

    <select id="selectAmProblemFiRatioList" parameterType="cn.cecep.talroad.domain.AmProblemFiRatio" resultMap="AmProblemFiRatioResult">
        <include refid="selectAmProblemFiRatioVo"></include>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and A.factory_id = #{factoryId}</if>
            <if test="stationId != null  and stationId != ''"> and A.station_id = #{stationId}</if>
            <if test="pollId != null  and pollId != ''"> and A.poll_id = #{pollId}</if>
            <if test="problemRatio != null  and problemRatio != ''"> and A.problem_ratio = #{problemRatio}</if>
            <if test="factoryName != null  and factoryName != ''"> and B.factory_name like concat('%', #{factoryName}, '%')</if>
            <if test="monitoringPointName != null  and monitoringPointName != ''"> and C.monitoring_point_name like concat('%', #{monitoringPointName}, '%')</if>
            <if test="pollName != null  and pollName != ''"> and D.poll_name = #{pollName}</if>
            order by A.update_time DESC
        </where>
    </select>

    <select id="pageList" parameterType="cn.cecep.talroad.domain.AmProblemFiRatio" resultMap="AmProblemFiRatioResult">
        <include refid="selectAmProblemFiRatioVo"></include>
        <where>
            <if test="query.factoryId != null  and query.factoryId != ''"> and A.factory_id = #{query.factoryId}</if>
            <if test="query.stationId != null  and query.stationId != ''"> and A.station_id = #{query.stationId}</if>
            <if test="query.pollId != null  and query.pollId != ''"> and A.poll_id = #{query.pollId}</if>
            <if test="query.problemRatio != null  and query.problemRatio != ''"> and A.problem_ratio = #{query.problemRatio}</if>
            <if test="query.factoryName != null  and query.factoryName != ''"> and B.factory_name like concat('%', #{query.factoryName}, '%')</if>
            <if test="query.monitoringPointName != null  and query.monitoringPointName != ''"> and C.monitoring_point_name like concat('%', #{query.monitoringPointName}, '%')</if>
            <if test="query.pollName != null  and query.pollName != ''"> and D.poll_name = #{query.pollName}</if>
        </where>
        order by A.update_time DESC
    </select>

    <select id="pcPollutantList"  resultType="cn.cecep.talroad.vo.PcPollutantVo">
        SELECT
            DISTINCT b.poll_Code pollCode,
            b.poll_Name pollName
        FROM
            m_am_problem_fi_ratio A
            LEFT JOIN pc_pollutant B ON A.poll_id = B.ID
    </select>

    <select id="selectAmProblemFiRatio" parameterType="java.lang.Long" resultType="cn.cecep.talroad.vo.AmProblemFiRatioVo">
        <include refid="selectAmProblemFiRatioVo"></include>
        WHERE A.ID = #{id}
    </select>
</mapper>
