<?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.djhk.uav.equ.mapper.MetasploitableMapper">
    
    <resultMap type="com.djhk.uav.equ.domain.Metasploitable" id="MetasploitableResult">
        <result property="id"    column="id"    />
        <result property="brand"    column="brand"    />
        <result property="uavName"    column="uav_name"    />
        <result property="structure"    column="structure"    />
        <result property="product"    column="product"    />
        <result property="energy"    column="energy"    />
        <result property="size"    column="size"    />
        <result property="useType"    column="use_type"    />
        <result property="photoType"    column="photo_type"    />
        <result property="infoLinks"    column="info_links"    />
        <result property="positionSys"    column="position_sys"    />
        <result property="productPre"    column="product_pre"    />
        <result property="photo"    column="photo"    />
        <result property="price"    column="price"    />
        <result property="weight"    column="weight"    />
        <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="selectMetasploitableVo">
        select id, brand, uav_name, structure, product, energy, size, use_type, photo_type, info_links, position_sys, product_pre, photo,
        price,weight, create_by, create_time, update_by, update_time from uav_metasploitable
    </sql>

    <select id="selectMetasploitableList" parameterType="com.djhk.uav.equ.domain.Metasploitable" resultMap="MetasploitableResult">
        <include refid="selectMetasploitableVo"/>
        <where>  
            <if test="brand != null  and brand != ''"> and brand like concat('%', #{brand}, '%')</if>
            <if test="uavName != null  and uavName != ''"> and uav_name like concat('%', #{uavName}, '%')</if>
            <if test="structure != null  and structure != ''"> and structure =#{structure}</if>
            and del_mark='0'
        </where>
    </select>

    <select id="selectMetasploitableById" parameterType="com.djhk.uav.equ.domain.Metasploitable" resultMap="MetasploitableResult">
        <include refid="selectMetasploitableVo"/>
        <where>
            del_mark = '0'
            and id = #{id}
        </where>
    </select>

    <insert id="insertMetasploitable" parameterType="com.djhk.uav.equ.domain.Metasploitable" useGeneratedKeys="true" keyProperty="id">
        insert into uav_metasploitable
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="brand != null and brand != ''">brand,</if>
            <if test="uavName != null and uavName != ''">uav_name,</if>
            <if test="structure != null and structure != ''">structure,</if>
            <if test="product != null and product != ''">product,</if>
            <if test="energy != null and energy != ''">energy,</if>
            <if test="size != null and size != ''">size,</if>
            <if test="useType != null and useType != ''">use_type,</if>
            <if test="photoType != null and photoType != ''">photo_type,</if>
            <if test="infoLinks != null and infoLinks != ''">info_links,</if>
            <if test="positionSys != null and positionSys != ''">position_sys,</if>
            <if test="productPre != null and productPre != ''">product_pre,</if>
            <if test="price != null and price != ''">price,</if>
            <if test="weight != null and weight != ''">weight,</if>

            <if test="photo != null">photo,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="brand != null and brand != ''">#{brand},</if>
            <if test="uavName != null and uavName != ''">#{uavName},</if>
            <if test="structure != null and structure != ''">#{structure},</if>
            <if test="product != null and product != ''">#{product},</if>
            <if test="energy != null and energy != ''">#{energy},</if>
            <if test="size != null and size != ''">#{size},</if>
            <if test="useType != null and useType != ''">#{useType},</if>
            <if test="photoType != null and photoType != ''">#{photoType},</if>
            <if test="infoLinks != null and infoLinks != ''">#{infoLinks},</if>
            <if test="positionSys != null and positionSys != ''">#{positionSys},</if>
            <if test="productPre != null and productPre != ''">#{productPre},</if>
            <if test="price != null and price != ''">#{price},</if>
            <if test="weight != null and weight != ''">#{weight},</if>

            <if test="photo != null">#{photo},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <insert id="insertMetasploitables" parameterType="com.djhk.uav.equ.domain.Metasploitable" useGeneratedKeys="true" keyProperty="id">
        insert into uav_metasploitable
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="brand != null and brand != ''">brand,</if>
            <if test="uavName != null and uavName != ''">uav_name,</if>
            <if test="structure != null and structure != ''">structure,</if>
            <if test="product != null and product != ''">product,</if>
            <if test="energy != null and energy != ''">energy,</if>
            <if test="size != null and size != ''">size,</if>
            <if test="useType != null and useType != ''">use_type,</if>
            <if test="photoType != null and photoType != ''">photo_type,</if>
            <if test="infoLinks != null and infoLinks != ''">info_links,</if>
            <if test="positionSys != null and positionSys != ''">position_sys,</if>
            <if test="productPre != null and productPre != ''">product_pre,</if>
            <if test="price != null and price != ''">price,</if>
            <if test="weight != null and weight != ''">weight,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="brand != null and brand != ''">#{brand},</if>
            <if test="uavName != null and uavName != ''">#{uavName},</if>
            <if test="structure != null and structure != ''">#{structure},</if>
            <if test="product != null and product != ''">#{product},</if>
            <if test="energy != null and energy != ''">#{energy},</if>
            <if test="size != null and size != ''">#{size},</if>
            <if test="useType != null and useType != ''">#{useType},</if>
            <if test="photoType != null and photoType != ''">#{photoType},</if>
            <if test="infoLinks != null and infoLinks != ''">#{infoLinks},</if>
            <if test="positionSys != null and positionSys != ''">#{positionSys},</if>
            <if test="productPre != null and productPre != ''">#{productPre},</if>
            <if test="price != null and price != ''">#{price},</if>
            <if test="weight != null and weight != ''">#{weight},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>


    <select id="selectMetasploitableType" parameterType="com.djhk.uav.equ.domain.Metasploitable" resultMap="MetasploitableResult">
        select uav_name from uav_metasploitable
        <where>
            del_mark = '0'
            <if test="uavName != null  and uavName != ''"> and uav_name = #{uavName}</if>
        </where>
    </select>



    <select id="checkModelCode" parameterType="com.djhk.uav.equ.domain.Metasploitable" resultMap="MetasploitableResult">
        <include refid="selectMetasploitableVo"/>
        <where>
            del_mark = '0'
            <if test="modelCode != null  and modelCode != ''"> and model_code = #{modelCode}</if>
        </where>
    </select>
    <select id="selectEquInfoExportList" resultType="com.djhk.uav.equ.domain.Metasploitable">
        <include refid="selectMetasploitableVo"/>
        <where>
            del_mark = '0'
            <if test="createBy != null  and createBy != ''"> and create_by = #{createBy}</if>
        </where>
    </select>

    <!--    <update id="deleteMetasploitableByids" parameterType="Long">-->
<!--        update equ_model-->
<!--        <set>-->
<!--            del_mark = '2',-->
<!--            update_time = sysdate()-->
<!--        </set>-->
<!--        where model_Id in-->
<!--        <foreach item="id" collection="array" open="(" separator="," close=")">-->
<!--            #{id}-->
<!--        </foreach>-->
<!--    </update>-->

<!--    <update id="deleteMetasploitableByids" parameterType="Long">-->
<!--        delete from equ_model-->
<!--        where model_Id in-->
<!--        <foreach item="id" collection="array" open="(" separator="," close=")">-->
<!--            #{id}-->
<!--        </foreach>-->
<!--    </update>-->

    <update id="deleteMetasploitableByIds" parameterType="Long">
        update uav_metasploitable
        set del_mark = '2',
        update_time = sysdate()
        where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>


    <update id="updateMetasploitable" parameterType="com.djhk.uav.equ.domain.Metasploitable">
        update uav_metasploitable
        <set>
            <if test="brand != null and brand != ''">brand = #{brand},</if>
            <if test="uavName != null and uavName != ''">uav_name = #{uavName},</if>
            <if test="structure != null and structure != ''">structure = #{structure},</if>
            <if test="product != null and product != ''">product = #{product},</if>
            <if test="energy != null and energy != ''">energy = #{energy},</if>
            <if test="size != null and size != ''">size = #{size},</if>
            <if test="useType != null and useType != ''">use_type = #{useType},</if>
            <if test="photoType != null and photoType != ''">photo_type = #{photoType},</if>
            <if test="infoLinks != null and infoLinks != ''">info_links = #{infoLinks},</if>
            <if test="positionSys != null and positionSys != ''">position_sys = #{positionSys},</if>
            <if test="productPre != null and productPre != ''">product_pre = #{productPre},</if>
            <if test="price != null and price != ''">price = #{price},</if>
            <if test="weight != null and weight != ''">weight = #{weight},</if>
            <if test="photo != null and photo != ''">photo = #{photo},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = DATE_FORMAT(SYSDATE(), '%Y-%m-%d %H:%i:%s')
        </set>
        where id = #{id}
    </update>
</mapper>
