<?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.basedata.mapper.AlarmThresholdMapper">

    <select id="getThresholdInterval" resultType="java.util.Map">

        SELECT
            device_id,
            MAX(CASE WHEN (alarm_level = '1' AND decide_rule ='6') THEN base_line_value ELSE NULL END) AS commonLower,
            MAX(CASE WHEN (alarm_level = '1' AND decide_rule ='7') THEN base_line_value ELSE NULL END) AS commonUpper,
            MAX(CASE WHEN (alarm_level = '2' AND decide_rule ='6') THEN base_line_value ELSE NULL END) AS seriousLower,
            MAX(CASE WHEN (alarm_level = '2' AND decide_rule ='7') THEN base_line_value ELSE NULL END) AS seriousUpper,
            MAX(CASE WHEN (alarm_level = '3' AND decide_rule ='6') THEN base_line_value ELSE NULL END) AS dangerLower,
            MAX(CASE WHEN (alarm_level = '3' AND decide_rule ='7') THEN base_line_value ELSE NULL END) AS dangerUpper
        FROM
            iis_alarm_threshold
        WHERE device_id = #{deviceId}
    </select>
</mapper>
