新增评论举报接口

This commit is contained in:
2026-03-20 15:38:25 +08:00
7 changed files with 160 additions and 84 deletions

View File

@@ -10,7 +10,9 @@ import com.yolo.keyborad.exception.BusinessException;
import com.yolo.keyborad.model.dto.comment.CommentAddReq; import com.yolo.keyborad.model.dto.comment.CommentAddReq;
import com.yolo.keyborad.model.dto.comment.CommentLikeReq; import com.yolo.keyborad.model.dto.comment.CommentLikeReq;
import com.yolo.keyborad.model.dto.comment.CommentPageReq; import com.yolo.keyborad.model.dto.comment.CommentPageReq;
import com.yolo.keyborad.model.dto.comment.CommentReportReq;
import com.yolo.keyborad.model.vo.CommentVO; import com.yolo.keyborad.model.vo.CommentVO;
import com.yolo.keyborad.service.KeyboardAiCommentReportService;
import com.yolo.keyborad.service.KeyboardAiCompanionCommentService; import com.yolo.keyborad.service.KeyboardAiCompanionCommentService;
import com.yolo.keyborad.service.KeyboardAiCompanionCommentLikeService; import com.yolo.keyborad.service.KeyboardAiCompanionCommentLikeService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@@ -35,6 +37,9 @@ public class AiCompanionCommentController {
@Resource @Resource
private KeyboardAiCompanionCommentLikeService commentLikeService; private KeyboardAiCompanionCommentLikeService commentLikeService;
@Resource
private KeyboardAiCommentReportService commentReportService;
@PostMapping("/add") @PostMapping("/add")
@Operation(summary = "发表评论", description = "用户对AI陪聊角色发表评论") @Operation(summary = "发表评论", description = "用户对AI陪聊角色发表评论")
public BaseResponse<Long> addComment(@RequestBody CommentAddReq req) { public BaseResponse<Long> addComment(@RequestBody CommentAddReq req) {
@@ -75,4 +80,12 @@ public class AiCompanionCommentController {
boolean result = commentLikeService.toggleLike(userId, req.getCommentId()); boolean result = commentLikeService.toggleLike(userId, req.getCommentId());
return ResultUtils.success(result); return ResultUtils.success(result);
} }
@PostMapping("/report")
@Operation(summary = "举报评论", description = "举报AI陪聊角色评论支持多种举报类型可多选1=色情低俗, 2=政治敏感, 3=暴力恐怖, 4=侵权/冒充, 5=价值观问题, 99=其他")
public BaseResponse<Long> reportComment(@RequestBody CommentReportReq req) {
Long userId = StpUtil.getLoginIdAsLong();
Long reportId = commentReportService.reportComment(userId, req);
return ResultUtils.success(reportId);
}
} }

View File

@@ -5,8 +5,7 @@ import com.yolo.keyborad.model.entity.KeyboardAiCommentReport;
/* /*
* @author: ziin * @author: ziin
* @date: 2026/3/20 15:07 * @date: 2026/3/20
*/ */
public interface KeyboardAiCommentReportMapper extends BaseMapper<KeyboardAiCommentReport> { public interface KeyboardAiCommentReportMapper extends BaseMapper<KeyboardAiCommentReport> {
} }

View File

@@ -0,0 +1,30 @@
package com.yolo.keyborad.model.dto.comment;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/*
* @author: ziin
* @date: 2026/3/20
*/
@Data
@Schema(description = "评论举报请求")
public class CommentReportReq {
@Schema(description = "评论ID", requiredMode = Schema.RequiredMode.REQUIRED)
private Long commentId;
@Schema(description = "举报类型列表1=色情低俗, 2=政治敏感, 3=暴力恐怖, 4=侵权/冒充, 5=价值观问题, 99=其他,支持多选", requiredMode = Schema.RequiredMode.REQUIRED)
private List<Short> reportTypes;
@Schema(description = "详细描述")
private String reportDesc;
@Schema(description = "评论上下文快照JSON")
private String chatContext;
@Schema(description = "图片证据URL")
private String evidenceImageUrl;
}

View File

