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

    <resultMap type="cn.cecep.talroad.domain.SEnvWaterMonDay" id="SEnvWaterMonDayResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="outletId"    column="outlet_id"    />
        <result property="dataType"    column="data_type"    />
        <result property="monitoringTime"    column="monitoring_time"    />
        <result property="sewage"    column="sewage"    />
        <result property="sewageEmission"    column="sewage_emission"    />
        <result property="cod"    column="cod"    />
        <result property="codConcentration"    column="cod_concentration"    />
        <result property="codEmission"    column="cod_emission"    />
        <result property="ammoniaNitrogen"    column="ammonia_nitrogen"    />
        <result property="ammoniaNitrogenEmission"    column="ammonia_nitrogen_emission"    />
        <result property="nitrogenConcentration"    column="nitrogen_concentration"    />
        <result property="nitrogenConcentrationEmission"    column="nitrogen_concentration_emission"    />
        <result property="phosphorusConcentration"    column="phosphorus_concentration"    />
        <result property="phosphorusConcentrationEmission"    column="phosphorus_concentration_emission"    />
        <result property="phValue"    column="ph_value"    />
        <result property="wastewaterFlow"    column="wastewater_flow"    />
        <result property="codFlag" column="cod_flag" />
        <result property="ammoniaNitrogenFlag" column="ammonia_nitrogen_flag" />
        <result property="nitrogenConcentrationFlag" column="nitrogen_concentration_flag" />
        <result property="phosphorusConcentrationFlag" column="phosphorus_concentration_flag" />

    </resultMap>


    <sql id="selectSEnvWaterMonDayVo">
        select id, factory_id, outlet_id, data_type, monitoring_time, sewage, sewage_emission, cod, cod_concentration, cod_emission, ammonia_nitrogen, ammonia_nitrogen_emission, nitrogen_concentration, nitrogen_concentration_emission, phosphorus_concentration, phosphorus_concentration_emission, ph_value, wastewater_flow,cod_flag,ammonia_nitrogen_flag,phosphorus_concentration_flag,nitrogen_concentration_flag from s_env_water_mon_hour
    </sql>

    <select id="selectMaxByDate" resultMap="SEnvWaterMonDayResult">
        select factory_id,outlet_id,
               max(cod_emission) as cod_emission,
               max(ammonia_nitrogen_emission) as ammonia_nitrogen_emission,
               max(nitrogen_concentration_emission) as nitrogen_concentration_emission,
               max(phosphorus_concentration_emission) as phosphorus_concentration_emission
        from
            s_env_water_mon_day
        where
                monitoring_time &gt;= #{startTime}
            and monitoring_time &lt; #{endTime}
        GROUP BY
            factory_id,
            outlet_id
    </select>
    <select id="selectLastDayCountData"
        resultType="cn.cecep.talroad.vo.analysis.FactoryOutletStaticsVo">
        select a.* from
            (select
                 factory_id as factoryId,
                 outlet_id as outletId ,
                 count(1) as actualCount
             from
                 s_env_water_mon_real segmh
             WHERE
                 data_type = 'D'
               AND monitoring_time between #{lastDayBegin} and #{lastDayEnd}
             group by factory_id , outlet_id
            ) a
                inner join pc_outlet po on a.factoryId = po.factory_id and a.outletId = po.id
        where po.pollutant_type ='4'
          and po.pollutant_outlet_type ='2'
          and po.monitoring_point_name not like '%入口%'
          and po.monitoring_point_name not like '%进口%'

    </select>
    <select id="selectHourDataByTime" resultMap="SEnvWaterMonDayResult">
        select * from s_env_water_mon_day where factory_id = #{factoryId} and outlet_id = #{outletId} and data_type ='H' and monitoring_time = #{monitorTime}
    </select>
</mapper>
