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

    <resultMap type="cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisCoal" id="SRaRealTimeAnalysisCoalResult">
        <result property="dataId"    column="data_id"    />
        <result property="factoryId"    column="factory_id"    />
        <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"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceId"    column="device_id"    />
        <result property="coalNumber"    column="coal_number"    />
        <result property="cokeNumber"    column="coke_number"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="analyseTime"    column="analyse_time"    />
    </resultMap>


    <sql id="selectSRaRealTimeAnalysisCoalVo">
        select data_id, factory_id, factory_name, industry_category_name, industry_category_code, district_name, district_code, device_name, device_id, coal_number, coke_number, update_time, create_time, analyse_time from s_ra_real_time_analysis_coal
    </sql>

    <select id="selectSRaRealTimeAnalysisCoalList" resultMap="SRaRealTimeAnalysisCoalResult">
        <include refid="selectSRaRealTimeAnalysisCoalVo"/>
        <where>
            <if test="sRaRealTimeAnalysisCoal.factoryName != null  and sRaRealTimeAnalysisCoal.factoryName != ''"> and factory_name like concat('%', #{sRaRealTimeAnalysisCoal.factoryName}, '%')</if>
            <if test="sRaRealTimeAnalysisCoal.industryCategoryCode != null  and sRaRealTimeAnalysisCoal.industryCategoryCode != ''"> and industry_category_code = #{sRaRealTimeAnalysisCoal.industryCategoryCode}</if>
            <if test="sRaRealTimeAnalysisCoal.districtCode != null  and sRaRealTimeAnalysisCoal.districtCode != ''"> and district_code = #{sRaRealTimeAnalysisCoal.districtCode}</if>
            <if test="sRaRealTimeAnalysisCoal.deviceName != null  and sRaRealTimeAnalysisCoal.deviceName != ''"> and device_name like concat('%', #{sRaRealTimeAnalysisCoal.deviceName}, '%')</if>
            <if test="sRaRealTimeAnalysisCoal.deviceId != null  and sRaRealTimeAnalysisCoal.deviceId != ''"> and device_name = #{sRaRealTimeAnalysisCoal.deviceId}</if>
            <if test="sRaRealTimeAnalysisCoal.analyseStartTime != null  and sRaRealTimeAnalysisCoal.analyseStartTime != ''"> and analyse_time >=  CAST(concat(#{sRaRealTimeAnalysisCoal.analyseStartTime}, ':00:00') AS timestamp)</if>
            <if test="sRaRealTimeAnalysisCoal.analyseEndTime != null  and sRaRealTimeAnalysisCoal.analyseEndTime != ''"> and analyse_time &lt;= CAST(concat(#{sRaRealTimeAnalysisCoal.analyseEndTime}, ':59:59') AS timestamp)</if>
            <if test="sRaRealTimeAnalysisCoal.regionCodes != null and sRaRealTimeAnalysisCoal.regionCodes.size() != 0">
                and district_code IN
                <foreach collection="sRaRealTimeAnalysisCoal.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        order by analyse_time desc
    </select>

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

    <select id="statisticsList" resultMap="SRaRealTimeAnalysisCoalResult">
        select sum(coke_number) coke_number ,sum(coal_number) coal_number ,factory_name,industry_category_name,district_name from s_ra_real_time_analysis_coal
        <where>
            <if test="sRaRealTimeAnalysisCoal.factoryName != null  and sRaRealTimeAnalysisCoal.factoryName != ''"> and factory_name like concat('%', #{sRaRealTimeAnalysisCoal.factoryName}, '%')</if>
            <if test="sRaRealTimeAnalysisCoal.industryCategoryCode != null  and sRaRealTimeAnalysisCoal.industryCategoryCode != ''"> and industry_category_code = #{sRaRealTimeAnalysisCoal.industryCategoryCode}</if>
            <if test="sRaRealTimeAnalysisCoal.districtCode != null  and sRaRealTimeAnalysisCoal.districtCode != ''"> and district_code = #{sRaRealTimeAnalysisCoal.districtCode}</if>
            <if test="sRaRealTimeAnalysisCoal.deviceName != null  and sRaRealTimeAnalysisCoal.deviceName != ''"> and device_name like concat('%', #{sRaRealTimeAnalysisCoal.deviceName}, '%')</if>
            <if test="sRaRealTimeAnalysisCoal.deviceId != null  and sRaRealTimeAnalysisCoal.deviceId != ''"> and device_id = #{sRaRealTimeAnalysisCoal.deviceId}</if>
            <if test="sRaRealTimeAnalysisCoal.analyseStartTime != null  and sRaRealTimeAnalysisCoal.analyseStartTime != ''"> and analyse_time >=  CAST(concat(#{sRaRealTimeAnalysisCoal.analyseStartTime}, ':00:00') AS timestamp)</if>
            <if test="sRaRealTimeAnalysisCoal.analyseEndTime != null  and sRaRealTimeAnalysisCoal.analyseEndTime != ''"> and analyse_time &lt;= CAST(concat(#{sRaRealTimeAnalysisCoal.analyseEndTime}, ':59:59') AS timestamp)</if>
            <if test="sRaRealTimeAnalysisCoal.regionCodes != null and sRaRealTimeAnalysisCoal.regionCodes.size() != 0">
                and district_code IN
                <foreach collection="sRaRealTimeAnalysisCoal.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        group by factory_name,industry_category_name,district_name
        order by factory_name
    </select>
    <select id="statisticsListByDevice" resultMap="SRaRealTimeAnalysisCoalResult">
        select sum(coke_number) coke_number ,sum(coal_number) coal_number ,factory_name,industry_category_name,district_name,device_name from s_ra_real_time_analysis_coal
        <where>
            <if test="sRaRealTimeAnalysisCoal.factoryName != null  and sRaRealTimeAnalysisCoal.factoryName != ''"> and factory_name like concat('%', #{sRaRealTimeAnalysisCoal.factoryName}, '%')</if>
            <if test="sRaRealTimeAnalysisCoal.industryCategoryCode != null  and sRaRealTimeAnalysisCoal.industryCategoryCode != ''"> and industry_category_code = #{sRaRealTimeAnalysisCoal.industryCategoryCode}</if>
            <if test="sRaRealTimeAnalysisCoal.districtCode != null  and sRaRealTimeAnalysisCoal.districtCode != ''"> and district_code = #{sRaRealTimeAnalysisCoal.districtCode}</if>
            <if test="sRaRealTimeAnalysisCoal.deviceName != null  and sRaRealTimeAnalysisCoal.deviceName != ''"> and device_name like concat('%', #{sRaRealTimeAnalysisCoal.deviceName}, '%')</if>
            <if test="sRaRealTimeAnalysisCoal.deviceId != null  and sRaRealTimeAnalysisCoal.deviceId != ''"> and device_id = #{sRaRealTimeAnalysisCoal.deviceId}</if>
            <if test="sRaRealTimeAnalysisCoal.analyseStartTime != null  and sRaRealTimeAnalysisCoal.analyseStartTime != ''"> and analyse_time >=  CAST(concat(#{sRaRealTimeAnalysisCoal.analyseStartTime}, ':00:00') AS timestamp)</if>
            <if test="sRaRealTimeAnalysisCoal.analyseEndTime != null  and sRaRealTimeAnalysisCoal.analyseEndTime != ''"> and analyse_time &lt;= CAST(concat(#{sRaRealTimeAnalysisCoal.analyseEndTime}, ':59:59') AS timestamp)</if>
            <if test="sRaRealTimeAnalysisCoal.regionCodes != null and sRaRealTimeAnalysisCoal.regionCodes.size() != 0">
                and district_code IN
                <foreach collection="sRaRealTimeAnalysisCoal.regionCodes" separator="," item="item" close=")" open="(">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </if>
        </where>
        group by factory_name,industry_category_name,district_name,device_name
        order by device_name
    </select>

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