<?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.NodeconnectionMapper">
    
    <resultMap type="Nodeconnection" id="NodeconnectionResult">
        <result property="id"    column="id"    />
        <result property="parentNodeId"    column="parent_node_id"    />
        <result property="childNodeId"    column="child_node_id"    />
        <result property="orderIndex"    column="order_index"    />
    </resultMap>

    <sql id="selectNodeconnectionVo">
        select id, parent_node_id, child_node_id, order_index from nodeconnection
    </sql>

    <select id="selectNodeconnectionList" parameterType="Nodeconnection" resultMap="NodeconnectionResult">
        <include refid="selectNodeconnectionVo"/>
        <where>  
            <if test="parentNodeId != null "> and parent_node_id = #{parentNodeId}</if>
            <if test="childNodeId != null "> and child_node_id = #{childNodeId}</if>
            <if test="orderIndex != null "> and order_index = #{orderIndex}</if>
        </where>
    </select>
    
    <select id="selectNodeconnectionById" parameterType="Long" resultMap="NodeconnectionResult">
        <include refid="selectNodeconnectionVo"/>
        where id = #{id}
    </select>

    <insert id="insertNodeconnection" parameterType="Nodeconnection" useGeneratedKeys="true" keyProperty="id">
        insert into nodeconnection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentNodeId != null">parent_node_id,</if>
            <if test="childNodeId != null">child_node_id,</if>
            <if test="orderIndex != null">order_index,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentNodeId != null">#{parentNodeId},</if>
            <if test="childNodeId != null">#{childNodeId},</if>
            <if test="orderIndex != null">#{orderIndex},</if>
         </trim>
    </insert>

    <update id="updateNodeconnection" parameterType="Nodeconnection">
        update nodeconnection
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentNodeId != null">parent_node_id = #{parentNodeId},</if>
            <if test="childNodeId != null">child_node_id = #{childNodeId},</if>
            <if test="orderIndex != null">order_index = #{orderIndex},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNodeconnectionById" parameterType="Long">
        delete from nodeconnection where id = #{id}
    </delete>

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