<?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.ImpEquipMapper">
	<resultMap id="resultMap" type="com.yeejoin.amos.fas.dao.dto.EquipmentDTO">
		<id column="id" property="id"/>
		<result column="name" property="name"/>
		<result column="status" property="status"/>
		<result column="type" property="type"/>
	</resultMap>

    <select id="queryProtectObjNames" resultType="string" >

        SELECT
            GROUP_CONCAT(fe.`name`) protectObjNames
        FROM
            f_equipment fe
        WHERE
            EXISTS (
                SELECT
                    1
                FROM
                    f_equipment_fire_equipment efe
                WHERE
                    efe.fire_equipment_id = ${fireEquipmentId}
                AND efe.equipment_id = fe.id
            )
    </select>
	
	<!--分页查询 -->
	<select id="getEquipPage" resultType="java.util.HashMap">
		SELECT
		eq.id,
		eq.`code`,
		eq.`name`,
		eq.address,
		eq.building,
		eq.room,
		frs.full_name as  riskSourceName
		FROM
		f_equipment eq
		left join wl_warehouse_structure frs on frs.id = eq.risk_source_id
		<trim prefix="WHERE" prefixOverrides="AND ">
			<if test="name !=null and name != ''"> and (eq.name like concat(concat("%",#{name}),"%") or eq.code like concat(concat("%",#{name}),"%"))</if>
			<if test="id != null and id != ''"> and eq.id = #{id}</if>
		</trim>
		order by eq.id
		<choose>
	     <when test="pageSize==-1"></when>
	     <when test="pageSize!=-1">limit #{offset},#{pageSize}</when>  
	    </choose>
	</select>
	
	<select id="getEquipPageCount" resultType="long">
		SELECT
			count(eq.id)
		FROM
			f_equipment eq
		<trim prefix="WHERE" prefixOverrides="AND ">
			<if test="name !=null and name != ''"> and (eq.name like concat(concat("%",#{name}),"%") or eq.code like concat(concat("%",#{name}),"%"))</if>
			<if test="id != null and id != ''"> and eq.id = #{id}</if>
		</trim>
	</select>

	<select id="reservePage" resultType="com.yeejoin.amos.fas.dao.dto.EquipmentDTO">
		SELECT
			a.id,
			a.`name`,
			a.`status`,
			'重点设备' AS type
		FROM
			`f_equipment` a
		WHERE
			a.reserve_plan IS NOT NULL
			AND a.reserve_plan != ''
		ORDER BY
			a.id
		<if test="start != -1 and length != -1">
			LIMIT ${start},${length} ;
		</if>
	</select>

	<select id="reservePageCount" resultType="long">
		SELECT
			COUNT(1)
		FROM
			`f_equipment` a
		WHERE
			a.reserve_plan IS NOT NULL
			AND a.reserve_plan != ''
	</select>
	
	<select id="getAllCode" resultType="string">
		select distinct code from f_equipment
	</select>
</mapper>