<?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.aucma.dms.mapper.DmsRecordShutDownMapper">

    <resultMap type="DmsRecordShutDown" id="DmsRecordShutDownResult">
        <result property="recordShutDownId" column="record_shut_down_id"/>
        <result property="deviceId" column="device_id"/>
        <result property="shutType" column="shut_type"/>
        <result property="shutReason" column="shut_reason"/>
        <result property="shutBeginTime" column="shut_begin_time"/>
        <result property="shutEndTime" column="shut_end_time"/>
        <result property="shutTime" column="shut_time"/>
        <result property="isFlag" column="is_flag"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectDmsRecordShutDownVo">
        select record_shut_down_id,
               device_id,
               shut_type,
               shut_reason,
               shut_begin_time,
               shut_end_time,
               shut_time,
               is_flag,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from dms_record_shut_down
    </sql>

    <select id="selectDmsRecordShutDownList" parameterType="DmsRecordShutDown" resultMap="DmsRecordShutDownResult">
        <include refid="selectDmsRecordShutDownVo"/>
        <where>
            <if test="deviceId != null ">and device_id = #{deviceId}</if>
            <if test="shutType != null ">and shut_type = #{shutType}</if>
            <if test="shutReason != null  and shutReason != ''">and shut_reason = #{shutReason}</if>
            <if test="shutBeginTime != null ">and shut_begin_time >= #{shutBeginTime}</if>
            <if test="shutEndTime != null ">and #{shutEndTime}>=shut_end_time</if>
            <if test="shutTime != null ">and shut_time = #{shutTime}</if>
            <if test="isFlag != null ">and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsRecordShutDownByRecordShutDownId" parameterType="Long" resultMap="DmsRecordShutDownResult">
        <include refid="selectDmsRecordShutDownVo"/>
        where record_shut_down_id = #{recordShutDownId}
    </select>

    <insert id="insertDmsRecordShutDown" parameterType="DmsRecordShutDown" useGeneratedKeys="true"
            keyProperty="recordShutDownId">
        insert into dms_record_shut_down
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="shutType != null">shut_type,</if>
            <if test="shutReason != null">shut_reason,</if>
            <if test="shutBeginTime != null">shut_begin_time,</if>
            <if test="shutEndTime != null">shut_end_time,</if>
            <if test="shutTime != null">shut_time,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="remark != null">remark,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="shutType != null">#{shutType},</if>
            <if test="shutReason != null">#{shutReason},</if>
            <if test="shutBeginTime != null">#{shutBeginTime},</if>
            <if test="shutEndTime != null">#{shutEndTime},</if>
            <if test="shutTime != null">#{shutTime},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="remark != null">#{remark},</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>
        </trim>
    </insert>

    <update id="updateDmsRecordShutDown" parameterType="DmsRecordShutDown">
        update dms_record_shut_down
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="shutType != null">shut_type = #{shutType},</if>
            <if test="shutReason != null">shut_reason = #{shutReason},</if>
            <if test="shutBeginTime != null">shut_begin_time = #{shutBeginTime},</if>
            <if test="shutEndTime != null">shut_end_time = #{shutEndTime},</if>
            <if test="shutTime != null">shut_time = #{shutTime},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="remark != null">remark = #{remark},</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>
        </trim>
        where record_shut_down_id = #{recordShutDownId}
    </update>

    <delete id="deleteDmsRecordShutDownByRecordShutDownId" parameterType="Long">
        delete
        from dms_record_shut_down
        where record_shut_down_id = #{recordShutDownId}
    </delete>

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