<?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.TemplateFileMapper">

    <resultMap type="com.ruoyi.generator.domain.TemplateFile" id="TemplateFileResult">
        <result property="templateFileId"    column="template_file_id"    />
        <result property="templateId"        column="template_id"         />
        <result property="fileName"          column="file_name"           />
        <result property="filePath"          column="file_path"           />
        <result property="fileContent"       column="file_content"        />
        <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="selectTemplateFileVo">
        select template_file_id, template_id, file_name, file_path, file_content, create_by, create_time, update_by, update_time from sys_template_file
    </sql>

    <select id="selectTemplateFileList" parameterType="com.ruoyi.generator.domain.TemplateFile" resultMap="TemplateFileResult">
        <include refid="selectTemplateFileVo"/>
        <where>
            <if test="templateId != null "> and template_id = #{templateId}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="filePath != null  and filePath != ''"> and file_path like concat('%', #{filePath}, '%')</if>
        </where>
    </select>

    <select id="selectTemplateFilesByTemplateId" parameterType="Long" resultMap="TemplateFileResult">
        <include refid="selectTemplateFileVo"/>
        where template_id = #{templateId}
    </select>

    <select id="selectTemplateFileByTemplateFileId" parameterType="Long" resultMap="TemplateFileResult">
        <include refid="selectTemplateFileVo"/>
        where template_file_id = #{templateFileId}
    </select>

    <insert id="insertTemplateFile" parameterType="com.ruoyi.generator.domain.TemplateFile" useGeneratedKeys="true" keyProperty="templateFileId">
        insert into sys_template_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="templateId != null">template_id,</if>
            <if test="fileName != null and fileName != ''">file_name,</if>
            <if test="filePath != null and filePath != ''">file_path,</if>
            <if test="fileContent != null and fileContent != ''">file_content,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="templateId != null">#{templateId},</if>
            <if test="fileName != null and fileName != ''">#{fileName},</if>
            <if test="filePath != null and filePath != ''">#{filePath},</if>
            <if test="fileContent != null and fileContent != ''">#{fileContent},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            sysdate()
        </trim>
    </insert>

    <update id="updateTemplateFile" parameterType="com.ruoyi.generator.domain.TemplateFile">
        update sys_template_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="templateId != null">template_id = #{templateId},</if>
            <if test="fileName != null and fileName != ''">file_name = #{fileName},</if>
            <if test="filePath != null and filePath != ''">file_path = #{filePath},</if>
            <if test="fileContent != null and fileContent != ''">file_content = #{fileContent},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            update_time = sysdate()
        </trim>
        where template_file_id = #{templateFileId}
    </update>

    <delete id="deleteTemplateFileByTemplateFileId" parameterType="Long">
        delete from sys_template_file where template_file_id = #{templateFileId}
    </delete>

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

    <delete id="deleteTemplateFilesByTemplateId" parameterType="Long">
        delete from sys_template_file where template_id = #{templateId}
    </delete>

</mapper> 