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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.EmailUsers">
        <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="email" property="email"/>
        <id column="password" property="password"/>
        <id column="host" property="host"/>
        <id column="port" property="port"/>
        <id column="smtp_agreement" property="smtpAgreement"/>
        <id column="is_default" property="isDefault"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, create_time, update_time, create_user, update_user, is_deleted, email, password, host, port, smtp_agreement, is_default
    </sql>

    <!-- 分页查询邮箱用户发送配置内容 -->
    <select id="selectListByPage" resultType="cn.bunny.dao.entity.system.EmailUsers">
        select
        <include refid="Base_Column_List"/>
        from sys_email_users
        <where>
            is_deleted = 0
            <if test="dto.email != null and dto.email != ''">
                and email like CONCAT('%',#{dto.email},'%')
            </if>
            <if test="dto.host != null and dto.host != ''">
                and host like CONCAT('%',#{dto.host},'%')
            </if>
            <if test="dto.port != null and dto.port != ''">
                and port like CONCAT('%',#{dto.port},'%')
            </if>
            <if test="dto.smtpAgreement != null and dto.smtpAgreement != ''">
                and smtp_agreement like CONCAT('%',#{dto.smtpAgreement},'%')
            </if>
        </where>
        order by create_time desc
    </select>

    <!-- 物理删除邮箱用户发送配置 -->
    <delete id="deleteBatchIdsWithPhysics">
        delete
        from sys_email_users
        where id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </delete>

</mapper>
