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

    <select id="selectListByTime" resultType="cn.cecep.talroad.domain.BMainThreeSupervisionEnforc">
        <if test="taskName != null and taskName.size() != 0">
            SELECT
                bmtse.task_id,
                bmtse.factory_id,
                bmtse.task_name
            FROM
            pc_factory pf
                LEFT JOIN b_main_three_supervision_enforc bmtse ON bmtse.factory_id = pf.ID
                INNER JOIN ( SELECT task_name, max(create_time) as create_time FROM b_main_three_supervision_enforc
                    WHERE  create_time &gt;= #{startTime,jdbcType=TIMESTAMP}   AND create_time &lt;= #{endTime,jdbcType=TIMESTAMP}
                    GROUP BY  task_name) tmp ON tmp.create_time = bmtse.create_time AND tmp.task_name = bmtse.task_name
            WHERE
                bmtse.task_status = '0'
                AND bmtse.task_name IN
            <foreach collection="taskName" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
    </select>



    <select id="selectMamProblemFiList" resultType="cn.cecep.talroad.domain.AmProblemFi">
        SELECT
            mapf.id ,
            mapf.factory_id
        FROM
            pc_factory pf
            LEFT JOIN m_am_problem_fi mapf ON pf.id = mapf.factory_id
        WHERE
            mapf.analyse_time &gt;= #{startTime,jdbcType=TIMESTAMP}
            AND mapf.analyse_time &lt;= #{endTime,jdbcType=TIMESTAMP}
            AND mapf.problem_sources = #{problemSources}
            AND mapf.problem_type = #{problemType}
            AND mapf.type = '0'

    </select>

    <select id="selectMamProblemFiListNew" resultType="cn.cecep.talroad.domain.AmProblemFi">
        SELECT
            mapf.id ,
            mapf.factory_id
        FROM
            pc_factory pf
            LEFT JOIN m_am_problem_fi mapf ON pf.id = mapf.factory_id
        WHERE
            mapf.analyse_time &gt;= #{startTime,jdbcType=TIMESTAMP}
            AND mapf.analyse_time &lt;= #{endTime,jdbcType=TIMESTAMP}
            AND mapf.problem_sources = #{problemSources}
            AND mapf.type = '0'
            <foreach collection="problemType" index="index" item="item" open="AND mapf.problem_type IN(" separator="," close=")">
                #{item,jdbcType=VARCHAR}
            </foreach>

    </select>

    <select id="selectBMainThreeSupervisionEnforcById" resultType="cn.cecep.talroad.domain.BMainThreeSupervisionEnforc">
        SELECT
            bmtse.task_status
        FROM
            b_main_three_supervision_enforc bmtse
        WHERE
            bmtse.task_id = #{taskId,jdbcType=VARCHAR}
    </select>

    <select id="selectMamProblemFiById" resultType="cn.cecep.talroad.domain.AmProblemFi">
        SELECT
            *
        FROM
            m_am_problem_fi
        WHERE
            id = #{id}
    </select>

    <select id="selectSRaSelfMonitoringDataList" resultType="cn.cecep.talroad.domain.analysis.SRaSelfMonitoringData">
        SELECT
            data_id,
            factory_id,
            pollutants_code
        FROM
            s_ra_self_monitoring_data
        WHERE
            monitor_time &gt;= #{startTime,jdbcType=TIMESTAMP}
        AND monitor_time &lt;= #{endTime,jdbcType=TIMESTAMP}
        AND exceeding_standard = '1'
    </select>

    <select id="selectSRaFactoryTransferRateAnalysisList"
            resultType="cn.cecep.talroad.domain.analysis.SRaFactoryTransferRateAnalysis">
        SELECT
            ID,
            factory_id,
            factory_id,
            factory_name
        FROM
            s_ra_factory_transfer_rate_analysis
        WHERE
            count_type = 'D'
            AND statistics_time = #{time}
    </select>

    <select id="selectSRaSelfMonitoringDataListByParams"
            resultType="cn.cecep.talroad.domain.analysis.SRaSelfMonitoringData">
        <if test="selfMonitorsIds != null and selfMonitorsIds.size() != 0">
            SELECT
                data_id,
                factory_id,
                pollutants_code
            FROM
                s_ra_self_monitoring_data
            WHERE
                monitor_time &gt;= #{startTime,jdbcType=TIMESTAMP}
                AND monitor_time &lt;= #{endTime,jdbcType=TIMESTAMP}
                AND exceeding_standard = '0'
                AND monitor_id IN
            <foreach collection="selfMonitorsIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

    </select>
</mapper>
