<?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.inspect.metadata.montdata.mapper.BasedataMontPatDevOnlineMapper">

    <resultMap type="BasedataMontPatDevOnline" id="BasedataMontPatDevOnlineResult">
        <result property="onlineId" column="online_id"/>
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="patrolDeviceName" column="patrol_device_name"/>
        <result property="status" column="status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="actionTime" column="action_time"/>
        <result property="onlineTime" column="online_time"/>
        <result property="offlineTime" column="offline_time"/>
        <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="selectBasedataMontPatDevOnlineVo">
        select online_id,
               eqp_book_id,
               patrol_device_code,
               patrol_device_name,
               status,
               del_flag,
               action_time,
               online_time,
               offline_time,
               create_by,
               create_time,
               update_by,
               update_time
        from basedata_mont_patdev_online
    </sql>

    <select id="selectBasedataMontPatDevOnlineList" parameterType="BasedataMontPatDevOnline"
            resultMap="BasedataMontPatDevOnlineResult">
        <include refid="selectBasedataMontPatDevOnlineVo"/>
        <where>
            <if test="eqpBookId != null ">and eqp_book_id = #{eqpBookId}</if>
            <if test="patrolDeviceCode != null  and patrolDeviceCode != ''">and patrol_device_code =
                #{patrolDeviceCode}
            </if>
            <if test="patrolDeviceName != null  and patrolDeviceName != ''">and patrol_device_name like concat('%',
                #{patrolDeviceName}, '%')
            </if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="onlineTime != null ">and online_time = #{onlineTime}</if>
            <if test="offlineTime != null ">and offline_time = #{offlineTime}</if>
            <if test="params.actionBeginTime != null and params.actionBeginTime != ''"><!-- 开始时间检索 -->
                and date_format(action_time,'%y-%m-%d %h:%i:%s') &gt;= date_format(#{params.actionBeginTime},'%y-%m-%d
                %h:%i:%s')
            </if>
            <if test="params.actionEndTime != null and params.actionEndTime != ''"><!-- 结束时间检索 -->
                and date_format(action_time,'%y-%m-%d %h:%i:%s') &lt;= date_format(#{params.actionEndTime},'%y-%m-%d
                %h:%i:%s')
            </if>
        </where>
    </select>

    <select id="selectBasedataMontPatDevOnlineByPatDevOnlineId" parameterType="Long"
            resultMap="BasedataMontPatDevOnlineResult">
        <include refid="selectBasedataMontPatDevOnlineVo"/>
        where online_id = #{onlineId}
    </select>

    <insert id="insertBasedataMontPatDevOnline" parameterType="BasedataMontPatDevOnline" useGeneratedKeys="true"
            keyProperty="onlineId">
        insert into basedata_mont_patdev_online
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="eqpBookId != null">eqp_book_id,</if>
            <if test="patrolDeviceCode != null">patrol_device_code,</if>
            <if test="patrolDeviceName != null">patrol_device_name,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="actionTime != null">action_time,</if>
            <if test="onlineTime != null">online_time,</if>
            <if test="offlineTime != null">offline_time,</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="eqpBookId != null">#{eqpBookId},</if>
            <if test="patrolDeviceCode != null">#{patrolDeviceCode},</if>
            <if test="patrolDeviceName != null">#{patrolDeviceName},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="actionTime != null">#{actionTime},</if>
            <if test="onlineTime != null">#{onlineTime},</if>
            <if test="offlineTime != null">#{offlineTime},</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="updateBasedataMontPatDevOnline" parameterType="BasedataMontPatDevOnline">
        update basedata_mont_patdev_online
        <trim prefix="SET" suffixOverrides=",">
            <if test="eqpBookId != null">eqp_book_id = #{eqpBookId},</if>
            <if test="patrolDeviceCode != null">patrol_device_code = #{patrolDeviceCode},</if>
            <if test="patrolDeviceName != null">patrol_device_name = #{patrolDeviceName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="actionTime != null">action_time = #{actionTime},</if>
            <if test="onlineTime != null">online_time = #{onlineTime},</if>
            <if test="offlineTime != null">offline_time = #{offlineTime},</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 online_id = #{onlineId}
    </update>

    <delete id="deleteBasedataMontPatDevOnlineByPatDevOnlineId" parameterType="Long">
        delete
        from basedata_mont_patdev_online
        where online_id = #{onlineId}
    </delete>

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