<?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.EquTypeMapper">
    
    <resultMap type="com.djhk.uav.equ.domain.EquType" id="EquTypeResult">
        <result property="typeId"    column="type_id"    />
        <result property="typeName"    column="type_name"    />
        <result property="useFlag"    column="use_flag"    />
        <result property="showOrder"    column="show_order"    />
        <result property="dynModelFile"    column="dyn_model_file"    />
        <result property="staModelFile"    column="sta_model_file"    />
        <result property="iconFile"    column="icon_file"    />
    </resultMap>

    <resultMap type="com.djhk.uav.equ.domain.EquType" id="EquTypeResult1">
        <result property="typeId"    column="type_id"    />
        <result property="typeName"    column="type_name"    />
    </resultMap>

    <sql id="selectEquTypeVo">
        select type_id, type_name, use_flag, show_order, dyn_model_file, sta_model_file, icon_file from equ_type
    </sql>

    <select id="selectEquTypeList" parameterType="com.djhk.uav.equ.domain.EquType" resultMap="EquTypeResult">
        <include refid="selectEquTypeVo"/>
        <where>  
            <if test="typeName != null  and typeName != ''"> and type_name like concat('%', #{typeName}, '%')</if>
            <if test="useFlag != null  and useFlag != ''"> and use_flag = #{useFlag}</if>
            <if test="showOrder != null "> and show_order = #{showOrder}</if>
            <if test="dynModelFile != null "> and dyn_model_file = #{dynModelFile}</if>
            <if test="staModelFile != null "> and sta_model_file = #{staModelFile}</if>
            <if test="iconFile != null "> and icon_file = #{iconFile}</if>
        </where>
    </select>
    
    <select id="selectEquTypeByTypeId" parameterType="String" resultMap="EquTypeResult">
        <include refid="selectEquTypeVo"/>
        where type_id = #{typeId}
    </select>

    <select id="selectEquType" parameterType="String" resultMap="EquTypeResult">
        select type_id, type_name  from equ_type where use_flag = '1'
    </select>

    <insert id="insertEquType" parameterType="com.djhk.uav.equ.domain.EquType">
        insert into equ_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeId != null">type_id,</if>
            <if test="typeName != null">type_name,</if>
            <if test="useFlag != null">use_flag,</if>
            <if test="showOrder != null">show_order,</if>
            <if test="dynModelFile != null">dyn_model_file,</if>
            <if test="staModelFile != null">sta_model_file,</if>
            <if test="iconFile != null">icon_file,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="typeId != null">#{typeId},</if>
            <if test="typeName != null">#{typeName},</if>
            <if test="useFlag != null">#{useFlag},</if>
            <if test="showOrder != null">#{showOrder},</if>
            <if test="dynModelFile != null">#{dynModelFile},</if>
            <if test="staModelFile != null">#{staModelFile},</if>
            <if test="iconFile != null">#{iconFile},</if>
         </trim>
    </insert>

    <update id="updateEquType" parameterType="com.djhk.uav.equ.domain.EquType">
        update equ_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="typeName != null">type_name = #{typeName},</if>
            <if test="useFlag != null">use_flag = #{useFlag},</if>
            <if test="showOrder != null">show_order = #{showOrder},</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>
        </trim>
        where type_id = #{typeId}
    </update>

    <delete id="deleteEquTypeByTypeId" parameterType="String">
        delete from equ_type where type_id = #{typeId}
    </delete>

    <delete id="deleteEquTypeByTypeIds" parameterType="String">
        delete from equ_type where type_id in 
        <foreach item="typeId" collection="array" open="(" separator="," close=")">
            #{typeId}
        </foreach>
    </delete>

    <select id="getEqumodelDefine" parameterType="Long" resultMap="EquTypeParamResult">
        select param_code,param_name,data_type,dec_cnt,min_val,max_val from equ_param_define where use_flag='1'
        and param_code in (select param_code from equ_type_param where type_id = #{typeId}) order by show_order
    </select>
    <resultMap type="com.djhk.uav.equ.domain.EquParamDefine" id="EquTypeParamResult">
        <result property="paramCode"    column="param_code"    />
        <result property="paramName"    column="param_name"    />
        <result property="dataType"    column="data_type"    />
        <result property="decCnt"    column="dec_cnt"    />
        <result property="minVal"    column="min_val"    />
        <result property="maxVal"    column="max_val"    />
    </resultMap>

    <select id="getEqumodelParam" parameterType="Long" resultMap="EquModelParamResult">
        SELECT a.param_seq,a.param_code,b.param_name ,a.param_value,a.model_id,b.data_type,b.dec_cnt,b.min_val,b.max_val
         FROM equ_model_param a left join equ_param_define b on a.param_code=b.param_code  where a.model_id=#{modelId}
                         ORDER BY b.show_order
    </select>
    <select id="selectEquTypeByTypeName" resultType="com.djhk.uav.equ.domain.EquType">
        <include refid="selectEquTypeVo"/>
        where type_name = #{typeNmae}
    </select>
    <resultMap type="com.djhk.uav.equ.domain.EquModelParam" id="EquModelParamResult">
        <result property="paramSeq"    column="param_seq"    />
        <result property="paramCode"    column="param_code"    />
        <result property="paramValue"    column="param_value"    />
        <result property="paramName"    column="param_name"    />
        <result property="modelId"    column="model_id"    />
        <result property="dataType"    column="data_type"    />
        <result property="decCnt"    column="dec_cnt"    />
        <result property="minVal"    column="min_val"    />
        <result property="maxVal"    column="max_val"    />
    </resultMap>
</mapper>
