<?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.FireStationMapper">


<!--	<select id="queryOne" resultType="java.util.Map">-->
<!--		SELECT-->
<!--		    fs.id,-->
<!--		    fs.name,-->
<!--		    fs.code,-->
<!--		    fs.type,-->
<!--		    fs.address,-->
<!--		    fs.floor3d,-->
<!--		    fs.position3d,-->
<!--		    fs.is_indoor AS isIndoor,-->
<!--		    fs.picture,-->
<!--		    fs.risk_source_id as riskSourceId-->
<!--		FROM-->
<!--		    f_fire_station fs-->
<!--		WHERE-->
<!--		    fs.id = ${id}-->
<!--	</select>-->


<!--	<select id="queryCountForFireEqumntPage" resultType="long">-->
<!--		SELECT-->
<!--				count(1)-->
<!--			FROM-->
<!--				f_fire_station_equipment fs-->
<!--			JOIN f_fire_equipment f ON fs.fire_equipment_id = f.id-->
<!--			WHERE-->
<!--				fs.fire_station_id = ${fireStationId}-->
<!--	</select>-->
<!--	<select id="queryForFireEqumntPage" resultType="java.util.Map">-->
<!--			SELECT-->
<!--				fs.fire_station_id,-->
<!--				fs.number numberInStation,-->
<!--				fs.unit unitInStation,-->
<!--				f.*,-->
<!--				frs.name riskSourceName-->
<!--			FROM-->
<!--				f_fire_station_equipment fs-->
<!--			left join f_fire_equipment f ON fs.fire_equipment_id = f.id-->
<!--			left join f_risk_source frs on frs.id = f.risk_source_id-->
<!--			WHERE-->
<!--				fs.fire_station_id = ${fireStationId}-->
<!--				and f.id is not null-->
<!--			LIMIT ${start}, ${length};-->
<!--	</select>-->

<!--	<select id="queryCountForPage" resultType="long">-->

<!--		SELECT-->
<!--		COUNT(1)-->
<!--		FROM-->
<!--		f_fire_station fs-->
<!--		WHERE-->
<!--		1=1-->
<!--		<if test="name!=null">-->
<!--			AND (fs.name LIKE '%${name}%' or fs.`code` LIKE '%${name}%')-->
<!--		</if>-->
<!--		<if test="code!=null">-->
<!--			AND fs.`code` LIKE '%${code}%'-->
<!--		</if>-->
<!--		<if test="type!=null">-->
<!--			AND fs.`type` LIKE '%${type}%';-->
<!--		</if>-->
<!--	</select>-->
<!--	<select id="queryForPage" resultType="java.util.Map">-->
<!--		SELECT-->
<!--		fs.id,-->
<!--		fs.name,-->
<!--		fs.code,-->
<!--		fs.type,-->
<!--		fs.address,-->
<!--		fs.floor3d,-->
<!--		fs.position3d,-->
<!--		fs.is_indoor as isIndoor,-->
<!--		frs.name riskSourceName-->
<!--		FROM-->
<!--		f_fire_station fs-->
<!--		left join f_risk_source frs on frs.id = fs.risk_source_id-->
<!--		WHERE-->
<!--		1=1-->

<!--		<if test="name!=null">-->
<!--			AND (fs.name LIKE '%${name}%' or fs.`code` LIKE '%${name}%')-->
<!--		</if>-->
<!--		<if test="code!=null">-->
<!--			AND fs.`code` LIKE '%${code}%'-->
<!--		</if>-->
<!--		<if test="type!=null">-->
<!--			AND fs.`type` LIKE '%${type}%'-->
<!--		</if>-->
<!--		LIMIT ${start},${length} ;-->

<!--	</select>-->


	<select id="queryForList" resultType="java.util.Map">
		SELECT
		*
		FROM
		(
		SELECT
		a.instance_id AS id,
		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,
		'1' as type
		FROM
		`wl_form_instance` a
		WHERE
		a.group_code IN ('fireRoom', 'r_fireRoom')
		GROUP BY
		a.instance_id
		) s
		<if test="name!=null">
			AND s.name LIKE '%${name}%'
		</if>
		<if test="code!=null">
			AND s.`code` LIKE '%${code}%'
		</if>

		<if test="type!=null">
			AND s.`type` LIKE '%${type}%';
		</if>

	</select>


<!--	<select id="queryEquipCountById" resultType="java.util.Map">-->

<!--		SELECT-->
<!--			fe.`name`,-->
<!--			SUM(fse.number) count,-->
<!--			fe.unit-->
<!--		FROM-->
<!--			`f_fire_station_equipment` fse-->
<!--		LEFT JOIN f_fire_equipment fe ON fe.id = fse.fire_equipment_id-->
<!--		WHERE-->
<!--			fire_station_id = #{id}-->
<!--		GROUP BY-->
<!--			fe.`name`,fe.unit-->
<!--	</select>-->

</mapper>