<?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.scriptinfonode.ScriptInfoNodeMapper">

    <resultMap type="ScriptInfoNode" id="ScriptInfoNodeResult">
        <result property="id" column="id"/>
        <result property="scriptInfoId" column="script_info_id"/>
        <result property="scriptNodeName" column="script_node_name"/>
        <result property="scriptContent" column="script_content"/>
        <result property="scriptNodeType" column="script_node_type"/>
        <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="selectScriptInfoNodeVo">
        select id,
               script_info_id,
               script_node_name,
               script_content,
               script_node_type,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from script_info_node
    </sql>

    <select id="selectScriptInfoNodeList" parameterType="ScriptInfoNode" resultMap="ScriptInfoNodeResult">
        <include refid="selectScriptInfoNodeVo"/>
        <where>
            <if test="scriptInfoId != null ">
                and script_info_id = #{scriptInfoId}
            </if>
            <if test="scriptNodeName != null  and scriptNodeName != ''">
                and script_node_name like concat('%', #{scriptNodeName}, '%')
            </if>
            <if test="scriptContent != null  and scriptContent != ''">
                and script_content = #{scriptContent}
            </if>
            <if test="scriptNodeType != null  and scriptNodeType != ''">
                and script_node_type = #{scriptNodeType}
            </if>
        </where>
    </select>

    <select id="selectScriptInfoNodeById" parameterType="Long"
            resultMap="ScriptInfoNodeResult">
        <include refid="selectScriptInfoNodeVo"/>
        where id = #{id}
    </select>

    <insert id="insertScriptInfoNode" parameterType="ScriptInfoNode" useGeneratedKeys="true"
            keyProperty="id">
        insert into script_info_node
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="scriptInfoId != null">script_info_id,
            </if>
            <if test="scriptNodeName != null">script_node_name,
            </if>
            <if test="scriptContent != null">script_content,
            </if>
            <if test="scriptNodeType != null">script_node_type,
            </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="scriptNodeName != null">#{scriptNodeName},
            </if>
            <if test="scriptContent != null">#{scriptContent},
            </if>
            <if test="scriptNodeType != null">#{scriptNodeType},
            </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="updateScriptInfoNode" parameterType="ScriptInfoNode">
        update script_info_node
        <trim prefix="SET" suffixOverrides=",">
            <if test="scriptInfoId != null">script_info_id =
                #{scriptInfoId},
            </if>
            <if test="scriptNodeName != null">script_node_name =
                #{scriptNodeName},
            </if>
            <if test="scriptContent != null">script_content =
                #{scriptContent},
            </if>
            <if test="scriptNodeType != null">script_node_type =
                #{scriptNodeType},
            </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="deleteScriptInfoNodeById" parameterType="Long">
        delete
        from script_info_node
        where id = #{id}
    </delete>

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

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

    <insert id="insertScriptInfoNodeList" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        insert into script_info_node(
        script_info_id,
        script_node_name,
        script_content,
        script_node_type,
        remark,
        create_by,
        create_time
        )values
        <foreach item="scriptInfoNodes" index="index" collection="list" separator=",">
            (
            #{scriptInfoNodes.scriptInfoId},
            #{scriptInfoNodes.scriptNodeName},
            #{scriptInfoNodes.scriptContent},
            #{scriptInfoNodes.scriptNodeType},
            #{scriptInfoNodes.remark},
            #{scriptInfoNodes.createBy},
            #{scriptInfoNodes.createTime}
            )
        </foreach>
    </insert>
</mapper>