EmailConfigMapper.xml 4.8 KB
<?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.ruoyi.email.mapper.EmailConfigMapper">
    
    <resultMap type="EmailConfig" id="EmailConfigResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="email"    column="email"    />
        <result property="sort"    column="sort"    />
        <result property="type"    column="type"    />
        <result property="parentId"    column="parent_id"    />
    </resultMap>

    <sql id="selectEmailConfigVo">
        select id, `name`, email, sort,`type`,parent_id from email_config
    </sql>

    <select id="selectEmailConfigList" parameterType="EmailConfig" resultMap="EmailConfigResult">
        <include refid="selectEmailConfigVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
        </where>
        order by sort
    </select>
    
    <select id="selectEmailConfigById" parameterType="Long" resultMap="EmailConfigResult">
        <include refid="selectEmailConfigVo"/>
        where id = #{id}
    </select>
    <select id="selectRecipientsEmailConfigList" resultType="com.ruoyi.email.domain.EmailConfig">
        <include refid="selectEmailConfigVo"/>
            where `type` = 0
    </select>
    <select id="selectEmailConfigListByIds"  resultType="com.ruoyi.email.domain.EmailConfig">
        select * from email_config
        where id in
        <foreach collection="ids" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>


    <insert id="insertEmailConfig" parameterType="EmailConfig">
        insert into email_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null">`name`,</if>
            <if test="email != null">email,</if>
            <if test="type != null">`type`,</if>
            <if test="sort != null">sort,</if>
            <if test="parentId != null">parentId,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null">#{name},</if>
            <if test="email != null">#{email},</if>
            <if test="type != null">#{type},</if>
            <if test="sort != null">#{sort},</if>
            <if test="parentId != null">#{parentId},</if>
         </trim>
    </insert>

    <update id="updateEmailConfig" parameterType="EmailConfig">
        update email_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="email != null">email = #{email},</if>
            <if test="type != null">`type` = #{type},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateEmailConfigByEmails">
        <if test="ids != null and ids.size() > 0">
            update email_config set type = 1 where id in
            <foreach collection="ids" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>;
            update email_config set type = 2 where id not in
            <foreach collection="ids" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>;
        </if>

        update email_config set type = #{config.type}, email = #{config.email}, `name` = #{config.name} , sort = #{config.sort}, parent_id = #{config.parentId} where id = #{config.id};
    </update>
    <update id="resetEmailConfigByEmails">
        <if test="ids != null and ids.size() > 0">
            update email_config set type = 2 where id in
            <foreach collection="ids" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>;
        </if>
        update email_config set `type` = #{config.type}, email = #{config.email} , sort = #{config.sort} , `name` = #{config.name} ,parent_id = null where id = #{config.id};
    </update>

    <delete id="deleteEmailConfigById" parameterType="Long">
        delete from email_config where id = #{id}
    </delete>

    <delete id="deleteEmailConfigByIds" parameterType="String">
        delete from email_config where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>