<?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.fs.watch.mapper.WatchDeviceSetupMapper">

    <resultMap type="WatchDeviceSetup" id="DeviceSetupResult">
        <result property="deviceId"    column="device_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="smartDoctor"    column="smart_doctor"    />
        <result property="sedentary"    column="sedentary"    />
        <result property="fallcheck"    column="fallcheck"    />
        <result property="heartHealth"    column="heart_health"    />
        <result property="hralarm"    column="hralarm"    />
        <result property="spo2alarm"    column="spo2alarm"    />
        <result property="alarmClock"    column="alarm_clock"    />
        <result property="power"    column="power"    />
        <result property="phonebook"    column="phonebook"    />
        <result property="time"    column="time"    />
        <result property="lcdgesture"    column="lcdgesture"    />
        <result property="unit"    column="unit"    />
        <result property="mode"    column="mode"    />
        <result property="version"    column="version"    />
    </resultMap>

    <sql id="selectDeviceSetupVo">
        select device_id, create_time, create_by, update_time, update_by, smart_doctor, sedentary, fallcheck, heart_health, hralarm, spo2alarm, alarm_clock, power, phonebook, time, lcdgesture, unit, mode, version from watch_device_setup
    </sql>

    <select id="selectDeviceSetupList" parameterType="WatchDeviceSetup" resultMap="DeviceSetupResult">
        <include refid="selectDeviceSetupVo"/>
        <where>
            <if test="smartDoctor != null "> and smart_doctor = #{smartDoctor}</if>
            <if test="sedentary != null  and sedentary != ''"> and sedentary = #{sedentary}</if>
            <if test="fallcheck != null "> and fallcheck = #{fallcheck}</if>
            <if test="heartHealth != null "> and heart_health = #{heartHealth}</if>
            <if test="hralarm != null  and hralarm != ''"> and hralarm = #{hralarm}</if>
            <if test="spo2alarm != null  and spo2alarm != ''"> and spo2alarm = #{spo2alarm}</if>
            <if test="alarmClock != null  and alarmClock != ''"> and alarm_clock = #{alarmClock}</if>
            <if test="power != null  and power != ''"> and power = #{power}</if>
            <if test="phonebook != null  and phonebook != ''"> and phonebook = #{phonebook}</if>
            <if test="time != null  and time != ''"> and time = #{time}</if>
            <if test="lcdgesture != null lcdgesture != ''"> and lcdgesture = #{lcdgesture}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="mode != null  and mode != ''"> and mode = #{mode}</if>
            <if test="version != null  and version != ''"> and version = #{version}</if>
        </where>
    </select>

    <select id="selectDeviceSetupByDeviceId" parameterType="String" resultMap="DeviceSetupResult">
        <include refid="selectDeviceSetupVo"/>
        where device_id = #{deviceId}
    </select>

    <insert id="insertDeviceSetup" parameterType="WatchDeviceSetup">
        insert into watch_device_setup
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="smartDoctor != null">smart_doctor,</if>
            <if test="sedentary != null">sedentary,</if>
            <if test="fallcheck != null">fallcheck,</if>
            <if test="heartHealth != null">heart_health,</if>
            <if test="hralarm != null">hralarm,</if>
            <if test="spo2alarm != null">spo2alarm,</if>
            <if test="alarmClock != null">alarm_clock,</if>
            <if test="power != null">power,</if>
            <if test="phonebook != null">phonebook,</if>
            <if test="time != null">time,</if>
            <if test="lcdgesture != null">lcdgesture,</if>
            <if test="unit != null">unit,</if>
            <if test="mode != null">mode,</if>
            <if test="version != null">version,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="smartDoctor != null">#{smartDoctor},</if>
            <if test="sedentary != null">#{sedentary},</if>
            <if test="fallcheck != null">#{fallcheck},</if>
            <if test="heartHealth != null">#{heartHealth},</if>
            <if test="hralarm != null">#{hralarm},</if>
            <if test="spo2alarm != null">#{spo2alarm},</if>
            <if test="alarmClock != null">#{alarmClock},</if>
            <if test="power != null">#{power},</if>
            <if test="phonebook != null">#{phonebook},</if>
            <if test="time != null">#{time},</if>
            <if test="lcdgesture != null">#{lcdgesture},</if>
            <if test="unit != null">#{unit},</if>
            <if test="mode != null">#{mode},</if>
            <if test="version != null">#{version},</if>
         </trim>
    </insert>

    <update id="updateDeviceSetup" parameterType="WatchDeviceSetup">
        update watch_device_setup
        <trim prefix="SET" suffixOverrides=",">
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="smartDoctor != null">smart_doctor = #{smartDoctor},</if>
            <if test="sedentary != null">sedentary = #{sedentary},</if>
            <if test="fallcheck != null">fallcheck = #{fallcheck},</if>
            <if test="heartHealth != null">heart_health = #{heartHealth},</if>
            <if test="hralarm != null">hralarm = #{hralarm},</if>
            <if test="spo2alarm != null">spo2alarm = #{spo2alarm},</if>
            <if test="alarmClock != null">alarm_clock = #{alarmClock},</if>
            <if test="power != null">power = #{power},</if>
            <if test="phonebook != null">phonebook = #{phonebook},</if>
            <if test="time != null">time = #{time},</if>
            <if test="lcdgesture != null">lcdgesture = #{lcdgesture},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="mode != null">mode = #{mode},</if>
            <if test="version != null">version = #{version},</if>
        </trim>
        where device_id = #{deviceId}
    </update>

    <delete id="deleteDeviceSetupByDeviceId" parameterType="String">
        delete from watch_device_setup where device_id = #{deviceId}
    </delete>

    <delete id="deleteDeviceSetupByDeviceIds" parameterType="String">
        delete from watch_device_setup where device_id in
        <foreach item="deviceId" collection="array" open="(" separator="," close=")">
            #{deviceId}
        </foreach>
    </delete>
</mapper>
