<?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.zbf.system.mapper.DeviceLogMapper">

    <resultMap type="DeviceLog" id="DeviceLogResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="msg"    column="msg"    />
        <result property="orders"    column="orders"    />
        <result property="obj"    column="obj"    />
    </resultMap>

    <sql id="selectDeviceLogVo">
        select id, code, msg, orders, obj from device_log
    </sql>

    <select id="selectDeviceLogList" parameterType="DeviceLog" resultMap="DeviceLogResult">
        <include refid="selectDeviceLogVo"/>
        <where>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="msg != null  and msg != ''"> and msg = #{msg}</if>
            <if test="orders != null  and orders != ''"> and orders = #{orders}</if>
            <if test="obj != null  and obj != ''"> and obj = #{obj}</if>
        </where>
    </select>

    <select id="selectDeviceLogById" parameterType="Long" resultMap="DeviceLogResult">
        <include refid="selectDeviceLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertDeviceLog" parameterType="DeviceLog" useGeneratedKeys="true" keyProperty="id">
        insert into device_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="code != null">code,</if>
            <if test="msg != null">msg,</if>
            <if test="orders != null">orders,</if>
            <if test="obj != null">obj,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="code != null">#{code},</if>
            <if test="msg != null">#{msg},</if>
            <if test="orders != null">#{orders},</if>
            <if test="obj != null">#{obj},</if>
        </trim>
    </insert>

    <update id="updateDeviceLog" parameterType="DeviceLog">
        update device_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null">code = #{code},</if>
            <if test="msg != null">msg = #{msg},</if>
            <if test="orders != null">orders = #{orders},</if>
            <if test="obj != null">obj = #{obj},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableDeviceLogByIds" parameterType="String">
        update device_log set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledDeviceLogByIds" parameterType="String">
        update device_log set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteDeviceLogById" parameterType="Long">
        delete from device_log  where id = #{id}
    </delete>

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