<?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="com.yfd.platform.modules.auxcontrol.mapper.DeviceWorkDataMapper">

    <select id="getDeviceWorkDataPage" resultType="com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData">
        SELECT
        station_id,
        device_id,
        systemcode,
        device_name,
        signal_id,
        signal_name,
        `value`,
        unit,
        start_time
        FROM
        fk_device_work_data
        WHERE 1=1
        <if test="signalId != null and signalId != ''">
            AND signal_id=#{signalId}
        </if>

        <if test="startDate != null and startDate != ''">
            AND start_time &gt;= #{startDate}
        </if>
        <if test="endDate != null and endDate != ''">
            AND start_time &lt;= #{endDate}
        </if>
        ORDER BY start_time DESC

    </select>
    <select id="getHistoricalCurve" resultType="com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData">
        SELECT
        start_time,
        `value`,
        unit
        FROM
        fk_device_work_data
        WHERE
        signal_id=#{signalId}
        AND start_time >= NOW() - INTERVAL 1 HOUR
        ORDER BY
        start_time DESC
    </select>
<!--    <select id="getDeviceWorkData" resultType="java.util.Map">-->
<!--        SELECT-->
<!--        ds.signal_id,-->
<!--        ds.signal_code itemcode,-->
<!--        ds.signal_name dictname,-->
<!--        COALESCE ( ds.yc_value, '无' ) AS value,-->
<!--        ds.signal_unit unit-->
<!--        FROM-->
<!--        fk_device_signal ds-->
<!--        INNER JOIN iis_substation_component sc ON ds.main_component_id = sc.component_id-->
<!--        INNER JOIN iis_substation ss ON ss.station_code = sc.station_code-->
<!--        WHERE-->
<!--        sc.component_name = '微气象设备部件'-->
<!--        <if test="stationId != null and stationId != ''">-->
<!--            AND ss.station_id=#{stationId}-->
<!--        </if>-->
<!--        ORDER BY orderno-->
<!--    </select>-->

    <select id="getDeviceWorkData" resultType="java.util.Map">
        SELECT
            di.itemcode,
            di.dictname,
            a.signal_id,
            COALESCE ( a.yc_value, '无' )
        VALUE
            ,
            a.unit
        FROM
            sys_dictionary_items di
            LEFT JOIN (
            SELECT
                ds.signal_id,
                ds.signal_code itemcode,
                ds.signal_name dictname,
                ds.yc_value,
                ds.signal_unit unit
            FROM
                fk_device_signal ds
                INNER JOIN iis_substation_component sc ON ds.main_component_id = sc.component_id
                INNER JOIN iis_substation ss ON ss.station_code = sc.station_code
            WHERE
                sc.component_name = '微气象设备部件'
        <if test="stationId != null and stationId != ''">
            AND ss.station_id=#{stationId}
        </if>
            ) a ON di.itemcode = a.itemcode
        WHERE
            di.parentcode = 'environment'
        ORDER BY
            di.custom3
    </select>
    <select id="getHistoricalCurveList" resultType="com.yfd.platform.modules.auxcontrol.domain.DeviceWorkData">
        SELECT
        start_time,
        `value`,
        unit,
        signal_id
        FROM
        fk_device_work_data
        WHERE
        1=1 and signal_id  IN
        <foreach collection="signalIdList" item="signalId" open="(" separator=","
                 close=")">
            #{signalId}
        </foreach>
        AND start_time >= NOW() - INTERVAL 1 HOUR
        ORDER BY
        start_time DESC
    </select>
</mapper>
