|
|
|
|
@ -89,11 +89,20 @@ public class PostReportService {
|
|
|
|
|
* @param createdAt 举报创建时间
|
|
|
|
|
* @param status 处理后的状态:reviewed(举报成立), dismissed(举报驳回)
|
|
|
|
|
* @param reviewedBy 审核人ID
|
|
|
|
|
* @param result 处理结果说明
|
|
|
|
|
* @param result 处理结果说明(会被自动标准化)
|
|
|
|
|
* @return 是否更新成功
|
|
|
|
|
*/
|
|
|
|
|
public boolean updateReportStatus(Long reporterId, Long postId, Timestamp createdAt,
|
|
|
|
|
String status, Long reviewedBy, String result) {
|
|
|
|
|
// 🎯 标准化 result 字段:只有两种情况
|
|
|
|
|
String standardizedResult;
|
|
|
|
|
if ("reviewed".equals(status)) {
|
|
|
|
|
// 举报成立 -> 统一显示"已封禁帖子"
|
|
|
|
|
standardizedResult = "已封禁帖子";
|
|
|
|
|
} else {
|
|
|
|
|
// 举报驳回 -> 统一显示"已驳回举报"
|
|
|
|
|
standardizedResult = "已驳回举报";
|
|
|
|
|
}
|
|
|
|
|
SqlSession sqlSession = null;
|
|
|
|
|
try {
|
|
|
|
|
sqlSession = sqlSessionFactory.openSession();
|
|
|
|
|
@ -104,15 +113,28 @@ public class PostReportService {
|
|
|
|
|
PostMapper postMapper = sqlSession.getMapper(PostMapper.class);
|
|
|
|
|
Post post = postMapper.selectByIdAsPost(postId);
|
|
|
|
|
|
|
|
|
|
// 更新举报状态
|
|
|
|
|
int rows = mapper.updateReportStatus(reporterId, postId, createdAt, status, reviewedBy, result);
|
|
|
|
|
// 更新举报状态(使用标准化的result)
|
|
|
|
|
int rows = mapper.updateReportStatus(reporterId, postId, createdAt, status, reviewedBy, standardizedResult);
|
|
|
|
|
|
|
|
|
|
// 判断是举报成立还是驳回
|
|
|
|
|
boolean isReportApproved = "reviewed".equals(status) ||
|
|
|
|
|
("dismissed".equals(status) && "恶意举报".equals(result));
|
|
|
|
|
|
|
|
|
|
// 判断是否为驳回举报(非恶意举报的dismissed)
|
|
|
|
|
boolean isReportDismissed = "dismissed".equals(status) && !"恶意举报".equals(result);
|
|
|
|
|
boolean isReportApproved = "reviewed".equals(status);
|
|
|
|
|
boolean isReportDismissed = "dismissed".equals(status);
|
|
|
|
|
|
|
|
|
|
// 🎯 记录帖子原始状态和 review_type(用于后续判断)
|
|
|
|
|
String originalPostStatus = post != null ? post.getStatus().toString() : null;
|
|
|
|
|
String originalReviewType = post != null ? post.getReview_type() : null;
|
|
|
|
|
|
|
|
|
|
System.out.println("=== 举报处理开始 ===");
|
|
|
|
|
System.out.println("举报状态: " + status);
|
|
|
|
|
System.out.println("是否举报成立: " + isReportApproved);
|
|
|
|
|
System.out.println("是否驳回举报: " + isReportDismissed);
|
|
|
|
|
System.out.println("帖子是否存在: " + (post != null));
|
|
|
|
|
if (post != null) {
|
|
|
|
|
System.out.println("帖子ID: " + postId);
|
|
|
|
|
System.out.println("帖子当前状态: " + originalPostStatus);
|
|
|
|
|
System.out.println("帖子review_type: " + originalReviewType);
|
|
|
|
|
}
|
|
|
|
|
System.out.println("==================");
|
|
|
|
|
|
|
|
|
|
// 如果举报成立,需要更新帖子状态为 rejected
|
|
|
|
|
if (isReportApproved && post != null) {
|
|
|
|
|
@ -146,34 +168,43 @@ public class PostReportService {
|
|
|
|
|
// 不影响主流程,继续执行
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 如果驳回举报,且帖子当前是rejected状态(可能是之前误判),需要恢复为approved
|
|
|
|
|
else if (isReportDismissed && post != null && post.getStatus() == Post.Status.rejected) {
|
|
|
|
|
try {
|
|
|
|
|
System.out.println("=== 驳回举报 - 恢复帖子状态为approved ===");
|
|
|
|
|
System.out.println("帖子ID: " + postId);
|
|
|
|
|
System.out.println("当前状态: " + post.getStatus());
|
|
|
|
|
System.out.println("新状态: approved");
|
|
|
|
|
System.out.println("原因: 重新审核后发现举报不成立,恢复帖子");
|
|
|
|
|
|
|
|
|
|
// 恢复帖子状态为 approved
|
|
|
|
|
int postRows = postMapper.updatePostStatus(
|
|
|
|
|
postId,
|
|
|
|
|
Post.Status.approved,
|
|
|
|
|
reviewedBy,
|
|
|
|
|
new Timestamp(System.currentTimeMillis()),
|
|
|
|
|
null, // 清空拒绝原因
|
|
|
|
|
"report_review_reversed" // 标记为举报审核撤销
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (postRows > 0) {
|
|
|
|
|
System.out.println("✅ 帖子状态恢复为approved成功");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("⚠️ 帖子状态恢复失败");
|
|
|
|
|
|
|
|
|
|
// 🎯 新增:驳回举报时,如果帖子是因举报被封禁的,则恢复帖子状态
|
|
|
|
|
if (isReportDismissed && post != null) {
|
|
|
|
|
// 检查帖子是否是因为举报被封禁的(状态为rejected且review_type为report_review)
|
|
|
|
|
if ("rejected".equals(originalPostStatus) && "report_review".equals(originalReviewType)) {
|
|
|
|
|
try {
|
|
|
|
|
System.out.println("=== 驳回举报 - 恢复因举报被封禁的帖子 ===");
|
|
|
|
|
System.out.println("帖子ID: " + postId);
|
|
|
|
|
System.out.println("原状态: rejected (review_type: report_review)");
|
|
|
|
|
System.out.println("新状态: approved (恢复帖子)");
|
|
|
|
|
|
|
|
|
|
// 恢复帖子状态为 approved
|
|
|
|
|
int postRows = postMapper.updatePostStatus(
|
|
|
|
|
postId,
|
|
|
|
|
Post.Status.approved,
|
|
|
|
|
reviewedBy,
|
|
|
|
|
new Timestamp(System.currentTimeMillis()),
|
|
|
|
|
"举报已驳回,帖子恢复正常",
|
|
|
|
|
"report_dismissed" // 新的 review_type,表示因驳回举报而恢复
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (postRows > 0) {
|
|
|
|
|
System.out.println("✅ 帖子状态已恢复为 approved");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("⚠️ 帖子状态恢复失败");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("❌ 恢复帖子状态失败: " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// 不影响主流程,继续执行
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("❌ 恢复帖子状态失败: " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// 不影响主流程,继续执行
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("=== 驳回举报 - 帖子状态保持不变 ===");
|
|
|
|
|
System.out.println("帖子ID: " + postId);
|
|
|
|
|
System.out.println("当前状态: " + originalPostStatus);
|
|
|
|
|
System.out.println("review_type: " + originalReviewType);
|
|
|
|
|
System.out.println("原因: 帖子不是因举报被封禁,保持原状态");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -202,71 +233,94 @@ public class PostReportService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果举报成立或驳回举报(且帖子状态有变化),同步帖子到ES索引
|
|
|
|
|
if (success && (isReportApproved || isReportDismissed) && post != null && postAdminSearchService != null) {
|
|
|
|
|
try {
|
|
|
|
|
System.out.println("=== 同步帖子状态到ES ===");
|
|
|
|
|
System.out.println("帖子ID: " + postId);
|
|
|
|
|
|
|
|
|
|
// 重新获取更新后的帖子信息
|
|
|
|
|
Post updatedPost = postMapper.selectByIdAsPost(postId);
|
|
|
|
|
if (updatedPost != null) {
|
|
|
|
|
postAdminSearchService.updatePost(updatedPost);
|
|
|
|
|
System.out.println("✅ 帖子ES索引更新成功");
|
|
|
|
|
// 🎯 修改:同步帖子到ES索引(举报成立或驳回举报恢复帖子时都需要同步)
|
|
|
|
|
if (success && post != null && postAdminSearchService != null) {
|
|
|
|
|
// 举报成立时需要同步(帖子变为rejected)
|
|
|
|
|
// 驳回举报且帖子被恢复时也需要同步(帖子从rejected变为approved)
|
|
|
|
|
boolean needSync = isReportApproved ||
|
|
|
|
|
(isReportDismissed && "rejected".equals(originalPostStatus) &&
|
|
|
|
|
"report_review".equals(originalReviewType));
|
|
|
|
|
|
|
|
|
|
if (needSync) {
|
|
|
|
|
try {
|
|
|
|
|
System.out.println("=== 同步帖子状态到ES ===");
|
|
|
|
|
System.out.println("帖子ID: " + postId);
|
|
|
|
|
|
|
|
|
|
// 重新获取更新后的帖子信息
|
|
|
|
|
Post updatedPost = postMapper.selectByIdAsPost(postId);
|
|
|
|
|
if (updatedPost != null) {
|
|
|
|
|
postAdminSearchService.updatePost(updatedPost);
|
|
|
|
|
System.out.println("✅ 帖子ES索引更新成功");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("❌ 帖子ES索引更新失败: " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// ES更新失败不影响主流程
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("❌ 帖子ES索引更新失败: " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// ES更新失败不影响主流程
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 发送通知
|
|
|
|
|
// 🎯 修改:发送通知(根据不同场景发送不同通知)
|
|
|
|
|
if (success && report != null) {
|
|
|
|
|
try {
|
|
|
|
|
System.out.println("=== 帖子举报通知 ===");
|
|
|
|
|
System.out.println("举报人ID: " + reporterId);
|
|
|
|
|
System.out.println("帖子ID: " + postId);
|
|
|
|
|
System.out.println("处理状态: " + status);
|
|
|
|
|
System.out.println("处理结果: " + result);
|
|
|
|
|
|
|
|
|
|
// 判断是举报成立还是驳回(使用前面已定义的变量)
|
|
|
|
|
// reviewed = 举报成立,需要通知举报人和帖子作者
|
|
|
|
|
// dismissed + "恶意举报" = 举报成立(帖子内容恶意),需要通知举报人和帖子作者
|
|
|
|
|
// dismissed + 其他 = 举报驳回,只通知举报人
|
|
|
|
|
System.out.println("原帖子状态: " + originalPostStatus);
|
|
|
|
|
System.out.println("原review_type: " + originalReviewType);
|
|
|
|
|
|
|
|
|
|
if (isReportApproved) {
|
|
|
|
|
// 举报成立:通知举报人和帖子作者
|
|
|
|
|
System.out.println("举报成立 - 通知举报人和帖子作者");
|
|
|
|
|
// ========== 场景1:举报成立 ==========
|
|
|
|
|
System.out.println("📢 场景1:举报成立");
|
|
|
|
|
|
|
|
|
|
// 通知举报人
|
|
|
|
|
// 1. 通知举报人:举报成立
|
|
|
|
|
noticeService.sendPostReportResultNotification(
|
|
|
|
|
reporterId,
|
|
|
|
|
postId,
|
|
|
|
|
"举报成立,已处理"
|
|
|
|
|
"已封禁帖子"
|
|
|
|
|
);
|
|
|
|
|
System.out.println("已发送通知给举报人: " + reporterId);
|
|
|
|
|
System.out.println("✅ 已通知举报人(ID:" + reporterId + "):举报成立");
|
|
|
|
|
|
|
|
|
|
// 通知帖子作者
|
|
|
|
|
// 2. 通知帖子作者:帖子因举报被封禁
|
|
|
|
|
if (post != null) {
|
|
|
|
|
String reportType = report.getReportType() != null ? report.getReportType() : "违规内容";
|
|
|
|
|
noticeService.sendPostReportedNotification(
|
|
|
|
|
noticeService.sendPostBannedByReportNotification(
|
|
|
|
|
post.getAuthor_id(),
|
|
|
|
|
postId,
|
|
|
|
|
reportType
|
|
|
|
|
);
|
|
|
|
|
System.out.println("已发送通知给帖子作者: " + post.getAuthor_id());
|
|
|
|
|
System.out.println("✅ 已通知帖子作者(ID:" + post.getAuthor_id() + "):帖子因举报被封禁");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 举报驳回:只通知举报人
|
|
|
|
|
System.out.println("举报驳回 - 只通知举报人");
|
|
|
|
|
|
|
|
|
|
} else if (isReportDismissed) {
|
|
|
|
|
// ========== 场景2/3:举报驳回 ==========
|
|
|
|
|
|
|
|
|
|
// 总是通知举报人:举报被驳回
|
|
|
|
|
noticeService.sendPostReportResultNotification(
|
|
|
|
|
reporterId,
|
|
|
|
|
postId,
|
|
|
|
|
result != null ? result : "举报不成立,已驳回"
|
|
|
|
|
"已驳回举报"
|
|
|
|
|
);
|
|
|
|
|
System.out.println("已发送通知给举报人: " + reporterId);
|
|
|
|
|
System.out.println("✅ 已通知举报人(ID:" + reporterId + "):举报被驳回");
|
|
|
|
|
|
|
|
|
|
// 判断是否需要通知帖子作者
|
|
|
|
|
if (post != null && "rejected".equals(originalPostStatus) &&
|
|
|
|
|
"report_review".equals(originalReviewType)) {
|
|
|
|
|
// ========== 场景2:帖子是因举报被封禁的,现在恢复了 ==========
|
|
|
|
|
System.out.println("📢 场景2:帖子因举报被封禁,现已恢复");
|
|
|
|
|
|
|
|
|
|
noticeService.sendPostReportDismissedNotification(
|
|
|
|
|
post.getAuthor_id(),
|
|
|
|
|
postId
|
|
|
|
|
);
|
|
|
|
|
System.out.println("✅ 已通知帖子作者(ID:" + post.getAuthor_id() + "):举报被驳回,帖子已恢复");
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// ========== 场景3:帖子不是因举报被封禁的,或本来就正常 ==========
|
|
|
|
|
System.out.println("📢 场景3:帖子状态保持不变,不通知作者");
|
|
|
|
|
System.out.println(" 原因:帖子不是因举报被封禁(status:" + originalPostStatus + ", review_type:" + originalReviewType + ")");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("===================");
|
|
|
|
|
@ -318,6 +372,26 @@ public class PostReportService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 对历史举报(processed状态)按处理时间降序排序
|
|
|
|
|
// 确保最新处理的举报在前面
|
|
|
|
|
allReports.sort((a, b) -> {
|
|
|
|
|
String statusA = (String) a.get("status");
|
|
|
|
|
String statusB = (String) b.get("status");
|
|
|
|
|
|
|
|
|
|
// 如果都是processed状态,按submitTime(实际是processedAt)降序排序
|
|
|
|
|
if ("processed".equals(statusA) && "processed".equals(statusB)) {
|
|
|
|
|
String timeA = (String) a.get("submitTime");
|
|
|
|
|
String timeB = (String) b.get("submitTime");
|
|
|
|
|
// 降序:B比A,如果B更晚则返回正数
|
|
|
|
|
return timeB.compareTo(timeA);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保持pending在前,processed在后
|
|
|
|
|
if ("pending".equals(statusA)) return -1;
|
|
|
|
|
if ("pending".equals(statusB)) return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 统计
|
|
|
|
|
long pendingCount = allReports.stream()
|
|
|
|
|
.filter(r -> "pending".equals(r.get("status")))
|
|
|
|
|
@ -519,7 +593,28 @@ public class PostReportService {
|
|
|
|
|
reportMap.put("reportedId", String.valueOf(report.getPostId()));
|
|
|
|
|
reportMap.put("reason", report.getReportType() != null ? report.getReportType() : "其他");
|
|
|
|
|
reportMap.put("reasonDetail", report.getDescription());
|
|
|
|
|
reportMap.put("submitTime", report.getCreatedAt() != null ? sdf.format(report.getCreatedAt()) : "-");
|
|
|
|
|
|
|
|
|
|
// 🔧 修复:始终保留原始的 created_at 用于查询详情
|
|
|
|
|
reportMap.put("createdAt", report.getCreatedAt() != null ?
|
|
|
|
|
sdf.format(report.getCreatedAt()) : "-");
|
|
|
|
|
|
|
|
|
|
// 根据状态显示不同的时间
|
|
|
|
|
// 待处理举报:显示提交时间(created_at)
|
|
|
|
|
// 历史举报:显示处理时间(processed_at)
|
|
|
|
|
if ("processed".equals(status)) {
|
|
|
|
|
// 历史举报:优先使用 processed_at,如果为空则使用 created_at
|
|
|
|
|
String timeToDisplay = "-";
|
|
|
|
|
if (report.getProcessedAt() != null) {
|
|
|
|
|
timeToDisplay = sdf.format(report.getProcessedAt());
|
|
|
|
|
} else if (report.getCreatedAt() != null) {
|
|
|
|
|
timeToDisplay = sdf.format(report.getCreatedAt());
|
|
|
|
|
}
|
|
|
|
|
reportMap.put("submitTime", timeToDisplay);
|
|
|
|
|
} else {
|
|
|
|
|
reportMap.put("submitTime", report.getCreatedAt() != null ?
|
|
|
|
|
sdf.format(report.getCreatedAt()) : "-");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reportMap.put("status", status);
|
|
|
|
|
|
|
|
|
|
// 如果是已处理的举报,添加处理信息
|
|
|
|
|
|