<?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.fastbee.iot.mapper.NgDeviceOperationRecordsMapper">

    <resultMap type="NgDeviceOperationRecords" id="NgDeviceOperationRecordsResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="operationMessage"    column="operation_message"    />
        <result property="operationType"    column="operation_type"    />
        <result property="operationContent"    column="operation_content"    />
        <result property="operationTime"    column="operation_time"    />
        <result property="operationResult"    column="operation_result"    />
        <result property="failureReason"    column="failure_reason"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="deviceNumber"    column="device_number"    />
    </resultMap>

    <sql id="selectNgDeviceOperationRecordsVo">
        select id, user_id, dept_id, operation_message, operation_type, operation_content, operation_time, operation_result, failure_reason, remark, create_time, update_time, create_by, update_by, device_number from ng_device_operation_records
    </sql>

    <select id="selectNgDeviceOperationRecordsList" parameterType="NgDeviceOperationRecords" resultMap="NgDeviceOperationRecordsResult">
        <include refid="selectNgDeviceOperationRecordsVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="operationMessage != null  and operationMessage != ''"> and operation_message = #{operationMessage}</if>
            <if test="operationType != null "> and operation_type = #{operationType}</if>
            <if test="operationContent != null  and operationContent != ''"> and operation_content = #{operationContent}</if>
            <if test="operationTime != null "> and operation_time = #{operationTime}</if>
            <if test="operationResult != null "> and operation_result = #{operationResult}</if>
            <if test="failureReason != null  and failureReason != ''"> and failure_reason = #{failureReason}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
        </where>
    </select>

    <select id="selectNgDeviceOperationRecordsById" parameterType="Long" resultMap="NgDeviceOperationRecordsResult">
        <include refid="selectNgDeviceOperationRecordsVo"/>
        where id = #{id}
    </select>

    <insert id="insertNgDeviceOperationRecords" parameterType="NgDeviceOperationRecords" useGeneratedKeys="true" keyProperty="id">
        insert into ng_device_operation_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="operationMessage != null">operation_message,</if>
            <if test="operationType != null">operation_type,</if>
            <if test="operationContent != null">operation_content,</if>
            <if test="operationTime != null">operation_time,</if>
            <if test="operationResult != null">operation_result,</if>
            <if test="failureReason != null">failure_reason,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="deviceNumber != null">device_number,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="operationMessage != null">#{operationMessage},</if>
            <if test="operationType != null">#{operationType},</if>
            <if test="operationContent != null">#{operationContent},</if>
            <if test="operationTime != null">#{operationTime},</if>
            <if test="operationResult != null">#{operationResult},</if>
            <if test="failureReason != null">#{failureReason},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="deviceNumber != null">#{deviceNumber},</if>
        </trim>
    </insert>

    <update id="updateNgDeviceOperationRecords" parameterType="NgDeviceOperationRecords">
        update ng_device_operation_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="operationMessage != null">operation_message = #{operationMessage},</if>
            <if test="operationType != null">operation_type = #{operationType},</if>
            <if test="operationContent != null">operation_content = #{operationContent},</if>
            <if test="operationTime != null">operation_time = #{operationTime},</if>
            <if test="operationResult != null">operation_result = #{operationResult},</if>
            <if test="failureReason != null">failure_reason = #{failureReason},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="deviceNumber != null">device_number = #{deviceNumber},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNgDeviceOperationRecordsById" parameterType="Long">
        delete from ng_device_operation_records where id = #{id}
    </delete>

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