<?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.MailboxInfoMapper">
    <resultMap id="BaseResultMap" type="com.simuwang.base.pojo.dos.MailboxInfoDO">
        <id column="id" property="id"/>
        <result column="type" property="type"/>
        <result column="email" property="email"/>
        <result column="password" property="password"/>
        <result column="protocol" property="protocol"/>
        <result column="server" property="server"/>
        <result column="port" property="port"/>
        <result column="cron" property="cron"/>
        <result column="open_status" property="openStatus"/>
        <result column="description" property="description"/>
        <result column="creatorid" property="creatorId"/>
        <result column="createtime" property="createTime"/>
        <result column="updaterid" property="updaterId"/>
        <result column="updatetime" property="updateTime"/>
        <result column="isvalid" property="isvalid"/>
    </resultMap>
    <update id="deleteEmailConfigByIds">
        update PPW_EMAIL.mailbox_info set isvalid =0,updatetime=sysdate(),updaterid=#{updaterId} where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <select id="listMailboxInfo" resultMap="BaseResultMap">
        select *
        from PPW_EMAIL.mailbox_info
        where isvalid = 1
          and open_status = 1
    </select>
    <select id="searchEmailConfigList" resultMap="BaseResultMap">
        select id, type, email, password, protocol, server, port, cron, open_status,description,isvalid,creatorid,createtime,updaterid,updatetime from PPW_EMAIL.mailbox_info
        where isvalid = 1
        <if test="email != null and email != ''">
            and email like concat('%',#{email},'%')
        </if>
        limit #{offset},#{pageSize}
    </select>
    <sql id="selectConfigVo">
        select id, type, email, password, protocol, server, port, cron, open_status,description,isvalid,creatorid,createtime,updaterid,updatetime
        from PPW_EMAIL.mailbox_info
    </sql>
    <select id="selectEmailConfigByEmail" resultType="com.simuwang.base.pojo.dos.MailboxInfoDO">
        <include refid="selectConfigVo"/>
        where email = #{email} and isvalid =1 limit 1
    </select>
    <select id="countEmailConfig" resultType="java.lang.Long"
            parameterType="com.simuwang.base.pojo.dto.query.EmailPageQuery">
        select count(1) from PPW_EMAIL.mailbox_info
        where isvalid = 1
        <if test="email != null and email != ''">
            and email like concat('%',#{email},'%')
        </if>
    </select>
    <select id="searchEmailConfigById" resultMap="BaseResultMap"
            parameterType="java.lang.Integer">
        <include refid="selectConfigVo"/>
        where id = #{id}
    </select>
    <select id="getAll" resultMap="BaseResultMap">
        <include refid="selectConfigVo"/>
        where isvalid = 1
    </select>

</mapper>