<?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.yeejoin.equipmanage.mapper.EquipmentSpecificIndexMapper">
    <resultMap id="EquipmentDetail" type="com.yeejoin.equipmanage.common.entity.vo.EquipmentSecificDetailVO">
        <result property="qrCode" column="qr_code"></result>
        <result property="code" column="CODE"></result>
        <result property="systemName" column="System_name"></result>
        <result property="categoryName" column="category_name"></result>
        <result property="warehouseName" column="warehouse_name"></result>
        <result property="standard" column="standard"></result>
        <result property="country" column="country"></result>
        <result property="remark" column="remark"></result>
        <result property="maintenanceCycle" column="maintenance_cycle"></result>
        <result property="isImport" column="is_import"></result>
        <result property="brand" column="brand"></result>
        <result property="unitName" column="unit_name"></result>
        <result property="manufacturerName" column="manufacturer_name"></result>
        <result property="serviceTel" column="service_tel"></result>
        <result property="salesTel" column="sales_tel"></result>
        <result property="address" column="address"></result>
        <result property="equipmentName" column="equipment_name"></result>
        <result property="status" column="status"></result>
        <result property="img" column="img"></result>
        <result property="equipId" column="equip_id"></result>
        <result property="equipDetailId" column="equip_detail_id"></result>
    </resultMap>
    <update id="updateIndexValueBatch">
        <foreach collection="list" item="item" index="index" separator=";">
            update wl_equipment_specific_index set
            value = #{item.value}
            where equipment_specific_id = #{item.equipmentSpecificId}
            and equipment_index_id = #{item.equipmentIndexId}
        </foreach>
    </update>
    <select id="getEquipmentSpeIndexBySpeIotCode"
            resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
        SELECT wesi.id      AS id,
               wei.name_key AS nameKey,
               wesi.value AS value,
	        wesi.equipment_specific_id AS equipmentSpecificId,
	        wesi.equipment_index_id AS equipmentIndexId,
	        wesi.equipment_index_name AS equipmentIndexName,
	        wesi.equipment_index_key AS equipmentIndexKey,
	        wesi.value_label AS valueLabel,
	        wei.type_code AS typeCode,
	        wei.type_name AS typeName,
	        wei.name AS indexName,
	        wei.unit AS indexUnitName,
	        wes.org_code AS orgCode,
			ed.`name` AS equipmentSpecificName,
			ed.equipment_name AS equipmentName,
			wes.iot_code AS iotCode,
			wes.code AS specificCode,
			wei.`name` AS equipmentSpecificIndexName,
			wei.`value_enum` AS valueEnum,
			wei.is_trend AS isTrend,
			wes.qr_code AS qrCode,
			wesi.update_date AS updateDate,
			ed.code AS equipmentCode,
			ed.equipment_id AS equipmentId,
			ed.id AS equipmentDetailId,
			wes.code as equipmentSpecificCode,
			wes.system_id as systemId,
			wesi.is_alarm as isAlarm,
			wesi.emergency_level_color as emergencyLevelColor,
			wesi.emergency_level as emergencyLevel,
			wesi.emergency_level_describe as emergencyLevelDescribe,
			TRIM(CONCAT_WS(' ',wes.position,sd.description)) AS location,
			sd.warehouse_structure_id AS buildId,
            wes.biz_org_name AS bizOrgName,
            wes.biz_org_code AS bizOrgCode
        FROM
            wl_equipment_specific_index AS wesi
            LEFT JOIN wl_equipment_specific AS wes
        ON wes.id = wesi.equipment_specific_id
            LEFT JOIN wl_equipment_detail ed ON ed.id = wes.equipment_detail_id
            LEFT JOIN wl_equipment_index AS wei ON wei.id = wesi.equipment_index_id
            LEFT JOIN wl_stock_detail sd ON sd.equipment_specific_id = wes.id
        WHERE
            wes.iot_code = #{iotCode}
          and wei.is_iot = true
    </select>

    <select id="getEquipmentSpeIndexByIotCode"
            resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
        SELECT wesi.id      AS id,
               wei.name_key AS nameKey,
               wesi.value AS value,
        wesi.equipment_specific_id AS equipmentSpecificId,
        wesi.equipment_index_id AS equipmentIndexId,
        wes.org_code AS code,
        wes.iot_code AS iotCode,
        wes.org_code AS orgCode,
        wei.type_code AS typeCode,
        wei.name AS indexName,
        wei.unit AS indexUnitName,
        wesi.update_date AS updateDate
        FROM
            wl_equipment_specific_index AS wesi
            LEFT JOIN wl_equipment_specific AS wes
        ON wes.id = wesi.equipment_specific_id
            LEFT JOIN wl_equipment_index AS wei ON wei.id = wesi.equipment_index_id
        WHERE
            wes.iot_code = #{iotCode}
    </select>

    <select id="getEquipmentSpeIndexByIotCodeAndTrend"
            resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
        SELECT wei.id       AS id,
               wei.name_key AS nameKey,
               wesi.value AS value,
        wesi.equipment_specific_id AS equipmentSpecificId,
        wesi.equipment_index_id AS equipmentIndexId,
        wes.org_code AS code,
        wes.iot_code AS iotCode,
        wes.org_code AS orgCode,
        wei.type_code AS typeCode,
        wei.name AS indexName,
        wei.unit AS indexUnitName,
        wesi.update_date AS updateDate
        FROM
            wl_equipment_specific_index AS wesi
            LEFT JOIN wl_equipment_specific AS wes
        ON wes.id = wesi.equipment_specific_id
            LEFT JOIN wl_equipment_index AS wei ON wei.id = wesi.equipment_index_id
        WHERE
            wes.iot_code = #{iotCode}
          AND
            wei.is_trend = 1
    </select>

    <select id="getEquipmentSpeIndexDataByIotCode"
            resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
        SELECT wesi.id                 AS id,
               wei.name_key            AS nameKey,
               IFNULL(si.value_label, si.`value`) AS 'value', wesi.equipment_specific_id AS equipmentSpecificId,
               wesi.equipment_index_id AS equipmentIndexId,
               wes.org_code            AS code,
               wes.iot_code            AS iotCode,
               wes.org_code            AS orgCode,
               wei.type_code           AS typeCode,
               wei.name                AS indexName,
               wei.unit                AS indexUnitName,
               wei.value_enum          AS valueEnum
        FROM wl_equipment_specific_index AS wesi
                 LEFT JOIN wl_equipment_specific AS wes ON wes.id = wesi.equipment_specific_id
                 LEFT JOIN wl_equipment_index AS wei ON wei.id = wesi.equipment_index_id
        WHERE wes.iot_code = #{iotCode}
    </select>

    <select id="getEquipmentSpeIndexByEquipmentSecificId"
            resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
        SELECT wesi.id,
               wesi.equipment_specific_id,
               wesi.VALUE,
               wesi.create_date,
               wesi.equipment_index_id,
               wli.`name` nameKey
        FROM wl_equipment_specific_index wesi
                 LEFT JOIN wl_equipment_index wli ON wesi.equipment_index_id = wli.id
        where wesi.equipment_specific_id = #{id}
    </select>
    <select id="getVideoByEquipmentSecificId" resultType="com.yeejoin.equipmanage.common.entity.Video">
        SELECT ip,
               `port`,
               url,
               `name`,
               token,
               `code`,
               video_type as videoType,
               preset_position
        FROM wl_video wlv
                 LEFT JOIN wl_video_equipment_specific wlves ON wlv.id = wlves.video_id
        WHERE wlves.equipment_specific_id = #{id}
    </select>
    <select id="getEquipmentDetailBySecificId" resultMap="EquipmentDetail">
        SELECT wled.NAME                                     equipment_name,
               wle.id                                        equip_id,
               wled.id                                       equip_detail_id,
               wles.qr_code,
               wles.CODE,
               (select GROUP_CONCAT(fs.name)
                from f_fire_fighting_system fs
                where FIND_IN_SET(fs.id, wles.system_id)) as System_name,
               wlec.NAME                                     category_name,
               wlws.full_name                                warehouse_name,
               wled.standard,
               sd.`name`                                     country,
               wled.remark,
               wled.maintenance_cycle,
               wled.is_import,
               wled.brand,
               wlun.`name`                                   unit_name,
               wlmi.`name`                                   manufacturer_name,
               wlmi.service_tel,
               wlmi.sales_tel,
               wlmi.address,
               wlmi.img,
               wleias.`value`                                STATUS
        FROM wl_equipment_specific wles
                 LEFT JOIN wl_equipment_detail wled ON wles.equipment_detail_id = wled.id
                 LEFT JOIN wl_system_dic sd ON sd.id = wled.country
                 LEFT JOIN wl_equipment wle ON wled.equipment_id = wle.id
                 LEFT JOIN wl_equipment_category wlec ON wle.category_id = wlec.id
                 LEFT JOIN wl_stock_detail wlsd ON wlsd.qr_code = wles.qr_code
                 LEFT JOIN wl_warehouse_structure wlws ON wlsd.warehouse_structure_id = wlws.id
                 LEFT JOIN wl_unit wlun ON wle.unit_id = wlun.id
                 LEFT JOIN wl_manufacturer_info wlmi ON wlmi.id = wled.manufacturer_id
                 LEFT JOIN (SELECT wlei.equipment_id,
                                   wlesi.`value`
                            FROM wl_equipment_index wlei
                                     LEFT JOIN wl_equipment_specific_index wlesi ON wlei.id = wlesi.equipment_index_id
                            WHERE wlei.name_key = 'runState') wleias ON wle.id = wleias.equipment_id
        WHERE wles.id = #{id}
    </select>
    <select id="selectEquProperty" resultType="java.util.HashMap">
        SELECT wlei.NAME,
               wlesi.`value`
        FROM wl_equipment_specific_index wlesi
                 LEFT JOIN wl_equipment_specific wleqs ON wleqs.id = wlesi.equipment_specific_id
                 LEFT JOIN wl_equipment_index wlei ON wlesi.equipment_index_id = wlei.id
        where wleqs.id = #{id}
    </select>
    <select id="selectEquList" resultType="java.util.HashMap">
        SELECT
        de.id,
        de.name,
        a.image,
        de.standard,
        (case wsd.`status`
        when '1' then '在位'
        when '2' then '执勤'
        when '3' then '维修'
        when '6' then '退役'
        when '7' then '报废'
        when '10' then '车载'
        when '11' then '损耗'
        else '未入库' END) statusName,
        (case LEFT(ca.`code`,1)
        when '4' then '04#'
        else '01#' END) typen,
        IFNULL(wsd.amount,0)amount,
        info.name manufacturerName,
        dic.name country,
        wesp.qr_code qrcode
        FROM
        wl_equipment_specific wesp
        LEFT JOIN wl_equipment_detail de on wesp.equipment_detail_id=de.id
        LEFT JOIN wl_manufacturer_info info on de.manufacturer_id=info.id
        LEFT JOIN wl_system_dic dic on dic.id=de.country
        LEFT JOIN wl_equipment ca on ca.id=de.equipment_id
        LEFT JOIN (SELECT object_id,
        (CASE `file_type` WHEN 'image' THEN GROUP_CONCAT(url SEPARATOR ',') ELSE '' END) as 'image',
        (CASE `file_type` WHEN 'video' THEN GROUP_CONCAT(url SEPARATOR ',') ELSE '' END) as 'video',
        (CASE `file_type` WHEN 'instruction' THEN GROUP_CONCAT(url SEPARATOR ',') ELSE '' END) as 'instruction',
        (CASE `file_type` WHEN 'certificate' THEN GROUP_CONCAT(url SEPARATOR ',') ELSE '' END) as 'certificate',
        (CASE `file_type` WHEN 'face' THEN GROUP_CONCAT(url SEPARATOR ',') ELSE '' END) as 'face'
        FROM wl_upload_file
        GROUP BY object_id) a on a.object_id=de.id
        LEFT JOIN wl_stock_detail wsd ON wsd.qr_code = wesp.qr_code
        <if test="name!= null and name!=''">
            AND de.name like CONCAT('%',#{name},'%')
        </if>
        <if test="standard!= null and standard!=''  ">
            AND de.standard like CONCAT('%',#{standard},'%')
        </if>
        <if test="manufacturerName != null and manufacturerName!='' ">
            AND info.name like CONCAT('%',#{manufacturerName},'%')
        </if>
        LIMIT #{pageNum},#{pageSize}
    </select>

    <select id="selectEquListcount" resultType="java.util.HashMap">
        SELECT
        de.name
        FROM
        wl_equipment_specific wesp
        LEFT JOIN wl_equipment_detail de on wesp.equipment_detail_id=de.id
        LEFT JOIN wl_manufacturer_info info on de.manufacturer_id=info.id
        LEFT JOIN wl_system_dic dic on dic.id=de.country
        LEFT JOIN wl_equipment ca on ca.id=de.equipment_id
        LEFT JOIN (SELECT object_id,
        (CASE `file_type` WHEN 'image' THEN GROUP_CONCAT(url SEPARATOR ',') ELSE '' END) as 'image',
        (CASE `file_type` WHEN 'video' THEN GROUP_CONCAT(url SEPARATOR ',') ELSE '' END) as 'video',
        (CASE `file_type` WHEN 'instruction' THEN GROUP_CONCAT(url SEPARATOR ',') ELSE '' END) as 'instruction',
        (CASE `file_type` WHEN 'certificate' THEN GROUP_CONCAT(url SEPARATOR ',') ELSE '' END) as 'certificate',
        (CASE `file_type` WHEN 'face' THEN GROUP_CONCAT(url SEPARATOR ',') ELSE '' END) as 'face'
        FROM wl_upload_file
        GROUP BY object_id) a on a.object_id=de.id
        LEFT JOIN wl_stock_detail wsd ON wsd.qr_code = wesp.qr_code
        LEFT JOIN wl_warehouse wwa ON wsd.warehouse_id = wwa.id
        LEFT JOIN wl_warehouse_structure wws ON wsd.warehouse_structure_id = wws.id
        LEFT JOIN wl_warehouse_structure wws1 ON wws.parent_id = wws1.id
        <if test="name!= null and name!=''  ">
            AND de.name like CONCAT('%',#{name},'%')
        </if>
        <if test="standard!= null and standard!=''  ">
            AND de.standard like CONCAT('%',#{standard},'%')
        </if>
        <if test="manufacturerName != null and manufacturerName!='' ">
            AND info.name like CONCAT('%',#{manufacturerName},'%')
        </if>
    </select>

    <select id="getEquipmentSpeIndexList" resultType="hashmap">
        SELECT wles.equipment_specific_id AS speId,
               wles.`value`               AS speIndexValue,
               wlei.type_name             AS typeName,
               wlei.type_code             AS typeCode,
               wlei.name_key              AS nameKey,
               wlei.`name`                as indexName
        FROM wl_equipment_specific_index wles
                 JOIN wl_equipment_index wlei ON wlei.id = wles.equipment_index_id
        WHERE wlei.is_iot = 1
          AND (
            wlei.type_code IN ('BREAKDOWN', 'SHIELD'))
          AND (wles.`value` IS NOT NULL AND LENGTH(TRIM(wles.`value`)) > 1)
    </select>
    <select id="getEquipSpecificIndexList" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentIndexVO">
        SELECT
        si.equipment_specific_id AS equipmentId,
        ei.id,
        ei.name_key,
        ei.name AS perfQuotaName,
        si.value,
        ei.is_iot,
        si.unit AS unitName,
        ei.sort_num,
        si.create_date,
        si.update_date,
        si.index_address,
        si.gateway_id,
        si.data_type,
        si.equipment_specific_name,
        si.equipment_index_name,
        si.is_alarm,
        si.value_enum AS valueEnum
        FROM
        wl_equipment_specific_index si
        LEFT JOIN wl_equipment_index ei ON si.equipment_index_id = ei.id
        <where>
            <if test="equipmentId != null and equipmentId !=''">
                si.equipment_specific_id = #{equipmentId}
            </if>
            <if test="isIot != null and isIot !=''">
                AND ei.is_iot = #{isIot}
            </if>
        </where>
    </select>
    <select id="getEquipIndexBySpecificIdIn" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentIndexVO">
        SELECT
        si.id,
        si.equipment_specific_id AS equipmentId,
        ei.name_key,
        ei.`name` AS perfQuotaName,
        si.`value`,
        ei.is_iot,
        ei.unit AS unitName,
        ei.sort_num,
        si.create_date,
        si.update_date,
        ei.type_code AS typeCode,
        ei.type_name AS typeName,
        ei.`id` AS indexId
        FROM
        wl_equipment_specific_index si
        LEFT JOIN wl_equipment_index ei ON si.equipment_index_id = ei.id
        LEFT JOIN wl_equipment_specific es ON si.equipment_specific_id = es.id
        LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
        <where>
            <if test="list != null and list.size > 0 and type = 'id'">
                si.equipment_specific_id IN
                <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
    <select id="getEquipIndexByIndexId" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentIndexVO">
        SELECT
        si.id,
        si.equipment_specific_id AS equipmentId,
        (case when si.value_label is null or trim(si.value_label) ='' then si.`value` else si.value_label end )AS
        'value',
        si.create_date,
        si.update_date
        FROM
        wl_equipment_specific_index si
        <where>
            <if test="id != null">
                si.equipment_index_id = #{id}
            </if>
            <if test="equipmentSpecificId!= null">
                AND si.equipment_specific_id = #{equipmentSpecificId}
            </if>
        </where>
    </select>
    <select id="getEquipIndexByIdIn" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentIndexVO">
        SELECT
        si.equipment_specific_id AS equipmentId,
        si.id,
        ei.name_key,
        ei.`name` AS perfQuotaName,
        si.`value`,
        ei.is_iot,
        ei.unit AS unitName,
        ei.sort_num,
        si.create_date,
        si.update_date,
        ei.type_code AS typeCode,
        ei.type_name AS typeName,
        es.`code` AS indexId
        FROM
        wl_equipment_specific_index si
        LEFT JOIN wl_equipment_index ei ON si.equipment_index_id = ei.id
        LEFT JOIN wl_equipment_specific es ON si.equipment_specific_id = es.id
        LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
        <where>
            <if test="list != null and list.size > 0 and type = 'id'">
                si.id IN
                <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
    <select id="getEquipSpecificIndexByUpdateDateDesc" resultType="java.util.HashMap">
        SELECT esi.id,
               es.`name`                AS equipmentSpecificName,
               esi.equipment_index_name AS equipmentSpecificIndexName,

               IF(
                               esi.value_label = ''
                           OR esi.value_label IS NULL,
                               esi.`value`,
                               esi.value_label
                   )                    AS valueLabel,
               es.position              AS location,
               esi.update_date          AS createDate
        FROM `wl_equipment_specific_index` esi
                 LEFT JOIN wl_equipment_specific es ON es.id = esi.equipment_specific_id
        WHERE esi.`value` IS NOT NULL
        ORDER BY esi.update_date DESC LIMIT 50
    </select>

    <select id="getEquipmentSpeIndexByIotCodeTrend"
            resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
        SELECT
        wei.id AS id,
        wei.name_key AS nameKey,
        wesi.value AS value,
        wesi.equipment_specific_id AS equipmentSpecificId,
        wesi.equipment_index_id AS equipmentIndexId,
        wes.org_code AS code,
        wes.iot_code AS iotCode,
        wes.org_code AS orgCode,
        wei.type_code AS typeCode,
        wei.name AS indexName,
        wei.unit AS indexUnitName,
        wei.is_trend isTrend,
        wesi.value_label,
        wesi.equipment_index_name,
        wesi.update_date AS updateDate,
        wei.type_name AS typeName
        FROM
        wl_equipment_specific_index AS wesi
        LEFT JOIN wl_equipment_specific AS wes ON wes.id = wesi.equipment_specific_id
        LEFT JOIN wl_equipment_index AS wei ON wei.id = wesi.equipment_index_id
        WHERE
        wes.iot_code = #{iotCode}
        <if test="isTrend != null">
            AND wei.is_trend = #{isTrend}
        </if>
        <if test="fieldKey != null">
            AND wei.name_key = #{fieldKey}
        </if>
    </select>
    <select id="getEquipSpecificScrap" resultType="java.util.Map">
        select wes.id,
               str.name as sname,
               wlsd.status,
               wes.position,
               wes.name,
               we.expiry_date as weExpiry,
               wed.area as area,
               wed.production_date as product,
               wes.biz_org_code  as bizOrgCode,
               wes.biz_org_name as bizOrgName
        from wl_equipment_specific wes
                 left join wl_equipment_detail wed on wes.equipment_detail_id = wed.id
                 left join wl_equipment we on wed.equipment_id = we.id
                 left join wl_warehouse_structure str on str.id = wes.warehouse_structure_id
                 left join wl_stock_detail wlsd on wes.id = wlsd.equipment_specific_id
        where wed.production_date is not null
          and wlsd.status != 7
    </select>
    <select id="getEquipIndexInIndex" resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
        SELECT
        si.equipment_specific_id AS equipmentId,
        si.id,
        si.`value`,
        si.create_date,
        si.update_date,
        si.equipment_index_key,
        si.equipment_specific_name,
        CONCAT_WS('-', es.position, wled.area) AS location, /*告警列表拼接详细地址*/
        es.`iot_code` AS iotCode
        FROM
        wl_equipment_specific_index si
        LEFT JOIN wl_equipment_specific es ON si.equipment_specific_id = es.id
        LEFT JOIN wl_equipment_detail wled ON es.equipment_detail_id = wled.id
        <where>
            <if test="list != null and list.size > 0 and type = 'id'">
                si.equipment_index_key  IN
                <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            and es.iot_code is not null
            and es.iot_code != ''
        </where>
    </select>

    <!-- 根据信号索引查询装备性能指标 -->
    <select id="getEquipmentSpeIndexByIndexAddress"
            resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
        SELECT wesi.id      AS id,
               wei.name_key AS nameKey,
               wesi.value AS value,
	           wesi.equipment_specific_id AS equipmentSpecificId,
	           wesi.equipment_index_id AS equipmentIndexId,
               wesi.equipment_index_name AS equipmentIndexName,
	           wesi.equipment_index_key AS equipmentIndexKey,
	           wesi.value_label AS valueLabel,
	           wei.type_code AS typeCode,
	           wei.type_name AS typeName,
	           wei.name AS indexName,
	           wei.unit AS indexUnitName,
	           wes.org_code AS orgCode,
			   ed.`name` AS equipmentSpecificName,
			   ed.equipment_name AS equipmentName,
			   wes.iot_code AS iotCode,
			   wes.code AS specificCode,
			   wei.`name` AS equipmentSpecificIndexName,
			   wei.`value_enum` AS valueEnum,
			   wei.is_trend AS isTrend,
			   wes.qr_code AS qrCode,
			   wesi.update_date AS updateDate,
			   ed.code AS equipmentCode,
			   ed.equipment_id AS equipmentId,
			   ed.id AS equipmentDetailId,
			   wes.code as equipmentSpecificCode,
			   wes.system_id as systemId,
			   wesi.is_alarm as isAlarm,
			   wesi.emergency_level_color as emergencyLevelColor,
			   wesi.emergency_level as emergencyLevel,
			   wesi.emergency_level_describe as emergencyLevelDescribe,
               wes.biz_org_name AS bizOrgName,
               wes.biz_org_code AS bizOrgCode
        FROM wl_equipment_specific_index AS wesi
        LEFT JOIN wl_equipment_specific AS wes ON wes.id = wesi.equipment_specific_id
        LEFT JOIN wl_equipment_detail ed ON ed.id = wes.equipment_detail_id
        LEFT JOIN wl_equipment_index AS wei ON wei.id = wesi.equipment_index_id
        WHERE
            wesi.index_address = #{indexAddress}
        <if test="gatewayId != null">
            AND wesi.gateway_id = #{gatewayId}
        </if>
    </select>
</mapper>