feat: comment complaint && handle complaint

main
wangqing 9 months ago
parent 97967b2eb7
commit 8d897c4089

@ -1,2 +0,0 @@
# 解析IP三方库
https://github.com/jarod/qqwry-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<Complaint> pageData = complaintService.search(page,size);
return Result.success(new PageResult<Complaint>(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();
}
}

@ -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();
}
}

@ -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<Complaint,String> {
public Page<Complaint> findAllByOrderByComplaintTimeDesc(Pageable pageable);
}

@ -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;
}

@ -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<Complaint> 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();
}
}
Loading…
Cancel
Save