<?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.ruoyi.generator.mapper.SysCodeSnippetMapper">
    
    <resultMap type="SysCodeSnippet" id="SysCodeSnippetResult">
        <result property="snippetId"    column="snippet_id"    />
        <result property="moduleId"    column="module_id"    />
        <result property="snippetContent"    column="snippet_content"    />
        <result property="insertPoint"    column="insert_point"    />
        <result property="param1"    column="param1"    />
        <result property="param2"    column="param2"    />
        <result property="param3"    column="param3"    />
        <result property="param4"    column="param4"    />
        <result property="param5"    column="param5"    />
        <result property="templateFileName"    column="template_file_name"    />
        <result property="relationTableName"    column="relation_table_name"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysCodeSnippetVo">
        select snippet_id, module_id, snippet_content, insert_point, param1, param2, param3, param4, param5, template_file_name, relation_table_name, status, del_flag, create_by, create_time, update_by, update_time, remark from sys_code_snippet
    </sql>

    <select id="selectSysCodeSnippetList" parameterType="SysCodeSnippet" resultMap="SysCodeSnippetResult">
        <include refid="selectSysCodeSnippetVo"/>
        <where>
            <if test="relationTableName != null  and relationTableName != ''"> and relation_table_name = #{relationTableName}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="moduleId != null  and moduleId != ''"> and module_id = #{moduleId}</if>
            <if test="moduleIds != null and moduleIds.size() > 0">
                and snippet_id IN (
                    SELECT DISTINCT snippet_id FROM sys_code_snippet_module WHERE module_id IN
                    <foreach item="moduleId" collection="moduleIds" open="(" separator="," close=")">
                        #{moduleId}
                    </foreach>
                )
            </if>
        </where>
    </select>
    
    <select id="selectSysCodeSnippetBySnippetId" parameterType="Long" resultMap="SysCodeSnippetResult">
        <include refid="selectSysCodeSnippetVo"/>
        where snippet_id = #{snippetId}
    </select>

    <insert id="insertSysCodeSnippet" parameterType="SysCodeSnippet" useGeneratedKeys="true" keyProperty="snippetId">
        insert into sys_code_snippet
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="moduleId != null">module_id,</if>
            <if test="snippetContent != null and snippetContent != ''">snippet_content,</if>
            <if test="insertPoint != null">insert_point,</if>
            <if test="param1 != null">param1,</if>
            <if test="param2 != null">param2,</if>
            <if test="param3 != null">param3,</if>
            <if test="param4 != null">param4,</if>
            <if test="param5 != null">param5,</if>
            <if test="templateFileName != null and templateFileName != ''">template_file_name,</if>
            <if test="relationTableName != null">relation_table_name,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="moduleId != null">#{moduleId},</if>
            <if test="snippetContent != null and snippetContent != ''">#{snippetContent},</if>
            <if test="insertPoint != null">#{insertPoint},</if>
            <if test="param1 != null">#{param1},</if>
            <if test="param2 != null">#{param2},</if>
            <if test="param3 != null">#{param3},</if>
            <if test="param4 != null">#{param4},</if>
            <if test="param5 != null">#{param5},</if>
            <if test="templateFileName != null and templateFileName != ''">#{templateFileName},</if>
            <if test="relationTableName != null">#{relationTableName},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysCodeSnippet" parameterType="SysCodeSnippet">
        update sys_code_snippet
        <trim prefix="SET" suffixOverrides=",">
            <if test="moduleId != null">module_id = #{moduleId},</if>
            <if test="snippetContent != null and snippetContent != ''">snippet_content = #{snippetContent},</if>
            <if test="insertPoint != null">insert_point = #{insertPoint},</if>
            <if test="param1 != null">param1 = #{param1},</if>
            <if test="param2 != null">param2 = #{param2},</if>
            <if test="param3 != null">param3 = #{param3},</if>
            <if test="param4 != null">param4 = #{param4},</if>
            <if test="param5 != null">param5 = #{param5},</if>
            <if test="templateFileName != null and templateFileName != ''">template_file_name = #{templateFileName},</if>
            <if test="relationTableName != null">relation_table_name = #{relationTableName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where snippet_id = #{snippetId}
    </update>

    <delete id="deleteSysCodeSnippetBySnippetId" parameterType="Long">
        delete from sys_code_snippet where snippet_id = #{snippetId}
    </delete>

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