<?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.pm.control.mapper.IbmsDeviceControlLogMapper">

    <resultMap type="pd" id="IbmsDeviceControlLogResult">
        <result property="id"    column="id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="pointId"    column="point_id"    />
        <result property="controlType"    column="control_type"    />
        <result property="oldValue"    column="old_value"    />
        <result property="newValue"    column="new_value"    />
        <result property="controlResult"    column="control_result"    />
        <result property="operatorId"    column="operator_id"    />
        <result property="operatorName"    column="operator_name"    />
        <result property="operateTime"    column="operate_time"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectIbmsDeviceControlLogVo">
        select id, device_id, point_id, control_type, old_value, new_value, control_result, operator_id, operator_name, operate_time, remark, create_time from ibms_device_control_log
    </sql>

    <select id="selectIbmsDeviceControlLogList" parameterType="pd" resultMap="IbmsDeviceControlLogResult">
        <include refid="selectIbmsDeviceControlLogVo"/>
        <where>
            <if test="deviceId != null and deviceId != ''"> and device_id = #{deviceId}</if>
            <if test="pointId != null and pointId != ''"> and point_id = #{pointId}</if>
            <if test="controlType != null and controlType != ''"> and control_type = #{controlType}</if>
            <if test="controlResult != null and controlResult != ''"> and control_result = #{controlResult}</if>
            <if test="operatorName != null and operatorName != ''"> and operator_name like concat('%', #{operatorName}, '%')</if>
        </where>
    </select>

    <select id="selectIbmsDeviceControlLogById" parameterType="pd" resultMap="IbmsDeviceControlLogResult">
        <include refid="selectIbmsDeviceControlLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertIbmsDeviceControlLog" parameterType="pd" useGeneratedKeys="true" keyProperty="id">
        insert into ibms_device_control_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null and deviceId != ''">device_id,</if>
            <if test="pointId != null and pointId != ''">point_id,</if>
            <if test="controlType != null and controlType != ''">control_type,</if>
            <if test="oldValue != null and oldValue != ''">old_value,</if>
            <if test="newValue != null and newValue != ''">new_value,</if>
            <if test="controlResult != null and controlResult != ''">control_result,</if>
            <if test="operatorId != null and operatorId != ''">operator_id,</if>
            <if test="operatorName != null and operatorName != ''">operator_name,</if>
            <if test="operateTime != null and operateTime != ''">operate_time,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="createTime != null and createTime != ''">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null and deviceId != ''">#{deviceId},</if>
            <if test="pointId != null and pointId != ''">#{pointId},</if>
            <if test="controlType != null and controlType != ''">#{controlType},</if>
            <if test="oldValue != null and oldValue != ''">#{oldValue},</if>
            <if test="newValue != null and newValue != ''">#{newValue},</if>
            <if test="controlResult != null and controlResult != ''">#{controlResult},</if>
            <if test="operatorId != null and operatorId != ''">#{operatorId},</if>
            <if test="operatorName != null and operatorName != ''">#{operatorName},</if>
            <if test="operateTime != null and operateTime != ''">#{operateTime},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="createTime != null and createTime != ''">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateIbmsDeviceControlLog" parameterType="pd">
        update ibms_device_control_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
            <if test="pointId != null and pointId != ''">point_id = #{pointId},</if>
            <if test="controlType != null and controlType != ''">control_type = #{controlType},</if>
            <if test="oldValue != null and oldValue != ''">old_value = #{oldValue},</if>
            <if test="newValue != null and newValue != ''">new_value = #{newValue},</if>
            <if test="controlResult != null and controlResult != ''">control_result = #{controlResult},</if>
            <if test="operatorId != null and operatorId != ''">operator_id = #{operatorId},</if>
            <if test="operatorName != null and operatorName != ''">operator_name = #{operatorName},</if>
            <if test="operateTime != null and operateTime != ''">operate_time = #{operateTime},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="createTime != null and createTime != ''">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIbmsDeviceControlLogById" parameterType="Long">
        delete from ibms_device_control_log where id = #{id}
    </delete>

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