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

    <resultMap type="cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisFurnace" id="SRaRealTimeAnalysisFurnaceResult">
        <result property="dataId"    column="data_id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="factoryName"    column="factory_name"    />
        <result property="districtName"    column="district_name"    />
        <result property="districtCode"    column="district_code"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceId"    column="device_id"    />
        <result property="tapNumber"    column="tap_number"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="analyseTime"    column="analyse_time"    />
    </resultMap>


    <sql id="selectSRaRealTimeAnalysisFurnaceVo">
        select data_id, factory_id, factory_name, district_name, district_code, device_name, device_id, tap_number, update_time, create_time, analyse_time from s_ra_real_time_analysis_furnace
    </sql>

    <select id="selectSRaRealTimeAnalysisFurnaceList" parameterType="cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisFurnace" resultMap="SRaRealTimeAnalysisFurnaceResult">
        <include refid="selectSRaRealTimeAnalysisFurnaceVo"/>
        <where>
            <if test="sRaRealTimeAnalysisCo.factoryName != null  and sRaRealTimeAnalysisCo.factoryName != ''"> and factory_name like concat('%', #{sRaRealTimeAnalysisCo.factoryName}, '%')</if>
            <if test="sRaRealTimeAnalysisCo.districtCode != null  and sRaRealTimeAnalysisCo.districtCode != ''"> and district_code = #{sRaRealTimeAnalysisCo.districtCode}</if>
            <if test="sRaRealTimeAnalysisCo.deviceId != null  and sRaRealTimeAnalysisCo.deviceId != ''"> and device_id = #{sRaRealTimeAnalysisCo.deviceId}</if>
            <if test="sRaRealTimeAnalysisCo.deviceName != null  and sRaRealTimeAnalysisCo.deviceName != ''"> and device_name = #{sRaRealTimeAnalysisCo.deviceName}</if>
            <if test="sRaRealTimeAnalysisCo.analyseStartTime != null  and sRaRealTimeAnalysisCo.analyseStartTime != ''"> and analyse_time >=CAST(#{sRaRealTimeAnalysisCo.analyseStartTime} AS timestamp) </if>
            <if test="sRaRealTimeAnalysisCo.analyseEndTime != null  and sRaRealTimeAnalysisCo.analyseEndTime != ''"> and analyse_time &lt;=CAST(#{sRaRealTimeAnalysisCo.analyseEndTime} AS timestamp) </if>
            <if test="sRaRealTimeAnalysisCo.regionCodes != null and sRaRealTimeAnalysisCo.regionCodes.size() != 0">
                and district_code IN
                <foreach collection="sRaRealTimeAnalysisCo.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
       order by analyse_time desc ,factory_name asc, device_name asc
    </select>

    <select id="statisticsList" resultMap="SRaRealTimeAnalysisFurnaceResult">
        select sum(tap_number) tap_number ,factory_name,district_name from s_ra_real_time_analysis_furnace
        <where>
            <if test="sRaRealTimeAnalysisCo.factoryName != null  and sRaRealTimeAnalysisCo.factoryName != ''"> and factory_name like concat('%', #{sRaRealTimeAnalysisCo.factoryName}, '%')</if>
            <if test="sRaRealTimeAnalysisCo.districtCode != null  and sRaRealTimeAnalysisCo.districtCode != ''"> and district_code = #{sRaRealTimeAnalysisCo.districtCode}</if>
            <if test="sRaRealTimeAnalysisCo.deviceId != null  and sRaRealTimeAnalysisCo.deviceId != ''"> and device_id = #{sRaRealTimeAnalysisCo.deviceId}</if>
            <if test="sRaRealTimeAnalysisCo.deviceName != null  and sRaRealTimeAnalysisCo.deviceName != ''"> and device_name = #{sRaRealTimeAnalysisCo.deviceName}</if>
            <if test="sRaRealTimeAnalysisCo.analyseStartTime != null  and sRaRealTimeAnalysisCo.analyseStartTime != ''"> and analyse_time >=CAST(#{sRaRealTimeAnalysisCo.analyseStartTime} AS timestamp) </if>
            <if test="sRaRealTimeAnalysisCo.analyseEndTime != null  and sRaRealTimeAnalysisCo.analyseEndTime != ''"> and analyse_time &lt;=CAST(#{sRaRealTimeAnalysisCo.analyseEndTime} AS timestamp) </if>
            <if test="sRaRealTimeAnalysisCo.regionCodes != null and sRaRealTimeAnalysisCo.regionCodes.size() != 0">
                and district_code IN
                <foreach collection="sRaRealTimeAnalysisCo.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        group by factory_name,district_name
        order by factory_name
    </select>

    <select id="resultCurve" resultMap="SRaRealTimeAnalysisFurnaceResult">
        select sum(tap_number) tap_number ,analyse_time from s_ra_real_time_analysis_furnace
        <where>
            <if test="sRaRealTimeAnalysisCo.factoryName != null  and sRaRealTimeAnalysisCo.factoryName != ''"> and factory_name like concat('%', #{sRaRealTimeAnalysisCo.factoryName}, '%')</if>
            <if test="sRaRealTimeAnalysisCo.districtCode != null  and sRaRealTimeAnalysisCo.districtCode != ''"> and district_code = #{sRaRealTimeAnalysisCo.districtCode}</if>
            <if test="sRaRealTimeAnalysisCo.deviceId != null  and sRaRealTimeAnalysisCo.deviceId != ''"> and device_id = #{sRaRealTimeAnalysisCo.deviceId}</if>
            <if test="sRaRealTimeAnalysisCo.deviceName != null  and sRaRealTimeAnalysisCo.deviceName != ''"> and device_name = #{sRaRealTimeAnalysisCo.deviceName}</if>
            <if test="sRaRealTimeAnalysisCo.analyseStartTime != null  and sRaRealTimeAnalysisCo.analyseStartTime != ''"> and analyse_time >=CAST(#{sRaRealTimeAnalysisCo.analyseStartTime} AS timestamp) </if>
            <if test="sRaRealTimeAnalysisCo.analyseEndTime != null  and sRaRealTimeAnalysisCo.analyseEndTime != ''"> and analyse_time &lt;=CAST(#{sRaRealTimeAnalysisCo.analyseEndTime} AS timestamp) </if>
            <if test="sRaRealTimeAnalysisCo.regionCodes != null and sRaRealTimeAnalysisCo.regionCodes.size() != 0">
                and district_code IN
                <foreach collection="sRaRealTimeAnalysisCo.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        group by analyse_time
        order by analyse_time
    </select>

    <select id="statisticsListByDevice" resultMap="SRaRealTimeAnalysisFurnaceResult">
        select sum(tap_number) tap_number ,factory_name,district_name,device_name from s_ra_real_time_analysis_furnace
        <where>
            <if test="sRaRealTimeAnalysisCo.factoryName != null  and sRaRealTimeAnalysisCo.factoryName != ''"> and factory_name like concat('%', #{sRaRealTimeAnalysisCo.factoryName}, '%')</if>
            <if test="sRaRealTimeAnalysisCo.districtCode != null  and sRaRealTimeAnalysisCo.districtCode != ''"> and district_code = #{sRaRealTimeAnalysisCo.districtCode}</if>
            <if test="sRaRealTimeAnalysisCo.deviceId != null  and sRaRealTimeAnalysisCo.deviceId != ''"> and device_id = #{sRaRealTimeAnalysisCo.deviceId}</if>
            <if test="sRaRealTimeAnalysisCo.deviceName != null  and sRaRealTimeAnalysisCo.deviceName != ''"> and device_name = #{sRaRealTimeAnalysisCo.deviceName}</if>
            <if test="sRaRealTimeAnalysisCo.analyseStartTime != null  and sRaRealTimeAnalysisCo.analyseStartTime != ''"> and analyse_time >=CAST(#{sRaRealTimeAnalysisCo.analyseStartTime} AS timestamp) </if>
            <if test="sRaRealTimeAnalysisCo.analyseEndTime != null  and sRaRealTimeAnalysisCo.analyseEndTime != ''"> and analyse_time &lt;=CAST(#{sRaRealTimeAnalysisCo.analyseEndTime} AS timestamp) </if>
            <if test="sRaRealTimeAnalysisCo.regionCodes != null and sRaRealTimeAnalysisCo.regionCodes.size() != 0">
                and district_code IN
                <foreach collection="sRaRealTimeAnalysisCo.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        group by factory_name,district_name,device_name
        order by factory_name,device_name
    </select>

    <select id="pullDeviceNameOptions" resultType="java.util.Map">
        select
        device_name AS label,
        device_id AS value
        from
        s_ra_real_time_analysis_furnace
        <where>
            <if test="factoryName != null  and factoryName != ''"> and factory_name like concat('%', #{factoryName}, '%')</if>
        </where>
        group by device_id, device_name
    </select>
</mapper>
