<?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.EquModelMapper">
    
    <resultMap type="com.djhk.uav.equ.domain.EquModel" id="EquModelResult">
        <result property="modelId"    column="model_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="modelCode"    column="model_code"    />
        <result property="modelName"    column="model_name"    />
        <result property="showOrder"    column="show_order"    />
        <result property="delMark"    column="del_mark"    />
        <result property="dynModelFile"    column="dyn_model_file"    />
        <result property="staModelFile"    column="sta_model_file"    />
        <result property="iconFile"    column="icon_file"    />
        <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="selectEquModelVo">
        select model_id, type_id, model_code, model_name, show_order, del_mark, dyn_model_file, sta_model_file,
        icon_file, create_by, create_time, update_by, update_time from equ_model
    </sql>

    <select id="selectEquModelList" parameterType="com.djhk.uav.equ.domain.EquModel" resultMap="EquModelResult">
        <include refid="selectEquModelVo"/>
        <where>  
            <if test="typeId != null  and typeId != ''"> and type_id = #{typeId}</if>
            <if test="modelCode != null  and modelCode != ''"> and model_code like concat('%', #{modelCode}, '%')</if>
            <if test="modelName != null  and modelName != ''"> and model_name like concat('%', #{modelName}, '%')</if>
            and del_mark='0' order by create_time desc
        </where>
    </select>

    <select id="selectEquModelByModelId" parameterType="com.djhk.uav.equ.domain.EquModel" resultMap="EquModelResult">
        <include refid="selectEquModelVo"/>
        <where>
            del_mark = '0'
            and model_id = #{modelId}
        </where>
    </select>

    <insert id="insertEquModel" parameterType="com.djhk.uav.equ.domain.EquModel" useGeneratedKeys="true" keyProperty="modelId">
        insert into equ_model
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeId != null and typeId != ''">type_id,</if>
            <if test="modelCode != null and modelCode != ''">model_code,</if>
            <if test="modelName != null and modelName != ''">model_name,</if>
            <if test="showOrder != null">show_order,</if>
            <if test="delMark != null">del_mark,</if>
            <if test="dynModelFile != null">dyn_model_file,</if>
            <if test="staModelFile != null">sta_model_file,</if>
            <if test="iconFile != null">icon_file,</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="typeId != null and typeId != ''">#{typeId},</if>
            <if test="modelCode != null and modelCode != ''">#{modelCode},</if>
            <if test="modelName != null and modelName != ''">#{modelName},</if>
            <if test="showOrder != null">#{showOrder},</if>
            <if test="delMark != null">#{delMark},</if>
            <if test="dynModelFile != null">#{dynModelFile},</if>
            <if test="staModelFile != null">#{staModelFile},</if>
            <if test="iconFile != null">#{iconFile},</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>

    <select id="checkModelCode" parameterType="com.djhk.uav.equ.domain.EquModel" resultMap="EquModelResult">
        <include refid="selectEquModelVo"/>
        <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.EquModel">
        <include refid="selectEquModelVo"/>
        <where>
            del_mark = '0'
            <if test="createBy != null  and createBy != ''"> and create_by = #{createBy}</if>
        </where>
    </select>

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

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

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


    <update id="updateEquModel" parameterType="com.djhk.uav.equ.domain.EquModel">
        update equ_model
        <set>
            <if test="typeId != null and typeId != ''">type_id = #{typeId},</if>
            <if test="modelCode != null and modelCode != ''">model_code = #{modelCode},</if>
            <if test="modelName != null and modelName != ''">model_name = #{modelName},</if>
            <if test="showOrder != null">show_order = #{showOrder},</if>
            <if test="delMark != null">del_mark = #{delMark},</if>
            <if test="dynModelFile != null">dyn_model_file = #{dynModelFile},</if>
            <if test="staModelFile != null">sta_model_file = #{staModelFile},</if>
            <if test="iconFile != null">icon_file = #{iconFile},</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>
            update_time = DATE_FORMAT(SYSDATE(), '%Y-%m-%d %H:%i:%s')
        </set>
        where model_id = #{modelId}
    </update>
</mapper>
