<?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.huatek.busi.mapper.BusiSiteTreeMapper">

 <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.huatek.busi.entity.BusiSiteTree">
        <id column="id" property="id"/>
        <result column="parent_id" property="parentId"/>
        <result column="name" property="name"/>
        <result column="status" property="status"/>
        <result column="site_id" property="siteId"/>
        <result column="equipment_type" property="equipmentType"/>
        <result column="system_code" property="systemCode"/>
        <result column="create_time" property="createTime"/>

    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, parent_id AS parentId, name AS name,  status AS status, site_id AS siteId,
        equipment_type as  equipmentType,  system_code as systemCode,
        create_time as  createTime
    </sql>

     <select id = "findByEquipmentType" resultMap="BaseResultMap">
      SELECT
       *
      FROM busi_site_tree b
      WHERE  b.parent_id = #{parentId}
      AND b.`status` = '1'
      AND b.equipment_type = #{equipmentType}
    </select>

     <select id = "getChildrens" resultMap="BaseResultMap">
      SELECT
      *
      FROM busi_site_tree b
      WHERE  b.parent_id = #{parentId}
      and b.status = '1'
    </select>

      <select id = "findlist" resultMap="BaseResultMap">
      SELECT
      *
      FROM busi_site_tree b
      WHERE  b.status = '1'

    </select>


     <select id = "findlist2" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
		SELECT
		  b.id,
		  b.name,
		  b.parent_id AS pid,
		  b.equipment_type AS type,
		  b.site_id AS siteId,
		  b.parent_id
		FROM busi_site_tree b,
		     busi_site s
		WHERE b.site_id = s.id
		AND b.status = '1'
		AND s.status = '1'
		ORDER BY b.create_time ASC,
		b.equipment_type ASC, b.name ASC
    </select>

	<select id="findListWithoutGis" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
		SELECT
		b.id,
		b.name,
		b.parent_id AS pid,
		b.equipment_type AS type,
		b.site_id AS siteId,
		b.parent_id
		FROM busi_site_tree b,
		busi_site s
		WHERE b.site_id = s.id
		AND b.status = '1'
		AND s.status = '1'
		AND b.equipment_type != #{eqType}
		ORDER BY b.create_time ASC,
		b.equipment_type ASC, b.name ASC
	</select>

	<select id="geBusiSiteTreeBysystemCode" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List"/>
      FROM busi_site_tree
      WHERE system_code = #{systemCode,jdbcType=VARCHAR}
    </select>

    <!-- 根据站点ID查询站点信息 -->
    <select id="findListBySiteId" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List"/>
      FROM busi_site_tree
      WHERE site_id = #{siteId,jdbcType=VARCHAR} AND status = '1'
    </select>


     <!-- 根据站点ID查询站点信息 -->
    <select id="findByEquipmentTypeAndSiteId" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List"/>
      FROM busi_site_tree
      WHERE site_id = #{siteId,jdbcType=VARCHAR}
       AND equipment_type = #{equipmentType,jdbcType=VARCHAR}
    </select>

    <select id="findMainEquipmentList" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
    	SELECT
		  b.id,
		  b.name,
		  b.parent_id AS pid,
		  b.equipment_type AS type,
		  b.site_id AS siteId,
		  b.parent_id,
          b.system_code as systemCode
		FROM busi_site_tree b,
		     busi_site s
		WHERE b.site_id = s.id
		AND b.status = '1'
		AND s.status = '1'
		<foreach collection="equipmentTypes" item="item" index="index"
			open="AND b.equipment_type in(" separator="," close=")">
			#{item}
		</foreach>
		ORDER BY b.create_time ASC,
		b.equipment_type ASC, b.name ASC
    </select>


	<select id="findGisMainEquipmentList" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
		SELECT
		b.id,
		b.name,
		b.parent_id AS pid,
		b.equipment_type AS type,
		b.site_id AS siteId,
		b.parent_id,
		b.system_code as systemCode
		FROM busi_site_tree b LEFT JOIN busi_offline_gis_brand c ON c.main_equipment_id = b.id,
		busi_site s
		WHERE b.site_id = s.id
		AND b.status = '1'
		AND s.status = '1'
		AND b.equipment_type = #{equipmentTypes}
		AND c.gis_type IN ('01','02')
		ORDER BY b.create_time ASC,
		b.equipment_type ASC, b.name ASC
	</select>

    <select id="findByNameAndNameAndEquType" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
        SELECT
            b.id,
            b.name,
            b.parent_id AS pid,
            b.equipment_type AS type,
            b.site_id AS siteId,
            b.parent_id,
            b.system_code as systemCode
        FROM busi_site_tree b,
            busi_site s
        WHERE b.site_id = s.id
        AND b.status = '1'
        AND s.status = '1'
        and b.equipment_type = #{eqType}
        and b.name = #{name}
        and b.system_code = #{systemCode}
    </select>

    <select id="findByEquType" parameterType="java.lang.String" resultType="com.huatek.busi.entity.BusiSiteTree">
        SELECT
            <include refid="Base_Column_List"/>
        FROM
            busi_site_tree
        WHERE
            equipment_type = #{equType}
        AND `status` = 1
    </select>

    <select id="findByNameAndEquType" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
        SELECT
            b.id,
            b.NAME,
            b.parent_id AS pid,
            b.equipment_type AS type,
            b.site_id AS siteId,
            b.parent_id,
            b.system_code AS systemCode
        FROM
        busi_site_tree b,
        busi_site s
        WHERE
        b.site_id = s.id
        AND b.STATUS = '1'
        AND s.STATUS = '1'
        AND b.equipment_type = #{eqType}
        AND b.NAME = #{equName}
    </select>

    <select id="findByIdAndEquType" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
        SELECT
            b.id,
            b. NAME,
            b.parent_id AS pid,
            b.equipment_type AS type,
            b.site_id AS siteId,
            b.parent_id,
            b.system_code AS systemCode
        FROM
            busi_site_tree A
        INNER JOIN busi_site_tree B ON A.parent_id = B.id
        WHERE
            A.id = #{id}
        AND b.STATUS = '1'
        AND A.STATUS = '1'
        AND b.equipment_type = #{eqType}
    </select>

    <select id="findByParentId" parameterType="java.lang.String" resultType="com.huatek.busi.entity.BusiSiteTree">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        busi_site_tree
        WHERE
        parent_id = #{id}
        AND `status` = 1
    </select>

    <select id="findByParentIds" parameterType="java.lang.String" resultType="com.huatek.busi.entity.BusiSiteTree">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        busi_site_tree
        WHERE
        `status` = 1
        <foreach collection="ids" item="item" index="index"
                 open="and parent_id in(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="findByEquNumAndequNameAndEquType" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
        SELECT
            b.id,
            b.name,
            b.parent_id AS pid,
            b.equipment_type AS type,
            b.site_id AS siteId,
            b.parent_id,
            b.system_code as systemCode
        FROM busi_site_tree b,
            busi_site s
        WHERE b.site_id = s.id
        AND b.status = '1'
        AND s.status = '1'
        and b.equipment_type = #{eqType}
        and b.name = #{equName}
        and b.system_code = #{systemCode}
    </select>
	<select id="getSiteIds" resultType="java.lang.String">
		SELECT t.site_id FROM busi_site_tree t WHERE t.parent_id = '1' AND t.status = '1'
	</select>
    <select id="findAll" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
        SELECT
            b.id,
            b.name,
            b.parent_id AS pid,
            b.equipment_type AS type,
            b.site_id AS siteId,
            b.parent_id,
            b.system_code as systemCode
        FROM busi_site_tree b,
            busi_site s
        WHERE b.site_id = s.id
        AND b.status = '1'
        AND s.status = '1'
        and b.equipment_type in ('1', '2', '3', '4','5','6','7')
        Order by b.equipment_type
    </select>

    <select id="findByEquTypes" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
        SELECT
            b.id,
            b. NAME,
            t.id as equId,
            t.`name` AS equName,
            b.parent_id AS pid,
            b.equipment_type AS type,
            b.site_id AS siteId,
            b.parent_id,
            b.system_code AS systemCode
        FROM
            busi_site_tree b,
            busi_site s,
            busi_site_tree t
        WHERE
            b.site_id = s.id
        AND b.id = t.parent_id
        AND b. STATUS = '1'
        AND s. STATUS = '1'
        AND t. STATUS = '1'
        AND b.equipment_type = #{equType}
        ORDER BY
            t.`name`
    </select>

    <select id="findThirdLevelByEquTypes" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
        SELECT
            b.id,
            b. NAME,
            t.id AS equId,
            t.`name` AS equName,
            st.name AS stName,
            st.id AS stId,
            b.parent_id AS pid,
            b.equipment_type AS type,
            b.site_id AS siteId,
            b.parent_id,
            b.system_code AS systemCode
        FROM
            busi_site_tree b,
            busi_site s,
            busi_site_tree t,
            busi_site_tree st
        WHERE
            b.site_id = s.id
        AND b.id = t.parent_id
        AND t.id = st.parent_id
        AND b. STATUS = '1'
        AND s. STATUS = '1'
        AND t. STATUS = '1'
        AND st. STATUS = '1'
        AND b.equipment_type = #{equType}
        AND t.id = #{equId}
        ORDER BY
            t.`name`
    </select>

    <select id="selectByTransformerBySiteId" resultType="com.huatek.busi.vo.TransformerTmpVo">
		SELECT
			t.id AS transformerId,
			b.transformer_name AS transformerName,
			b.equipment_model AS equipmentModel,
			b.manufacturer AS manufacturer
		FROM
			busi_offline_transformer_brand b
		LEFT JOIN
			busi_site_tree t ON t.id = b.main_equipment_id
		WHERE
			b.site_id = #{siteId};
    </select>

    <!-- 查询系统传感器列表绑定关系 -->
    <select id="selectByTransformerAndBindRelationBySiteId" resultType="com.huatek.busi.vo.TransformerTmpVo">
		SELECT
			t.id AS transformerId,
			b.transformer_name AS transformerName,
			b.equipment_model AS equipmentModel,
			b.manufacturer AS manufacturer,
			(SELECT COUNT(transformer_id) FROM busi_equipment_relationship ber WHERE b.`main_equipment_id` = ber.`transformer_id` and ber.equipment_id = #{equipmentId}) AS bindNumber
		FROM
			busi_offline_transformer_brand b
		LEFT JOIN
			busi_site_tree t ON t.id = b.main_equipment_id
		WHERE
			b.site_id = #{siteId}
			and t.`status` = '1'
    </select>

    <!-- 查询系统传感器列表 -->
    <select id="selectSensorListBySiteId" resultType="com.huatek.busi.vo.SensiorIdExportVo">
		SELECT
		  bs.`site_name` siteName,
		  '变压器设备'  equipmentType,
		  '1' type,
		  st.`name`  equipmentName,
		  ts.equipment_type pendantType,
		  tst.name pendantName,
		  ts.`sensor_name` sensorName,
		  ts.`sensor_code` sensorCode,
		  ts.sensor_brand sensorBrand,
		  ts.manufactor,
		  ts.position_des positionDes,
		  ts.production_date productionDate,
		  ts.use_date useDate
		FROM
		  busi_transformer_sensor ts
		  LEFT JOIN busi_site bs ON ts.`site_id` = bs.`id`
		  LEFT JOIN busi_transformer_sub_tree tst ON tst.`id` = ts.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = tst.`equipment_id`
		WHERE ts.`site_id` =  #{siteId} AND ts.status = '1' AND st.`status` = '1'
		UNION
		SELECT
		  bs.`site_name` siteName,
		  'Gis设备'  equipmentType,
		  '2' type,
		  st.`name`  equipmentName,
		  gs.equipment_type pendantType,
		  gst.name pendantName,
		  gs.`sensor_name` sensorName,
		  gs.`sensor_code` sensorCode,
		  gs.sensor_brand sensorBrand,
		  gs.manufactor,
		  gs.position_des positionDes,
		  gs.production_date productionDate,
		  gs.use_date useDate
		FROM
		  busi_gis_sensor gs
		  LEFT JOIN busi_site bs ON gs.`site_id` = bs.`id`
		  LEFT JOIN busi_gis_sub_tree gst ON gst.`id` = gs.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = gst.`equipment_id`
		WHERE gs.`site_id` =  #{siteId} AND gs.status = '1' AND st.`status` = '1'
		UNION
		SELECT
		  bs.`site_name` siteName,
		  '开关柜设备'  equipmentType,
		  '3' type,
		  st.`name`  equipmentName,
		  ss.equipment_type pendantType,
		  '开关柜测温点' pendantName,
		  ss.`sensor_name` sensorName,
		  ss.`sensor_code` sensorCode,
		  ss.sensor_brand sensorBrand,
		  ss.manufactor,
		  ss.position_des positionDes,
		  ss.production_date productionDate,
		  ss.use_date useDate
		FROM
		  busi_temper_point ss
		  LEFT JOIN busi_site bs ON ss.`site_id` = bs.`id`
		  LEFT JOIN busi_site_tree st ON st.`id` = ss.`equipment_id`
		WHERE ss.`site_id` =  #{siteId} AND ss.status = '1' AND st.`status` = '1'
		UNION
		SELECT
		  bs.`site_name` siteName,
		  '避雷器设备'  equipmentType,
		  '4' type,
		  st.`name`  equipmentName,
		  bas.equipment_type pendantType,
		  ast.name pendantName,
		  bas.`sensor_name` sensorName,
		  bas.`sensor_code` sensorCode,
		  bas.sensor_brand sensorBrand,
		  bas.manufactor,
		  bas.position_des positionDes,
		  bas.production_date productionDate,
		  bas.use_date useDate
		FROM
		  busi_arrester_sensor bas
		  LEFT JOIN busi_site bs ON bas.`site_id` = bs.`id`
		  LEFT JOIN busi_arrester_sub_tree ast ON ast.`id` = bas.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = ast.`equipment_id`
		WHERE bas.`site_id` =  #{siteId} AND bas.status = '1' AND st.`status` = '1'
		UNION
		SELECT
		  bs.`site_name` siteName,
		  '其他设备'  equipmentType,
		  '5' type,
		  st.`name`  equipmentName,
		  os.equipment_type pendantType,
		  ost.name pendantName,
		  os.`sensor_name` sensorName,
		  os.`sensor_code` sensorCode,
		  os.sensor_brand sensorBrand,
		  os.manufactor,
		  os.position_des positionDes,
		  os.production_date productionDate,
		  os.use_date useDate
		FROM
		  busi_other_sensor os
		  LEFT JOIN busi_site bs ON os.`site_id` = bs.`id`
		  LEFT JOIN busi_other_sub_tree ost ON ost.`id` = os.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = ost.`equipment_id`
		WHERE os.`site_id` =  #{siteId} AND os.status = '1' AND st.`status` = '1'
		UNION
		SELECT
		  bs.`site_name` siteName,
		  '发电机设备'  equipmentType,
		  '6' type,
		  st.`name`  equipmentName,
		  gs.equipment_type pendantType,
		  gst.name pendantName,
		  gs.`sensor_name` sensorName,
		  gs.`sensor_code` sensorCode,
		  gs.sensor_brand sensorBrand,
		  gs.manufactor,
		  gs.position_des positionDes,
		  gs.production_date productionDate,
		  gs.use_date useDate
		FROM
		  busi_generator_sensor gs
		  LEFT JOIN busi_site bs ON gs.`site_id` = bs.`id`
		  LEFT JOIN busi_generator_sub_tree gst ON gst.`id` = gs.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = gst.`equipment_id`
		WHERE gs.`site_id` =  #{siteId} AND gs.status = '1' AND st.`status` = '1'
		UNION
		SELECT
		  bs.`site_name` siteName,
		  '电缆设备'  equipmentType,
		  '7' type,
		  st.`name`  equipmentName,
		  cs.equipment_type pendantType,
		  cst.name pendantName,
		  cs.`sensor_name` sensorName,
		  cs.`sensor_code` sensorCode,
		  cs.sensor_brand sensorBrand,
		  cs.manufactor,
		  cs.position_des positionDes,
		  cs.production_date productionDate,
		  cs.use_date useDate
		FROM
		  busi_cable_sensor cs
		  LEFT JOIN busi_site bs ON cs.`site_id` = bs.`id`
		  LEFT JOIN busi_cable_sub_tree cst ON cst.`id` = cs.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = cst.`equipment_id`
		WHERE cs.`site_id` =  #{siteId} AND cs.status = '1' AND st.`status` = '1'
    </select>
	<!-- 查询系统传感器列表 -->
	<select id="findSensorListBySiteId" resultType="com.huatek.busi.vo.SensiorIdExportVo">
		SELECT
		  bs.`site_name` siteName,
		  '变压器设备'  equipmentType,
		  '1' type,
		  st.`name`  equipmentName,
		  ts.equipment_type pendantType,
		  tst.name pendantName,
		  ts.`sensor_name` sensorName,
		  ts.`sensor_code` sensorCode,
		  ts.sensor_brand sensorBrand,
		  ts.manufactor,
		  ts.position_des positionDes,
		  ts.production_date productionDate,
		  ts.use_date useDate,
		  ts.`status`,
		  ts.equipment_id equipmentId,
		  st.id mainEquipmentId
		FROM
		  busi_transformer_sensor ts
		  LEFT JOIN busi_site bs ON ts.`site_id` = bs.`id`
		  LEFT JOIN busi_transformer_sub_tree tst ON tst.`id` = ts.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = tst.`equipment_id`
		WHERE  ts.status = '1'
		AND st.`status` = '1'
		AND  ts.`sensor_code` !='' AND ts.`sensor_code` is not null
		UNION
		SELECT
		  bs.`site_name` siteName,
		  'Gis设备'  equipmentType,
		  '2' type,
		  st.`name`  equipmentName,
		  gs.equipment_type pendantType,
		  gst.name pendantName,
		  gs.`sensor_name` sensorName,
		  gs.`sensor_code` sensorCode,
		  gs.sensor_brand sensorBrand,
		  gs.manufactor,
		  gs.position_des positionDes,
		  gs.production_date productionDate,
		  gs.use_date useDate,
		  gs.`status`,
		  gs.equipment_id equipmentId,
		  st.id mainEquipmentId
		FROM
		  busi_gis_sensor gs
		  LEFT JOIN busi_site bs ON gs.`site_id` = bs.`id`
		  LEFT JOIN busi_gis_sub_tree gst ON gst.`id` = gs.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = gst.`equipment_id`
		WHERE  gs.status = '1' AND st.`status` = '1' AND gs.`sensor_code` !='' AND gs.`sensor_code` is not null
		UNION
		SELECT
		  bs.`site_name` siteName,
		  '开关柜设备'  equipmentType,
		  '3' type,
		  st.`name`  equipmentName,
		  ss.equipment_type pendantType,
		  '开关柜测温点' pendantName,
		  ss.`sensor_name` sensorName,
		  ss.`sensor_code` sensorCode,
		  ss.sensor_brand sensorBrand,
		  ss.manufactor,
		  ss.position_des positionDes,
		  ss.production_date productionDate,
		  ss.use_date useDate,
		  ss.`status`,
		  ss.equipment_id equipmentId,
		  st.id mainEquipmentId
		FROM
		  busi_temper_point ss
		  LEFT JOIN busi_site bs ON ss.`site_id` = bs.`id`
		  LEFT JOIN busi_site_tree st ON st.`id` = ss.`equipment_id`
		WHERE  ss.status = '1' AND st.`status` = '1' AND ss.`sensor_code`!='' AND ss.`sensor_code` is not null
		UNION
		SELECT
		  bs.`site_name` siteName,
		  '避雷器设备'  equipmentType,
		  '4' type,
		  st.`name`  equipmentName,
		  bas.equipment_type pendantType,
		  ast.name pendantName,
		  bas.`sensor_name` sensorName,
		  bas.`sensor_code` sensorCode,
		  bas.sensor_brand sensorBrand,
		  bas.manufactor,
		  bas.position_des positionDes,
		  bas.production_date productionDate,
		  bas.use_date useDate,
		  bas.`status`,
		  bas.equipment_id equipmentId,
		  st.id mainEquipmentId
		FROM
		  busi_arrester_sensor bas
		  LEFT JOIN busi_site bs ON bas.`site_id` = bs.`id`
		  LEFT JOIN busi_arrester_sub_tree ast ON ast.`id` = bas.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = ast.`equipment_id`
		WHERE  bas.status = '1' AND st.`status` = '1' AND bas.`sensor_code` !='' AND bas.`sensor_code` is not null
		UNION
		SELECT
		  bs.`site_name` siteName,
		  '其他设备'  equipmentType,
		  '5' type,
		  st.`name`  equipmentName,
		  os.equipment_type pendantType,
		  ost.name pendantName,
		  os.`sensor_name` sensorName,
		  os.`sensor_code` sensorCode,
		  os.sensor_brand sensorBrand,
		  os.manufactor,
		  os.position_des positionDes,
		  os.production_date productionDate,
		  os.use_date useDate,
		  os.`status`,
		  os.equipment_id equipmentId,
		  st.id mainEquipmentId
		FROM
		  busi_other_sensor os
		  LEFT JOIN busi_site bs ON os.`site_id` = bs.`id`
		  LEFT JOIN busi_other_sub_tree ost ON ost.`id` = os.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = ost.`equipment_id`
		WHERE os.status = '1'  AND st.`status` = '1' AND os.`sensor_code` !='' AND os.`sensor_code` is not null
		UNION
		SELECT
		  bs.`site_name` siteName,
		  '发电机设备'  equipmentType,
		  '6' type,
		  st.`name`  equipmentName,
		  gs.equipment_type pendantType,
		  gst.name pendantName,
		  gs.`sensor_name` sensorName,
		  gs.`sensor_code` sensorCode,
		  gs.sensor_brand sensorBrand,
		  gs.manufactor,
		  gs.position_des positionDes,
		  gs.production_date productionDate,
		  gs.use_date useDate,
		  gs.`status`,
		  gs.equipment_id equipmentId,
		  st.id mainEquipmentId
		FROM
		  busi_generator_sensor gs
		  LEFT JOIN busi_site bs ON gs.`site_id` = bs.`id`
		  LEFT JOIN busi_generator_sub_tree gst ON gst.`id` = gs.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = gst.`equipment_id`
		WHERE gs.status = '1' AND st.`status` = '1' AND gs.`sensor_code` !='' AND gs.`sensor_code` is not null
		UNION
		SELECT
		  bs.`site_name` siteName,
		  '电缆设备'  equipmentType,
		  '7' type,
		  st.`name`  equipmentName,
		  cs.equipment_type pendantType,
		  cst.name pendantName,
		  cs.`sensor_name` sensorName,
		  cs.`sensor_code` sensorCode,
		  cs.sensor_brand sensorBrand,
		  cs.manufactor,
		  cs.position_des positionDes,
		  cs.production_date productionDate,
		  cs.use_date useDate,
		  cs.`status`,
		  cs.equipment_id equipmentId,
		  st.id mainEquipmentId
		FROM
		  busi_cable_sensor cs
		  LEFT JOIN busi_site bs ON cs.`site_id` = bs.`id`
		  LEFT JOIN busi_cable_sub_tree cst ON cst.`id` = cs.`equipment_id`
		  LEFT JOIN busi_site_tree st ON st.`id` = cst.`equipment_id`
		WHERE cs.status = '1' AND st.`status` = '1' AND cs.sensor_code !='' AND cs.`sensor_code` is not null
    </select>

    <!-- 查询避雷器树 -->
    <select id="selectArresterBySensorCode" resultType="com.huatek.busi.vo.BusiEquipmentVo">
		SELECT
		  sub_tree.name AS equipmentName,
		  site_tree.name AS mainEquipmentName
		FROM
		  busi_arrester_sensor bas
		  LEFT JOIN busi_arrester_sub_tree sub_tree
		    ON bas.equipment_id = sub_tree.id
		   LEFT JOIN busi_site_tree site_tree
		    ON sub_tree.equipment_id = site_tree.id
		    WHERE bas.sensor_code = #{sensorCode}
	</select>

    <!-- 查询GIS树 -->
    <select id="selectGisBySensorCode" resultType="com.huatek.busi.vo.BusiEquipmentVo">
		SELECT
		  sub_tree.name AS equipmentName,
		  site_tree.name AS mainEquipmentName
		FROM
		  busi_gis_sensor bgs
		  LEFT JOIN busi_gis_sub_tree sub_tree
		    ON bgs.equipment_id = sub_tree.id
		   LEFT JOIN busi_site_tree site_tree
		    ON sub_tree.equipment_id = site_tree.id
		    WHERE bgs.sensor_code = #{sensorCode}
	</select>

    <!-- 查询变压器树 -->
    <select id="selectTransformerBySensorCode" resultType="com.huatek.busi.vo.BusiEquipmentVo">
		SELECT
		  sub_tree.name AS equipmentName,
		  site_tree.name AS mainEquipmentName
		FROM
		  busi_transformer_sensor bts
		  LEFT JOIN busi_transformer_sub_tree sub_tree
		    ON bts.equipment_id = sub_tree.id
		   LEFT JOIN busi_site_tree site_tree
		    ON sub_tree.equipment_id = site_tree.id
		    WHERE bts.sensor_code = #{sensorCode}
	</select>

    <select id = "findInputDataTree" resultType="com.huatek.busi.vo.BusiTreeNodeVo">
		SELECT
		  b.id,
		  b.name,
		  b.parent_id AS pid,
		  b.equipment_type AS type,
		  b.site_id AS siteId,
		  b.parent_id
		FROM busi_site_tree b,
		     busi_site s
		WHERE b.site_id = s.id
		AND b.status = '1'
		AND s.status = '1'
		AND equipment_type not in ('3','4','31','41','311','411')
		ORDER BY b.create_time ASC,
		b.equipment_type ASC, b.name ASC
    </select>

    <update id="updateTree" parameterType="com.huatek.busi.dto.BusiSiteTreeDto">
        UPDATE busi_site_tree
            SET
             NAME = #{name}
            WHERE
                id = #{id}
    </update>
    <update id="isDelete" parameterType="com.huatek.busi.dto.BusiSiteTreeDto">
        UPDATE busi_site_tree
            SET
             status = #{status}
            WHERE
                id = #{id}
    </update>

    <select id="findByMainEquipmentIdAndSiteId" parameterType="java.lang.String" resultType="com.huatek.busi.entity.BusiSiteTree">
        SELECT
            <include refid="Base_Column_List"/>
        FROM
            busi_site_tree
        WHERE
            id = #{mainEquipmentId}
        AND site_id = #{siteId}
        AND `status` = 1
    </select>
</mapper>
