119 lines
3.4 KiB
XML
119 lines
3.4 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="com.imyeyu.api.modules.common.mapper.NotifyMapper">
|
|
<insert id="insertIfAbsent">
|
|
INSERT INTO `notify` (
|
|
`id`,
|
|
`biz_type`,
|
|
`biz_reminded_type`,
|
|
`biz_reminded_key`,
|
|
`args`,
|
|
`created_by`,
|
|
`created_at`,
|
|
`updated_at`,
|
|
`deleted_at`
|
|
) VALUES (
|
|
#{id},
|
|
#{bizType},
|
|
#{bizRemindedType},
|
|
#{bizRemindedKey},
|
|
#{args},
|
|
#{createdBy},
|
|
#{createdAt},
|
|
#{updatedAt},
|
|
#{deletedAt}
|
|
)
|
|
ON DUPLICATE KEY UPDATE `id` = `id`
|
|
</insert>
|
|
|
|
<select id="selectByBusinessKey" resultType="com.imyeyu.api.modules.common.entity.Notify">
|
|
SELECT *
|
|
FROM `notify`
|
|
WHERE `biz_type` = #{bizType}
|
|
AND `biz_reminded_type` = #{bizRemindedType}
|
|
AND `biz_reminded_key` = #{bizRemindedKey}
|
|
AND `deleted_at` IS NULL
|
|
ORDER BY `created_at` DESC, `id` DESC
|
|
LIMIT 1
|
|
</select>
|
|
|
|
<select id="selectManagementPage" resultType="com.imyeyu.api.modules.common.vo.NotifyManagementItem">
|
|
SELECT
|
|
n.`id`,
|
|
n.`created_by`,
|
|
n.`created_at`,
|
|
n.`updated_at`,
|
|
MAX(detail.`subject`) AS `subject`,
|
|
MAX(detail.`content`) AS `content`,
|
|
MAX(detail.`content_type`) AS `content_type`,
|
|
MAX(detail.`send_at`) AS `send_at`,
|
|
COUNT(detail.`id`) AS `recipient_count`,
|
|
COUNT(CASE WHEN detail.`read_at` IS NOT NULL THEN 1 END) AS `read_count`,
|
|
COUNT(CASE WHEN detail.`status` = 'WAITING' THEN 1 END) AS `waiting_count`,
|
|
COUNT(CASE WHEN detail.`status` = 'REMINDED' THEN 1 END) AS `reminded_count`,
|
|
COUNT(CASE WHEN detail.`status` = 'TIMEOUT' THEN 1 END) AS `timeout_count`,
|
|
COUNT(CASE WHEN detail.`status` = 'CANCEL' THEN 1 END) AS `cancel_count`,
|
|
COUNT(CASE WHEN detail.`status` = 'FAIL' THEN 1 END) AS `fail_count`
|
|
FROM `notify` n
|
|
INNER JOIN `notify_detail` detail
|
|
ON detail.`notify_id` = n.`id`
|
|
AND detail.`msg_type` = 'INTERNAL'
|
|
AND detail.`deleted_at` IS NULL
|
|
WHERE n.`deleted_at` IS NULL
|
|
AND (
|
|
n.`created_by` = #{userId}
|
|
OR EXISTS (
|
|
SELECT 1
|
|
FROM `notify_detail` owner_detail
|
|
WHERE owner_detail.`notify_id` = n.`id`
|
|
AND owner_detail.`send_from` = #{userId}
|
|
AND owner_detail.`deleted_at` IS NULL
|
|
)
|
|
)
|
|
GROUP BY n.`id`, n.`created_by`, n.`created_at`, n.`updated_at`
|
|
ORDER BY n.`created_at` DESC
|
|
LIMIT #{offset}, #{limit}
|
|
</select>
|
|
|
|
<select id="countManagement" resultType="long">
|
|
SELECT COUNT(*)
|
|
FROM `notify` n
|
|
WHERE n.`deleted_at` IS NULL
|
|
AND (
|
|
n.`created_by` = #{userId}
|
|
OR EXISTS (
|
|
SELECT 1
|
|
FROM `notify_detail` owner_detail
|
|
WHERE owner_detail.`notify_id` = n.`id`
|
|
AND owner_detail.`send_from` = #{userId}
|
|
AND owner_detail.`deleted_at` IS NULL
|
|
)
|
|
)
|
|
AND EXISTS (
|
|
SELECT 1
|
|
FROM `notify_detail` detail
|
|
WHERE detail.`notify_id` = n.`id`
|
|
AND detail.`msg_type` = 'INTERNAL'
|
|
AND detail.`deleted_at` IS NULL
|
|
)
|
|
</select>
|
|
|
|
<select id="selectManagement" resultType="com.imyeyu.api.modules.common.entity.Notify">
|
|
SELECT n.*
|
|
FROM `notify` n
|
|
WHERE n.`id` = #{notifyId}
|
|
AND n.`deleted_at` IS NULL
|
|
AND (
|
|
n.`created_by` = #{userId}
|
|
OR EXISTS (
|
|
SELECT 1
|
|
FROM `notify_detail` owner_detail
|
|
WHERE owner_detail.`notify_id` = n.`id`
|
|
AND owner_detail.`send_from` = #{userId}
|
|
AND owner_detail.`deleted_at` IS NULL
|
|
)
|
|
)
|
|
LIMIT 1
|
|
</select>
|
|
</mapper>
|