<?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.eqpbook.mapper.BasedataUavResumeInfoMapper">

    <resultMap type="BasedataUavResumeInfo" id="BasedataUavResumeInfoResult">
        <result property="recordId" column="record_id"/>
        <result property="devType" column="dev_type"/>
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="devName" column="dev_name"/>
        <result property="recordType" column="record_type"/>
        <result property="recordName" column="record_name"/>
        <result property="recordTime" column="record_time"/>
        <result property="createTime" column="create_time"/>
        <result property="maintainTime" column="maintain_time"/>
        <result property="inTime" column="in_time"/>
        <result property="outTime" column="out_time"/>
        <result property="againTime" column="again_time"/>
    </resultMap>

    <sql id="selectBasedataUavResumeInfoVo">
        select record_id,
               dev_type,
               eqp_book_id,
               dev_name,
               record_type,
               record_name,
               record_time,
               create_time,
               maintain_time,
               in_time,
               out_time,
               again_time
        from basedata_uav_resume_info
    </sql>

    <select id="selectBasedataUavResumeInfoList" parameterType="BasedataUavResumeInfo"
            resultMap="BasedataUavResumeInfoResult">
        SELECT
        record_id,
        dev_type,
        a.eqp_book_id,
        b.patroldevice_name dev_name,
        record_type,
        record_name,
        record_time,
        a.create_time,
        maintain_time,
        in_time,
        out_time,
        again_time
        FROM
        basedata_uav_resume_info a
        LEFT JOIN basedata_eqpbook b on a.eqp_book_id = b.eqp_book_id
        <where>
            <if test="eqpBookId != null  and eqpBookId != ''">and eqp_book_id = #{eqpBookId}</if>
            <if test="recordType != null  and recordType != ''">and record_type = #{recordType}</if>
        </where>
        <!--        SELECT-->
        <!--            a.record_id,-->
        <!--            a.eqp_book_id,-->
        <!--            b.patroldevice_name dev_name,-->
        <!--            a.record_type,-->
        <!--            a.record_name,-->
        <!--            a.record_time,-->
        <!--            a.create_time,-->
        <!--            a.maintain_time,-->
        <!--            a.in_time,-->
        <!--            a.out_time,-->
        <!--            a.again_time,-->
        <!--            c.dict_label dev_type-->
        <!--        FROM-->
        <!--            basedata_uav_resume_info a,-->
        <!--            basedata_eqpbook b,-->
        <!--            sys_dict_data c-->
        <!--        WHERE-->
        <!--            a.eqp_book_id = b.eqp_book_id-->
        <!--            AND c.dict_type = 'device_type'-->
        <!--            AND b.type = c.dict_value-->
        <!--        <where>-->
        <!--            <if test="devType != null  and devType != ''"> and a.dev_type = #{devType}</if>-->
        <!--            <if test="devName != null  and devName != ''"> and a.devnamedev_name like concat('%', #{devName}, '%')</if>-->
        <!--            <if test="recordType != null  and recordType != ''"> and a.record_type = #{recordType}</if>-->
        <!--            <if test="createTime != null "> and a.create_time = #{createTime}</if>-->
        <!--        </where>-->

    </select>

    <select id="selectBasedataUavResumeInfoByRecordId" parameterType="Long" resultMap="BasedataUavResumeInfoResult">
        <include refid="selectBasedataUavResumeInfoVo"/>
        where record_id = #{recordId}
    </select>

    <insert id="insertBasedataUavResumeInfo" parameterType="BasedataUavResumeInfo" useGeneratedKeys="true"
            keyProperty="recordId">
        insert into basedata_uav_resume_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="devType != null">dev_type,</if>
            <if test="eqpBookId != null">eqp_book_id,</if>
            <if test="devName != null">dev_name,</if>
            <if test="recordType != null">record_type,</if>
            <if test="recordName != null">record_name,</if>
            <if test="recordTime != null">record_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="maintainTime != null">maintain_time,</if>
            <if test="inTime != null">in_time,</if>
            <if test="outTime != null">out_time,</if>
            <if test="againTime != null">again_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="devType != null">#{devType},</if>
            <if test="eqpBookId != null">#{eqpBookId},</if>
            <if test="devName != null">#{devName},</if>
            <if test="recordType != null">#{recordType},</if>
            <if test="recordName != null">#{recordName},</if>
            <if test="recordTime != null">#{recordTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="maintainTime != null">#{maintainTime},</if>
            <if test="inTime != null">#{inTime},</if>
            <if test="outTime != null">#{outTime},</if>
            <if test="againTime != null">#{againTime},</if>
        </trim>
    </insert>

    <update id="updateBasedataUavResumeInfo" parameterType="BasedataUavResumeInfo">
        update basedata_uav_resume_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="devType != null">dev_type = #{devType},</if>
            <if test="eqpBookId != null">eqp_book_id = #{eqpBookId},</if>
            <if test="devName != null">dev_name = #{devName},</if>
            <if test="recordType != null">record_type = #{recordType},</if>
            <if test="recordName != null">record_name = #{recordName},</if>
            <if test="recordTime != null">record_time = #{recordTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="maintainTime != null">maintain_time = #{maintainTime},</if>
            <if test="inTime != null">in_time = #{inTime},</if>
            <if test="outTime != null">out_time = #{outTime},</if>
            <if test="againTime != null">again_time = #{againTime},</if>
        </trim>
        where record_id = #{recordId}
    </update>

    <delete id="deleteBasedataUavResumeInfoByRecordId" parameterType="Long">
        delete
        from basedata_uav_resume_info
        where record_id = #{recordId}
    </delete>

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