<?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.ruoyi.system.mapper.TDeviceClockMapper">
    
    <resultMap type="TDeviceClock" id="TDeviceClockResult">
        <result property="id"    column="id"    />
        <result property="deviceIdCode"    column="device_id_code"    />
        <result property="alarmClock"    column="alarm_clock"    />
        <result property="clockTime"    column="clock_time"    />
        <result property="clockUse"    column="clock_use"    />
        <result property="clockWeek"    column="clock_week"    />
    </resultMap>

    <sql id="selectTDeviceClockVo">
        select id, device_id_code, alarm_clock, clock_time, clock_use, clock_week from t_device_clock
    </sql>

    <select id="selectTDeviceClockList" parameterType="TDeviceClock" resultMap="TDeviceClockResult">
        <include refid="selectTDeviceClockVo"/>
        <where>  
            <if test="deviceIdCode != null  and deviceIdCode != ''"> and device_id_code = #{deviceIdCode}</if>
            <if test="alarmClock != null  and alarmClock != ''"> and alarm_clock = #{alarmClock}</if>
            <if test="clockTime != null  and clockTime != ''"> and clock_time = #{clockTime}</if>
            <if test="clockUse != null "> and clock_use = #{clockUse}</if>
            <if test="clockWeek != null  and clockWeek != ''"> and clock_week = #{clockWeek}</if>
        </where>
    </select>
    
    <select id="selectTDeviceClockById" parameterType="Integer" resultMap="TDeviceClockResult">
        <include refid="selectTDeviceClockVo"/>
        where id = #{id}
    </select>
    <select id="selectTDeviceClockByCode" resultMap="TDeviceClockResult">
        <include refid="selectTDeviceClockVo"/>
        where device_id_code = #{deviceIdCode}
    </select>

    <insert id="insertTDeviceClock" parameterType="TDeviceClock" useGeneratedKeys="true" keyProperty="id">
        insert into t_device_clock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceIdCode != null">device_id_code,</if>
            <if test="alarmClock != null">alarm_clock,</if>
            <if test="clockTime != null">clock_time,</if>
            <if test="clockUse != null">clock_use,</if>
            <if test="clockWeek != null">clock_week,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceIdCode != null">#{deviceIdCode},</if>
            <if test="alarmClock != null">#{alarmClock},</if>
            <if test="clockTime != null">#{clockTime},</if>
            <if test="clockUse != null">#{clockUse},</if>
            <if test="clockWeek != null">#{clockWeek},</if>
         </trim>
    </insert>

    <update id="updateTDeviceClock" parameterType="TDeviceClock">
        update t_device_clock
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceIdCode != null">device_id_code = #{deviceIdCode},</if>
            <if test="alarmClock != null">alarm_clock = #{alarmClock},</if>
            <if test="clockTime != null">clock_time = #{clockTime},</if>
            <if test="clockUse != null">clock_use = #{clockUse},</if>
            <if test="clockWeek != null">clock_week = #{clockWeek},</if>
        </trim>
        where device_id_code = #{deviceIdCode}
    </update>

    <delete id="deleteTDeviceClockById" parameterType="Integer">
        delete from t_device_clock where id = #{id}
    </delete>

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