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

    <resultMap type="cn.cecep.talroad.domain.analysis.SRaHandworkEmissionsGas" id="SRaHandworkEmissionsGasResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="pointName"    column="point_name"    />
        <result property="outletCode"    column="outlet_code"    />
        <result property="outletType"    column="outlet_type"    />
        <result property="pollutantName"    column="pollutant_name"    />
        <result property="monitorTime"    column="monitor_time"    />
        <result property="monitorVal"    column="monitor_val"    />
        <result property="unit"    column="unit"    />
        <result property="flueGasFlow"    column="flue_gas_flow"    />
        <result property="checkCycleStart"    column="check_cycle_start"    />
        <result property="checkCycleEnd"    column="check_cycle_end"    />
        <result property="checkRunTime"    column="check_run_time"    />
        <result property="runTimeSource"    column="run_time_source"    />
        <result property="emissions"    column="emissions"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <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"    />
    </resultMap>


    <sql id="selectSRaHandworkEmissionsGasVo">
        select id, factory_id, point_name, outlet_code, outlet_type, pollutant_name, monitor_time, monitor_val, unit, flue_gas_flow, check_cycle_start, check_cycle_end, check_run_time, run_time_source, emissions, create_by, create_time, update_by, update_time, factory_name, industry_category_name, industry_category_code, district_name, district_code from s_ra_handwork_emissions_gas
    </sql>

    <select id="selectSRaHandworkEmissionsGasList" parameterType="cn.cecep.talroad.vo.query.analysis.SRaHandworkEmissionsGasQuery" resultMap="SRaHandworkEmissionsGasResult">
        <include refid="selectSRaHandworkEmissionsGasVo"/>
        <where>
            <if test="sRaHandworkEmissionsGas.factoryName != null  and sRaHandworkEmissionsGas.factoryName != ''"> and factory_name like concat('%', #{sRaHandworkEmissionsGas.factoryName}, '%')</if>
            <if test="sRaHandworkEmissionsGas.pointName != null  and sRaHandworkEmissionsGas.pointName != ''"> and point_name like concat('%', #{sRaHandworkEmissionsGas.pointName}, '%')</if>
            <if test="sRaHandworkEmissionsGas.outletCode != null  and sRaHandworkEmissionsGas.outletCode != ''"> and outlet_code like concat('%', #{sRaHandworkEmissionsGas.outletCode}, '%')</if>
            <if test="sRaHandworkEmissionsGas.outletType != null  and sRaHandworkEmissionsGas.outletType != ''"> and outlet_type = #{sRaHandworkEmissionsGas.outletType}</if>
            <if test="sRaHandworkEmissionsGas.pollutantName != null  and sRaHandworkEmissionsGas.pollutantName != ''"> and pollutant_name like concat('%', #{sRaHandworkEmissionsGas.pollutantName}, '%')</if>
            <if test="startTime != null  and endTime != null"> and monitor_time between #{startTime} and #{endTime}</if>
            <if test="sRaHandworkEmissionsGas.monitorVal != null  and sRaHandworkEmissionsGas.monitorVal != ''"> and monitor_val = #{sRaHandworkEmissionsGas.monitorVal}</if>
            <if test="sRaHandworkEmissionsGas.unit != null  and sRaHandworkEmissionsGas.unit != ''"> and unit = #{sRaHandworkEmissionsGas.unit}</if>
            <if test="sRaHandworkEmissionsGas.flueGasFlow != null  and sRaHandworkEmissionsGas.flueGasFlow != ''"> and flue_gas_flow = #{sRaHandworkEmissionsGas.flueGasFlow}</if>
            <if test="cycStartTime != null "> and check_cycle_start >= #{cycStartTime}</if>
            <if test="cycEndTime != null "> and check_cycle_end &lt;= #{cycEndTime}</if>
            <if test="sRaHandworkEmissionsGas.checkRunTime != null  and sRaHandworkEmissionsGas.checkRunTime != ''"> and check_run_time = #{sRaHandworkEmissionsGas.checkRunTime}</if>
            <if test="sRaHandworkEmissionsGas.runTimeSource != null  and sRaHandworkEmissionsGas.runTimeSource != ''"> and run_time_source = #{sRaHandworkEmissionsGas.runTimeSource}</if>
            <if test="sRaHandworkEmissionsGas.emissions != null  and sRaHandworkEmissionsGas.emissions != ''"> and emissions = #{sRaHandworkEmissionsGas.emissions}</if>
            <if test="sRaHandworkEmissionsGas.industryCategoryName != null  and sRaHandworkEmissionsGas.industryCategoryName != ''"> and industry_category_name = #{sRaHandworkEmissionsGas.industryCategoryName}</if>
            <if test="sRaHandworkEmissionsGas.districtName != null  and sRaHandworkEmissionsGas.districtName != ''"> and district_name = #{sRaHandworkEmissionsGas.districtName}</if>
        </where>
    </select>

    <select id="pullPointOptions" resultType="java.util.Map">
        select
            point_name AS label,
            point_name AS value
        from
            s_ra_handwork_emissions_gas
        group by point_name
    </select>

    <select id="pullPollutantOptions" resultType="java.util.Map">
        select
            pollutant_name AS label,
            pollutant_name AS value
        from
            s_ra_handwork_emissions_gas
        group by pollutant_name
    </select>
    <select id="selectAgvDataList" resultType="cn.cecep.talroad.domain.analysis.SRaHandworkEmissionsGas">
        select
            factory_id,
            pollutant_name,
            round(avg(cast(monitor_val as decimal)),2) as monitor_val,
            round(avg(cast(flue_gas_flow as decimal)),2) as flue_gas_flow,
            round(avg(cast(check_run_time as decimal)),2) as check_run_time
        from s_ra_handwork_emissions_gas
        where
            monitor_val is not null and  flue_gas_flow is not null and check_run_time is not null
            and monitor_val!= '/' and flue_gas_flow!= '/' and check_run_time != '/'
			and factory_id = #{factoryId}
            and monitor_time >= to_timestamp( #{dateStr}, 'YYYY-MM-DD HH24:MI:SS' )
            and monitor_time &lt;= to_timestamp( #{dateStrEnd}, 'YYYY-MM-DD HH24:MI:SS' )
        GROUP BY factory_id,pollutant_name
    </select>
</mapper>
