<?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.xinelu.manage.mapper.scriptinfoedge.ScriptInfoEdgeMapper">

    <resultMap type="ScriptInfoEdge" id="ScriptInfoEdgeResult">
        <result property="id" column="id"/>
        <result property="scriptInfoId" column="script_info_id"/>
        <result property="scriptEdgeName" column="script_edge_name"/>
        <result property="startNodeId" column="start_node_id"/>
        <result property="startNodeName" column="start_node_name"/>
        <result property="endNodeId" column="end_node_id"/>
        <result property="endNodeName" column="end_node_name"/>
        <result property="condition" column="condition"/>
        <result property="keywords" column="keywords"/>
        <result property="remark" column="remark"/>
        <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="selectScriptInfoEdgeVo">
        select id,
               script_info_id,
               script_edge_name,
               start_node_id,
               start_node_name,
               end_node_id,
               end_node_name,
               condition,
               keywords,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from script_info_edge
    </sql>

    <select id="selectScriptInfoEdgeList" parameterType="ScriptInfoEdge" resultMap="ScriptInfoEdgeResult">
        <include refid="selectScriptInfoEdgeVo"/>
        <where>
            <if test="scriptInfoId != null ">
                and script_info_id = #{scriptInfoId}
            </if>
            <if test="scriptEdgeName != null  and scriptEdgeName != ''">
                and script_edge_name like concat('%', #{scriptEdgeName}, '%')
            </if>
            <if test="startNodeId != null ">
                and start_node_id = #{startNodeId}
            </if>
            <if test="startNodeName != null  and startNodeName != ''">
                and start_node_name like concat('%', #{startNodeName}, '%')
            </if>
            <if test="endNodeId != null ">
                and end_node_id = #{endNodeId}
            </if>
            <if test="endNodeName != null  and endNodeName != ''">
                and end_node_name like concat('%', #{endNodeName}, '%')
            </if>
            <if test="condition != null  and condition != ''">
                and condition = #{condition}
            </if>
            <if test="keywords != null  and keywords != ''">
                and keywords = #{keywords}
            </if>
        </where>
    </select>

    <select id="selectScriptInfoEdgeById" parameterType="Long"
            resultMap="ScriptInfoEdgeResult">
        <include refid="selectScriptInfoEdgeVo"/>
        where id = #{id}
    </select>

    <insert id="insertScriptInfoEdge" parameterType="ScriptInfoEdge" useGeneratedKeys="true"
            keyProperty="id">
        insert into script_info_edge
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="scriptInfoId != null">script_info_id,
            </if>
            <if test="scriptEdgeName != null">script_edge_name,
            </if>
            <if test="startNodeId != null">start_node_id,
            </if>
            <if test="startNodeName != null">start_node_name,
            </if>
            <if test="endNodeId != null">end_node_id,
            </if>
            <if test="endNodeName != null">end_node_name,
            </if>
            <if test="condition != null">condition,
            </if>
            <if test="keywords != null">keywords,
            </if>
            <if test="remark != null">remark,
            </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="scriptInfoId != null">#{scriptInfoId},
            </if>
            <if test="scriptEdgeName != null">#{scriptEdgeName},
            </if>
            <if test="startNodeId != null">#{startNodeId},
            </if>
            <if test="startNodeName != null">#{startNodeName},
            </if>
            <if test="endNodeId != null">#{endNodeId},
            </if>
            <if test="endNodeName != null">#{endNodeName},
            </if>
            <if test="condition != null">#{condition},
            </if>
            <if test="keywords != null">#{keywords},
            </if>
            <if test="remark != null">#{remark},
            </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>

    <update id="updateScriptInfoEdge" parameterType="ScriptInfoEdge">
        update script_info_edge
        <trim prefix="SET" suffixOverrides=",">
            <if test="scriptInfoId != null">script_info_id =
                #{scriptInfoId},
            </if>
            <if test="scriptEdgeName != null">script_edge_name =
                #{scriptEdgeName},
            </if>
            <if test="startNodeId != null">start_node_id =
                #{startNodeId},
            </if>
            <if test="startNodeName != null">start_node_name =
                #{startNodeName},
            </if>
            <if test="endNodeId != null">end_node_id =
                #{endNodeId},
            </if>
            <if test="endNodeName != null">end_node_name =
                #{endNodeName},
            </if>
            <if test="condition != null">condition =
                #{condition},
            </if>
            <if test="keywords != null">keywords =
                #{keywords},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </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>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteScriptInfoEdgeById" parameterType="Long">
        delete
        from script_info_edge
        where id = #{id}
    </delete>

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

    <delete id="deleteScriptInfoEdgeByScriptInfoIds">
        delete from script_info_edge where script_info_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <insert id="insertScriptInfoEdgeList" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        insert into script_info_edge (
        script_info_id,
        script_edge_name,
        start_node_id,
        start_node_name,
        end_node_id,
        end_node_name,
        `condition`,
        keywords,
        remark,
        create_by,
        create_time
        )values
        <foreach item="scriptInfoEdges" index="index" collection="list" separator=",">
            (
            #{scriptInfoEdges.scriptInfoId},
            #{scriptInfoEdges.scriptEdgeName},
            #{scriptInfoEdges.startNodeId},
            #{scriptInfoEdges.startNodeName},
            #{scriptInfoEdges.endNodeId},
            #{scriptInfoEdges.endNodeName},
            #{scriptInfoEdges.condition},
            #{scriptInfoEdges.keywords},
            #{scriptInfoEdges.remark},
            #{scriptInfoEdges.createBy},
            #{scriptInfoEdges.createTime}
            )
        </foreach>
    </insert>
</mapper>