<?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.simuwang.base.mapper.EmailTemplateInfoMapper">
    <resultMap id="BaseResultMap" type="com.simuwang.base.pojo.dos.EmailTemplateInfoDO">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="type" property="type"/>
        <result column="direction" property="direction"/>
        <result column="start_index" property="startIndex"/>
        <result column="end_index" property="endIndex"/>
        <result column="description" property="description"/>
        <result column="status" property="status"/>
        <result column="isvalid" property="isvalid"/>
        <result column="creatorid" property="creatorId"/>
        <result column="createtime" property="createTime"/>
        <result column="updaterid" property="updaterId"/>
        <result column="updatetime" property="updateTime"/>
    </resultMap>
    <insert id="saveTemplateInfo"  useGeneratedKeys="true" keyProperty="id">
        insert into PPW_EMAIL.email_template_info(name,type,direction,start_index,end_index,description,status,isvalid,creatorid,createtime,updaterid,updatetime)
        values
            (#{name},#{type},#{direction},#{startIndex},#{endIndex},#{description},#{status},#{isvalid},#{creatorId},#{createTime},#{updaterId},#{updateTime})
    </insert>
    <update id="deleteTemplateList">
        update PPW_EMAIL.email_template_info set isvalid=0,updatetime=sysdate(),updaterid=#{userId} where isvalid=1
        and id in
        <foreach item="id" collection="idList" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="updateTemplateInfo">
        update PPW_EMAIL.email_template_info set name=#{name},type=#{type},description=#{description},status=#{status},updatetime=#{updateTime},updaterid=#{updaterId}
        where id=#{id} and isvalid=1
    </update>
    <select id="searchTemplateList" resultMap="BaseResultMap">
        select id,name,type,direction,start_index,end_index,description,status,isvalid,creatorid,createtime,updaterid,updatetime
        from PPW_EMAIL.email_template_info where isvalid=1
        <if test="name != null and name !=''">
            and name =#{name}
        </if>
        <if test="type != null">
            and type =#{type}
        </if>
        <if test="status != null">
            and status =#{status}
        </if>
        order by updatetime desc
        limit #{offset},#{pageSize}
    </select>
    <select id="countTemplateList" resultType="java.lang.Long">
        select count(1)
        from PPW_EMAIL.email_template_info where isvalid=1
        <if test="name != null and name !=''">
            and name =#{name}
        </if>
        <if test="type != null">
            and type =#{type}
        </if>
        <if test="status != null">
            and status =#{status}
        </if>
    </select>
    <select id="searchTemplateById" resultMap="BaseResultMap">
        select id,name,type,direction,start_index,end_index,description,status,isvalid,creatorid,createtime,updaterid,updatetime
        from PPW_EMAIL.email_template_info where isvalid=1 and id=#{id}
    </select>


</mapper>