<?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.eq.dao.DlswjInfoHourDao">
	<!-- Result Map -->
	<resultMap id="BaseResultMap" type="com.devplatform.admin.modules.eq.bean.DlswjInfoHour">
	    <result column="id" property="id"/>
	    <result column="resource_id" property="resourceId"/>
	    <result column="electric_energy" property="electricEnergy"/>
	    <result column="type" property="type"/>
	    <result column="station_id" property="stationId"/>
	    <result column="create_time" property="createTime"/>
	</resultMap>

	<!-- dlswj_info_hour table all fields -->
	<sql id="Base_Column_List">
		id,resource_id,electric_energy,type,station_id,create_time
	</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="electricEnergy!=null and electricEnergy!=''">and t.electric_energy = #{electricEnergy}</if>
		<if test="type!=null ">and t.type = #{type}</if>
		<if test="stationId!=null and stationId!=''">and t.station_id = #{stationId}</if>
		<if test="createTime!=null ">and t.create_time = #{createTime}</if>
	</sql>

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

	<select id="queryPageList" parameterType="Object" resultMap="BaseResultMap">
	select t.* from dlswj_info_hour 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="queryPageListByParam" resultType="java.util.Map">
		select t.* from dlswj_info_hour t
		where 1=1
		<if test="params.resourceId!=null and params.resourceId!=''">
			and t.resource_id = #{params.resourceId}
		</if>
		<if test="(params.startTime == null or params.startTime == '') and (params.endTime == null or params.endTime == '')">
			and TO_DAYS(t.create_time) = TO_DAYS(NOW())
		</if>
		<if test="params.startTime != null and params.startTime != ''">
			and t.create_time &gt;= #{params.startTime}
		</if>
		<if test="params.endTime != null and params.endTime != ''">
			and t.create_time &lt;= #{params.endTime}
		</if>
		<if test="params.sort != null and params.sort != '' and params.order != null and params.order != ''">
			ORDER BY ${params.sort} ${params.order}
		</if>
		<if test="params.sort == null or params.sort == '' or params.order == null or params.order == ''">
			ORDER BY t.create_time
		</if>
	</select>

	<select id="queryListByParam" resultType="java.util.Map">
		select create_time,sum(cast(electric_energy as decimal(10, 5))) as electric_energy
		from dlswj_info_hour
		where 1=1
		<if test="(startTime == null or startTime == '') and (endTime == null or endTime == '')">
			and TO_DAYS(create_time) = TO_DAYS(NOW())
		</if>
		<if test="startTime != null and startTime != ''">
			and create_time &gt;= #{startTime}
		</if>
		<if test="endTime != null and endTime != ''">
			and create_time &lt;= #{endTime}
		</if>
		group by create_time
		order by create_time
	</select>

</mapper>


