From 8d897c4089f667074d4b6df8ae2eb74d66d65f2b Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Tue, 20 Feb 2024 19:26:23 +0800 Subject: [PATCH] feat: comment complaint && handle complaint --- luoo_comment/redeme.md | 2 - .../controller/CmsCommentController.java | 60 ++++++++++++++----- .../comment/controller/CommentController.java | 41 +++++++++++++ .../com/luoo/comment/dao/ComplaintDao.java | 11 ++++ .../java/com/luoo/comment/pojo/Complaint.java | 57 ++++++++++++++++++ .../comment/service/ComplaintService.java | 31 ++++++++++ 6 files changed, 185 insertions(+), 17 deletions(-) delete mode 100644 luoo_comment/redeme.md create mode 100644 luoo_comment/src/main/java/com/luoo/comment/dao/ComplaintDao.java create mode 100644 luoo_comment/src/main/java/com/luoo/comment/pojo/Complaint.java create mode 100644 luoo_comment/src/main/java/com/luoo/comment/service/ComplaintService.java diff --git a/luoo_comment/redeme.md b/luoo_comment/redeme.md deleted file mode 100644 index 105b980..0000000 --- a/luoo_comment/redeme.md +++ /dev/null @@ -1,2 +0,0 @@ -# 解析IP三方库 -https://github.com/jarod/qqwry-java \ No newline at end of file diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CmsCommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CmsCommentController.java index 5c88c34..cd1ff5f 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CmsCommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CmsCommentController.java @@ -3,25 +3,20 @@ package com.luoo.comment.controller; import api.PageResult; import api.Result; -import api.StatusCode; import com.luoo.comment.pojo.Comment; -import com.luoo.comment.pojo.CommentVo; + +import com.luoo.comment.pojo.Complaint; import com.luoo.comment.service.CommentService; -import constants.Constants; +import com.luoo.comment.service.ComplaintService; import controller.BaseController; -import dto.UserLoginDto; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; -import java.util.concurrent.TimeUnit; +import java.util.Date; + @RestController @CrossOrigin @@ -36,11 +31,7 @@ public class CmsCommentController extends BaseController { @Autowired - private RedisTemplate redisTemplate; - - - @Autowired - private HttpServletRequest request; + private ComplaintService complaintService; @@ -85,6 +76,45 @@ public class CmsCommentController extends BaseController { + // 评论举报列表 + @ApiOperation(value = "评论举报分页列表") + @GetMapping("/complaint/{page}/{size}") + public Result complainList(@PathVariable int page,@PathVariable int size){ + Page pageData = complaintService.search(page,size); + return Result.success(new PageResult(pageData.getTotalElements(),pageData.getContent())); + } + @ApiOperation(value = "评论详情") + @GetMapping("/complaint/{complaintId}") + public Result findByComplaintId(@PathVariable String complaintId) { + Complaint complaint = complaintService.findByComplaintId(complaintId); + return Result.success(complaint); + } + + @ApiOperation(value = "举报处理",notes = "flag 1为有效举报 2为无效举报") + @PostMapping("/complaintHandle/{complaintId}/{flag}") + public Result handleComplaint(@PathVariable String complaintId, @PathVariable int flag) { + + Complaint complaint = complaintService.findByComplaintId(complaintId); + if(flag==1){ + // 有效举报,删除评论 + complaint.setState("已处理"); + complaint.setHandleBy("落在低处"); + complaint.setHandleResult("删除评论"); + complaint.setHandleTime(new Date()); + commentService.deleteById(complaint.getCommentId()); + } + if(flag==2){ + // 有效举报,删除评论 + complaint.setState("已处理"); + complaint.setHandleBy("落在低处"); + complaint.setHandleResult("保留评论"); + complaint.setHandleTime(new Date()); + } + + complaintService.save(complaint); + + return Result.success(); + } } diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java index 72cd4ff..b71dda7 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java @@ -6,6 +6,7 @@ import api.Result; import api.StatusCode; import com.luoo.comment.pojo.*; import com.luoo.comment.service.CommentService; +import com.luoo.comment.service.ComplaintService; import com.luoo.comment.service.LikeService; import com.luoo.comment.util.IpUtil; import constants.Constants; @@ -26,8 +27,10 @@ import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; +import util.IdWorker; import javax.servlet.http.HttpServletRequest; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -60,6 +63,11 @@ public class CommentController extends BaseController { private HttpServletRequest request; + @Autowired + private ComplaintService complaintService; + + @Autowired + private IdWorker idWorker; @GetMapping public Result findAll(){ @@ -268,4 +276,37 @@ public class CommentController extends BaseController { } + + @ApiOperation(value = "评论举报",notes = "type为举报类型") + @PostMapping("/complaint/{commentId}/{type}") + public Result complaint(@PathVariable String commentId,@PathVariable String type,@RequestHeader(value = "Authorization", required = true) String authorization){ + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + + Comment comment = commentService.findById(commentId); + Complaint complaint = new Complaint(); + complaint.set_id(idWorker.nextId()+""); + complaint.setCommentId(commentId); + complaint.setCommentContent(comment.getContent()); + complaint.setType(type); + complaint.setComplaintFrom(userLoginDto.getNickName()); + complaint.setComplaintTime(new Date()); + complaint.setJournalId(""); + complaint.setJournalTitle(""); + complaint.setComplaintTo(comment.getNickName()); + complaint.setState("未处理"); + complaint.setHandleResult(""); + + + complaintService.save(complaint); + return Result.success(); + } + + + + } diff --git a/luoo_comment/src/main/java/com/luoo/comment/dao/ComplaintDao.java b/luoo_comment/src/main/java/com/luoo/comment/dao/ComplaintDao.java new file mode 100644 index 0000000..1bbef91 --- /dev/null +++ b/luoo_comment/src/main/java/com/luoo/comment/dao/ComplaintDao.java @@ -0,0 +1,11 @@ +package com.luoo.comment.dao; + +import com.luoo.comment.pojo.Complaint; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.mongodb.repository.MongoRepository; + +public interface ComplaintDao extends MongoRepository { + + public Page findAllByOrderByComplaintTimeDesc(Pageable pageable); +} diff --git a/luoo_comment/src/main/java/com/luoo/comment/pojo/Complaint.java b/luoo_comment/src/main/java/com/luoo/comment/pojo/Complaint.java new file mode 100644 index 0000000..f129965 --- /dev/null +++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/Complaint.java @@ -0,0 +1,57 @@ +package com.luoo.comment.pojo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class Complaint implements Serializable { + + @Id + private String _id; + + // 举报的评论ID + private String commentId; + + // 举报的评论内容 + private String commentContent; + + // 举报类型 + private String type; + + //举报人 + private String complaintFrom; + + // 举报时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date complaintTime; + + // 举报关联 + private String journalId; + + private String journalTitle; + + // 举报对象 + private String complaintTo; + + // 举报状态 + private String state; + + // 处理结果 + private String handleResult; + + + // 处理人 + private String handleBy; + + // 处理时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date handleTime; + +} diff --git a/luoo_comment/src/main/java/com/luoo/comment/service/ComplaintService.java b/luoo_comment/src/main/java/com/luoo/comment/service/ComplaintService.java new file mode 100644 index 0000000..48ad1ca --- /dev/null +++ b/luoo_comment/src/main/java/com/luoo/comment/service/ComplaintService.java @@ -0,0 +1,31 @@ +package com.luoo.comment.service; + +import com.luoo.comment.dao.ComplaintDao; +import com.luoo.comment.pojo.Complaint; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +@Service +public class ComplaintService { + + @Autowired + private ComplaintDao complaintDao; + + public Page search(int page, int size) { + Pageable pageable = PageRequest.of(page-1,size); + + return complaintDao.findAllByOrderByComplaintTimeDesc(pageable); + } + + public void save(Complaint complaint) { + + complaintDao.save(complaint); + } + + public Complaint findByComplaintId(String complaintId) { + return complaintDao.findById(complaintId).get(); + } +}