system-oa/src/main/resources/mybatis/mapper/mail/mail-mapper.xml
2022-04-29 15:09:32 +08:00

325 lines
13 KiB
XML

<?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="cn.com.tenlion.systemoa.dao.mail.IMailDao">
<!-- 发件箱DTO -->
<resultMap id="mailSendDTO" type="cn.com.tenlion.systemoa.pojo.dtos.mail.MailSendDTO">
<id column="mail_id" property="mailId"/>
<result column="recipient_ids" property="recipientIds"/>
<result column="recipient_names" property="recipientNames"/>
<result column="copy_for_ids" property="copyForIds"/>
<result column="copy_for_names" property="copyForNames"/>
<result column="secret_ids" property="secretIds"/>
<result column="secret_names" property="secretNames"/>
<result column="title" property="title"/>
<result column="mail_files" property="mailFiles"/>
<result column="content_rich" property="contentRich"/>
<result column="content" property="content"/>
<result column="creator" property="creator"/>
<result column="gmt_create" property="gmtCreate"/>
<result column="modifier" property="modifier"/>
<result column="gmt_modified" property="gmtModified"/>
</resultMap>
<!-- 收件箱DTO -->
<resultMap id="mailInboxDTO" type="cn.com.tenlion.systemoa.pojo.dtos.mail.MailInboxDTO">
<id column="id" property="id"/>
<result column="mail_id_link" property="mailIdLink"/>
<result column="recipient_ids" property="recipientIds"/>
<result column="recipient_names" property="recipientNames"/>
<result column="copy_for_ids" property="copyForIds"/>
<result column="copy_for_names" property="copyForNames"/>
<result column="secret_ids" property="secretIds"/>
<result column="secret_names" property="secretNames"/>
<result column="title" property="title"/>
<result column="mail_files" property="mailFiles"/>
<result column="content_rich" property="contentRich"/>
<result column="content" property="content"/>
<result column="creator" property="creator"/>
<result column="gmt_create" property="gmtCreate"/>
</resultMap>
<!-- 垃圾箱DTO -->
<resultMap id="mailDelDTO" type="cn.com.tenlion.systemoa.pojo.dtos.mail.MailDelDTO">
<id column="id" property="id"/>
<result column="mail_id" property="mailId"/>
<result column="recipient_ids" property="recipientIds"/>
<result column="recipient_names" property="recipientNames"/>
<result column="copy_for_ids" property="copyForIds"/>
<result column="copy_for_names" property="copyForNames"/>
<result column="secret_ids" property="secretIds"/>
<result column="secret_names" property="secretNames"/>
<result column="title" property="title"/>
<result column="mail_files" property="mailFiles"/>
<result column="content_rich" property="contentRich"/>
<result column="content" property="content"/>
<result column="creator" property="creator"/>
<result column="gmt_create" property="gmtCreate"/>
<result column="source_from" property="sourceFrom"/>
<result column="del_user_id" property="delUserId"/>
<result column="del_time" property="delTime"/>
</resultMap>
<!-- 添加已阅记录 -->
<insert id="saveMailReadTag" parameterType="map">
INSERT INTO oa_mail_read_tag (
id, user_id, read_time
) VALUES (
#{id}, #{userId}, #{readTime}
)
</insert>
<!-- 查询邮件是否已读 -->
<select id="getUserMailReadTag" parameterType="map" resultType="map">
SELECT
id,
user_id userId,
read_time readTime
FROM
oa_mail_read_tag
WHERE
id = # {id}
AND user_id = #{userId}
LIMIT 1
</select>
<!-- 发信 -->
<insert id="saveSendMail" parameterType="map">
INSERT INTO oa_mail_send(
mail_id, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create, modifier, gmt_modified
) VALUES(
#{mailId}, #{recipientIds}, #{recipientNames}, #{copyForIds}, #{copyForNames}, #{secretIds}, #{secretNames},
#{title}, #{mailFiles}, #{contentRich}, #{content}, #{creator}, #{gmtCreate}, #{modifier}, #{gmtModified}
)
</insert>
<!-- 发件箱列表 -->
<select id="listSendMail" parameterType="map" resultMap="mailSendDTO">
SELECT
mail_id, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create, modifier, gmt_modified
FROM
oa_mail_send
WHERE
creator = #{creator}
<if test="keywords != null and keywords != ''">
AND (
recipient_names like CONCAT('%', CONCAT(#{keywords}, '%'))
OR
title like CONCAT('%', CONCAT(#{keywords}, '%'))
)
</if>
ORDER BY gmt_create DESC
</select>
<!-- 发件箱详情 -->
<select id="getSendMail" parameterType="map" resultMap="mailSendDTO">
SELECT
mail_id, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create, modifier, gmt_modified
FROM
oa_mail_send
WHERE
mail_id = #{mailId}
</select>
<!-- 保存到收件箱 -->
<insert id="saveInboxMail" parameterType="map">
INSERT INTO oa_mail_inbox(
mail_id_link, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create
) VALUES (
#{mailIdLink}, #{recipientIds}, #{recipientNames}, #{copyForIds}, #{copyForNames}, #{secretIds}, #{secretNames},
#{title}, #{mailFiles}, #{contentRich}, #{content}, #{creator}, #{gmtCreate}
)
</insert>
<!-- 收件箱列表 -->
<select id="listInboxMail" parameterType="map" resultMap="mailInboxDTO">
SELECT
id, mail_id_link, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create
FROM
oa_mail_inbox
WHERE
(
FIND_IN_SET(#{userId}, recipient_ids)
OR
FIND_IN_SET(#{userId}, copy_for_ids)
OR
FIND_IN_SET(#{userId}, secret_ids)
)
<if test="keywords != null and keywords != ''">
AND title like CONCAT('%', CONCAT(#{keywords}, '%'))
</if>
ORDER BY gmt_create DESC
</select>
<select id="getInboxMail" parameterType="map" resultMap="mailInboxDTO">
SELECT
id, mail_id_link, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create
FROM
oa_mail_inbox
WHERE
id = #{id}
</select>
<!-- 保存草稿 -->
<insert id="saveDraftMail" parameterType="map">
INSERT INTO oa_mail_send_draft(
mail_id, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create
) VALUES(
#{mailId}, #{recipientIds}, #{recipientNames}, #{copyForIds}, #{copyForNames}, #{secretIds}, #{secretNames},
#{title}, #{mailFiles}, #{contentRich}, #{content}, #{creator}, #{gmtCreate}
)
</insert>
<!-- 草稿箱列表 -->
<select id="listDraftMail" parameterType="map" resultMap="mailSendDTO">
SELECT
mail_id, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create
FROM
oa_mail_send_draft
WHERE
creator = #{creator}
<if test="keywords != null and keywords != ''">
AND (
recipient_names like CONCAT('%', CONCAT(#{keywords}, '%'))
OR
title like CONCAT('%', CONCAT(#{keywords}, '%'))
)
</if>
ORDER BY gmt_create DESC
</select>
<!-- 草稿箱详情 -->
<select id="getDraftMail" parameterType="map" resultMap="mailSendDTO">
SELECT
mail_id, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create
FROM
oa_mail_send_draft
WHERE
mail_id = #{mailId}
</select>
<!-- 修改草稿 -->
<update id="updateDraftMail" parameterType="map">
UPDATE oa_mail_send_draft SET
mail_id = #{mailId}
<if test="recipientIds != null">
,recipient_ids = #{recipientIds}
</if>
<if test="recipientNames != null">
,recipient_names = #{recipientNames}
</if>
<if test="copyForIds != null">
,copy_for_ids = #{copyForIds}
</if>
<if test="copyForNames != null">
,copy_for_names = #{copyForNames}
</if>
<if test="secretIds != null">
,secret_ids = #{secretIds}
</if>
<if test="secretNames != null">
,secret_names = #{secretNames}
</if>
<if test="title != null">
,title = #{title}
</if>
<if test="mailFiles != null">
,mail_files = #{mailFiles}
</if>
<if test="contentRich != null">
,content_rich = #{contentRich}
</if>
<if test="content != null">
,content = #{content}
</if>
<if test="gmtCreate != null">
,gmt_create = #{gmtCreate}
</if>
WHERE
mail_id = #{mailId}
</update>
<!-- 删除草稿 -->
<delete id="deleteDraftMail" parameterType="string">
DELETE FROM oa_mail_send_draft
WHERE
FIND_IN_SET(mail_id, #{mailIds})
</delete>
<!-- 删除发件箱 -->
<delete id="deleteSendMail" parameterType="string">
DELETE FROM oa_mail_send
WHERE
FIND_IN_SET(mail_id, #{mailIds})
</delete>
<!-- 删除收件箱 -->
<delete id="deleteInboxMail" parameterType="string">
DELETE FROM oa_mail_inbox
WHERE
FIND_IN_SET(id, #{ids})
</delete>
<!-- 删除删除垃圾箱邮件 -->
<delete id="deleteDelMail" parameterType="string">
DELETE FROM oa_mail_del
WHERE
FIND_IN_SET(id, #{ids})
</delete>
<!-- 删除所有垃圾箱邮件 -->
<delete id="deleteAppDelMailAll" parameterType="map">
DELETE FROM oa_mail_del
WHERE
del_user_id = #{delUserId}
</delete>
<!-- 垃圾箱保存 -->
<insert id="saveDelMail" parameterType="map">
INSERT INTO oa_mail_del (
mail_id, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create, source_from, del_user_id, del_time
) VALUES(
#{mailId}, #{recipientIds}, #{recipientNames}, #{copyForIds}, #{copyForNames}, #{secretIds}, #{secretNames},
#{title}, #{mailFiles}, #{contentRich}, #{content}, #{creator}, #{gmtCreate}, #{sourceFrom}, #{delUserId}, #{delTime}
)
</insert>
<!-- 垃圾箱分页列表 -->
<select id="listDelMail" parameterType="map" resultMap="mailDelDTO">
SELECT
id, mail_id, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create, source_from, del_user_id, del_time
FROM
oa_mail_del
WHERE
del_user_id = #{delUserId}
<if test="keywords != null and keywords != ''">
AND (
recipient_names like CONCAT('%', CONCAT(#{keywords}, '%'))
OR
title like CONCAT('%', CONCAT(#{keywords}, '%'))
)
</if>
</select>
<!-- 垃圾箱详情 -->
<select id="getDelMail" parameterType="map" resultMap="mailDelDTO">
SELECT
id, mail_id, recipient_ids, recipient_names, copy_for_ids, copy_for_names, secret_ids, secret_names,
title, mail_files, content_rich, content, creator, gmt_create, source_from, del_user_id, del_time
FROM
oa_mail_del
WHERE
id = #{id}
</select>
</mapper>