@@ -5,94 +5,63 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Date;
import lombok.Data; import lombok.Data;
import java.util.Date;
/* /*
* @author: ziin * @author: ziin
* @date: 2026/3/20 15:07 * @date: 2026/3/20
*/ */
/** /**
* AI角色评论举报记录表 * AI评论举报记录表
*/ */
@Schema(description="AI角色评论举报记录表")
@Data @Data
@Schema(description = "AI评论举报记录表")
@TableName(value = "keyboard_ai_comment_report") @TableName(value = "keyboard_ai_comment_report")
public class KeyboardAiCommentReport { public class KeyboardAiCommentReport {
/**
* 举报记录唯一ID
*/
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
@Schema(description = "举报记录唯一ID") @Schema(description = "举报记录唯一ID")
private Long id; private Long id;
/**
* 被举报的评论Id
*/
@TableField(value = "comment_id") @TableField(value = "comment_id")
@Schema(description="被举报的评论Id") @Schema(description = "被举报的评论ID")
private Long commentId; private Long commentId;
/**
* 发起举报的用户ID逻辑关联用户表
*/
@TableField(value = "user_id") @TableField(value = "user_id")
@Schema(description="发起举报的用户ID(逻辑关联用户表)") @Schema(description = "发起举报的用户ID")
private Long userId; private Long userId;
/**
* 举报类型1=色情低俗, 2=政治敏感, 3=暴力恐怖, 4=侵权/冒充, 5=价值观问题, 99=其他
*/
@TableField(value = "report_type") @TableField(value = "report_type")
@Schema(description="举报类型1=色情低俗, 2=政治敏感, 3=暴力恐怖, 4=侵权/冒充, 5=价值观问题, 99=其他") @Schema(description = "举报类型,多选时逗号分隔")
private String reportType; private String reportType;
/**
* 用户填写的详细举报描述
*/
@TableField(value = "report_desc") @TableField(value = "report_desc")
@Schema(description = "用户填写的详细举报描述") @Schema(description = "用户填写的详细举报描述")
private String reportDesc; private String reportDesc;
/** @TableField(value = "chat_context")
* 违规现场:举报时的评论的内容,用于审核取证 @Schema(description = "评论上下文快照JSON")
*/ private String chatContext;
@TableField(value = "comment_context")
@Schema(description="违规现场:举报时的评论的内容,用于审核取证")
private String commentContext;
/**
* 图片证据用户上传的截图URL
*/
@TableField(value = "evidence_image_url") @TableField(value = "evidence_image_url")
@Schema(description="图片证据:用户上传的截图URL") @Schema(description = "图片证据URL")
private String evidenceImageUrl; private String evidenceImageUrl;
/**
* 处理状态0=待处理, 1=违规确立(已处罚), 2=无效举报/已驳回, 3=已忽略
*/
@TableField(value = "\"status\"") @TableField(value = "\"status\"")
@Schema(description="处理状态0=待处理, 1=违规确立(已处罚), 2=无效举报/已驳回, 3=已忽略") @Schema(description = "处理状态0=待处理, 1=违规确立, 2=无效举报, 3=已忽略")
private Short status; private Short status;
/**
* 管理员处理备注(记录处理理由或处罚措施)
*/
@TableField(value = "admin_remark") @TableField(value = "admin_remark")
@Schema(description="管理员处理备注(记录处理理由或处罚措施)") @Schema(description = "管理员处理备注")
private String adminRemark; private String adminRemark;
/**
* 举报提交时间
*/
@TableField(value = "created_at") @TableField(value = "created_at")
@Schema(description = "举报提交时间") @Schema(description = "举报提交时间")
private Date createdAt; private Date createdAt;
/**
* 最后更新时间
*/
@TableField(value = "updated_at") @TableField(value = "updated_at")
@Schema(description = "最后更新时间") @Schema(description = "最后更新时间")
private Date updatedAt; private Date updatedAt;

View File

@@ -1,13 +1,21 @@
package com.yolo.keyborad.service; package com.yolo.keyborad.service;
import com.yolo.keyborad.model.entity.KeyboardAiCommentReport;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.yolo.keyborad.model.dto.comment.CommentReportReq;
import com.yolo.keyborad.model.entity.KeyboardAiCommentReport;
/* /*
* @author: ziin * @author: ziin
* @date: 2026/3/20 15:07 * @date: 2026/3/20
*/ */
public interface KeyboardAiCommentReportService extends IService<KeyboardAiCommentReport> { public interface KeyboardAiCommentReportService extends IService<KeyboardAiCommentReport> {
/**
* 举报评论
*
* @param userId 用户ID
* @param req 举报请求
* @return 举报记录ID
*/
Long reportComment(Long userId, CommentReportReq req);
} }

View File

@@ -1,18 +1,78 @@
package com.yolo.keyborad.service.impl; package com.yolo.keyborad.service.impl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yolo.keyborad.model.entity.KeyboardAiCommentReport; import com.yolo.keyborad.common.ErrorCode;
import com.yolo.keyborad.exception.BusinessException;
import com.yolo.keyborad.mapper.KeyboardAiCommentReportMapper; import com.yolo.keyborad.mapper.KeyboardAiCommentReportMapper;
import com.yolo.keyborad.model.dto.comment.CommentReportReq;
import com.yolo.keyborad.model.entity.KeyboardAiCommentReport;
import com.yolo.keyborad.model.entity.KeyboardAiCompanionComment;
import com.yolo.keyborad.service.KeyboardAiCommentReportService; import com.yolo.keyborad.service.KeyboardAiCommentReportService;
import com.yolo.keyborad.service.KeyboardAiCompanionCommentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.Set;
import java.util.stream.Collectors;
/* /*
* @author: ziin * @author: ziin
* @date: 2026/3/20 15:07 * @date: 2026/3/20
*/ */
@Service @Service
public class KeyboardAiCommentReportServiceImpl extends ServiceImpl<KeyboardAiCommentReportMapper, KeyboardAiCommentReport> implements KeyboardAiCommentReportService{ public class KeyboardAiCommentReportServiceImpl extends ServiceImpl<KeyboardAiCommentReportMapper, KeyboardAiCommentReport>
implements KeyboardAiCommentReportService {
private static final short PENDING_STATUS = 0;
private static final Set<Short> VALID_REPORT_TYPES = Set.of(
(short) 1, (short) 2, (short) 3, (short) 4, (short) 5, (short) 99
);
@Resource
private KeyboardAiCompanionCommentService commentService;
@Override
public Long reportComment(Long userId, CommentReportReq req) {
validateRequest(req);
KeyboardAiCompanionComment comment = commentService.getById(req.getCommentId());
if (comment == null) {
throw new BusinessException(ErrorCode.COMMENT_NOT_FOUND);
}
KeyboardAiCommentReport report = buildReport(userId, req);
boolean saved = this.save(report);
if (!saved) {
throw new BusinessException(ErrorCode.OPERATION_ERROR);
}
return report.getId();
}
private void validateRequest(CommentReportReq req) {
if (req.getCommentId() == null) {
throw new BusinessException(ErrorCode.COMMENT_ID_EMPTY);
}
if (req.getReportTypes() == null || req.getReportTypes().isEmpty()) {
throw new BusinessException(ErrorCode.REPORT_TYPE_EMPTY);
}
boolean hasInvalidType = req.getReportTypes().stream().anyMatch(type -> !VALID_REPORT_TYPES.contains(type));
if (hasInvalidType) {
throw new BusinessException(ErrorCode.REPORT_TYPE_INVALID);
}
}
private KeyboardAiCommentReport buildReport(Long userId, CommentReportReq req) {
KeyboardAiCommentReport report = new KeyboardAiCommentReport();
report.setUserId(userId);
report.setCommentId(req.getCommentId());
report.setReportType(req.getReportTypes().stream().map(String::valueOf).collect(Collectors.joining(",")));
report.setReportDesc(req.getReportDesc());
report.setChatContext(req.getChatContext());
report.setEvidenceImageUrl(req.getEvidenceImageUrl());
report.setStatus(PENDING_STATUS);
report.setCreatedAt(new Date());
return report;
}
} }

View File

@@ -2,14 +2,12 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yolo.keyborad.mapper.KeyboardAiCommentReportMapper"> <mapper namespace="com.yolo.keyborad.mapper.KeyboardAiCommentReportMapper">
<resultMap id="BaseResultMap" type="com.yolo.keyborad.model.entity.KeyboardAiCommentReport"> <resultMap id="BaseResultMap" type="com.yolo.keyborad.model.entity.KeyboardAiCommentReport">
<!--@mbg.generated-->
<!--@Table keyboard_ai_comment_report-->
<id column="id" jdbcType="BIGINT" property="id" /> <id column="id" jdbcType="BIGINT" property="id" />
<result column="comment_id" jdbcType="BIGINT" property="commentId" /> <result column="comment_id" jdbcType="BIGINT" property="commentId" />
<result column="user_id" jdbcType="BIGINT" property="userId" /> <result column="user_id" jdbcType="BIGINT" property="userId" />
<result column="report_type" jdbcType="VARCHAR" property="reportType" /> <result column="report_type" jdbcType="VARCHAR" property="reportType" />
<result column="report_desc" jdbcType="VARCHAR" property="reportDesc" /> <result column="report_desc" jdbcType="VARCHAR" property="reportDesc" />
<result column="comment_context" jdbcType="VARCHAR" property="commentContext" /> <result column="chat_context" jdbcType="VARCHAR" property="chatContext" />
<result column="evidence_image_url" jdbcType="VARCHAR" property="evidenceImageUrl" /> <result column="evidence_image_url" jdbcType="VARCHAR" property="evidenceImageUrl" />
<result column="status" jdbcType="SMALLINT" property="status" /> <result column="status" jdbcType="SMALLINT" property="status" />
<result column="admin_remark" jdbcType="VARCHAR" property="adminRemark" /> <result column="admin_remark" jdbcType="VARCHAR" property="adminRemark" />
@@ -17,8 +15,7 @@
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" /> <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!--@mbg.generated--> id, comment_id, user_id, report_type, report_desc, chat_context, evidence_image_url,
id, comment_id, user_id, report_type, report_desc, comment_context, evidence_image_url,
"status", admin_remark, created_at, updated_at "status", admin_remark, created_at, updated_at
</sql> </sql>
</mapper> </mapper>