<?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.zehong.system.mapper.PipeInterfaceMapper">
     <!--管道-->
    <resultMap type="PipeDate" id="PipeDateResult">
        <result property="pipeId"    column="pipe_id"    />
        <result property="pipePressure"    column="pipe_pressure"    />
        <result property="pipeDiameter"    column="pipe_diameter"    />
        <result property="pipeMaterial"     column="pipe_material"     />
        <result property="pipeDepth"   column="buried_depth"   />
        <result property="pipeTrend"   column="pipe_trend"   />
        <result property="buildyear"   column="build_date"   />
        <result property="pipeAddr"   column="pipe_addr"   />
        <result property="path"   column="coordinates"   />
        <result property="buildCompany"   column="build_unit"   />
        <result property="powerCompany"   column="beyond_enterprise_name"   />
        <result property="companyType"   column="beyond_enterprise_id"   />
        <result property="pipeLength"   column="pipe_length"   />


        <result property="pipeName"    column="pipe_name"    />
        <result property="detaildAddress"    column="detaild_address"    />
        <result property="indRegAuth"    column="ind_reg_auth"    />
        <result property="indRegAuthPer"    column="ind_reg_auth_per"    />
        <result property="indRegAuthPerCon"    column="ind_reg_auth_per_con"    />
        <result property="keyAreasGasUsage"    column="key_areas_gas_usage"    />
        <result property="affGasCom"    column="aff_gas_com"    />
        <result property="affGasComSecPer"    column="aff_gas_com_sec_per"    />
        <result property="affGasComSecPerCon"    column="aff_gas_com_sec_per_con"    />
        <result property="secCheckTime"    column="sec_check_time"    />
        <result property="unitGasUserRes"    column="unit_gas_user_res"    />
        <result property="unitGasUserResCon"    column="unit_gas_user_res_con"    />
    </resultMap>

    <!--调压箱-->
    <resultMap type="DeviceData" id="DeviceDateResult">
        <result property="deviceId"    column="device_id"    />
        <result property="type"   column="device_type"   />
        <result property="deviceName"   column="device_name"   />
        <result property="deviceCode"   column="device_code"   />
        <result property="deviceAddr"   column="device_addr"   />
        <result property="longitude"   column="longitude"   />
        <result property="latitude"   column="latitude"   />
        <result property="companyType"   column="device_id"   />
        <result property="beyondEnterpriseName"   column="beyond_enterprise_name"   />
        <result property="companyType"   column="beyond_enterprise_id"   />
        <result property="iconUrl"   column="icon_url"   />
    </resultMap>

    <!--下级设备数据-->
    <resultMap type="PressureFlow" id="PressureFlowResult">
        <result property="deviceId"    column="relation_device_id"    />
        <result property="deviceNo"    column="device_model"    />
        <result property="deviceType"   column="device_type"   />
        <result property="reportTime"   column="create_time"   />
        <result property="iotNo"   column="iot_no"   />
    </resultMap>

    <!--场站数据-->
    <resultMap type="TSiteStationInfoData" id="TSiteStationInfoDataResult">
        <result property="siteStationId"    column="site_station_id"    />
        <result property="stationName"    column="site_station_name"    />
        <result property="stationType"    column="site_station_type"    />
        <result property="longitude"   column="longitude"   />
        <result property="latitude"   column="latitude"   />
        <result property="buildyear"   column="create_time"   />
        <result property="buildCompany"   column="build_unit"   />
        <result property="powerCompany"   column="beyond_enterprise_name"   />
        <result property="companyType"   column="beyond_enterprise_id"   />
        <result property="pictureAddress"   column="picture_address"   />
    </resultMap>

    <!--监控数据-->
    <resultMap type="TvideoManagerData" id="TvideoManagerDataResult">
        <result property="companyType"    column="video_manager_id"    />
        <result property="videoManagerId"    column="video_manager_id"    />
        <result property="videoName"    column="video_name"    />
        <result property="resourceId"   column="resource_id"   />
        <result property="longitude"   column="longitude"   />
        <result property="latitude"   column="latitude"   />
        <result property="videoAddress"   column="video_address"   />
        <result property="type"   column="type"   />
        <result property="companyType"   column="beyond_enterprise_id"   />
    </resultMap>

    <!--燃气用户数据-->
    <resultMap type="TdetectorUserData" id="TdetectorUserDataResult">
        <result property="usrName"    column="nick_name"    />
        <result property="usrType"    column="user_type"    />
        <result property="longitude"   column="longitude"   />
        <result property="latitude"   column="latitude"   />
        <result property="phone"   column="phone"   />
        <result property="address"   column="address"   />
    </resultMap>

    <!--查询企业名称id-->
    <resultMap type="TenterpriseInfoData" id="TenterpriseInfoDataResult">
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterprise_name"    />
        <result property="enterpriseType"    column="enterprise_type"    />

    </resultMap>

    <!--感知设备列表-->
    <resultMap type="TAssociatedEquipment" id="TAssociatedEquipmentResult">
        <result property="deviceCode"    column="device_code"    />
        <result property="deviceName"    column="device_name"    />
        <result property="detectionMedium"    column="detection_medium"    />
        <result property="linkman"    column="linkman"    />
        <result property="phone"    column="phone"    />
        <result property="detectorStatus"    column="detector_status"    />
        <result property="createTime"    column="alarm_time"    />
    </resultMap>

    <!--查询管道数据列表-->
    <select id="selectPipeData" parameterType="PipeDate" resultMap="PipeDateResult">
        select format(pipe_length,2)pipe_length,pipe_name,pipe_pressure,beyond_enterprise_id,pipe_id,pipe_diameter,pipe_material,buried_depth,pipe_trend,build_date,pipe_addr,coordinates,remarks,build_unit,beyond_enterprise_name from t_pipe_info
        where is_del='0'
        <if test="enterId != null and enterId != 0">
            and beyond_enterprise_id=#{enterId}
        </if>
    </select>

    <!--查询管道数据列表-->
    <select id="getPipeForSelect" parameterType="PipeDate" resultMap="PipeDateResult">
        select format(pipe_length,2)pipe_length,pipe_pressure,beyond_enterprise_id,pipe_id,pipe_diameter,pipe_material,
               buried_depth,pipe_trend,build_date,pipe_addr,coordinates,remarks,build_unit,beyond_enterprise_name,
               pipe_name,detaild_address,ind_reg_auth,ind_reg_auth_per,ind_reg_auth_per_con,key_areas_gas_usage,
               aff_gas_com,aff_gas_com_sec_per,aff_gas_com_sec_per_con,sec_check_time,unit_gas_user_res,unit_gas_user_res_con from t_pipe_info
        where is_del='0' and pipe_name is not null
        <if test="enterId != null and enterId != 0">
            and beyond_enterprise_id=#{enterId}
        </if>
    </select>

    <select id="getPipeBypipeId" parameterType="PipeDate" resultMap="PipeDateResult">
        select format(pipe_length,2)pipe_length,pipe_pressure,beyond_enterprise_id,pipe_id,pipe_diameter,pipe_material,
               buried_depth,pipe_trend,build_date,pipe_addr,coordinates,remarks,build_unit,beyond_enterprise_name,
               pipe_name,detaild_address,ind_reg_auth,ind_reg_auth_per,ind_reg_auth_per_con,key_areas_gas_usage,
               aff_gas_com,aff_gas_com_sec_per,aff_gas_com_sec_per_con,sec_check_time,unit_gas_user_res,unit_gas_user_res_con from t_pipe_info
        where pipe_id = #{pipeId}
    </select>

    <!--获取分组数据-->
    <select id="selectGroupPipeData" parameterType="PipeDate" resultMap="PipeDateResult">
        select beyond_enterprise_id,pipe_id,pipe_diameter,pipe_material,buried_depth,pipe_trend,build_date,pipe_addr,coordinates,remarks,build_unit,beyond_enterprise_name from t_pipe_info
        where is_del='0'
		group by beyond_enterprise_name
    </select>

    <!--调压箱数据查询方法-->
    <select id="selectDeviceData" resultMap="DeviceDateResult">
       select beyond_enterprise_id,icon_url,device_id,device_type,device_name,device_code,device_addr,longitude,latitude,beyond_enterprise_name from t_device_info
       where device_type='2' and is_del='0'
        <if test="enterId != null and enterId != 0">
            and beyond_enterprise_id=#{enterId}
        </if>
    </select>

    <!--查询下级设备数据-->
    <select id="selectPressureFlow" parameterType="java.util.List" resultMap="PressureFlowResult">
      select device_model,device_type,create_time,relation_device_id,iot_no from t_relation_device_detail_info
      where  relation_device_type='1' and  relation_device_id = #{deviceId}
    </select>

    <!--场站信息查询方法-->
    <select id="selectTSiteStationInfoData" resultMap="TSiteStationInfoDataResult">
       select beyond_enterprise_id,picture_address,site_station_id,site_station_name,site_station_type,longitude,latitude,address,create_time,build_unit,beyond_enterprise_name
       from t_site_station_info where is_del='0'
        <if test="enterId != null and enterId != 0">
            and beyond_enterprise_id=#{enterId}
        </if>
    </select>

    <!--查询场站下级数据-->
    <select id="selecttSiteStationInfoDataList" parameterType="DeviceData" resultMap="PressureFlowResult">
         select device_model,device_type,create_time,relation_device_id from t_relation_device_detail_info
         where  relation_device_type='2' and relation_device_id = #{deviceId}
    </select>

    <!--监控信息查询-->
    <select id="selectTvideoManagerData" resultMap="TvideoManagerDataResult">
        select beyond_enterprise_id,video_manager_id,video_name,resource_id,longitude,latitude,video_address,type from  t_video_manager
        where is_del='0'
    </select>

    <!--燃气用户信息查询接口-->
    <select id="selectTdetectorUser"  resultMap="TdetectorUserDataResult">
        select nick_name,user_type,longitude,latitude,phone,address from t_detector_user
        where is_del='0'
    </select>

    <!--查询企业名称id方法-->
    <select id="selectTenterpriseInfoData" resultMap="TenterpriseInfoDataResult">
        select enterprise_id,enterprise_name,enterprise_type from t_enterprise_info where is_del='0'
    </select>

    <!--查询阀门井数据-->
    <select id="selectvalveData" resultMap="DeviceDateResult">
       select beyond_enterprise_id,device_id,icon_url,device_type,device_name,device_code,device_addr,longitude,latitude,beyond_enterprise_name from t_device_info
       where device_type='1' and is_del='0'
        <if test="enterId != null and enterId != 0">
            and beyond_enterprise_id=#{enterId}
        </if>
    </select>

    <!--查询在线下级设备数量-->
    <select id="selectOnlineQuantity" parameterType="java.util.List" resultType="java.lang.Integer">
       select count(detector_id) as id from t_detector_info
       where is_del ='0' and detector_status=#{isOnLine} and detector_code in
        (
        <foreach collection="pressureList" item="item" index="index" separator=",">
            #{item.iotNo}
        </foreach>
        )
    </select>

    <!--查询历史报警数量-->
    <select id="selectHistoricalAlarm"  parameterType="java.util.List" resultType="java.lang.Integer">
        select count(id) from t_detector_report_data
        where detector_code in
        <foreach collection="list" item="pressureList" open="(" close=")" index="index" separator=",">
            #{pressureList.iotNo}
        </foreach>
    </select>

    <!--查询已处理报警-->
    <select id="selectProcessAlarm" parameterType="java.util.List"  resultType="java.lang.Integer">
         select count(id) from t_detector_report_data
        where is_cancel_alarm !='0'  and detector_code in
        <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
            #{item.iotNo}
        </foreach>
    </select>

    <!--查询报警中-->
    <select id="selectInAlarm" parameterType="java.util.List"  resultType="java.lang.Integer">
        select count(id) from t_detector_report_data
        where is_cancel_alarm ='0'  and detector_code in
        <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
            #{item.iotNo}
        </foreach>
    </select>

    <!--查询 场站/设备 列表信息方法-->
    <select id="selectSensingDevice" resultMap="TAssociatedEquipmentResult">
      select b.iot_no device_code,b.device_name device_name,b.detection_medium,a.linkman,a.phone,c.detector_status,c.alarm_time
      from t_device_info a
      left join t_relation_device_detail_info b on a.device_id=b.relation_device_id
      left join t_detector_info c on b.iot_no=c.detector_code
      where a.device_id=#{devId} and b.relation_device_type=#{relationDeviceType}
    </select>

    <!--查询上级设备是否有下级设备-->
    <select id="selectValveWellIsNUll" resultType="java.lang.Integer">
        select count(relation_device_detail_id) from t_relation_device_detail_info where relation_device_id = #{deviceId} and relation_device_type=#{type}
    </select>

    <!--查询下级全部数据方法-->
    <select id="selectPressureFlows"   resultMap="PressureFlowResult">
      select device_model,device_type,create_time,relation_device_id,iot_no from t_relation_device_detail_info
      where  relation_device_type=#{type}
    </select>

</mapper>
