<?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.WatchInfoDAO">
    <resultMap id="WatchInfoMap" type="com.jpsoft.shinestar.modules.base.entity.WatchInfo">
        <id property="id" column="id_"/>
        <result property="personId" column="person_id"/>
        <result property="deviceNo" column="device_no"/>
        <result property="aliasName" column="alias_name"/>
        <result property="orderNo" column="order_no"/>
        <result property="isDefault" column="is_default"/>
        <result property="heartBeatUpdateTime" column="heart_beat_update_time"/>
        <result property="isOnline" column="is_online"/>
        <result property="sos1" column="sos1"/>
        <result property="sos2" column="sos2"/>
        <result property="sos3" column="sos3"/>
        <result property="stepSwitch" column="step_switch"/>
        <result property="locationTimeInterval" column="location_time_interval"/>
        <result property="heartRateTimeInterval" column="heart_rate_time_interval"/>
        <result property="bpi" column="bpi"/>
        <result property="heartRateMax" column="heart_rate_max"/>
        <result property="heartRateMin" column="heart_rate_min"/>
        <result property="bpHighMax" column="bp_high_max"/>
        <result property="bpHighMin" column="bp_high_min"/>
        <result property="bpLowMax" column="bp_low_max"/>
        <result property="bpLowMin" column="bp_low_min"/>
        <result property="bloodOxMax" column="blood_ox_max"/>
        <result property="bloodOxMin" column="blood_ox_min"/>
        <result property="num1" column="num1"/>
        <result property="tempMin" column="temp_min"/>
        <result property="frequency" column="frequency_"/>
        <result property="delFlag" column="del_flag"/>
        <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="latestLocation" column="latest_location"/>
        <result property="bloodOxygenInterval" column="blood_oxygen_time_interval"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.WatchInfo">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_watch_info
	    (id_,device_no,alias_name,order_no,is_default,heart_beat_update_time,is_online,
	    sos1,sos2,sos3,step_switch,location_time_interval,heart_rate_time_interval,
	    bpi,heart_rate_max,heart_rate_min,bp_high_max,bp_high_min,bp_low_max,
	    bp_low_min,blood_ox_max,blood_ox_min,num1,del_flag,
	    create_by,create_time,update_by,update_time,
	    person_id,temp_min,frequency_,latest_location,blood_oxygen_time_interval)
		values
		(
			#{id,jdbcType=VARCHAR}
			,#{deviceNo,jdbcType=VARCHAR}
			,#{aliasName,jdbcType=VARCHAR}
			,#{orderNo,jdbcType=VARCHAR}
			,#{isDefault,jdbcType= NUMERIC }
			,#{heartBeatUpdateTime,jdbcType= TIMESTAMP }
			,#{isOnline,jdbcType= NUMERIC }
			,#{sos1,jdbcType= VARCHAR }
			,#{sos2,jdbcType= VARCHAR }
			,#{sos3,jdbcType= VARCHAR }
			,#{stepSwitch,jdbcType= NUMERIC }
			,#{locationTimeInterval,jdbcType=VARCHAR}
			,#{heartRateTimeInterval,jdbcType=VARCHAR}
			,#{bpi,jdbcType=VARCHAR}
			,#{heartRateMax,jdbcType=VARCHAR}
			,#{heartRateMin,jdbcType=VARCHAR}
			,#{bpHighMax,jdbcType=VARCHAR}
			,#{bpHighMin,jdbcType=VARCHAR}
			,#{bpLowMax,jdbcType=VARCHAR}
			,#{bpLowMin,jdbcType=VARCHAR}
			,#{bloodOxMax,jdbcType=VARCHAR}
			,#{bloodOxMin,jdbcType=VARCHAR}
			,#{num1,jdbcType= VARCHAR }
			,#{delFlag,jdbcType= NUMERIC }
			,#{createBy,jdbcType=VARCHAR}
			,#{createTime,jdbcType= TIMESTAMP }
			,#{updateBy,jdbcType=VARCHAR}
			,#{updateTime,jdbcType= TIMESTAMP }
			,#{personId,jdbcType= NUMERIC }
			,#{tempMin,jdbcType= VARCHAR }
			,#{frequency,jdbcType= NUMERIC }
			,#{latestLocation,jdbcType= VARCHAR }
			,#{bloodOxygenInterval,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_watch_info where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.WatchInfo">
        update base_watch_info
        <set>
            <if test="deviceNo!=null">
                device_no=#{deviceNo,jdbcType=VARCHAR},
            </if>
            <if test="aliasName!=null">
                alias_name=#{aliasName,jdbcType=VARCHAR},
            </if>
            <if test="orderNo!=null">
                order_no=#{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="isDefault!=null">
                is_default=#{isDefault,jdbcType= NUMERIC },
            </if>
            <if test="heartBeatUpdateTime!=null">
                heart_beat_update_time=#{heartBeatUpdateTime,jdbcType= TIMESTAMP },
            </if>
            <if test="isOnline!=null">
                is_online=#{isOnline,jdbcType= NUMERIC },
            </if>
            <if test="sos1!=null">
                sos1=#{sos1,jdbcType= VARCHAR },
            </if>
            <if test="sos2!=null">
                sos2=#{sos2,jdbcType= VARCHAR },
            </if>
            <if test="sos3!=null">
                sos3=#{sos3,jdbcType= VARCHAR },
            </if>
            <if test="stepSwitch!=null">
                step_switch=#{stepSwitch,jdbcType= NUMERIC },
            </if>
            <if test="locationTimeInterval!=null">
                location_time_interval=#{locationTimeInterval,jdbcType=VARCHAR},
            </if>
            <if test="heartRateTimeInterval!=null">
                heart_rate_time_interval=#{heartRateTimeInterval,jdbcType=VARCHAR},
            </if>
            <if test="bpi!=null">
                bpi=#{bpi,jdbcType=VARCHAR},
            </if>
            <if test="heartRateMax!=null">
                heart_rate_max=#{heartRateMax,jdbcType=VARCHAR},
            </if>
            <if test="heartRateMin!=null">
                heart_rate_min=#{heartRateMin,jdbcType=VARCHAR},
            </if>
            <if test="bpHighMax!=null">
                bp_high_max=#{bpHighMax,jdbcType=VARCHAR},
            </if>
            <if test="bpHighMin!=null">
                bp_high_min=#{bpHighMin,jdbcType=VARCHAR},
            </if>
            <if test="bpLowMax!=null">
                bp_low_max=#{bpLowMax,jdbcType=VARCHAR},
            </if>
            <if test="bpLowMin!=null">
                bp_low_min=#{bpLowMin,jdbcType=VARCHAR},
            </if>
            <if test="bloodOxMax!=null">
                blood_ox_max=#{bloodOxMax,jdbcType=VARCHAR},
            </if>
            <if test="bloodOxMin!=null">
                blood_ox_min=#{bloodOxMin,jdbcType=VARCHAR},
            </if>
            <if test="num1!=null">
                num1=#{num1,jdbcType= VARCHAR },
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </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="personId!=null">
                person_id=#{personId,jdbcType= NUMERIC },
            </if>
            <if test="tempMin!=null">
                temp_min=#{tempMin,jdbcType= VARCHAR },
            </if>
            <if test="frequency!=null">
                frequency_=#{frequency,jdbcType= NUMERIC },
            </if>
            <if test="latestLocation!=null">
                latest_location=#{latestLocation,jdbcType= NUMERIC },
            </if>
            <if test="bloodOxygenInterval!=null">
                blood_oxygen_time_interval=#{bloodOxygenInterval,jdbcType=VARCHAR},
            </if>
        </set>
        where id_=#{id}
    </update>
    <update id="updateHeartBeatUpdateTime">
        update base_watch_info
        set heart_beat_update_time=#{updateTime}
        where device_no=#{deviceNo} and del_flag=0
    </update>
    <select id="get" parameterType="string" resultMap="WatchInfoMap">
        select * from base_watch_info where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_watch_info where id_=#{0}
    </select>
    <select id="list" resultMap="WatchInfoMap">
        select * from base_watch_info
    </select>
    <select id="search" parameterType="hashmap" resultMap="WatchInfoMap">
        <![CDATA[
			select * from base_watch_info
		]]>
        <where>
            del_flag=0
            <if test="searchParams.personId != null">
                and person_id = #{searchParams.personId}
            </if>
            <if test="searchParams.deviceNo != null">
                and device_no like #{searchParams.deviceNo}
            </if>
            <if test="searchParams.aliasName != null">
                and alias_name like #{searchParams.aliasName}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
    <select id="findOneByDeviceNo" resultMap="WatchInfoMap">
        select * from base_watch_info where device_no=#{0} and del_flag=0
        order by create_time desc
        limit 1
    </select>
    <select id="findDefaultByPersonId" resultMap="WatchInfoMap">
        select * from base_watch_info
        where
        person_id=#{0}
        and del_flag=0
        and is_default=1
        order by create_time desc
        limit 1
    </select>
    <select id="onlineList" resultMap="WatchInfoMap">
        select * from base_watch_info
        where del_flag=0
        and is_online=1
        order by heart_beat_update_time asc
    </select>
</mapper>