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


	<select id="queryForPage" resultType="map">
		SELECT * FROM(
			SELECT
			DATE_FORMAT(create_date,'%Y-%m-%d %H:%i:%s') create_time,

				t.*
			FROM
				contingency_original_data t
			WHERE
				1 = 1

			<if test="equipmentId!=null">
				AND t.equipment_Id = #{equipmentId}
			</if>

			<if test="createTime!=null">
				AND TO_DAYS(t.create_date) = TO_DAYS(#{createTime})
			</if>
		) m
		WHERE
			1 = 1
		<if test="contingencyName!=null and contingencyName!=''">
			OR m.fire_Equipment_Name like concat('%',#{contingencyName},'%')
			OR m.equipment_Name like concat('%',#{contingencyName},'%')
		</if>
		order  by m.create_date desc
		LIMIT #{start},#{length} ;
	</select>


	<select id="queryCountForPage" resultType="long">
		SELECT count(1)	FROM (
			SELECT
			*
			FROM
			contingency_original_data t
			WHERE
			1 = 1

			<if test="equipmentId!=null">
				AND t.equipment_Id = #{equipmentId}
			</if>

			<if test="createTime!=null">
				AND TO_DAYS(t.create_date) = TO_DAYS(#{createTime})
			</if>
		) m
		WHERE
			1=1
		<if test="contingencyName!=null and contingencyName!=''">
			OR m.fire_Equipment_Name like concat('%',#{contingencyName},'%')
			OR m.equipment_Name like concat('%',#{contingencyName},'%')
		</if>
	</select>



</mapper>