2026-06-28 18:05:10 +09:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
|
|
<mapper namespace="com.sb.web.board.mapper.ReportMapper">
|
|
|
|
|
|
|
|
|
|
<insert id="insertIgnore">
|
|
|
|
|
INSERT IGNORE INTO report (target_type, target_id, member_id, reason, created_at)
|
|
|
|
|
VALUES (#{targetType}, #{targetId}, #{memberId}, #{reason}, NOW())
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
<select id="countByTarget" resultType="int">
|
|
|
|
|
SELECT COUNT(*) FROM report WHERE target_type = #{targetType} AND target_id = #{targetId}
|
|
|
|
|
</select>
|
|
|
|
|
|
2026-07-04 12:11:58 +09:00
|
|
|
<!-- 신고된 글/댓글 목록 (대상별 집계). 신고 많은 순 → 최근 신고 순. -->
|
|
|
|
|
<select id="listReported" resultType="com.sb.web.board.dto.ReportedItem">
|
|
|
|
|
SELECT 'POST' AS targetType, r.target_id AS targetId, p.id AS postId,
|
|
|
|
|
p.category AS category, p.title AS title, LEFT(p.content, 120) AS content,
|
|
|
|
|
p.author_id AS authorId, p.author_name AS authorName, p.blocked AS blocked,
|
|
|
|
|
COUNT(*) AS reportCount, MAX(r.created_at) AS lastReportedAt
|
|
|
|
|
FROM report r
|
|
|
|
|
JOIN post p ON p.id = r.target_id
|
|
|
|
|
WHERE r.target_type = 'POST'
|
|
|
|
|
GROUP BY p.id
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 'COMMENT' AS targetType, r.target_id AS targetId, c.post_id AS postId,
|
|
|
|
|
pp.category AS category, pp.title AS title, LEFT(c.content, 120) AS content,
|
|
|
|
|
c.author_id AS authorId, c.author_name AS authorName, c.blocked AS blocked,
|
|
|
|
|
COUNT(*) AS reportCount, MAX(r.created_at) AS lastReportedAt
|
|
|
|
|
FROM report r
|
|
|
|
|
JOIN comment c ON c.id = r.target_id
|
|
|
|
|
JOIN post pp ON pp.id = c.post_id
|
|
|
|
|
WHERE r.target_type = 'COMMENT'
|
|
|
|
|
GROUP BY c.id
|
|
|
|
|
ORDER BY reportCount DESC, lastReportedAt DESC
|
|
|
|
|
</select>
|
|
|
|
|
|
2026-06-28 18:05:10 +09:00
|
|
|
<delete id="deleteByTarget">
|
|
|
|
|
DELETE FROM report WHERE target_type = #{targetType} AND target_id = #{targetId}
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<delete id="deleteByMember">
|
|
|
|
|
DELETE FROM report WHERE member_id = #{memberId}
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
</mapper>
|