<?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.amos.fas.business.dao.mapper.View3dMapper">

    <!--	<select id="getPointByType" resultType="com.yeejoin.amos.fas.core.common.response.RegionTreeResponse">-->
    <!--		<choose>-->
    <!--			<when	test="type == 'riskSource'">-->
    <!--				select-->
    <!--					R.id,R.name,R.code,R.parent_id,R.ue4_location,R.ue4_rotation,R.ue4_extent,-->
    <!--					<choose>-->
    <!--						<when test="channelType == '3dpage'">-->
    <!--							IF(ISNULL(position3d) || LENGTH(trim(position3d)) <![CDATA[ <]]> 1,0,1) as is_bind,-->
    <!--						</when>-->
    <!--						<otherwise>-->
    <!--							IF(ISNULL(IF(replace(trim(ue4_rotation),'[]','')='',NULL,R.ue4_rotation))-->
    <!--							AND ISNULL(IF(replace(trim(ue4_location),'[]','')='',NULL,R.ue4_location)),0,1) as is_bind,-->
    <!--						</otherwise>-->
    <!--					</choose>-->
    <!--					#{type} as type,-->
    <!--					route_path,-->
    <!--					rl.level,-->
    <!--					CONCAT('level_',rl.level) as level_str,-->
    <!--					0 as is_region,-->
    <!--					R.position3d-->
    <!--				from f_risk_source R-->
    <!--				left join f_risk_level rl on rl.id = R.risk_level_id-->
    <!--				where 1=1-->
    <!--				AND R.risk_level_id is not null-->
    <!--				AND R.is_region = 'FALSE'-->
    <!--			</when>-->
    <!--			<when	test="type == 'patrol'">-->
    <!--				select-->
    <!--					B.id,B.risk_source_id as parent_id,-->
    <!--					<choose>-->
    <!--						<when test="channelType == '3dpage'">-->
    <!--							IF(ISNULL(B.coordinates) || LENGTH(trim(B.coordinates)) <![CDATA[ <]]> 1,0,1) as is_bind,-->
    <!--						</when>-->
    <!--						<otherwise>-->
    <!--							IF(ISNULL(IF(replace(trim(B.ue4_rotation),'[]','')='',NULL,B.ue4_rotation))-->
    <!--							AND ISNULL(IF(replace(trim(B.ue4_location),'[]','')='',NULL,B.ue4_location)),0,1) as is_bind,-->
    <!--						</otherwise>-->
    <!--					</choose>-->
    <!--					#{type} as type,-->
    <!--					B.name as name,B.point_no as code,B.ue4_location,B.ue4_rotation,-->
    <!--					0 as is_region,-->
    <!--					B.coordinates as position3d,-->
    <!--					B.status as level,-->
    <!--					CONCAT('level_',B.status) as level_str-->
    <!--				from f_risk_source R-->
    <!--				left join p_point B on B.risk_source_id = R.id AND R.is_region='TRUE'-->
    <!--				where 1=1-->
    <!--					AND B.id is not null AND B.is_delete = 0-->
    <!--			</when>-->
    <!--			<when	test="type == 'impEquipment'">-->
    <!--				select-->
    <!--					B.id,B.risk_source_id as parent_id,-->
    <!--					<choose>-->
    <!--						<when test="channelType == '3dpage'">-->
    <!--							IF(ISNULL(B.position3d) || LENGTH(trim(B.position3d)) <![CDATA[ <]]> 1,0,1) as is_bind,-->
    <!--						</when>-->
    <!--						<otherwise>-->
    <!--							IF(ISNULL(IF(replace(trim(B.ue4_rotation),'[]','')='',NULL,B.ue4_rotation))-->
    <!--								AND ISNULL(IF(replace(trim(B.ue4_location),'[]','')='',NULL,B.ue4_location)),0,1) as is_bind,-->
    <!--						</otherwise>-->
    <!--					</choose>-->
    <!--					#{type} as type,-->
    <!--					B.name,B.code,B.ue4_location,B.ue4_rotation,-->
    <!--					0 as is_region,-->
    <!--					B.position3d-->
    <!--				from f_risk_source R-->
    <!--				left join f_equipment B on B.risk_source_id = R.id AND R.is_region='TRUE'-->
    <!--				where 1=1-->
    <!--					AND B.id is not null-->
    <!--			</when>-->
    <!--			<when	test="type == 'monitorEquipment'">-->
    <!--				select-->
    <!--					B.id,B.risk_source_id as parent_id,-->
    <!--					<choose>-->
    <!--						<when test="channelType == '3dpage'">-->
    <!--							IF(ISNULL(B.position3d) || LENGTH(trim(B.position3d)) <![CDATA[ <]]> 1,0,1) as is_bind,-->
    <!--						</when>-->
    <!--						<otherwise>-->
    <!--							IF(ISNULL(IF(replace(trim(B.ue4_rotation),'[]','')='',NULL,B.ue4_rotation))-->
    <!--							AND ISNULL(IF(replace(trim(B.ue4_location),'[]','')='',NULL,B.ue4_location)),0,1) as is_bind,-->
    <!--						</otherwise>-->
    <!--					</choose>-->
    <!--					#{type} as type,-->
    <!--					B.name,B.code,B.ue4_location,B.ue4_rotation,-->
    <!--					0 as is_region,-->
    <!--					B.position3d-->
    <!--				from f_risk_source R-->
    <!--				left join f_fire_equipment B on B.risk_source_id = R.id AND B.equip_classify = 0-->
    <!--				where 1=1-->
    <!--					AND B.id is not null-->
    <!--			</when>-->
    <!--			<when	test="type == 'video'">-->
    <!--				select-->
    <!--					B.id,B.risk_source_id as parent_id,-->
    <!--					<choose>-->
    <!--						<when test="channelType == '3dpage'">-->
    <!--							IF(ISNULL(B.position3d) || LENGTH(trim(B.position3d)) <![CDATA[ <]]> 1,0,1) as is_bind,-->
    <!--						</when>-->
    <!--						<otherwise>-->
    <!--							IF(ISNULL(IF(replace(trim(B.ue4_rotation),'[]','')='',NULL,B.ue4_rotation))-->
    <!--								AND ISNULL(IF(replace(trim(B.ue4_location),'[]','')='',NULL,B.ue4_location)),0,1) as is_bind,-->
    <!--						</otherwise>-->
    <!--					</choose>-->
    <!--					#{type} as type,-->
    <!--					B.name,B.code,B.ue4_location,B.ue4_rotation,-->
    <!--					0 as is_region,-->
    <!--					B.position3d-->
    <!--				from f_risk_source R-->
    <!--				left join f_fire_equipment B on B.risk_source_id = R.id AND B.equip_classify = 2-->
    <!--				where 1=1-->
    <!--					AND B.id is not null-->
    <!--			</when>-->
    <!--			<when	test="type == 'fireEquipment'">-->
    <!--				select tmp.id,tmp.name,tmp.type,tmp.position3d,tmp.ue4_rotation,tmp.ue4_location,tmp.code,R.id as parent_id,-->
    <!--					<choose>-->
    <!--						<when test="channelType == '3dpage'">-->
    <!--							IF(ISNULL(tmp.position3d) || LENGTH(trim(tmp.position3d)) <![CDATA[ <]]> 1,0,1) as isBind-->
    <!--						</when>-->
    <!--						<otherwise>-->
    <!--							IF(ISNULL(IF(replace(trim(tmp.ue4_rotation),'[]','')='',NULL,tmp.ue4_rotation))-->
    <!--							AND ISNULL(IF(replace(trim(tmp.ue4_location),'[]','')='',NULL,tmp.ue4_location)),0,1) as isBind-->
    <!--						</otherwise>-->
    <!--					</choose>-->
    <!--					from (-->
    <!--							select id,name,'fireCar' as type,position3d,car_num as code,ue4_location,ue4_rotation,risk_source_id-->
    <!--						from f_fire_car-->
    <!--						union all-->
    <!--						select id,name,'fireEquipment' as type,position3d,code,ue4_location,ue4_rotation,risk_source_id-->
    <!--						from f_fire_equipment-->
    <!--						where equip_classify =3-->
    <!--						union all-->
    <!--						select id,name,CASE-->
    <!--							WHEN S.type = 1 then 'fireChamber'-->
    <!--							WHEN S.type = 2 then 'fireFoamRoom'-->
    <!--						END as type,position3d,code,ue4_location,ue4_rotation,risk_source_id-->
    <!--						from f_fire_station s-->
    <!--						union all-->
    <!--						select id,name,-->
    <!--							CASE-->
    <!--							WHEN W.type = 1 then 'hydrant'-->
    <!--							WHEN W.type = 2 then 'pool'-->
    <!--						END as type,position3d,code,ue4_location,ue4_rotation,risk_source_id-->
    <!--						from f_water_resource w-->
    <!--					) tmp-->
    <!--					left join f_risk_source R on R.id = tmp.risk_source_id-->

    <!--			</when>-->
    <!--		</choose>-->
    <!--		<if test="orgCode != null">-->
    <!--			AND (R.org_code = #{orgCode} OR R.org_code like CONCAT(#{orgCode},'-%'))-->
    <!--		</if>-->
    <!--	</select>-->

    <!--	<select id="getPointDetailByTypeAndId" resultType="java.util.HashMap">-->
    <!--		<choose>-->
    <!--			<when	test="type == 'riskSource'">-->
    <!--				select rs.id,rs.name,rs.code,rs.ue4_location as ue4Location,rs.ue4_rotation as ue4Rotation,rs.position3d,-->
    <!--				rl.level,rl.name as levelStr,rs.floor3d ,rs.is_indoor as isIndoor,-->
    <!--				rs.flicker_frequency as frequency,-->
    <!--				true as 'showInfo',-->
    <!--				#{type} as type,-->
    <!--				rs.rpn as title-->
    <!--				from f_risk_source rs-->
    <!--				left join f_risk_level rl ON rl.id = rs.risk_level_id-->
    <!--				where 1=1-->
    <!--				<if test="pointId != null">-->
    <!--					AND rs.id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--			<when	test="type == 'patrol'">-->
    <!--				select id,name,point_no as code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,coordinates as position3d,-->
    <!--				status,floor as floor3d,is_indoor as isIndoor,-->
    <!--				0 as frequency,-->
    <!--				case p.status-->
    <!--					when '0' then false-->
    <!--					when '1' then false-->
    <!--					else true-->
    <!--				end as `showInfo`,-->
    <!--				case p.status-->
    <!--					when '0' then '未计划'-->
    <!--					when '1' then '合格'-->
    <!--					when '2' then '不合格'-->
    <!--					when '3' then '漏检'-->
    <!--				end as title,-->
    <!--				case p.status-->
    <!--					when '0' then '未计划'-->
    <!--					when '1' then '合格'-->
    <!--					when '2' then '不合格'-->
    <!--					when '3' then '漏检'-->
    <!--				end as levelStr,-->
    <!--				#{type} as type,-->
    <!--				status as level-->
    <!--				from p_point p-->
    <!--				where 1=1 and is_delete = 0-->
    <!--				<if test="pointId != null">-->
    <!--					AND id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--			<when	test="type == 'impEquipment'">-->
    <!--				select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,position3d,-->
    <!--				floor3d,is_indoor as isIndoor,-->
    <!--				0 as frequency,-->
    <!--				false as 'showInfo',-->
    <!--				#{type} as type,-->
    <!--				name as 'title'-->
    <!--				from f_equipment-->
    <!--				where 1=1-->
    <!--				<if test="pointId != null">-->
    <!--					AND id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--			<when	test="type == 'monitorEquipment'">-->
    <!--				select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,position3d,-->
    <!--				floor3d,is_indoor as isIndoor,-->
    <!--				0 as frequency,-->
    <!--				false as 'showInfo',-->
    <!--				#{type} as type,-->
    <!--				name as 'title'-->
    <!--				from f_fire_equipment-->
    <!--				where  equip_classify = 0-->
    <!--				<if test="pointId != null">-->
    <!--					AND id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--			<when	test="type == 'video'">-->
    <!--				select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,position3d,-->
    <!--				floor3d,is_indoor as isIndoor,-->
    <!--				0 as frequency,-->
    <!--				false as 'showInfo',-->
    <!--				#{type} as type,-->
    <!--				name as 'title'-->
    <!--				from f_fire_equipment-->
    <!--				where  equip_classify = 2-->
    <!--				<if test="pointId != null">-->
    <!--					AND id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--			<when	test="type == 'hydrant'">-->
    <!--				select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,position3d,-->
    <!--				floor3d,is_indoor as isIndoor,-->
    <!--				0 as frequency,-->
    <!--				false as 'showInfo',-->
    <!--				#{type} as type,-->
    <!--				name as 'title'-->
    <!--				from f_water_resource-->
    <!--				where type = 1-->
    <!--				<if test="pointId != null">-->
    <!--					AND id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--			<when	test="type == 'pool'">-->
    <!--				select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,position3d,-->
    <!--				floor3d,is_indoor as isIndoor,-->
    <!--				0 as frequency,-->
    <!--				false as 'showInfo',-->
    <!--				#{type} as type,-->
    <!--				name as 'title'-->
    <!--				from f_water_resource-->
    <!--				where type = 2-->
    <!--				<if test="pointId != null">-->
    <!--					AND id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--			<when	test="type == 'fireCar'">-->
    <!--				select id,name,car_num as code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,position3d,-->
    <!--				floor3d,is_indoor as isIndoor,-->
    <!--				0 as frequency,-->
    <!--				true as 'showInfo',-->
    <!--				#{type} as type,-->
    <!--				name as 'title'-->
    <!--				from f_fire_car-->
    <!--				where 1=1-->
    <!--				<if test="pointId != null">-->
    <!--					AND id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--			<when	test="type == 'fireEquipment'">-->
    <!--				select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,position3d,-->
    <!--				floor3d,is_indoor as isIndoor,-->
    <!--				0 as frequency,-->
    <!--				true as 'showInfo',-->
    <!--				#{type} as type,-->
    <!--				name as 'title'-->
    <!--				from f_fire_equipment-->
    <!--				where  equip_classify = 3-->
    <!--				<if test="pointId != null">-->
    <!--					AND id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--			<when	test="type == 'fireChamber'">-->
    <!--				select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,position3d,-->
    <!--				floor3d,is_indoor as isIndoor,-->
    <!--				0 as frequency,-->
    <!--				true as 'showInfo',-->
    <!--				#{type} as type,-->
    <!--				name as 'title'-->
    <!--				from f_fire_station-->
    <!--				where type = 1-->
    <!--				<if test="pointId != null">-->
    <!--					AND id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--			<when	test="type == 'fireFoamRoom'">-->
    <!--				select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,position3d,-->
    <!--				floor3d,is_indoor as isIndoor,-->
    <!--				0 as frequency,-->
    <!--				true as 'showInfo',-->
    <!--				#{type} as type,-->
    <!--				name as 'title'-->
    <!--				from f_fire_station-->
    <!--				where type = 2-->
    <!--				<if test="pointId != null">-->
    <!--					AND id = #{pointId}-->
    <!--				</if>-->
    <!--			</when>-->
    <!--		</choose>-->
    <!--	</select>-->

    <select id="getSafetyIndexWeek" resultType="java.util.HashMap">
		<![CDATA[
			SELECT distinct temp1.*,IFNULL(S.safety_index,0) as value
			FROM (
				SELECT @s :=@s + 1 as `index`, DATE(DATE_SUB(CURRENT_DATE, INTERVAL @s DAY)) AS date
				FROM mysql.help_topic,(SELECT @s := 0) temp
				WHERE @s < 7
				) temp1
			left join f_safety_index_change_log S on s.collect_date =  temp1.date AND (S.org_code = #{orgCode} OR S.org_code like CONCAT(#{orgCode},'-%'))
			ORDER BY temp1.date
		]]>
	</select>

    <select id="countUpperRiskPoint" resultType="long">
		SELECT
			count(DISTINCT frcl.risk_source_id)
		FROM
			(
				SELECT
					a.id,
					a.risk_source_id
				FROM
					`f_rpn_change_log` a,
			   		 `f_risk_source` b
				WHERE
					a.type = #{type}
					and a.risk_source_id = b.id
					and b.org_code = #{orgCode}
					and date_format(a.create_date, '%Y-%m-%d') = #{date}
					and b.risk_level_id is not NULL
		) as frcl
	</select>
    <select id="countCheckException" resultType="long">
		SELECT
			count(distinct pc.point_id)
		FROM
			p_check pc
		WHERE
			DATE_FORMAT(pc.check_time, '%Y-%m-%d') = #{date}
		AND (
			pc.org_code = #{orgCode}
			OR pc.org_code LIKE CONCAT(#{orgCode}, '-%')
		)
		AND pc.`is_ok` = '2'
	</select>

    <select id="countFireException" resultType="long">
		SELECT
			count(1)
		FROM
			wl_equipment_specific_alarm a
		WHERE
		 status = 1
		AND org_code = #{orgCode}
		AND type = 'BREAKDOWN'
		AND	date_format(a.update_date, '%Y-%m-%d') = #{date}
	</select>

    <select id="getAllErrorRiskPoint" resultType="com.yeejoin.amos.fas.business.bo.RiskPointRpnChangeBo">
		SELECT
			rcl.id,
			rcl.create_date AS changeDate,
			rs.risk_level_id AS riskLevelId,
			rs.`name`
		FROM
			(
				SELECT
					risk_source_id,
					MAX(create_date) create_date,
					MAX(id) id
				FROM
					f_rpn_change_log
				WHERE
					type = '0'
				AND DATE_FORMAT(create_date, '%Y-%m-%d') =  #{date}
				group by risk_source_id
			) rcl
		LEFT JOIN f_risk_source rs ON rs.id = rcl.risk_source_id
		WHERE rs.risk_level_id is not NULL
			AND (rs.org_code = #{orgCode} OR rs.org_code like CONCAT(#{orgCode},'-%'))

	</select>
    <select id="getAllErrorPatrolPoint" resultType="com.yeejoin.amos.fas.business.bo.CheckErrorBo">

		SELECT
			pc.point_id id,
			pc.point_name 'name',
			pc.`is_ok` as status,
			max(pc.check_time) as changeDate
		FROM
			p_check pc
		WHERE
			DATE_FORMAT(pc.check_time, '%Y-%m-%d') = #{date}
		AND (
			pc.org_code = #{orgCode}
			OR pc.org_code LIKE CONCAT(#{orgCode}, '-%')
		)
		AND pc.`is_ok` = '2'
		GROUP BY pc.point_id,pc.`is_ok`,pc.point_name
	</select>

    <select id="getAllFaultAlarm" resultType="com.yeejoin.amos.fas.business.bo.CheckErrorBo">
		select
		ala.id,
		ala.equipment_specific_name as name,
		cate.name as status,
		ala.update_date as changeDate
		from
		wl_equipment_specific_alarm as ala
		left join wl_equipment_specific as spe on ala.equipment_specific_id = spe.id
		left join wl_equipment_detail as det on spe.equipment_detail_id  = det.id
		left join wl_equipment as equ on equ.id = det.equipment_id
		left join wl_equipment_category as cate on equ.category_id = cate.id
		where ala.status = TRUE
		AND ala.type = 'alarm_type_trouble'
		AND ala.org_code = #{orgCode}
		AND	date_format(ala.update_date, '%Y-%m-%d') = #{date}

	</select>

    <select id="getStatisticsCheck" resultType="java.util.HashMap">
		<![CDATA[
        SELECT IFNULL(d.STATUS,'') AS type, count(1) as value
		FROM p_plan_task_detail d
		left JOIN p_plan_task t on t.id=d.task_no
		WHERE
		DATEDIFF(t.begin_time,CURRENT_DATE) <= 0 AND DATEDIFF(t.end_time,CURRENT_DATE) >= 0
		AND (t.org_code like CONCAT(#{orgCode},'-%') OR t.org_code = #{orgCode})
		AND d.status = 0
		UNION ALL
			select
				is_ok as type,count(1) as value
			from p_check a
			where  (a.org_code like CONCAT(#{orgCode},'-%') OR a.org_code = #{orgCode})
				and TO_DAYS(a.check_time) = TO_DAYS(CURRENT_DATE)
			GROUP BY a.is_ok
		]]>
	</select>

    <select id="getRiskErrorTop5" resultType="com.yeejoin.amos.fas.business.bo.SafetyExecuteBo">
		SELECT n.id,r.code,r.name as label,r.id as pointId,'risk' as type,n.create_date as changeDate
		FROM f_rpn_change_log n
		LEFT JOIN f_risk_source r ON r.id = n.risk_source_id
		WHERE n.type = 0
		AND (r.org_code = #{org_code} OR r.org_code like CONCAT(#{org_code},'-%'))
		ORDER BY n.create_date desc
		limit 0,5
	</select>

    <select id="getCheckErrorTop5" resultType="com.yeejoin.amos.fas.business.bo.SafetyExecuteBo">
		SELECT p.id,I.point_no as code,
			IF(p.is_ok = '2', CONCAT(I.name,' 不合格') ,CONCAT(I.name,' 漏检') ) as label,
			p.point_id,'patrol' as type,p.check_time as changeDate
		FROM p_check p
		left join p_point I ON I.id = p.point_id
		where p.is_ok IN ('2', '3')
			AND I.is_delete = 0
			AND (p.org_code = #{orgCode} OR p.org_code like CONCAT(#{orgCode},'-%') )
		ORDER BY p.check_time desc
		limit 0,5
	</select>

    <select id="getFireAlarmTop5" resultType="com.yeejoin.amos.fas.business.bo.SafetyExecuteBo">
			SELECT
			ala.id,
			ala.equipment_specific_id AS pointId,
			'monitorEquipment' AS type,
			spe. CODE,
			ala.equipment_specific_index_name,
			CONCAT(
				ala.equipment_specific_index_name,
				'(',
				ala.equipment_specific_name,
				')',

			IF (
				(
					ISNULL(ws.full_name)
					AND ISNULL(sd.description)
				),
				'',
				CONCAT(
					'【',
					IFNULL(ws.full_name, ''),
					' ',
					IFNULL(sd.description, ''),
					'】'
				)
			)
			) AS label,
			ala.create_date AS changeDate
		FROM
			wl_equipment_specific_alarm AS ala
		LEFT JOIN wl_equipment_specific AS spe ON ala.equipment_specific_id = spe.id
		LEFT JOIN wl_stock_detail sd ON sd.equipment_specific_id = spe.id
		LEFT JOIN wl_warehouse_structure ws ON ws.id = sd.warehouse_structure_id
		WHERE  ala.status = true
		AND	   (ala.org_code = #{orgCode} OR ala.org_code like CONCAT(#{orgCode},'-%'))
		AND    ala.type = 'FIREALARM'
		ORDER BY ala.create_date DESC
		limit 0,5
	</select>

    <select id="getEquipStatusTop5" resultType="com.yeejoin.amos.fas.business.bo.SafetyExecuteBo">
		SELECT
			wlesi.id,
			wlesi.`value` STATUS,
			wlesi.update_date changeDate,
			CONCAT(ed. NAME, ' ', wlei. NAME,IF((ISNULL(ws.full_name) AND ISNULL(sd.description)),'',CONCAT(
				'【',
				IFNULL(ws.full_name, ''),
				' ',
				IFNULL(sd.description, ''),
				'】'
			))) label
		FROM
			wl_equipment_specific_index wlesi
		LEFT JOIN wl_equipment_index wlei ON wlesi.equipment_index_id = wlei.id
		LEFT JOIN wl_equipment_specific wles ON wlesi.equipment_specific_id = wles.id
		LEFT JOIN wl_equipment_detail ed ON ed.id = wles.equipment_detail_id
		LEFT JOIN wl_stock_detail sd ON sd.equipment_specific_id = wles.id
		LEFT JOIN wl_warehouse_structure ws ON ws.id = sd.warehouse_structure_id
		WHERE
			wles.org_code = '10'
		AND wlei.type_code != 'BREAKDOWN'
		AND wlei.type_code != 'FIREALARM'
		AND (
			wlesi.`value` = 'true'
			OR wlesi.`value` = 'false'
		)
		ORDER BY
			wlesi.update_date DESC
		LIMIT 0,
		 5
	</select>

    <!--	<select id="getPintsByType" resultType="hashmap">-->
    <!--		select CONCAT(type,'-',id) as `key`,sp.* from-->
    <!--		(select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation ,'riskSource' as type,org_code as orgCode,-->
    <!--			null as relationKeys-->
    <!--			from f_risk_source where is_region = 'FALSE'-->
    <!--		UNION all-->
    <!--		select id,name,point_no as code,ue4_location as ue4Location,ue4_rotation as ue4Rotation ,'patrol' as type,org_code as orgCode,-->
    <!--			null as relationKeys-->
    <!--			from p_point WHERE is_delete = FALSE-->
    <!--		UNION all-->
    <!--		select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation ,'impEquipment' as type,org_code as orgCode,-->
    <!--			tmp.relationKeys-->
    <!--			from f_equipment e-->
    <!--			LEFT JOIN-->
    <!--				(select GROUP_CONCAT(fire_equipment_id)  as relationKeys,equipment_id from f_equipment_fire_equipment GROUP BY equipment_id) tmp-->
    <!--				ON TMP.equipment_id = e.id-->
    <!--		UNION all-->
    <!--		select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation ,'monitorEquipment' as type,org_code as orgCode,-->
    <!--			null as relationKeys-->
    <!--			from f_fire_equipment where  equip_classify = 0-->
    <!--		UNION all-->
    <!--		select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation ,'video' as type,org_code as orgCode,-->
    <!--			null as relationKeys-->
    <!--			from f_fire_equipment where  equip_classify = 2-->
    <!--		UNION all-->
    <!--		select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation ,'hydrant' as type,org_code as orgCode,-->
    <!--			null as relationKeys-->
    <!--			from f_water_resource  where type = 1-->
    <!--		UNION all-->
    <!--		select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,'pool' as type,org_code as orgCode,-->
    <!--			null as relationKeys-->
    <!--			from f_water_resource  where type = 2-->
    <!--		UNION all-->
    <!--		select id,name,car_num as code,ue4_location as ue4Location,ue4_rotation as ue4Rotation, 'fireCar' as type,org_code as orgCode,-->
    <!--			null as relationKeys-->
    <!--			from f_fire_car-->
    <!--		UNION all-->
    <!--		select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,'fireEquipment' as type,org_code as orgCode,-->
    <!--			null as relationKeys-->
    <!--			from f_fire_equipment where  equip_classify = 3-->
    <!--		UNION all-->
    <!--		select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation , 'fireChamber' as type,org_code as orgCode,-->
    <!--			null as relationKeys-->
    <!--			from f_fire_station where type = 2-->
    <!--		UNION all-->
    <!--		select id,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation  ,'fireFoamRoom' as type,org_code as orgCode,-->
    <!--			null as relationKeys-->
    <!--			from f_fire_station where type = 1-->
    <!--		) as sp-->
    <!--		where-->
    <!--		sp.orgCode = #{orgCode}-->
    <!--        <if test="type!=null">and sp.type =#{type}</if>-->
    <!--	</select>-->

    <!--	<select id="getImpEqu3dPoints" resultType="com.yeejoin.amos.fas.business.vo.View3dNodeVo">-->
    <!--		SELECT id,name,code,ue4_location,ue4_rotation,-->
    <!--		case-->
    <!--			when equip_classify= 0 then 'monitorEquipment'-->
    <!--			when equip_classify= 2 then 'video'-->
    <!--			when equip_classify= 3 then 'fireEquipment'-->
    <!--		end as type,-->
    <!--		case-->
    <!--			when equip_classify= 0 then 'monitorEquipment'-->
    <!--			when equip_classify= 2 then 'video'-->
    <!--			when equip_classify= 3 then 'fireEquipment'-->
    <!--		end as level,-->
    <!--			null as relationKeys,-->
    <!--			CASE-->
    <!--				WHEN (-->
    <!--					ISNULL(fe.position3d) || LENGTH(trim(fe.position3d)) <![CDATA[ <]]> 1-->
    <!--				) THEN-->
    <!--					NULL-->
    <!--				ELSE-->
    <!--					CONCAT(-->
    <!--						'{"x":',-->
    <!--						substring_index(fe.position3d, ',', 1),-->
    <!--						',"y":',-->
    <!--						substring_index(-->
    <!--							substring_index(fe.position3d, ',', - 2),-->
    <!--							',',-->
    <!--							1-->
    <!--						),-->
    <!--						',"z":',-->
    <!--						substring_index(fe.position3d, ',', - 1),-->
    <!--						'}'-->
    <!--					)-->
    <!--				END position,-->
    <!--				concat('monitorEquipment-',fe.id) as `key`-->
    <!--			FROM f_fire_equipment fe-->
    <!--			WHERE fe.id IN (-->
    <!--				select fire_equipment_id from f_equipment_fire_equipment-->
    <!--			) AND (org_code = #{orgCode} OR org_code LIKE CONCAT(#{orgCode},'-%'))-->
    <!--			AND fe.equip_classify <![CDATA[ <> ]]> 1-->
    <!--		UNION ALL-->
    <!--		SELECT e.id,e.name,e.code,e.ue4_location,e.ue4_rotation,'impEquipment' as type,'impEquipment' as level,-->
    <!--			TMP.relationKeys,-->
    <!--			CASE-->
    <!--				WHEN (-->
    <!--					ISNULL(e.position3d) || LENGTH(trim(e.position3d)) <![CDATA[ <]]> 1-->
    <!--				) THEN-->
    <!--					NULL-->
    <!--				ELSE-->
    <!--					CONCAT(-->
    <!--						'{"x":',-->
    <!--						substring_index(e.position3d, ',', 1),-->
    <!--						',"y":',-->
    <!--						substring_index(-->
    <!--							substring_index(e.position3d, ',', - 2),-->
    <!--							',',-->
    <!--							1-->
    <!--						),-->
    <!--						',"z":',-->
    <!--						substring_index(e.position3d, ',', - 1),-->
    <!--						'}'-->
    <!--					)-->
    <!--				END position,-->
    <!--				concat('impEquipment-',e.id) as `key`-->
    <!--			FROM f_equipment e-->
    <!--			LEFT JOIN-->
    <!--				(select GROUP_CONCAT(fire_equipment_id)  as relationKeys,equipment_id from f_equipment_fire_equipment GROUP BY equipment_id) tmp-->
    <!--				ON TMP.equipment_id = e.id-->
    <!--			WHERE e.org_code = #{orgCode} OR e.org_code like CONCAT(#{orgCode},'-%')-->
    <!--		UNION ALL-->
    <!--		SELECT id,name,code,ue4_location,ue4_rotation,-->
    <!--			case type-->
    <!--				when 1 then 'hydrant'-->
    <!--				when 2 then 'pool'-->
    <!--			end as type,-->
    <!--			case type-->
    <!--				when 1 then 'hydrant'-->
    <!--				when 2 then 'pool'-->
    <!--			end as level,-->
    <!--			null as relationKeys,-->
    <!--			CASE-->
    <!--				WHEN (-->
    <!--					ISNULL(position3d) || LENGTH(trim(position3d)) <![CDATA[ <]]> 1-->
    <!--				) THEN-->
    <!--					NULL-->
    <!--				ELSE-->
    <!--					CONCAT(-->
    <!--						'{"x":',-->
    <!--						substring_index(position3d, ',', 1),-->
    <!--						',"y":',-->
    <!--						substring_index(-->
    <!--							substring_index(position3d, ',', - 2),-->
    <!--							',',-->
    <!--							1-->
    <!--						),-->
    <!--						',"z":',-->
    <!--						substring_index(position3d, ',', - 1),-->
    <!--						'}'-->
    <!--					)-->
    <!--				END position,-->
    <!--				case type-->
    <!--					when 1 then concat('hydrant-',id)-->
    <!--					when 2 then concat('pool-',id)-->
    <!--				end as `key`-->
    <!--			FROM f_water_resource-->
    <!--			WHERE org_code = #{orgCode} OR org_code like CONCAT(#{orgCode},'-%')-->
    <!--		UNION ALL-->
    <!--		SELECT id,name,code,ue4_location,ue4_rotation,-->
    <!--		case-->
    <!--			when type = 1 then 'fireChamber'-->
    <!--			when type = 2 then 'fireFoamRoom'-->
    <!--		end as type,-->
    <!--		case-->
    <!--			when type = 1 then 'fireChamber'-->
    <!--			when type = 2 then 'fireFoamRoom'-->
    <!--		end as level,-->
    <!--			null as relationKeys,-->
    <!--			CASE-->
    <!--				WHEN (-->
    <!--					ISNULL(position3d) || LENGTH(trim(position3d)) <![CDATA[ <]]> 1-->
    <!--				) THEN-->
    <!--					NULL-->
    <!--				ELSE-->
    <!--					CONCAT(-->
    <!--						'{"x":',-->
    <!--						substring_index(position3d, ',', 1),-->
    <!--						',"y":',-->
    <!--						substring_index(-->
    <!--							substring_index(position3d, ',', - 2),-->
    <!--							',',-->
    <!--							1-->
    <!--						),-->
    <!--						',"z":',-->
    <!--						substring_index(position3d, ',', - 1),-->
    <!--						'}'-->
    <!--					)-->
    <!--				END position,-->
    <!--				concat('fireChamber-',id) as `key`-->
    <!--			FROM f_fire_station-->
    <!--			WHERE  org_code = #{orgCode} OR org_code LIKE CONCAT(#{orgCode},'-%')-->
    <!--		UNION ALL-->
    <!--		SELECT id,name,car_num as code,ue4_location,ue4_rotation,'fireCar' as type,'fireCar' as level,-->
    <!--			null as relationKeys,-->
    <!--			CASE-->
    <!--				WHEN (-->
    <!--					ISNULL(position3d) || LENGTH(trim(position3d)) <![CDATA[ <]]> 1-->
    <!--				) THEN-->
    <!--					NULL-->
    <!--				ELSE-->
    <!--					CONCAT(-->
    <!--						'{"x":',-->
    <!--						substring_index(position3d, ',', 1),-->
    <!--						',"y":',-->
    <!--						substring_index(-->
    <!--							substring_index(position3d, ',', - 2),-->
    <!--							',',-->
    <!--							1-->
    <!--						),-->
    <!--						',"z":',-->
    <!--						substring_index(position3d, ',', - 1),-->
    <!--						'}'-->
    <!--					)-->
    <!--				END position,-->
    <!--				concat('fireCar-',id) as `key`-->
    <!--			FROM f_fire_car-->
    <!--			WHERE org_code = #{orgCode} OR org_code LIKE CONCAT(#{orgCode},'-%')-->
    <!--	</select>-->

	<select id="initViewErrorNode" resultType="com.yeejoin.amos.fas.business.vo.View3dNodeVo">
		select * from (
			select
					R.id,R.name,R.code,R.ue4_location,R.ue4_rotation,
					'riskSource' as type,
					rl.level,
					CONCAT('level_',rl.level) as level_str,
					R.id as risk_source_id,
		            r.flicker_frequency as frequency,
		            true as 'showInfo',
					r.rpn as title
				from f_risk_source R ,f_risk_level rl
				where
				r.is_region <![CDATA[<>]]> 'TRUE'
				AND R.status = 'ANOMALY'
				AND rl.id = r.risk_level_id
				AND (R.org_code = #{orgCode} OR R.org_code like CONCAT(#{orgCode},'-%'))
			UNION ALL
			select
					p.id,p.name,p.point_no as code,p.ue4_location,p.ue4_rotation,
					'patrol' as type,
					p.status as level,
					CONCAT('level_',p.status) as level_str,
					p.risk_source_id,
		            0 as frequency,
		            case p.status
						when '0'
						then false
						else
						true
		            end as `showInfo`,
		            case p.status
						when '0'
						then '未计划'
						when '2'
						then '不合格'
						when '3'
						then '漏检'
		            end as title
				from p_point p
				where status in ('0','2','3')
				AND (p.org_code = #{orgCode} OR p.org_code like CONCAT(#{orgCode},'-%'))
			UNION ALL
				select
				distinct e.id,e.name,e.code,e.ue4_location,e.ue4_rotation,
				'impEquipment' as type,
				0 as level,
				'level_0' as kevek_str,
				e.risk_source_id,
				0 as frequency,
				false as 'showInfo',
				'' as title
				from
				f_equipment e
				left join f_equipment_fire_equipment efe ON e.id = efe.equipment_id
				left join wl_equipment_specific fe ON efe.fire_equipment_id = fe.id
				where   (e.org_code = #{orgCode} OR e.org_code like CONCAT(#{orgCode},'-%'))
		) tmp
			where 1=1
			<if test="riskSourceId != null">
			 	AND FIND_IN_SET(tmp.risk_source_id,queryRiskSourceChildrenIds(#{riskSourceId}))
			</if>
			<if test="type != null">
				AND tmp.type = #{type}
			</if>
	</select>

<!--	<select id="findViewDataByType" resultType="com.yeejoin.amos.fas.core.common.response.Node3DVoResponse">-->
<!--	SELECT-->
<!--			*-->
<!--		FROM-->
<!--			(-->
<!--				SELECT-->
<!--					rs.code,-->
<!--					rs.id,-->
<!--					rs.is_indoor inDoor,-->
<!--					CONCAT('riskSource-', rs.id) 'key',-->
<!--					rs.`name` label,-->
<!--					rl.`level` 'level',-->
<!--					CONCAT('level_', rl.`level`) levelStr,-->
<!--					CONCAT('floor_1', floor3d) objKey,-->
<!--					CASE-->
<!--				WHEN (-->
<!--					ISNULL(rs.position3d) || LENGTH(trim(rs.position3d)) <![CDATA[ <]]> 1-->
<!--				) THEN-->
<!--					NULL-->
<!--				ELSE-->
<!--					CONCAT(-->
<!--						'{"x":',-->
<!--						substring_index(rs.position3d, ',', 1),-->
<!--						',"y":',-->
<!--						substring_index(-->
<!--							substring_index(rs.position3d, ',', - 2),-->
<!--							',',-->
<!--							1-->
<!--						),-->
<!--						',"z":',-->
<!--						substring_index(rs.position3d, ',', - 1),-->
<!--						'}'-->
<!--					)-->
<!--				END positionDTO,-->
<!--				'{ "x": 0, "y": 0, "z": 0 }' rotationDTO,-->
<!--				'{ "x": 1, "y": 1, "z": 1 }' scaleDTO,-->
<!--				true as showInfo,-->
<!--				rs.rpn as title,-->
<!--				'riskSource' type,-->
<!--				rs.org_code as orgCode,-->
<!--				rs.id as riskSourceId,-->
<!--		        rs.flicker_frequency as frequency,-->
<!--		        if('NORMAL'=rs.status,FALSE,TRUE) as twinkle-->
<!--		FROM-->
<!--				f_risk_source rs-->
<!--			LEFT JOIN f_risk_level rl ON rl.id = rs.risk_level_id-->
<!--			WHERE-->
<!--				rs.position3d IS NOT NULL-->
<!--			AND rs.position3d != ''-->
<!--			AND rs.risk_level_id is not null-->
<!--			<if test="abnormalStatus != false">-->
<!--				AND rs.status = 'ANOMALY'-->
<!--			</if>-->
<!--			AND rs.is_region <![CDATA[<>]]> 'TRUE'-->
<!--			UNION ALL-->
<!--				SELECT-->
<!--					eq.code,-->
<!--					id,-->
<!--					is_indoor inDoor,-->
<!--					CONCAT('impEquipment-', id) 'key',-->
<!--					`name` label,-->
<!--					'0' LEVEL,-->
<!--					'level_0' levelStr,-->
<!--					CONCAT('floor_1', floor3d) objKey,-->
<!--					CASE-->
<!--				WHEN (-->
<!--					ISNULL(eq.position3d) || LENGTH(trim(eq.position3d))  <![CDATA[ <]]> 1-->
<!--				) THEN-->
<!--					NULL-->
<!--				ELSE-->
<!--					CONCAT(-->
<!--						'{"x":',-->
<!--						substring_index(eq.position3d, ',', 1),-->
<!--						',"y":',-->
<!--						substring_index(-->
<!--							substring_index(eq.position3d, ',', - 2),-->
<!--							',',-->
<!--							1-->
<!--						),-->
<!--						',"z":',-->
<!--						substring_index(eq.position3d, ',', - 1),-->
<!--						'}'-->
<!--					)-->
<!--				END positionDTO,-->
<!--				'{ "x": 0, "y": 0, "z": 0 }' rotationDTO,-->
<!--				'{ "x": 1, "y": 1, "z": 1 }' scaleDTO,-->
<!--				FALSE as showInfo,-->
<!--				name as title,-->
<!--				'impEquipment' type,-->
<!--				eq.org_code as orgCode,-->
<!--				eq.risk_source_id as riskSourceId,-->
<!--		        0 as frequency,-->
<!--		        FALSE as twinkle-->
<!--		FROM-->
<!--				f_equipment eq-->
<!--			WHERE-->
<!--				position3d IS NOT NULL-->
<!--				AND eq.risk_source_id in (select id from f_risk_source where is_region='TRUE')-->
<!--				AND position3d != ''-->
<!--				<if test="abnormalStatus != false">-->
<!--					AND eq.id in-->
<!--						(select equipment_id from f_equipment_fire_equipment fefe-->
<!--						left join f_fire_equipment fe ON fe.id = fefe.fire_equipment_id-->
<!--						where fe.equip_status = 1)-->
<!--				</if>-->
<!--			UNION ALL-->
<!--			select-->
<!--			p.point_no code,-->
<!--			p.id,-->
<!--			p.is_indoor as  inDoor,-->
<!--			CONCAT('patrol',p.id) as `key`,-->
<!--			p.name,-->
<!--			p.status as LEVEL,-->
<!--			CONCAT('level_',p.status) as levelStr,-->
<!--			CONCAT('floor',p.floor) as  objKey,-->
<!--			CASE-->
<!--				WHEN (-->
<!--					ISNULL(p.coordinates) || LENGTH(trim(p.coordinates))  <![CDATA[ <]]> 1-->
<!--				) THEN-->
<!--					NULL-->
<!--				ELSE-->
<!--					CONCAT(-->
<!--						'{"x":',-->
<!--						substring_index(p.coordinates, ',', 1),-->
<!--						',"y":',-->
<!--						substring_index(-->
<!--							substring_index(p.coordinates, ',', - 2),-->
<!--							',',-->
<!--							1-->
<!--						),-->
<!--						',"z":',-->
<!--						substring_index(p.coordinates, ',', - 1),-->
<!--						'}'-->
<!--					)-->
<!--				END positionDTO,-->
<!--				'{ "x": 0, "y": 0, "z": 0 }' rotationDTO,-->
<!--				'{ "x": 1, "y": 1, "z": 1 }' scaleDTO,-->
<!--				case p.status-->
<!--					when '0'-->
<!--					then false-->
<!--					else-->
<!--					true-->
<!--				end as `showInfo`,-->
<!--				p.name as title,-->
<!--				'patrol' as type,-->
<!--				p.org_code as orgCode,-->
<!--				p.risk_source_id as riskSourceId,-->
<!--				0 as frequency,-->
<!--				if(p.status > 1 ,TRUE,FALSE) as twinkle-->
<!--			from-->
<!--			p_point p-->
<!--			left join f_risk_source rs on p.risk_source_id = rs.id AND rs.is_region='TRUE'-->
<!--			where rs.id is not null-->
<!--				<if test="abnormalStatus != false">-->
<!--					AND p.status in ('0','2','3')-->
<!--				</if>-->
<!--				AND p.coordinates != '' AND p.coordinates is not null AND p.is_delete = 0-->
<!--			UNION ALL-->
<!--				select-->
<!--					fe.code,-->
<!--					fe.id,-->
<!--					fe.is_indoor as inDoor,-->
<!--					case-->
<!--						when fe.equip_classify = 0 then CONCAT('monitorEquipment',fe.id)-->
<!--						when fe.equip_classify = 3 then CONCAT('fireEquipment',fe.id)-->
<!--					end as `key`,-->
<!--					fe.name,-->
<!--					'' as LEVEL,-->
<!--					'' as levelStr,-->
<!--					CONCAT('floor',fe.floor3d) as objKey,-->
<!--					CASE-->
<!--					WHEN (-->
<!--						ISNULL(fe.position3d) || LENGTH(trim(fe.position3d))  <![CDATA[ <]]> 1-->
<!--					) THEN-->
<!--						NULL-->
<!--					ELSE-->
<!--						CONCAT(-->
<!--							'{"x":',-->
<!--							substring_index(fe.position3d, ',', 1),-->
<!--							',"y":',-->
<!--							substring_index(-->
<!--								substring_index(fe.position3d, ',', - 2),-->
<!--								',',-->
<!--								1-->
<!--							),-->
<!--							',"z":',-->
<!--							substring_index(fe.position3d, ',', - 1),-->
<!--							'}'-->
<!--						)-->
<!--					END positionDTO,-->
<!--					'{ "x": 0, "y": 0, "z": 0 }' rotationDTO,-->
<!--					'{ "x": 1, "y": 1, "z": 1 }' scaleDTO,-->
<!--					false as `showInfo`,-->
<!--					fe.name as title,-->
<!--					case-->
<!--						when fe.equip_classify = 0 then 'monitorEquipment'-->
<!--						when fe.equip_classify = 3 then 'fireEquipment'-->
<!--					end as type,-->
<!--					fe.org_code as orgCode,-->
<!--					fe.risk_source_id as riskSourceId,-->
<!--					0 as frequency,-->
<!--					false as twinkle-->
<!--				from-->
<!--				f_fire_equipment fe-->
<!--				left join f_risk_source rs on fe.risk_source_id = rs.id AND rs.is_region='TRUE'-->
<!--				where rs.id is not null-->
<!--					<if test="abnormalStatus != false">-->
<!--						AND fe.equip_status = 1-->
<!--					</if>-->
<!--					AND fe.equip_classify in (0,2,3)-->
<!--					AND fe.position3d != '' AND fe.position3d is not null-->
<!--				UNION ALL-->
<!--					select-->
<!--						c.car_num code,-->
<!--						c.id,-->
<!--						c.is_indoor as  inDoor,-->
<!--						CONCAT('fireCar',c.id) as `key`,-->
<!--						c.name,-->
<!--						'' as LEVEL,-->
<!--						'' as levelStr,-->
<!--						CONCAT('floor',c.floor3d) as objKey,-->
<!--						CASE-->
<!--							WHEN (-->
<!--								ISNULL(c.position3d) || LENGTH(trim(c.position3d))  <![CDATA[ <]]> 1-->
<!--							) THEN-->
<!--								NULL-->
<!--							ELSE-->
<!--								CONCAT(-->
<!--									'{"x":',-->
<!--									substring_index(c.position3d, ',', 1),-->
<!--									',"y":',-->
<!--									substring_index(-->
<!--										substring_index(c.position3d, ',', - 2),-->
<!--										',',-->
<!--										1-->
<!--									),-->
<!--									',"z":',-->
<!--									substring_index(c.position3d, ',', - 1),-->
<!--									'}'-->
<!--								)-->
<!--							END positionDTO,-->
<!--							'{ "x": 0, "y": 0, "z": 0 }' rotationDTO,-->
<!--							'{ "x": 1, "y": 1, "z": 1 }' scaleDTO,-->
<!--							false as `showInfo`,-->
<!--							c.name as title,-->
<!--							'fireCar' as type,-->
<!--							c.org_code as orgCode,-->
<!--							c.risk_source_id as riskSourceId,-->
<!--							0 as frequency,-->
<!--							false as twinkle-->
<!--					from f_fire_car c-->
<!--					left join f_risk_source rs on c.risk_source_id = rs.id AND rs.is_region='TRUE'-->
<!--					where  rs.id is not null-->
<!--						AND c.position3d != '' AND c.position3d is not null-->
<!--				UNION ALL-->
<!--					select-->
<!--						s.code,-->
<!--						s.id,-->
<!--						s.is_indoor as inDoor,-->
<!--						case-->
<!--							when S.type = 1 then CONCAT('fireChamber',s.id)-->
<!--							when S.type = 2 then CONCAT('fireFoamRoom',s.id)-->
<!--						end as `key`,-->
<!--						s.name,-->
<!--						'' as LEVEL,-->
<!--						'' as levelStr,-->
<!--						CONCAT('floor',s.floor3d) as objKey,-->
<!--						CASE-->
<!--						WHEN (-->
<!--							ISNULL(s.position3d) || LENGTH(trim(s.position3d))  <![CDATA[ <]]> 1-->
<!--						) THEN-->
<!--							NULL-->
<!--						ELSE-->
<!--							CONCAT(-->
<!--								'{"x":',-->
<!--								substring_index(s.position3d, ',', 1),-->
<!--								',"y":',-->
<!--								substring_index(-->
<!--									substring_index(s.position3d, ',', - 2),-->
<!--									',',-->
<!--									1-->
<!--								),-->
<!--								',"z":',-->
<!--								substring_index(s.position3d, ',', - 1),-->
<!--								'}'-->
<!--							)-->
<!--						END positionDTO,-->
<!--						'{ "x": 0, "y": 0, "z": 0 }' rotationDTO,-->
<!--						'{ "x": 1, "y": 1, "z": 1 }' scaleDTO,-->
<!--						false as `showInfo`,-->
<!--						s.name as title,-->
<!--						case-->
<!--							when S.type = 1 then 'fireChamber'-->
<!--							when S.type = 2 then 'fireFoamRoom'-->
<!--						end as type,-->
<!--						s.org_code as orgCode,-->
<!--						s.risk_source_id as riskSourceId,-->
<!--						0 as frequency,-->
<!--						false as twinkle-->
<!--					from-->
<!--						f_fire_station s-->
<!--					left join f_risk_source rs on s.risk_source_id = rs.id AND rs.is_region='TRUE'-->
<!--					where rs.id is not null-->
<!--						AND s.position3d != '' AND s.position3d is not null-->
<!--				UNION ALL-->
<!--		SELECT-->
<!--		wlv.CODE,-->
<!--		wlv.id,-->
<!--		'' AS inDoor,-->
<!--		CONCAT( 'video', wlv.id ) AS `key`,-->
<!--		wlv.NAME,-->
<!--		'' AS LEVEL,-->
<!--		'' AS levelStr,-->
<!--		'' AS objKey,-->
<!--		CONCAT(-->
<!--		'{"x":',-->
<!--		substring_index( wlv.position3d, ',', 1 ),-->
<!--		',"y":',-->
<!--		substring_index( substring_index( wlv.position3d, ',', - 2 ), ',', 1 ),-->
<!--		',"z":',-->
<!--		substring_index( wlv.position3d, ',', - 1 ),-->
<!--		'}'-->
<!--		)-->
<!--		as positionDTO,-->
<!--		'{ "x": 0, "y": 0, "z": 0 }' rotationDTO,-->
<!--		'{ "x": 1, "y": 1, "z": 1 }' scaleDTO,-->
<!--		FALSE AS `showInfo`,-->
<!--		wlv.NAME AS title,-->
<!--		'video' AS type,-->
<!--		wlv.org_code AS orgCode,-->
<!--		'' AS riskSourceId,-->
<!--		0 AS frequency,-->
<!--		FALSE AS twinkle-->
<!--		FROM-->
<!--		wl_video wlv-->
<!--		WHERE-->
<!--		wlv.position3d != ''-->
<!--		AND wlv.position3d IS NOT NULL-->
<!--		union all-->
<!--					select-->
<!--						w.code,-->
<!--						w.id,-->
<!--						w.is_indoor as inDoor,-->
<!--						case-->
<!--							when w.type = 1 then CONCAT('hydrant',w.id)-->
<!--							when w.type = 2 then CONCAT('pool',w.id)-->
<!--						end as `key`,-->
<!--						w.name,-->
<!--						'' as LEVEL,-->
<!--						'' as levelStr,-->
<!--						CONCAT('floor',w.floor3d) as objKey,-->
<!--						CASE-->
<!--						WHEN (-->
<!--							ISNULL(w.position3d) || LENGTH(trim(w.position3d))  <![CDATA[ <]]> 1-->
<!--						) THEN-->
<!--							NULL-->
<!--						ELSE-->
<!--							CONCAT(-->
<!--								'{"x":',-->
<!--								substring_index(w.position3d, ',', 1),-->
<!--								',"y":',-->
<!--								substring_index(-->
<!--									substring_index(w.position3d, ',', - 2),-->
<!--									',',-->
<!--									1-->
<!--								),-->
<!--								',"z":',-->
<!--								substring_index(w.position3d, ',', - 1),-->
<!--								'}'-->
<!--							)-->
<!--						END positionDTO,-->
<!--						'{ "x": 0, "y": 0, "z": 0 }' rotationDTO,-->
<!--						'{ "x": 1, "y": 1, "z": 1 }' scaleDTO,-->
<!--						false as `showInfo`,-->
<!--						w.name as title,-->
<!--						case-->
<!--							when w.type = 1 then 'hydrant'-->
<!--							when w.type = 2 then 'pool'-->
<!--						end as type,-->
<!--						w.org_code as orgCode,-->
<!--						w.risk_source_id as riskSourceId,-->
<!--						0 as frequency,-->
<!--						false as twinkle-->
<!--					from-->
<!--						f_water_resource w-->
<!--					left join f_risk_source rs on w.risk_source_id = rs.id AND rs.is_region='TRUE'-->
<!--					where rs.id is not null-->
<!--						AND w.position3d != '' AND w.position3d is not null-->
<!--			) temp-->
<!--				WHERE 1=1-->
<!--				<if test="riskSourceId != null">-->
<!--					AND FIND_IN_SET(temp.riskSourceId,queryRiskSourceChildrenIds(#{riskSourceId}))-->
<!--				</if>-->
<!--				<if test="type != null and type !='fireResource' and type !=''">-->
<!--					AND temp.type = #{type}-->
<!--				</if>-->
<!--				<if test="type == 'fireResource'">-->
<!--					AND temp.type in ('fireCar','fireEquipment','fireChamber','fireFoamRoom','hydrant','pool')-->
<!--				</if>-->
<!--				<if test="orgCode != null">-->
<!--					AND (temp.orgCode = #{orgCode} OR temp.orgCode LIKE CONCAT(#{orgCode},'-%'))-->
<!--				</if>-->
<!--	</select>-->


	<select id="retrieveAllCount" resultType="long">
		select count(1)
		from (
		select r.name,r.code,'riskSource' as typeCode,r.org_code as orgCode, r.id as riskSourceId
		from f_risk_source r
		left join f_risk_level rl ON rl.id = r.risk_level_id
		where r.is_region = 'FALSE'
		<if test="dataLevel != null and dataLevel != ''">
			AND rl.level = #{dataLevel}
		</if>
		UNION all
		select p.name,p.point_no as code,'patrol' as typeCode,p.org_code as orgCode, p.risk_source_id as riskSourceId
		from p_point p
		WHERE is_delete = FALSE
		UNION all
		select name,code,'impEquipment' as typeCode,org_code as orgCode, e.risk_source_id as riskSourceId
		from f_equipment e
		UNION all
		-- 消防车
		select
		car.name ,
		car_num as code,
		'fireEquipment' as typeCode,
		car.org_code as orgCode,
		#{riskSourceId} as riskSourceId
		from
		wl_car as car
		left join wl_equipment as equ on car.equipment_id = equ.id
		left join wl_equipment_category as cat on equ.category_id = cat.id
		-- 视频
		UNION all
		select
		vi.name,
		vi.code as code,
		'video' as typeCode,
		vi.org_code as orgCode,
		visou.source_id as risk_source_id
		from
		wl_video as vi
		left join wl_video_source as visou on vi.id = visou.video_id
		where visou.source_id is not null
		group by vi.id
		-- 建筑
		UNION all
		SELECT
		s.`name`,
		s.`code`,
		'fireEquipment' AS typeCode,
		s.orgCode,
		r.id AS risk_source_id
		FROM
		(
		SELECT
		a.instance_id AS instanceId,
		A.group_code AS groupCode,
		MAX(
		CASE
		WHEN a.field_name = 'name' THEN
		a.field_value
		END
		) AS NAME,
		MAX(
		CASE
		WHEN a.field_name = 'code' THEN
		a.field_value
		END
		) AS CODE,
		MAX(
		CASE
		WHEN a.field_name = 'orgCode' THEN
		a.field_value
		END
		) AS orgCode
		FROM
		`wl_form_instance` a
		WHERE
		a.group_code IN (
		'fireRoom',
		'r_fireRoom',
		'pool',
		'r_pool',
		'fireFoamRoom',
		'r_fireFoamRoom'
		)
		GROUP BY
		a.instance_id
		) s,
		f_risk_source r
		WHERE
		s.instanceId = r.source_id
		-- 探测器
		UNION all
		select
		det.name,
		spe.code as code,
		'monitorEquipment' as typeCode,
		spe.org_code as  orgCode,
		risk.id as risk_source_id
		from
		wl_equipment_specific as spe
		left join wl_equipment_detail as det on spe.equipment_detail_id = det.id
		left join wl_equipment as equ on det.equipment_id = equ.id
		left join wl_equipment_category as cat on equ.category_id = cat.id
		left join wl_stock_detail as sto on  sto.qr_code = spe.qr_code
		left join wl_warehouse_structure as str on sto.warehouse_structure_id = str.source_id
		left join f_risk_source as risk on str.source_id = risk.source_id
		where   substr(cat.code ,1,4) = 8501 and risk.source_id is not null
		<if test="protectObjName != null and protectObjName != ''">
			AND f.name = #{protectObjName}
		</if>
		-- 消火栓 灭火器
		UNION all
		select
		det.name,
		spe.code as code,
		'fireEquipment' as typeCode,
		spe.org_code as  orgCode,
		risk.id as risk_source_id
		from
		wl_equipment_specific as spe
		left join wl_equipment_detail as det on spe.equipment_detail_id = det.id
		left join wl_equipment as equ on det.equipment_id = equ.id
		left join wl_equipment_category as cat on equ.category_id = cat.id
		left join wl_stock_detail as sto on  sto.qr_code = spe.qr_code
		left join wl_warehouse_structure as str on sto.warehouse_structure_id = str.source_id
		left join f_risk_source as risk on str.source_id = risk.source_id
		where   substr(cat.code ,1,4) in (3104,3105) and risk.source_id is not null
		) as tmp
		where 1=1
		<if test="inputText!=null and inputText != ''" >
			AND (
			tmp.code LIKE '%${inputText}%'
			OR tmp.name LIKE '%${inputText}%'
			)
		</if>
		<if test="type!=null and type!=''">
			AND tmp.typeCode = #{type}
		</if>
		<if test="riskSourceId != null">
			AND tmp.riskSourceId = #{riskSourceId}
		</if>
		<if test="orgCode!=null">
			AND (tmp.orgCode = #{orgCode} OR tmp.orgCode like CONCAT(#{orgCode},'-%') )
		</if>
	</select>
	<select id="retrieveAll" resultType="java.util.HashMap">
		select *,'{ "x": 0, "y": 0, "z": 0 }' rotationDTO,'{ "x": 1, "y": 1, "z": 1 }' scaleDTO
		from (select concat('riskSource-',r.id) as id,concat(r.id) as originId,r.name,r.code,r.ue4_location as ue4Location,r.ue4_rotation as ue4Rotation ,'riskSource' as type,r.org_code as orgCode,
		rl.level as level,rl.name as levelStr,r.is_indoor as isIndoor,'风险点' as typeName,'riskSource' as typeCode,
		CASE
		WHEN (
		ISNULL(r.position3d) || LENGTH(trim(r.position3d))  <![CDATA[ <]]> 1
		) THEN
		NULL
		ELSE
		CONCAT(
		'{"x":',
		substring_index(r.position3d, ',', 1),
		',"y":',
		substring_index(
		substring_index(r.position3d, ',', - 2),
		',',
		1
		),
		',"z":',
		substring_index(r.position3d, ',', - 1),
		'}'
		)
		END positionDTO,
		r.name as label,
		r.name as protectObjName,
		'' as routeName,
		'' as person,
		r.rpn as title,
		CONCAT('riskSource-',r.id) as `key`,
		r.id as riskSourceId,
		'' as room
		from f_risk_source r
		left join f_risk_level rl ON rl.id = r.risk_level_id
		where r.is_region = 'FALSE'
		<if test="dataLevel != null and dataLevel != ''">
			AND rl.level = #{dataLevel}
		</if>
		UNION all
		select concat('patrol-',p.id) as id,concat(p.id) as originId,p.name,p.point_no as code,p.ue4_location as ue4Location,p.ue4_rotation as ue4Rotation ,'patrol' as type,p.org_code as orgCode,
		p.status as level,CONCAT('level_',p.status) as levelStr,p.is_indoor as isIndoor,'巡检点' as typeName,'patrol' as typeCode,
		CASE
		WHEN (
		ISNULL(p.coordinates) || LENGTH(trim(p.coordinates))  <![CDATA[ <]]> 1
		) THEN
		NULL
		ELSE
		CONCAT(
		'{"x":',
		substring_index(p.coordinates, ',', 1),
		',"y":',
		substring_index(
		substring_index(p.coordinates, ',', - 2),
		',',
		1
		),
		',"z":',
		substring_index(p.coordinates, ',', - 1),
		'}'
		)
		END positionDTO,
		p.name as label,
		p.name as protectObjName,
		p.route_name as routeName,
		p.charge_person_id as person,
		case
		when p.status = '0' then '未执行'
		when p.status = '1' then '合格'
		when p.status = '2' then '不合格'
		when p.status = '3' then '漏检'
		end as title,
		concat('patrol-',p.id) as `key`,
		p.risk_source_id as riskSourceId,
		r.name as room
		from p_point p
		left join f_risk_source r on r.id = p.risk_source_id
		WHERE is_delete = FALSE
		UNION all
		select concat('impEquipment-',e.id) as id,concat(e.id) as originId,e.name,e.code,e.ue4_location as ue4Location,e.ue4_rotation as ue4Rotation ,'impEquipment' as type,e.org_code as orgCode,
		0 as level,'level_0' as levelStr,e.is_indoor as isIndoor,'重点设备' as typeName,'impEquipment' as typeCode,
		CASE
		WHEN (
		ISNULL(e.position3d) || LENGTH(trim(e.position3d))  <![CDATA[ <]]> 1
		) THEN
		NULL
		ELSE
		CONCAT(
		'{"x":',
		substring_index(e.position3d, ',', 1),
		',"y":',
		substring_index(
		substring_index(e.position3d, ',', - 2),
		',',
		1
		),
		',"z":',
		substring_index(e.position3d, ',', - 1),
		'}'
		)
		END positionDTO,
		e.name as label,
		e.name as protectObjName,
		'' as routeName,
		'' as person,
		e.name as title,
		concat('impEquipment-',e.id) as `key`,
		e.risk_source_id as riskSourceId,
		r.name as room
		from f_equipment e
		left join f_risk_source r on r.id = e.risk_source_id
		UNION all
		select concat('monitorEquipment-',m.id) as id,concat(m.id) as originId,det.name,m.code as code,'' as ue4Location,'' as ue4Rotation ,'monitorEquipment' as type,m.org_code as orgCode,
		null as level , concat('level_',null) as levelStr,null as isIndoor,'探测器' as typeName,'monitorEquipment' as typeCode,
		CASE
		WHEN (
		ISNULL(null) || LENGTH(trim(null))  <![CDATA[ <]]> 1
		) THEN
		NULL
		ELSE
		CONCAT(
		'{"x":',
		substring_index(null, ',', 1),
		',"y":',
		substring_index(
		substring_index(null, ',', - 2),
		',',
		1
		),
		',"z":',
		substring_index(null, ',', - 1),
		'}'
		)
		END positionDTO,
		det.name as label,
		IFNULL(group_concat(f.name),'') as protectObjName,
		'' as routeName,
		'' as person,
		det.name as title,
		concat('monitorEquipment-',m.id) as `key`,
		risk.id as riskSourceId,
		str.full_name as room
		from wl_equipment_specific  m
		left join wl_equipment_detail as det on m.equipment_detail_id = det.id
		left join wl_equipment as equ on det.equipment_id = equ.id
		left join wl_equipment_category as cat on equ.category_id = cat.id
		left join wl_stock_detail as sto on  sto.qr_code = m.qr_code
		left join wl_warehouse_structure as str on sto.warehouse_structure_id = str.source_id
		left join f_risk_source as risk on str.source_id = risk.source_id
		left join f_equipment_fire_equipment fe on fe.fire_equipment_id = m.id
		left join f_equipment f on f.id = fe.equipment_id
		where   substr(cat.code ,1,4) = '8501'
		<if test="protectObjName != null and protectObjName != ''">
			AND f.name = #{protectObjName}
		</if>
		group By m.code
		UNION all
		select concat('video-',vi.id) as id,concat(vi.id) as originId,vi.name,vi.code,null as ue4Location,null as ue4Rotation ,'video' as type,vi.org_code as orgCode,
		null as level , concat('level_',null) as levelStr,null as isIndoor,'摄像头' as typeName,'video' as typeCode,
		CASE
		WHEN (
		ISNULL(null) || LENGTH(trim(null))    <![CDATA[ <]]>  1
		) THEN
		NULL
		ELSE
		CONCAT(
		'{"x":',
		substring_index(null, ',', 1),
		',"y":',
		substring_index(
		substring_index(null, ',', - 2),
		',',
		1
		),
		',"z":',
		substring_index(null, ',', - 1),
		'}'
		)
		END positionDTO,
		vi.name as label,
		ws.name as protectObjName,
		'' as routeName,
		'' as person,
		vi.name as title,
		concat('video-',vi.id) as `key`,
		vis.source_id as riskSourceId,
		CONCAT(ws.full_name,vi.address) AS room
		from wl_video as vi
		left join wl_video_source as vis on vi.id = vis.video_id
		LEFT JOIN wl_warehouse_structure AS ws ON ws.id = vis.source_id
		where vis.source_id is not null
		group by vi.id
		UNION all
		select concat('hydrant-',spe.id) as id,concat(spe.id) as originId,det.name,spe.code as code,null as ue4Location,null as ue4Rotation ,'hydrant' as type,spe.org_code as orgCode,
		0 as level , 'level_0' as levelStr,null as isIndoor,'消防栓' as typeName,'fireEquipment' as typeCode,
		CASE
		WHEN (
		ISNULL(null ) || LENGTH(trim(null ))  <![CDATA[ <]]>  1
		) THEN
		NULL
		ELSE
		CONCAT(
		'{"x":',
		substring_index(null, ',', 1),
		',"y":',
		substring_index(
		substring_index(null, ',', - 2),
		',',
		1
		),
		',"z":',
		substring_index(null, ',', - 1),
		'}'
		)
		END positionDTO,
		det.name as label,
		det.name as protectObjName,
		'' as routeName,
		'' as person,
		det.name as title,
		concat('hydrant-',spe.id) as `key`,
		str.source_id as riskSourceId,
		str.full_name as room
		from
		wl_equipment_specific as spe
		left join wl_equipment_detail as det on spe.equipment_detail_id = det.id
		left join wl_equipment as equ on det.equipment_id = equ.id
		left join wl_equipment_category as cat on equ.category_id = cat.id
		left join wl_stock_detail as sto on  sto.qr_code = spe.qr_code
		left join wl_warehouse_structure as str on sto.warehouse_structure_id = str.source_id
		where   substr(cat.code ,1,4)= '3105' and str.source_id is not null
		UNION all
		select
		concat('pool-',s.instanceId) as id,
		concat(s.instanceId) as originId,s.name,s.code,null as ue4Location,null as ue4Rotation,'pool' as type,s.orgCode,
		0 as level , 'level_0' as levelStr,null as isIndoor,'消防水池' as typeName,'fireEquipment' as typeCode,
		null as positionDTO,
		s.name as label,
		s.name as protectObjName,
		'' as routeName,
		'' as person,
		s.name as title,
		concat('pool-',s.instanceId) as `key`,
		r.id as riskSourceId,
		s.address as room
		from (SELECT
		a.instance_id AS instanceId,
		A.group_code AS groupCode,
		MAX(
		CASE
		WHEN a.field_name = 'name' THEN
		a.field_value
		END
		) AS name,
		MAX(
		CASE
		WHEN a.field_name = 'code' THEN
		a.field_value
		END
		) AS code,
		MAX(
		CASE
		WHEN a.field_name = 'address' THEN
		a.field_value
		END
		) AS address,
		MAX(
		CASE
		WHEN a.field_name = 'orgCode' THEN
		a.field_value
		END
		) AS orgCode
		FROM
		`wl_form_instance` a where a.group_code in('pool','r_pool')
		GROUP BY
		a.instance_id) s
		LEFT JOIN f_risk_source r ON s.instanceId = r.source_id
		UNION all
		select concat('fireCar-',car.id) as id,concat(car.id) as originId,car.name,car.car_num as code,null as ue4Location,null as ue4Rotation, 'fireCar' as type,car.org_code as orgCode,
		0 as level , 'level_0' as levelStr,null as isIndoor,'消防车' as typeName,'fireEquipment' as typeCode,
		CASE
		WHEN (
		ISNULL(null) || LENGTH(trim(null))   <![CDATA[ <]]>  1
		) THEN
		NULL
		ELSE
		CONCAT(
		'{"x":',
		substring_index(null, ',', 1),
		',"y":',
		substring_index(
		substring_index(null, ',', - 2),
		',',
		1
		),
		',"z":',
		substring_index(null, ',', - 1),
		'}'
		)
		END positionDTO,
		car.name as label,
		car.name as protectObjName,
		'' as routeName,
		'' as person,
		car.name as title,
		concat('fireCar-',car.id) as `key`,
		#{riskSourceId} as riskSourceId,
		'' as room
		from wl_car as car
		left join wl_equipment as equ on car.equipment_id = equ.id
		left join wl_equipment_category as cat on equ.category_id = cat.id
		UNION all
		select concat('extinguisher-',spe.id) as id,concat(spe.id) as originId,det.name,spe.code  as code,null as ue4Location,null as ue4Rotation,'extinguisher' as type,spe.org_code as orgCode,
		null as level , concat('level_',null) as levelStr,null as isIndoor,'灭火器' as typeName,'fireEquipment' as typeCode,
		CASE
		WHEN (
		ISNULL(null) || LENGTH(trim(null))  <![CDATA[ <]]>  1
		) THEN
		NULL
		ELSE
		CONCAT(
		'{"x":',
		substring_index(null, ',', 1),
		',"y":',
		substring_index(
		substring_index(null, ',', - 2),
		',',
		1
		),
		',"z":',
		substring_index(null, ',', - 1),
		'}'
		)
		END positionDTO,
		det.name as label,
		det.name as protectObjName,
		'' as routeName,
		'' as person,
		det.name as title,
		concat('extinguisher-',spe.id) as `key`,
		risk.id as riskSourceId,
		str.full_name as room
		from wl_equipment_specific as spe
		left join wl_equipment_detail as det on spe.equipment_detail_id = det.id
		left join wl_equipment as equ on det.equipment_id = equ.id
		left join wl_equipment_category as cat on equ.category_id = cat.id
		left join wl_stock_detail as sto on  sto.qr_code = spe.qr_code
		left join wl_warehouse_structure as str on sto.warehouse_structure_id = str.source_id
		left join f_risk_source as risk on str.source_id = risk.source_id
		where   substr(cat.code ,1,4) = '3104' and risk.source_id is not null
		UNION all
		select
		concat('fireChamber-',s.instanceId) as id,
		concat(s.instanceId) as originId,s.name,s.code,null as ue4Location,null as ue4Rotation,'fireChamber' as type,s.orgCode,
		0 as level , 'level_0' as levelStr,null as isIndoor,'泡沫间' as typeName,'fireEquipment' as typeCode,
		null as positionDTO,
		s.name as label,
		s.name as protectObjName,
		'' as routeName,
		'' as person,
		s.name as title,
		concat('fireChamber-',s.instanceId) as `key`,
		r.id as riskSourceId,
		s.address as room
		from (SELECT
		a.instance_id AS instanceId,
		A.group_code AS groupCode,
		MAX(
		CASE
		WHEN a.field_name = 'name' THEN
		a.field_value
		END
		) AS name,
		MAX(
		CASE
		WHEN a.field_name = 'code' THEN
		a.field_value
		END
		) AS code,
		MAX(
		CASE
		WHEN a.field_name = 'address' THEN
		a.field_value
		END
		) AS address,
		MAX(
		CASE
		WHEN a.field_name = 'orgCode' THEN
		a.field_value
		END
		) AS orgCode
		FROM
		`wl_form_instance` a where a.group_code in('fireFoamRoom','r_fireFoamRoom')
		GROUP BY
		a.instance_id) s,
		f_risk_source r
		where s.instanceId = r.source_id
		UNION all
		select
		concat('fireFoamRoom-',s.instanceId) as id,
		concat(s.instanceId) as originId,s.name,s.code,null as ue4Location,null as ue4Rotation,'fireFoamRoom' as type,s.orgCode,
		0 as level , 'level_0' as levelStr,null as isIndoor,'消防室' as typeName,'fireEquipment' as typeCode,
		null as positionDTO,
		s.name as label,
		s.name as protectObjName,
		'' as routeName,
		'' as person,
		s.name as title,
		concat('fireFoamRoom-',s.instanceId) as `key`,
		r.id as riskSourceId,
		s.address as room
		from (SELECT
		a.instance_id AS instanceId,
		A.group_code AS groupCode,
		MAX(
		CASE
		WHEN a.field_name = 'name' THEN
		a.field_value
		END
		) AS name,
		MAX(
		CASE
		WHEN a.field_name = 'code' THEN
		a.field_value
		END
		) AS code,
		MAX(
		CASE
		WHEN a.field_name = 'address' THEN
		a.field_value
		END
		) AS address,
		MAX(
		CASE
		WHEN a.field_name = 'orgCode' THEN
		a.field_value
		END
		) AS orgCode

        FROM
        `wl_form_instance` a where a.group_code in('fireRoom','r_fireRoom')
        GROUP BY
        a.instance_id) s,
        f_risk_source r
        where s.instanceId = r.source_id
        ) as tmp
        <where>
            <if test="inputText!=null and inputText != ''">
                AND (
                tmp.code LIKE '%${inputText}%'
                OR tmp.name LIKE '%${inputText}%'
                )
            </if>
            <if test="type!=null and type!=''">
                AND tmp.typeCode = #{type}
            </if>
            <if test="riskSourceId != null">
                AND tmp.riskSourceId = #{riskSourceId}
            </if>
            <if test="orgCode!=null">
                AND (tmp.orgCode = #{orgCode} OR tmp.orgCode like CONCAT(#{orgCode},'-%') )
            </if>
        </where>
        LIMIT ${start},${length}
    </select>
    <select id="retrieve3AllCount" resultType="long">
        SELECT COUNT(1) FROM (
        SELECT
        concat( 'riskSource-', r.id ) AS id,
        concat( r.id ) AS originId,
        r.NAME,
        r.CODE,
        'riskSource' AS type,
        r.org_code as orgCode,
        rl.LEVEL AS LEVEL,
        rl.NAME AS levelStr,
        r.is_indoor AS isIndoor,
        '风险点' AS typeName,
        'riskSource' AS typeCode,
        r.NAME AS label,
        '' AS routeName,
        '' AS person,
        r.rpn AS title,
        CONCAT( 'riskSource-', r.id ) AS `key`,
        r.id AS riskSourceId,
        null AS areaId,
        '' AS room
        FROM
        f_risk_source r
        LEFT JOIN f_risk_level rl ON rl.id = r.risk_level_id
        WHERE
        r.is_region = 'FALSE'
        <if test="dataLevel != null and dataLevel != ''">
            AND rl.level = #{dataLevel}
        </if>
        UNION ALL
        SELECT
        concat( 'patrol-', p.id ) AS id,
        concat( p.id ) AS originId,
        p.NAME,
        p.point_no AS CODE,
        'patrol' AS type,
        p.org_code as orgCode,
        p.STATUS AS LEVEL,
        CONCAT( 'level_', p.STATUS ) AS levelStr,
        p.is_indoor AS isIndoor,
        '巡检点' AS typeName,
        'patrol' AS typeCode,
        p.NAME AS label,
        p.route_name AS routeName,
        p.charge_person_id AS person,
        CASE

        WHEN p.STATUS = '0' THEN
        '未执行'
        WHEN p.STATUS = '1' THEN
        '合格'
        WHEN p.STATUS = '2' THEN
        '不合格'
        WHEN p.STATUS = '3' THEN
        '漏检'
        END AS title,
        concat( 'patrol-', p.id ) AS `key`,
        p.risk_source_id AS riskSourceId,
        p.area_id AS areaId,
        r.NAME AS room
        FROM
        p_point p
        LEFT JOIN f_risk_source r ON r.id = p.risk_source_id
        <where>
            is_delete = FALSE
            <if test="areaId != null">
                AND p.area_id = #{areaId}
            </if>
        </where>
        UNION ALL
        SELECT
        concat( 'fireEquipment-', m.id ) AS id,
        concat( m.id ) AS originId,
        det.NAME,
        m.CODE AS CODE,
        'fireEquipment' AS type,
        m.org_code as orgCode,
        NULL AS LEVEL,
        concat( 'level_', NULL ) AS levelStr,
        NULL AS isIndoor,
        '消防设备' AS typeName,
        'fireEquipment' AS typeCode,
        det.NAME AS label,
        '' AS routeName,
        '' AS person,
        det.NAME AS title,
        concat( 'fireEquipment-', m.id ) AS `key`,
        risk.id AS riskSourceId,
        m.area_id AS areaId,
        str.full_name AS room
        FROM
        wl_equipment_specific m
        LEFT JOIN wl_equipment_detail AS det ON m.equipment_detail_id = det.id
        LEFT JOIN wl_equipment AS equ ON det.equipment_id = equ.id
        LEFT JOIN wl_equipment_category AS cat ON equ.category_id = cat.id
        LEFT JOIN wl_stock_detail AS sto ON sto.qr_code = m.qr_code
        LEFT JOIN wl_warehouse_structure AS str ON sto.warehouse_structure_id = str.source_id
        LEFT JOIN f_risk_source AS risk ON str.source_id = risk.source_id
        <where>
            <if test="areaId != null">
                m.area_id = #{areaId}
            </if>
            <if test="equipmentId != null">
                AND equ.id = #{equipmentId}
            </if>
        </where>
        GROUP BY
        m.CODE) as tmp
        <where>
            <if test="inputText!=null and inputText != ''">
                AND (
                tmp.code LIKE '%${inputText}%'
                OR tmp.name LIKE '%${inputText}%'
                )
            </if>
            <if test="type!=null and type!=''">
                AND tmp.typeCode = #{type}
            </if>
            <if test="riskSourceId != null">
                AND tmp.riskSourceId = #{riskSourceId}
            </if>
            <if test="orgCode!=null">
                AND (tmp.orgCode = #{orgCode} OR tmp.orgCode like CONCAT(#{orgCode},'-%') )
            </if>
        </where>
    </select>
    <select id="retrieve3All" resultType="java.util.HashMap">
        SELECT * FROM (
        SELECT
        concat( 'riskSource-', r.id ) AS id,
        concat( r.id ) AS originId,
        r.NAME,
        r.CODE,
        'riskSource' AS type,
        r.org_code as orgCode,
        rl.LEVEL AS LEVEL,
        rl.NAME AS levelStr,
        r.is_indoor AS isIndoor,
        '风险点' AS typeName,
        'riskSource' AS typeCode,
        r.NAME AS label,
        '' AS routeName,
        '' AS person,
        r.rpn AS title,
        CONCAT( 'riskSource-', r.id ) AS `key`,
        r.id AS riskSourceId,
        null AS areaId,
        '' AS room
        FROM
        f_risk_source r
        LEFT JOIN f_risk_level rl ON rl.id = r.risk_level_id
        WHERE
        r.is_region = 'FALSE'
        <if test="dataLevel != null and dataLevel != ''">
            AND rl.level = #{dataLevel}
        </if>
        UNION ALL
        SELECT
        concat( 'patrol-', p.id ) AS id,
        concat( p.id ) AS originId,
        p.NAME,
        p.point_no AS CODE,
        'patrol' AS type,
        p.org_code as orgCode,
        p.STATUS AS LEVEL,
        CONCAT( 'level_', p.STATUS ) AS levelStr,
        p.is_indoor AS isIndoor,
        '巡检点' AS typeName,
        'patrol' AS typeCode,
        p.NAME AS label,
        p.route_name AS routeName,
        p.charge_person_id AS person,
        CASE

        WHEN p.STATUS = '0' THEN
        '未执行'
        WHEN p.STATUS = '1' THEN
        '合格'
        WHEN p.STATUS = '2' THEN
        '不合格'
        WHEN p.STATUS = '3' THEN
        '漏检'
        END AS title,
        concat( 'patrol-', p.id ) AS `key`,
        p.risk_source_id AS riskSourceId,
        p.area_id AS areaId,
        r.NAME AS room
        FROM
        p_point p
        LEFT JOIN f_risk_source r ON r.id = p.risk_source_id
        <where>
            is_delete = FALSE
            <if test="areaId != null">
                AND p.area_id = #{areaId}
            </if>
        </where>
        UNION ALL
        SELECT
        concat( 'fireEquipment-', m.id ) AS id,
        concat( m.id ) AS originId,
        det.NAME,
        m.CODE AS CODE,
        'fireEquipment' AS type,
        m.org_code as orgCode,
        NULL AS LEVEL,
        concat( 'level_', NULL ) AS levelStr,
        NULL AS isIndoor,
        '消防设备' AS typeName,
        'fireEquipment' AS typeCode,
        det.NAME AS label,
        '' AS routeName,
        '' AS person,
        det.NAME AS title,
        concat( 'fireEquipment-', m.id ) AS `key`,
        risk.id AS riskSourceId,
        m.area_id AS areaId,
        str.full_name AS room
        FROM
        wl_equipment_specific m
        LEFT JOIN wl_equipment_detail AS det ON m.equipment_detail_id = det.id
        LEFT JOIN wl_equipment AS equ ON det.equipment_id = equ.id
        LEFT JOIN wl_equipment_category AS cat ON equ.category_id = cat.id
        LEFT JOIN wl_stock_detail AS sto ON sto.qr_code = m.qr_code
        LEFT JOIN wl_warehouse_structure AS str ON sto.warehouse_structure_id = str.source_id
        LEFT JOIN f_risk_source AS risk ON str.source_id = risk.source_id
        <where>
            <if test="areaId != null">
                m.area_id = #{areaId}
            </if>
            <if test="equipmentId != null">
                AND equ.id = #{equipmentId}
            </if>
        </where>
        GROUP BY
        m.CODE) as tmp
        <where>
            <if test="inputText!=null and inputText != ''">
                AND (
                tmp.code LIKE '%${inputText}%'
                OR tmp.name LIKE '%${inputText}%'
                )
            </if>
            <if test="type!=null and type!=''">
                AND tmp.typeCode = #{type}
            </if>
            <if test="riskSourceId != null">
                AND tmp.riskSourceId = #{riskSourceId}
            </if>
            <if test="orgCode!=null">
                AND (tmp.orgCode = #{orgCode} OR tmp.orgCode like CONCAT(#{orgCode},'-%') )
            </if>
        </where>
        LIMIT ${start},${length}
    </select>
    <!--	<select id="getAllPointInRegions" resultType="java.util.Map">-->
    <!--		select-->
    <!--		CONCAT(type,'-',id) as `key`,-->
    <!--		id as pointId,-->
    <!--		name,-->
    <!--		type,-->
    <!--		risk_source_id as regionId,-->
    <!--		position3d-->
    <!--		from-->
    <!--		(select id,name,'riskSource' as type, parent_id as risk_source_id,position3d-->
    <!--		from f_risk_source where is_region = 'FALSE'-->
    <!--		UNION all-->
    <!--		select id,name,'patrol' as type,risk_source_id,coordinates as position3d-->
    <!--		from p_point WHERE is_delete = FALSE-->
    <!--		UNION all-->
    <!--		select id,name ,'impEquipment' as type,risk_source_id,position3d-->
    <!--		from f_equipment e-->
    <!--		UNION all-->
    <!--		select id,name,'monitorEquipment' as type,risk_source_id,position3d-->
    <!--		from f_fire_equipment where  equip_classify = 0-->
    <!--		UNION all-->
    <!--		select id,name,'video' as type,risk_source_id,position3d-->
    <!--		from f_fire_equipment where  equip_classify = 2-->
    <!--		UNION all-->
    <!--		select id,name ,'hydrant' as type,risk_source_id,position3d-->
    <!--		from f_water_resource  where type = 1-->
    <!--		UNION all-->
    <!--		select id,name,'pool' as type,risk_source_id,position3d-->
    <!--		from f_water_resource  where type = 2-->
    <!--		UNION all-->
    <!--		select id,name,'fireCar' as type,risk_source_id,position3d-->
    <!--		from f_fire_car-->
    <!--		UNION all-->
    <!--		select id,name,'fireEquipment' as type,risk_source_id,position3d-->
    <!--		from f_fire_equipment where  equip_classify = 3-->
    <!--		UNION all-->
    <!--		select id,name,'fireChamber' as type,risk_source_id,position3d-->
    <!--		from f_fire_station where type = 2-->
    <!--		UNION all-->
    <!--		select id,name,'fireFoamRoom' as type,risk_source_id,position3d-->
    <!--		from f_fire_station where type = 1-->
    <!--		) as sp-->
    <!--		where-->
    <!--		position3d  <![CDATA[<>]]> '' and-->
    <!--		risk_source_id in-->
    <!--		<foreach collection="ids" open="(" separator="," close=")" item="id">-->
    <!--			#{id}-->
    <!--		</foreach>-->
    <!--		order by regionId-->
    <!--	</select>-->
</mapper>