<?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="cn.bunny.services.mapper.EmailTemplateMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.EmailTemplate">
        <id column="id" property="id"/>
        <id column="create_time" property="createTime"/>
        <id column="update_time" property="updateTime"/>
        <id column="create_user" property="createUser"/>
        <id column="update_user" property="updateUser"/>
        <id column="is_deleted" property="isDeleted"/>
        <id column="template_name" property="templateName"/>
        <id column="email_user" property="emailUser"/>
        <id column="subject" property="subject"/>
        <id column="body" property="body"/>
        <id column="type" property="type"/>
        <id column="is_default" property="isDefault"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, create_time, update_time, create_user, update_user, is_deleted, template_name, email_user, subject, body, type, is_default
    </sql>

    <!-- 分页查询邮件模板表内容 -->
    <select id="selectListByPage" resultType="cn.bunny.dao.vo.system.email.EmailTemplateVo">
        select
        template.*,
        create_user.username as create_username,
        update_user.username as update_username
        from sys_email_template template
        left join sys_user create_user on create_user.id = template.create_user
        left join sys_user update_user on update_user.id = template.update_user
        <where>
            template.is_deleted = 0
            <if test="dto.templateName != null and dto.templateName != ''">
                and template.template_name like CONCAT('%',#{dto.templateName},'%')
            </if>
            <if test="dto.subject != null and dto.subject != ''">
                and template.subject like CONCAT('%',#{dto.subject},'%')
            </if>
            <if test="dto.body != null and dto.body != ''">
                and template.body like CONCAT('%',#{dto.body},'%')
            </if>
            <if test="dto.type != null and dto.type != ''">
                and template.type like CONCAT('%',#{dto.type},'%')
            </if>
            <if test="dto.isDefault != null and dto.isDefault != ''">
                and template.isDefault = #{dto.isDefault}
            </if>
        </where>
    </select>

    <!-- 物理删除邮件模板表 -->
    <delete id="deleteBatchIdsWithPhysics">
        delete
        from sys_email_template
        where id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </delete>

</mapper>
