<?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.crm.manager.dao.mapper.BusinessEmailSentRecordMapper">
    <select id="selectCount" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.business.email.sent.BusinessEmailSentRecordSearchEntity">
        select count(*)
        <include refid="fromTable">
        </include>
        <include refid="selectCondition">
        </include>
    </select>

    <select id="selectList" resultType="com.crm.rely.backend.core.pojo.table.BusinessEmailSentRecordTable"
            parameterType="com.crm.rely.backend.core.entity.business.email.sent.BusinessEmailSentRecordSearchEntity">
        select business_email_sent_record.*
        <include refid="fromTable">
        </include>
        <include refid="selectCondition">
        </include>
        order by business_email_sent_record.send_date desc
        <if test="page!=null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

    <sql id="fromTable">
        from business_email_sent_record
        <if test="stamp!=null and stamp!=''">
            left join user_info agent on business_email_sent_record.agent_id=agent.id
        </if>
    </sql>
    <sql id="selectCondition">
        <where>
            <if test="subject!=null and subject!=''">
                and subject like concat('%',#{subject},'%')
            </if>
            <if test="receiveAccount!=null and receiveAccount!=''">
                and users like concat('%',#{receiveAccount},'%')
            </if>
            <if test="stamp!=null and stamp!=''">
                agent.stamp like concat(#{stamp},'%')
            </if>
        </where>
    </sql>
</mapper>