<?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.securitycontrol.screen.mapper.OperatingMapper">

    <!--作业环境-实时监测-->
    <select id="getRealTimeMonitoring" resultType="com.securitycontrol.entity.screen.vo.OperatingQualityVo">
        SELECT
            tdd.mode_name as dataType,
            tdv.val as val,  tdv.unit,
            tdv.is_warn as isWarn
            FROM tb_device_detail tdd
            LEFT JOIN tb_device_value tdv ON tdd.id = tdv.attribute_id
            LEFT JOIN tb_bd_device tbd ON tdd.device_id = tbd.device_id
            LEFT JOIN tb_pro_bd tpb ON tbd.bd_id = tpb.id
        WHERE tpb.bid_code = #{bidCode}  and  tbd.device_code='1902001'
    </select>

    <!--作业环境-有限空间监测-->
    <select id="getFiniteSpace" resultType="com.securitycontrol.entity.screen.vo.OperatingQualityVo">
        SELECT
            tbd.device_id AS deviceId,
            tbd.device_name AS deviceName,
            tbd.status AS status
        FROM
            tb_bd_device tbd
        LEFT JOIN  tb_pro_bd tpb ON tpb.id = tbd.bd_id
        WHERE  tbd.devic_type = 1909  and  tpb.bid_code = #{bidCode}
    </select>

    <!--作业环境-边坡位移监测设备-->
    <select id="getSlopeDisplacement" resultType="com.securitycontrol.entity.screen.vo.OperatingQualityVo">
        SELECT
        tbd.device_id deviceId,
        ta.area_name AS areaName,
        tdd.mode_name modeName,
        tbd.device_name AS deviceName,
        thdv.val AS val,
        thdv.change_val AS changeVal,
        thdv.create_time AS createTime,
        thdv.unit,
        thdv.is_warn AS isWarn
        FROM tb_bd_device tbd
        LEFT JOIN tb_device_detail tdd  ON tbd.device_id = tdd.device_id
        LEFT JOIN tb_area ta ON tbd.area_id = ta.area_id
        LEFT JOIN tb_device_value thdv ON tdd.id = thdv.attribute_id
        LEFT JOIN tb_pro_bd tpb ON tbd.bd_id = tpb.id
        WHERE    tbd.devic_type = 1908  and  tpb.bid_code = #{bidCode}
            <if test="deviceId!=null and deviceId!=''">
               and   tbd.device_id=#{deviceId}
            </if>

    </select>

    <!--作业环境-GPS安装检测-->
    <select id="getGisInstallation" resultType="com.securitycontrol.entity.screen.vo.OperatingQualityVo">
        SELECT
            tbd.device_id AS id,
            tbd.device_name AS deviceName,
            tbd.status AS status
        FROM
            tb_bd_device tbd
                LEFT JOIN
            tb_pro_bd tpb ON  tpb.id = tbd.bd_id
        WHERE
            tbd.devic_type = 1910 and tpb.bid_code = #{bidCode}

    </select>

    <!--作业环境-有限空间检测环境-->
    <select id="getFiniteSpaceEnvironment"
            resultType="com.securitycontrol.entity.screen.vo.OperatingQualityVo">
        SELECT
        tdv.val  val,
        tdv.unit,
        tdd.mode_name AS modeName
        FROM tb_device_detail tdd
        LEFT JOIN tb_device_value tdv ON tdd.id = tdv.attribute_id
        LEFT JOIN tb_bd_device tbd on tdd.device_id = tbd.device_id
        LEFT JOIN tb_pro_bd tpb on tbd.bd_id = tpb.id
        WHERE  tbd.devic_type =1909
        and  tpb.bid_code = #{bidCode}
    </select>

    <!--作业环境-GPS安装检测设备查询-->
    <select id="getGisInstallationEnvironment"
            resultType="com.securitycontrol.entity.screen.vo.OperatingQualityVo">
        SELECT
             tdv.val  val,
            tdv.unit,
            tdd.mode_name AS modeName
            FROM tb_device_detail tdd
            LEFT JOIN tb_device_value tdv ON tdd.id = tdv.attribute_id
            LEFT JOIN tb_bd_device tbd on tdd.device_id = tbd.device_id
            LEFT JOIN tb_pro_bd tpb on tbd.bd_id = tpb.id
            WHERE  tbd.devic_type =1910
        and  tpb.bid_code = #{bidCode}
    </select>

    <!--作业环境-边坡位移监测列表-->
    <select id="getSlopeDisplacementList"
            resultType="com.securitycontrol.entity.screen.vo.ConstructionQualityVo">
        SELECT
        ta.area_name AS areaName,
        tbd.device_name AS deviceName,
        concat(thdv.val,'(',thdv.unit,')') val,
        thdv.change_val AS changeVal,
        thdv.create_time AS createTime,
        tdd.mode_name moduleName,
        thdv.is_warn AS isWarn,
        thdv.unit
        FROM tb_bd_device tbd
        LEFT JOIN tb_device_detail tdd ON tbd.device_id = tdd.device_id
        LEFT JOIN tb_area ta ON tbd.area_id = ta.area_id
        LEFT JOIN tb_device_value thdv ON tdd.id = thdv.attribute_id
        LEFT JOIN tb_pro_bd tpb ON tbd.bd_id = tpb.id
        WHERE tpb.bid_code = #{bidCode}   and   tbd.devic_type = 1908
        <if test="deviceId != null and deviceId != ''">
            AND tbd.device_id LIKE CONCAT('%', #{deviceId}, '%')
        </if>
    </select>
</mapper>