<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.WatchMeasureDAO">
	<resultMap id="WatchMeasureMap" type="com.jpsoft.shinestar.modules.base.entity.WatchMeasure">
		<id property="id" column="id_" />
			<result property="deviceNo" column="device_no" />
			<result property="name" column="name_" />
			<result property="value" column="value_" />
			<result property="recordTime" column="record_time" />
			<result property="createBy" column="create_by" />
			<result property="createTime" column="create_time" />
			<result property="updateBy" column="update_by" />
			<result property="updateTime" column="update_time" />
			<result property="delFlag" column="del_flag" />
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.WatchMeasure">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into base_watch_measure
	    (id_,device_no,name_,value_,record_time,create_by,create_time,update_by,update_time,del_flag)
		values
		(
#{id,jdbcType=VARCHAR}
,#{deviceNo,jdbcType=VARCHAR}
,#{name,jdbcType=VARCHAR}
,#{value,jdbcType=VARCHAR}
,#{recordTime,jdbcType= TIMESTAMP }
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from base_watch_measure where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.WatchMeasure">
		update base_watch_measure
		<set>
				<if test="deviceNo!=null">
		device_no=#{deviceNo,jdbcType=VARCHAR},
		</if>
				<if test="name!=null">
		name_=#{name,jdbcType=VARCHAR},
		</if>
				<if test="value!=null">
		value_=#{value,jdbcType=VARCHAR},
		</if>
				<if test="recordTime!=null">
		record_time=#{recordTime,jdbcType= TIMESTAMP },
		</if>
				<if test="createBy!=null">
		create_by=#{createBy,jdbcType=VARCHAR},
		</if>
				<if test="createTime!=null">
		create_time=#{createTime,jdbcType= TIMESTAMP },
		</if>
				<if test="updateBy!=null">
		update_by=#{updateBy,jdbcType=VARCHAR},
		</if>
				<if test="updateTime!=null">
		update_time=#{updateTime,jdbcType= TIMESTAMP },
		</if>
				<if test="delFlag!=null">
		del_flag=#{delFlag,jdbcType= NUMERIC },
		</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="WatchMeasureMap">
		select 
id_,device_no,name_,value_,record_time,create_by,create_time,update_by,update_time,del_flag		from base_watch_measure where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from base_watch_measure where id_=#{0}
	</select>
	<select id="list" resultMap="WatchMeasureMap">
		select * from base_watch_measure
	</select>
	<select id="search" parameterType="hashmap" resultMap="WatchMeasureMap">
		<![CDATA[
			select * from base_watch_measure
		]]>
		<where>
			<if test="searchParams.deviceNo != null">
				and device_no like #{searchParams.deviceNo}
			</if>
			<if test="searchParams.name != null">
				and name_ like #{searchParams.name}
			</if>
			<if test="searchParams.startTime != null">
			<![CDATA[
				and record_time >= #{searchParams.startTime}
			]]>
			</if>
			<if test="searchParams.endTime != null">
			<![CDATA[
				and record_time <= #{searchParams.endTime}
			]]>
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>
	<select id="getWatchNewData" resultType="string">
		<![CDATA[
			select value_ from base_watch_measure where del_flag=0
			and value_ <> '0'
			and device_no=#{deviceNo}
			and name_=#{name}
			order by record_time desc
			limit 1
		]]>
	</select>
	<resultMap id="WatchMeasureCurve" type="com.jpsoft.shinestar.modules.base.dto.WatchMeasureCurve">
		<result property="value" column="value_" />
		<result property="recordTime" column="record_time" />
	</resultMap>
	<select id="getCurveData" resultMap="WatchMeasureCurve">
		<![CDATA[
			select record_time,value_ from base_watch_measure where del_flag=0
			and value_ <> '0'
			and device_no=#{deviceNo}
			and name_=#{name}
			order by record_time desc
			limit ${limit}
		]]>
	</select>
	<select id="getLbsData" resultMap="WatchMeasureCurve">
		<![CDATA[
			select record_time,value_ from base_watch_measure where del_flag=0
			and value_ <> '0.0,0.0'
			and device_no=#{deviceNo}
			and name_= 'lbs'
			and record_time >= #{startTime}
			and record_time <= #{endTime}
			order by record_time desc
		]]>
	</select>
	<select id="getLastDataByDay" resultMap="WatchMeasureMap">
		select * from base_watch_measure where del_flag=0
		and device_no=#{deviceNo}
		and name_= #{name}
		<if test="date!=null">
			and DATE_FORMAT(record_time,'%Y-%m-%d') = #{date}
		</if>
		order by record_time desc
		limit 1
	</select>
</mapper>