<?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.solution.system.mapper.TemplateparameterdefMapper">
    
    <resultMap type="Templateparameterdef" id="TemplateparameterdefResult">
        <result property="id"    column="id"    />
        <result property="templateId"    column="template_id"    />
        <result property="paramKey"    column="param_key"    />
        <result property="dataType"    column="data_type"    />
        <result property="defaultValue"    column="default_value"    />
        <result property="description"    column="description"    />
        <result property="templateType"    column="template_type"    />
    </resultMap>

    <sql id="selectTemplateparameterdefVo">
        select id, template_id, param_key, data_type, default_value, description, template_type from templateparameterdef
    </sql>

    <select id="selectTemplateparameterdefList" parameterType="Templateparameterdef" resultMap="TemplateparameterdefResult">
        <include refid="selectTemplateparameterdefVo"/>
        <where>  
            <if test="templateId != null "> and template_id = #{templateId}</if>
            <if test="paramKey != null  and paramKey != ''"> and param_key = #{paramKey}</if>
            <if test="dataType != null  and dataType != ''"> and data_type = #{dataType}</if>
            <if test="defaultValue != null  and defaultValue != ''"> and default_value = #{defaultValue}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="templateType != null  and templateType != ''"> and template_type = #{templateType}</if>
        </where>
    </select>
    
    <select id="selectTemplateparameterdefById" parameterType="Long" resultMap="TemplateparameterdefResult">
        <include refid="selectTemplateparameterdefVo"/>
        where id = #{id}
    </select>

    <insert id="insertTemplateparameterdef" parameterType="Templateparameterdef" useGeneratedKeys="true" keyProperty="id">
        insert into templateparameterdef
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="templateId != null">template_id,</if>
            <if test="paramKey != null and paramKey != ''">param_key,</if>
            <if test="dataType != null and dataType != ''">data_type,</if>
            <if test="defaultValue != null and defaultValue != ''">default_value,</if>
            <if test="description != null">description,</if>
            <if test="templateType != null and templateType != ''">template_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="templateId != null">#{templateId},</if>
            <if test="paramKey != null and paramKey != ''">#{paramKey},</if>
            <if test="dataType != null and dataType != ''">#{dataType},</if>
            <if test="defaultValue != null and defaultValue != ''">#{defaultValue},</if>
            <if test="description != null">#{description},</if>
            <if test="templateType != null and templateType != ''">#{templateType},</if>
         </trim>
    </insert>

    <update id="updateTemplateparameterdef" parameterType="Templateparameterdef">
        update templateparameterdef
        <trim prefix="SET" suffixOverrides=",">
            <if test="templateId != null">template_id = #{templateId},</if>
            <if test="paramKey != null and paramKey != ''">param_key = #{paramKey},</if>
            <if test="dataType != null and dataType != ''">data_type = #{dataType},</if>
            <if test="defaultValue != null and defaultValue != ''">default_value = #{defaultValue},</if>
            <if test="description != null">description = #{description},</if>
            <if test="templateType != null and templateType != ''">template_type = #{templateType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTemplateparameterdefById" parameterType="Long">
        delete from templateparameterdef where id = #{id}
    </delete>

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