<?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.SysProjectTemplateMapper">
    
    <resultMap type="SysProjectTemplate" id="SysProjectTemplateResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="templateId"    column="template_id"    />
        <result property="templateType"    column="template_type"    />
    </resultMap>

    <sql id="selectSysProjectTemplateVo">
        select id, project_id, template_id, template_type from sys_project_template
    </sql>

    <select id="selectSysProjectTemplateList" parameterType="SysProjectTemplate" resultMap="SysProjectTemplateResult">
        <include refid="selectSysProjectTemplateVo"/>
        <where>  
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="templateId != null "> and template_id = #{templateId}</if>
            <if test="templateType != null  and templateType != ''"> and template_type = #{templateType}</if>
        </where>
    </select>
    
    <select id="selectSysProjectTemplateById" parameterType="Long" resultMap="SysProjectTemplateResult">
        <include refid="selectSysProjectTemplateVo"/>
        where id = #{id}
    </select>

    <select id="selectSysProjectTemplateByProjectAndType" parameterType="SysProjectTemplate" resultMap="SysProjectTemplateResult">
        <include refid="selectSysProjectTemplateVo"/>
        where project_id = #{projectId} and template_type = #{templateType}
    </select>

    <insert id="insertSysProjectTemplate" parameterType="SysProjectTemplate" useGeneratedKeys="true" keyProperty="id">
        insert into sys_project_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="templateId != null">template_id,</if>
            <if test="templateType != null">template_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="templateId != null">#{templateId},</if>
            <if test="templateType != null">#{templateType},</if>
         </trim>
    </insert>

    <update id="updateSysProjectTemplate" parameterType="SysProjectTemplate">
        update sys_project_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="templateId != null">template_id = #{templateId},</if>
            <if test="templateType != null">template_type = #{templateType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysProjectTemplateById" parameterType="Long">
        delete from sys_project_template where id = #{id}
    </delete>

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

    <delete id="deleteSysProjectTemplateByProjectId" parameterType="Long">
        delete from sys_project_template where project_id = #{projectId}
    </delete>

    <select id="selectSysProjectTemplateListByProjectId" parameterType="Long" resultMap="SysProjectTemplateResult">
        <include refid="selectSysProjectTemplateVo"/>
        where project_id = #{projectId}
    </select>
</mapper>