<?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.bonus.system.mapper.SysTemplateMapper">
    
    <resultMap type="com.bonus.system.api.domain.SysTemplate" id="SysTemplateResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <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="selectSysTemplateVo">
        select id, name, remark, create_by, create_time, update_by, update_time from sys_template
    </sql>

    <select id="selectSysTemplateList" parameterType="com.bonus.system.api.domain.SysTemplate" resultMap="SysTemplateResult">
        <include refid="selectSysTemplateVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
        </where>
    </select>
    
    <select id="selectSysTemplateById" parameterType="Long" resultMap="SysTemplateResult">
        <include refid="selectSysTemplateVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSysTemplate" parameterType="com.bonus.system.api.domain.SysTemplate" useGeneratedKeys="true" keyProperty="id">
        insert into sys_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            create_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            sysdate()
         </trim>
    </insert>

    <update id="updateSysTemplate" parameterType="com.bonus.system.api.domain.SysTemplate">
        update sys_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            update_time = sysdate()
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysTemplateById" parameterType="java.lang.String">
        delete from sys_template where id = #{id}
    </delete>

    <delete id="deleteSysTemplateByIds" parameterType="Long">
        delete from sys_template where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>