<?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.casic.missiles.modular.system.dao.SmartAnalysisMapper">

    <select id="selectAlarmList" resultType="com.casic.missiles.modular.system.dto.AlarmListDto">
        SELECT t.id AS id, w.id AS wellId, w.well_code AS wellCode, w.well_type AS wellType, w.deptid AS deptid, w.position AS position, t.alarm_type AS alarmType, t.alarm_content AS alarmContent, t.alarm_value AS alarmValue, t.alarm_time AS alarmTime, t.status AS status
        FROM bus_well_info w JOIN
        (SELECT a.*
        FROM alarm_records a
        INNER JOIN bus_device b
        ON a.device_id = b.id
        AND b.device_type = ${deviceType}
        AND b.valid='1'
        AND a.status='1') t
        ON t.well_code = w.well_code
        AND w.well_type IN ${wellTypes}
    </select>

    <select id="selectAlarmInfo" resultType="com.casic.missiles.modular.system.dto.SmartAnalysisDto">
        SELECT t.id AS id, w.id AS wellId, w.well_code AS wellCode, w.position AS position, w.COORDINATE_X AS coordinateX, w.COORDINATE_Y AS coordinateY, w.LNG_BAIDU AS lngBaidu, w.LAT_BAIDU  AS latBaidu,w.LNG_GAODE AS lngGaode, w.LAT_GAODE AS latGaode, t.alarm_value AS analysisValue, t.alarm_time AS alarmTime, t.devcode AS devcode
        FROM bus_well_info w
        JOIN alarm_records t
        ON w.id = ${wellId}
        AND t.status='1'
        AND t.well_code = w.well_code
        LIMIT 1
    </select>

    <select id="getThresholdByDevcode" resultType="String">
        select highvalue from alarm_rule where devcode = ${devcode}
    </select>

    <select id="getRealtimeRainfall" resultType="String">
        select realtimedata from data_hyetometer order by logtime desc limit 1
    </select>

</mapper>
