<?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.data_type as dataType,
            tdv.val as val,
            tdv.is_warn as isWarn
            FROM tb_device_detail tdd
            JOIN tb_device_value tdv ON tdd.id = tdv.attribute_id
            JOIN tb_bd_device tbd ON tdd.device_id = tbd.device_id
            JOIN tb_pro_bd tpb ON tbd.bd_id = tpb.id
        WHERE tpb.bid_code = #{bidCode}
    </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.bid_code = #{bidCode} AND tpb.id = tbd.bd_id
        WHERE
            tbd.devic_type = 1806
    </select>

    <!--作业环境-边坡位移监测设备-->
    <select id="getSlopeDisplacement" 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.bid_code = #{bidCode} AND tpb.id = tbd.bd_id
        WHERE
            tbd.devic_type = 1806
    </select>

    <!--作业环境-GPS安装检测-->
    <select id="getGPSInstallation" 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.bid_code = #{bidCode} AND tpb.id = tbd.bd_id
        WHERE
            tbd.devic_type = 1806
    </select>

    <!--作业环境-有限空间检测环境-->
    <select id="getFiniteSpaceEnvironment"
            resultType="com.securitycontrol.entity.screen.vo.OperatingQualityVo">
        SELECT
            tdv.val AS val,
            tdd.mode_name AS modeName
        FROM tb_device_detail tdd
            JOIN tb_device_value tdv ON tdd.id = tdv.attribute_id
            join tb_bd_device tbd on tdd.device_id = tbd.device_id
            join tb_pro_bd tpb on tbd.bd_id = tpb.id
        WHERE tdd.device_id = #{deviceId}
            AND tpb.bid_code = #{bidCode}
            AND tdd.mode_name IN ('温度', '湿度', '毒气浓度');
    </select>

    <!--作业环境-GPS安装检测设备查询-->
    <select id="getGPSInstallationEnvironment"
            resultType="com.securitycontrol.entity.screen.vo.OperatingQualityVo">
        SELECT
            tdv.val AS val,
            tdd.mode_name AS modeName
        FROM tb_device_detail tdd
                 JOIN tb_device_value tdv ON tdd.id = tdv.attribute_id
                 join tb_bd_device tbd on tdd.device_id = tbd.device_id
                 join tb_pro_bd tpb on tbd.bd_id = tpb.id
        WHERE tdd.device_id = #{deviceId}
          AND tpb.bid_code = #{bidCode}
          AND tdd.mode_name IN ('温度', '湿度', '粉尘度');
    </select>
    <select id="getSlopeDisplacementList"
            resultType="com.securitycontrol.entity.screen.vo.ConstructionQualityVo">
        SELECT
            ta.area_name AS areaName,
            tbd.device_name AS deviceName,
            thdv.val AS val,
            thdv.change_val AS changeVal,
            thdv.create_time AS createTime,
            thdv.source_data AS sourceData,
            thdv.is_warn AS isWarn
            FROM tb_bd_device tbd
            JOIN tb_device_detail tdd ON tbd.device_id = tdd.device_id
            JOIN tb_area ta ON tbd.area_id = ta.area_id
            JOIN tb_his_device_value thdv ON tdd.id = thdv.attribute_id
            JOIN tb_pro_bd tpb ON tbd.bd_id = tpb.id
        WHERE tpb.bid_code = #{bidCode}
        <if test="deviceId != null and deviceId != ''">
            AND tbd.device_id LIKE CONCAT('%', #{deviceId}, '%')
        </if>
    </select>
</mapper>