<?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.xzzn.ems.mapper.EmsDeviceChangeLogMapper">

    <resultMap type="EmsDeviceChangeLog" id="EmsDeviceChangeLogResult">
        <result property="id"    column="id"    />
        <result property="logId"    column="log_id"    />
        <result property="logTime"    column="log_time"    />
        <result property="siteId"    column="siteId"    />
        <result property="deviceId"    column="deviceId"    />
        <result property="beforeStatus"    column="before_status"    />
        <result property="afterStatus"    column="after_status"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectEmsDeviceChangeLogVo">
        select id, log_id, log_time, siteId, deviceId, before_status, after_status, create_by, create_time, update_by, update_time, remark from ems_device_change_log
    </sql>

    <select id="selectEmsDeviceChangeLogList" parameterType="EmsDeviceChangeLog" resultMap="EmsDeviceChangeLogResult">
        <include refid="selectEmsDeviceChangeLogVo"/>
        <where>
            <if test="logId != null  and logId != ''"> and log_id = #{logId}</if>
            <if test="logTime != null "> and log_time = #{logTime}</if>
            <if test="siteId != null  and siteId != ''"> and siteId = #{siteId}</if>
            <if test="deviceId != null  and deviceId != ''"> and deviceId = #{deviceId}</if>
            <if test="beforeStatus != null  and beforeStatus != ''"> and before_status = #{beforeStatus}</if>
            <if test="afterStatus != null  and afterStatus != ''"> and after_status = #{afterStatus}</if>
        </where>
    </select>

    <select id="selectEmsDeviceChangeLogById" parameterType="Long" resultMap="EmsDeviceChangeLogResult">
        <include refid="selectEmsDeviceChangeLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertEmsDeviceChangeLog" parameterType="EmsDeviceChangeLog" useGeneratedKeys="true" keyProperty="id">
        insert into ems_device_change_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="logId != null and logId != ''">log_id,</if>
            <if test="logTime != null">log_time,</if>
            <if test="siteId != null">siteId,</if>
            <if test="deviceId != null">deviceId,</if>
            <if test="beforeStatus != null">before_status,</if>
            <if test="afterStatus != null">after_status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="logId != null and logId != ''">#{logId},</if>
            <if test="logTime != null">#{logTime},</if>
            <if test="siteId != null">#{siteId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="beforeStatus != null">#{beforeStatus},</if>
            <if test="afterStatus != null">#{afterStatus},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateEmsDeviceChangeLog" parameterType="EmsDeviceChangeLog">
        update ems_device_change_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="logId != null and logId != ''">log_id = #{logId},</if>
            <if test="logTime != null">log_time = #{logTime},</if>
            <if test="siteId != null">siteId = #{siteId},</if>
            <if test="deviceId != null">deviceId = #{deviceId},</if>
            <if test="beforeStatus != null">before_status = #{beforeStatus},</if>
            <if test="afterStatus != null">after_status = #{afterStatus},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsDeviceChangeLogById" parameterType="Long">
        delete from ems_device_change_log where id = #{id}
    </delete>

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

    <select id="selectDeviceChangeLogByLogId" parameterType="String" resultMap="EmsDeviceChangeLogResult">
        <include refid="selectEmsDeviceChangeLogVo"/>
        where log_id = #{logId}
    </select>
</mapper>