<?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.auth.dao.base.mapper.v1.EmailConfigMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.auth.dao.base.entity.EmailConfigEntity">
        <id column="id" property="id"/>
        <id column="config_name" property="configName"/>
        <id column="email" property="email"/>
        <id column="username" property="username"/>
        <id column="password" property="password"/>
        <id column="host" property="host"/>
        <id column="port" property="port"/>
        <id column="protocol" property="protocol"/>
        <id column="ssl_enable" property="sslEnable"/>
        <id column="is_default" property="isDefault"/>
        <id column="test_status" property="testStatus"/>
        <id column="test_time" property="testTime"/>
        <id column="is_deleted" property="isDeleted"/>
        <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"/>
    </resultMap>

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

    <!-- 分页查询系统邮件服务器配置内容 -->
    <select id="selectListByPage" resultType="com.auth.model.base.vo.EmailConfigVo">
        select
        base.*,
        create_user.username as create_username,
        update_user.username as update_username
        from sys_email_config base
        left join sys_user create_user on create_user.id = base.create_user
        left join sys_user update_user on update_user.id = base.update_user
        <where>
            base.is_deleted = 0
            <if test="dto.configName != null and dto.configName != ''">
                and base.config_name like CONCAT('%',#{dto.configName},'%')
            </if>
            <if test="dto.email != null and dto.email != ''">
                and base.email like CONCAT('%',#{dto.email},'%')
            </if>
            <if test="dto.username != null and dto.username != ''">
                and base.username like CONCAT('%',#{dto.username},'%')
            </if>
            <if test="dto.password != null and dto.password != ''">
                and base.password like CONCAT('%',#{dto.password},'%')
            </if>
            <if test="dto.host != null and dto.host != ''">
                and base.host like CONCAT('%',#{dto.host},'%')
            </if>
            <if test="dto.port != null and dto.port != ''">
                and base.port like CONCAT('%',#{dto.port},'%')
            </if>
            <if test="dto.protocol != null and dto.protocol != ''">
                and base.protocol like CONCAT('%',#{dto.protocol},'%')
            </if>
            <if test="dto.sslEnable != null and dto.sslEnable != ''">
                and base.ssl_enable like CONCAT('%',#{dto.sslEnable},'%')
            </if>
            <if test="dto.isDefault != null and dto.isDefault != ''">
                and base.is_default like CONCAT('%',#{dto.isDefault},'%')
            </if>
            <if test="dto.testStatus != null and dto.testStatus != ''">
                and base.test_status like CONCAT('%',#{dto.testStatus},'%')
            </if>
            <if test="dto.testTime != null and dto.testTime != ''">
                and base.test_time like CONCAT('%',#{dto.testTime},'%')
            </if>
            <if test="dto.isDeleted != null and dto.isDeleted != ''">
                and base.is_deleted like CONCAT('%',#{dto.isDeleted},'%')
            </if>
        </where>
    </select>

</mapper>
