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

    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.system.email.template.SysEmailTemplateSearchEntity">

        select count(*) from sys_email_template
        <where>
            <if test="code!=null and code!=''">
                and code=#{code}
            </if>
            <if test="name!=null and name!=''">
                and `name`=#{name}
            </if>
            <if test="type!=null and type!=''">
                and `type`=#{type}
            </if>
        </where>

    </select>

    <select id="pageList" resultType="com.crm.rely.backend.core.pojo.view.SysEmailTemplateView"
            parameterType="com.crm.rely.backend.core.entity.system.email.template.SysEmailTemplateSearchEntity">

        select sys_email_template.*,
        IFNULL(sys_email_config.from_account_name,sys_email_config.from_account) as from_account
        from sys_email_template
        left join  sys_email_config on  sys_email_config.id=sys_email_template.email_config_id
        <where>
            <if test="code!=null and code!=''">
                and sys_email_template.code=#{code}
            </if>
            <if test="name!=null and name!=''">
                and sys_email_template.`name`=#{name}
            </if>
            <if test="type!=null and type!=''">
                and sys_email_template.`type`=#{type}
            </if>
            <if test="notificationObject!=null">
                and sys_email_template.`notification_object`=#{notificationObject}
            </if>
        </where>
        <if test="page!=null">
            limit #{page.offset},#{page.row}
        </if>

    </select>
    <select id="getOne" resultType="com.crm.rely.backend.core.pojo.view.SysEmailTemplateView">

        select sys_email_template.*,
        IFNULL(sys_email_config.from_account_name,sys_email_config.from_account) as from_account
         from sys_email_template
        left join  sys_email_config on  sys_email_config.id=sys_email_template.email_config_id
        sys_email_template.id=#{id}
    </select>
    <select id="list" resultType="com.crm.rely.backend.core.pojo.view.SysEmailTemplateView"
    >

        select sys_email_template.*,
        IFNULL(sys_email_config.from_account_name,sys_email_config.from_account) as from_account
         from sys_email_template
        left join  sys_email_config on  sys_email_config.id=sys_email_template.email_config_id
    </select>

</mapper>