<?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.TreenodeinstanceMapper">
    
    <resultMap type="Treenodeinstance" id="TreenodeinstanceResult">
        <result property="id"    column="id"    />
        <result property="treeId"    column="tree_id"    />
        <result property="templateId"    column="template_id"    />
        <result property="instanceName"    column="instance_name"    />
        <result property="isRoot"    column="is_root"    />
        <result property="preconditionTempleteId"    column="precondition_templete_id"    />
        <result property="uuid"    column="uuid"    />
    </resultMap>

    <sql id="selectTreenodeinstanceVo">
        select id, tree_id, template_id, instance_name, is_root, precondition_templete_id, uuid from treenodeinstance
    </sql>

    <select id="selectTreenodeinstanceList" parameterType="Treenodeinstance" resultMap="TreenodeinstanceResult">
        <include refid="selectTreenodeinstanceVo"/>
        <where>  
            <if test="treeId != null "> and tree_id = #{treeId}</if>
            <if test="templateId != null "> and template_id = #{templateId}</if>
            <if test="instanceName != null  and instanceName != ''"> and instance_name like concat('%', #{instanceName}, '%')</if>
            <if test="isRoot != null "> and is_root = #{isRoot}</if>
            <if test="preconditionTempleteId != null "> and precondition_templete_id = #{preconditionTempleteId}</if>
            <if test="uuid != null  and uuid != ''"> and uuid = #{uuid}</if>
        </where>
    </select>
    
    <select id="selectTreenodeinstanceById" parameterType="Long" resultMap="TreenodeinstanceResult">
        <include refid="selectTreenodeinstanceVo"/>
        where id = #{id}
    </select>

    <insert id="insertTreenodeinstance" parameterType="Treenodeinstance" useGeneratedKeys="true" keyProperty="id">
        insert into treenodeinstance
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="treeId != null">tree_id,</if>
            <if test="templateId != null">template_id,</if>
            <if test="instanceName != null">instance_name,</if>
            <if test="isRoot != null">is_root,</if>
            <if test="preconditionTempleteId != null">precondition_templete_id,</if>
            <if test="uuid != null">uuid,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="treeId != null">#{treeId},</if>
            <if test="templateId != null">#{templateId},</if>
            <if test="instanceName != null">#{instanceName},</if>
            <if test="isRoot != null">#{isRoot},</if>
            <if test="preconditionTempleteId != null">#{preconditionTempleteId},</if>
            <if test="uuid != null">#{uuid},</if>
         </trim>
    </insert>

    <update id="updateTreenodeinstance" parameterType="Treenodeinstance">
        update treenodeinstance
        <trim prefix="SET" suffixOverrides=",">
            <if test="treeId != null">tree_id = #{treeId},</if>
            <if test="templateId != null">template_id = #{templateId},</if>
            <if test="instanceName != null">instance_name = #{instanceName},</if>
            <if test="isRoot != null">is_root = #{isRoot},</if>
            <if test="preconditionTempleteId != null">precondition_templete_id = #{preconditionTempleteId},</if>
            <if test="uuid != null">uuid = #{uuid},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTreenodeinstanceById" parameterType="Long">
        delete from treenodeinstance where id = #{id}
    </delete>

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