<?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.devplatform.admin.modules.sys.dao.SysFaulalarmDao">
	<!-- Result Map -->
	<resultMap id="BaseResultMap" type="com.devplatform.admin.modules.sys.bean.SysFaulalarm">
	    <result column="id" property="id"/>
	    <result column="resource_id" property="resourceId"/>
	    <result column="resource_type" property="resourceType"/>
	    <result column="start_time" property="startTime"/>
	    <result column="end_time" property="endTime"/>
	    <result column="station_id" property="stationId"/>
	</resultMap>

	<!-- sys_fault_alarm table all fields -->
	<sql id="Base_Column_List">
		id,resource_id,resource_type,start_time,end_time,station_id
	</sql>

	<!-- 公共查询条件 -->
	<sql id="Example_Where_Clause">
		where t.deleted=0
		<if test="id!=null and id!=''">and t.id = #{id}</if>
		<if test="resourceId!=null and resourceId!=''">and t.resource_id = #{resourceId}</if>
		<if test="resourceType!=null and resourceType!=''">and t.resource_type = #{resourceType}</if>
		<if test="startTime!=null ">and t.start_time = #{startTime}</if>
		<if test="endTime!=null ">and t.end_time = #{endTime}</if>
		<if test="stationId!=null and stationId!=''">and t.station_id = #{stationId}</if>
	</sql>

	<select id="queryPageByCount" parameterType="Object" resultType="java.lang.Integer">
	select count(1) from sys_fault_alarm t
	<include refid="Example_Where_Clause"/>
	</select>

	<select id="queryPageList" parameterType="Object" resultMap="BaseResultMap">
	select t.* from sys_fault_alarm t
	<include refid="Example_Where_Clause"/>
	<if test="pager.orderCondition != null and pager.orderCondition != ''">
		${pager.orderCondition}
	</if>
	<if test="pager.mysqlQueryCondition != null and pager.mysqlQueryCondition != ''">
		${pager.mysqlQueryCondition}
	</if>
	</select>
	<select id="getListGroupByResourceType" resultType="java.util.Map">
		select sd.name as name,t.value from
		(select resource_type,count(1) as value from
		sys_fault_alarm
		 where 1=1
		<if test="(params.startTime == null or params.startTime == '') and (params.endTime == null or params.endTime == '')">
			and TO_DAYS(start_time) = TO_DAYS(NOW())
		</if>
		<if test="params.startTime != null and params.startTime != ''">
			and start_time &gt;= #{params.startTime}
		</if>
		<if test="params.endTime != null and params.endTime != ''">
			and start_time &lt;= #{params.endTime}
		</if>
		 group by resource_type) t
		 left join sys_dictionary sd on sd.id = t.resource_type
		 order by t.value desc
	</select>

	<select id="getListGroupByResourceId" resultType="java.util.Map">
		select lr.name as name,t.value from
		(select resource_id,count(1) as value from
		sys_fault_alarm
		where 1=1
		<if test="(params.startTime == null or params.startTime == '') and (params.endTime == null or params.endTime == '')">
			and TO_DAYS(start_time) = TO_DAYS(NOW())
		</if>
		<if test="params.startTime != null and params.startTime != ''">
			and start_time &gt;= #{params.startTime}
		</if>
		<if test="params.endTime != null and params.endTime != ''">
			and start_time &lt;= #{params.endTime}
		</if>
		group by resource_id) t
		left join li_resource lr on lr.id = t.resource_id
		order by t.value desc
	</select>

</mapper>


