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

    <resultMap type="cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysicComsit" id="SRaRealTimeAnalysicComsitResult">
        <result property="dataId"    column="data_id"    />
        <result property="sectionalizationName"    column="sectionalization_name"    />
        <result property="paramName"    column="param_name"    />
        <result property="analysisTime"    column="analysis_time"    />
        <result property="stationNum"    column="station_num"    />
        <result property="createTime"    column="create_time"    />
        <result property="avgValue"    column="avg_value"    />
    </resultMap>


    <sql id="selectSRaRealTimeAnalysicComsitVo">
        select data_id, sectionalization_name, param_name, analysis_time, station_num, create_time, avg_value from s_ra_real_time_analysic_comsit
    </sql>

    <select id="selectSRaRealTimeAnalysicComsitList" parameterType="cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysicComsit" resultMap="SRaRealTimeAnalysicComsitResult">
        <include refid="selectSRaRealTimeAnalysicComsitVo"/>
        <where>
            <if test="sectionalizationName != null  and sectionalizationName != ''"> and sectionalization_name like concat('%', #{sectionalizationName}, '%')</if>
            <if test="paramName != null  and paramName != ''"> and param_name like concat('%', #{paramName}, '%')</if>
            <if test="analysisTime != null  and analysisTime != ''"> and analysis_time = #{analysisTime}</if>
            <if test="stationNum != null "> and station_num = #{stationNum}</if>
            <if test="avgValue != null  and avgValue != ''"> and avg_value = #{avgValue}</if>
        </where>
    </select>

    <select id="selectSRaRealTimeAnalysicComsitListBy"
            resultType="cn.cecep.talroad.vo.analysis.SRaRealTimeAnalysicComsitMonitorVo">
        select
        cm.data_id,
        po.id as monitorId,po.monitoring_point_name as monitoringPointName,
        pf.factory_name,pf.industry_permission_name as industryCategoryName
        ,pot.manage_facilities_name as manageFacilitiesName,pot.production_facilities_name as productionFacilitiesName,pot.outlet_name as outletName
        from s_ra_real_time_analysic_comsit as comsit inner  join s_ra_real_time_analysic_comsit_monitor as cm on comsit.data_id=cm.comsit_id
        left join pc_outlet as po on po.id=cm.monitor_id
        left join pc_factory as pf on po.factory_id=pf.id
        left join pc_outlet as pot on po.parent_outlet_id=pot.id
        <where>
            comsit.data_id=#{sRaRealTimeAnalysicComsit.comsitId}
            <if test="sRaRealTimeAnalysicComsit.monitoringPointName != null  and sRaRealTimeAnalysicComsit.monitoringPointName != ''"> and po.monitoring_point_name like concat('%', #{sRaRealTimeAnalysicComsit.monitoringPointName}, '%') </if>
            <if test="sRaRealTimeAnalysicComsit.factoryName != null  and sRaRealTimeAnalysicComsit.factoryName != ''"> and pf.factory_name like concat('%', #{sRaRealTimeAnalysicComsit.factoryName}, '%') </if>
        </where>
        order by pf.factory_name,po.monitoring_point_name
    </select>

    <select id="selectSRaRealTimeAnalysicComsitListBys"
            resultType="cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysicComsit">
        select
            comsit.data_id,comsit.sectionalization_name,comsit.param_name,count(cm.data_id) station_num
        from s_ra_real_time_analysic_comsit as comsit left  join s_ra_real_time_analysic_comsit_monitor as cm on comsit.data_id=cm.comsit_id
        <where>
            <if test="comsitQuery.sectionalizationName != null  and comsitQuery.sectionalizationName != ''"> and comsit.sectionalization_name like concat('%', #{comsitQuery.sectionalizationName}, '%') </if>
            <if test="comsitQuery.paramName != null  and comsitQuery.paramName != ''"> and comsit.param_name =  #{comsitQuery.paramName} </if>
        </where>
        GROUP BY comsit.data_id,comsit.sectionalization_name,comsit.param_name
        order by comsit.data_id,comsit.sectionalization_name,comsit.param_name
    </select>

    <select id="abnormalList" resultType="cn.cecep.talroad.vo.analysis.SRaRealTimeAnalysicComsitMonitorVo">
        select
        po.monitoring_point_name as monitoringPointName,pro.analysis_time as analysisTime,
        pf.factory_name,pf.industry_permission_name as industryCategoryName
        ,pro.param_name as parameterName,pro.exception_eclaration
        from s_ra_real_time_analysic_comsit as comsit inner  join s_ra_real_time_analysic_comsit_monitor as cm on comsit.data_id=cm.comsit_id
        inner join s_ra_real_time_analysic_comsit_pro as pro on pro.station_id=cm.monitor_id
        left join pc_outlet as po on po.id=pro.station_id
        left join pc_factory as pf on po.factory_id=pf.id
        left join pc_outlet as pot on po.parent_outlet_id=pot.id
        <where>
            comsit.data_id=#{sRaRealTimeAnalysicComsit.comsitId}
            <if test="sRaRealTimeAnalysicComsit.monitoringPointName != null  and sRaRealTimeAnalysicComsit.monitoringPointName != ''"> and po.monitoring_point_name like concat('%', #{sRaRealTimeAnalysicComsit.monitoringPointName}, '%') </if>
            <if test="sRaRealTimeAnalysicComsit.factoryName != null  and sRaRealTimeAnalysicComsit.factoryName != ''"> and pf.factory_name like concat('%', #{sRaRealTimeAnalysicComsit.factoryName}, '%') </if>
            <if test="sRaRealTimeAnalysicComsit.analysisTime != null  and sRaRealTimeAnalysicComsit.analysisTime != ''"> and pro.analysis_time like concat('%', #{sRaRealTimeAnalysicComsit.analysisTime}, '%') </if>
        </where>
        order by pf.factory_name,po.monitoring_point_name
    </select>

    <select id="abnormalEcharts" resultType="cn.cecep.talroad.domain.SRaRealTimeAnalysicComsitSt">
        select
        po.monitoring_point_name as paramName,st.min_value,st.max_value,st.q1_value,st.q2_value,st.acg_value
        from s_ra_real_time_analysic_comsit as comsit inner  join s_ra_real_time_analysic_comsit_monitor as cm on comsit.data_id=cm.comsit_id
        inner join s_ra_real_time_analysic_comsit_st as st on st.station_id=cm.monitor_id
        left join pc_outlet as po on po.id=st.station_id
        left join pc_factory as pf on po.factory_id=pf.id
        left join pc_outlet as pot on po.parent_outlet_id=pot.id
        <where>
            comsit.data_id=#{sRaRealTimeAnalysicComsit.comsitId}
            <if test="sRaRealTimeAnalysicComsit.monitoringPointName != null  and sRaRealTimeAnalysicComsit.monitoringPointName != ''"> and po.monitoring_point_name like concat('%', #{sRaRealTimeAnalysicComsit.monitoringPointName}, '%') </if>
            <if test="sRaRealTimeAnalysicComsit.factoryName != null  and sRaRealTimeAnalysicComsit.factoryName != ''"> and pf.factory_name like concat('%', #{sRaRealTimeAnalysicComsit.factoryName}, '%') </if>
            <if test="sRaRealTimeAnalysicComsit.analysisTime != null  and sRaRealTimeAnalysicComsit.analysisTime != ''"> and st.analysis_time like concat('%', #{sRaRealTimeAnalysicComsit.analysisTime}, '%') </if>
        </where>
        order by pf.factory_name,po.monitoring_point_name
    </select>

    <select id="editListDropdown" resultType="java.util.Map">
        select
        po.id as value,po.monitoring_point_name as label
        from s_ra_real_time_analysic_comsit as comsit inner  join s_ra_real_time_analysic_comsit_monitor as cm on comsit.data_id=cm.comsit_id
        left join pc_outlet as po on po.id=cm.monitor_id
        left join pc_factory as pf on po.factory_id=pf.id
        left join pc_outlet as pot on po.parent_outlet_id=pot.id
        <where>
            comsit.data_id=#{sRaRealTimeAnalysicComsit.comsitId}
            <if test="sRaRealTimeAnalysicComsit.monitoringPointName != null  and sRaRealTimeAnalysicComsit.monitoringPointName != ''"> and po.monitoring_point_name like concat('%', #{sRaRealTimeAnalysicComsit.monitoringPointName}, '%') </if>
            <if test="sRaRealTimeAnalysicComsit.factoryName != null  and sRaRealTimeAnalysicComsit.factoryName != ''"> and pf.factory_name like concat('%', #{sRaRealTimeAnalysicComsit.factoryName}, '%') </if>
        </where>
        order by pf.factory_name,po.monitoring_point_name
    </select>
</mapper>
