<?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.statis.mapper.BasedataStatisRobotUavOnlineDayMapper">

    <resultMap type="BasedataStatisRobotUavOnlineDay" id="BasedataStatisRobotUavOnlineDayResult">
        <result property="statId" column="stat_id"/>
        <result property="day" column="day"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="totalOnlineTime" column="total_online_time"/>
        <result property="offlineCount" column="offline_count"/>
        <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="deleteFlag" column="delete_flag"/>
    </resultMap>

    <sql id="selectBasedataStatisRobotUavOnlineDayVo">
        select stat_id, day, patrol_device_code, eqp_book_id, total_online_time, offline_count, create_by, create_time, update_by, update_time, delete_flag
        from basedata_statis_robotuav_online_day
    </sql>

    <select id="selectBasedataStatisRobotUavOnlineDayList" parameterType="BasedataStatisRobotUavOnlineDay"
            resultMap="BasedataStatisRobotUavOnlineDayResult">
        <include refid="selectBasedataStatisRobotUavOnlineDayVo"/>
        <where>
            <if test="day != null ">and day = #{day}</if>
            <if test="patrolDeviceCode != null  and patrolDeviceCode != ''">and patrol_device_code =
                #{patrolDeviceCode}
            </if>
            <if test="eqpBookId != null ">and eqp_book_id = #{eqpBookId}</if>
            <if test="totalOnlineTime != null ">and total_online_time = #{totalOnlineTime}</if>
            <if test="offlineCount != null ">and offline_count = #{offlineCount}</if>
            <if test="deleteFlag != null  and deleteFlag != ''">and delete_flag = #{deleteFlag}</if>
        </where>
    </select>
    <select id="selectBasedataStatisRobotUavOnlineDayByDayStartTime" parameterType="BasedataStatisRobotUavOnlineDay"
            resultMap="BasedataStatisRobotUavOnlineDayResult">
        <include refid="selectBasedataStatisRobotUavOnlineDayVo"/>
        <where>
            <if test="day != null ">and day = #{day}</if>
            <if test="patrolDeviceCode != null ">and patrol_device_code = #{patrolDeviceCode}</if>
            <if test="eqpBookId != null ">and eqp_book_id = #{eqpBookId}</if>
            limit 1
        </where>
    </select>
    <select id="selectBasedataStatisRobotUavOnlineDayByRobotUavOnlineStatId" parameterType="Long"
            resultMap="BasedataStatisRobotUavOnlineDayResult">
        <include refid="selectBasedataStatisRobotUavOnlineDayVo"/>
        where stat_id = #{statId}
    </select>

    <insert id="insertBasedataStatisRobotUavOnlineDay" parameterType="BasedataStatisRobotUavOnlineDay"
            useGeneratedKeys="true" keyProperty="statId">
        insert into basedata_statis_robotuav_online_day
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="day != null">day,</if>
            <if test="patrolDeviceCode != null">patrol_device_code,</if>
            <if test="eqpBookId != null">eqp_book_id,</if>
            <if test="totalOnlineTime != null">total_online_time,</if>
            <if test="offlineCount != null">offline_count,</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="deleteFlag != null">delete_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="day != null">#{day},</if>
            <if test="patrolDeviceCode != null">#{patrolDeviceCode},</if>
            <if test="eqpBookId != null">#{eqpBookId},</if>
            <if test="totalOnlineTime != null">#{totalOnlineTime},</if>
            <if test="offlineCount != null">#{offlineCount},</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="deleteFlag != null">#{deleteFlag},</if>
        </trim>
    </insert>

    <update id="updateBasedataStatisRobotUavOnlineDay" parameterType="BasedataStatisRobotUavOnlineDay">
        update basedata_statis_robotuav_online_day
        <trim prefix="SET" suffixOverrides=",">
            <if test="day != null">day = #{day},</if>
            <if test="patrolDeviceCode != null">patrol_device_code = #{patrolDeviceCode},</if>
            <if test="eqpBookId != null">eqp_book_id = #{eqpBookId},</if>
            <if test="totalOnlineTime != null">total_online_time = #{totalOnlineTime},</if>
            <if test="offlineCount != null">offline_count = #{offlineCount},</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="deleteFlag != null">delete_flag = #{deleteFlag},</if>
        </trim>
        where stat_id = #{statId}
    </update>

    <delete id="deleteBasedataStatisRobotUavOnlineDayByRobotUavOnlineStatId" parameterType="Long">
        delete
        from basedata_statis_robotuav_online_day
        where stat_id = #{statId}
    </delete>

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