#I1KMTP 增加删除评论功能
This commit is contained in:
@@ -25,6 +25,7 @@ import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -58,6 +59,7 @@ public class WikiPageCommentController {
|
||||
return DocResponseJson.warn("您没有查看该空间的评论权!");
|
||||
}
|
||||
UpdateWrapper<WikiPageComment> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("del_flag", 0);
|
||||
wrapper.eq("page_id", pageComment.getPageId());
|
||||
wrapper.eq(pageComment.getParentId() != null, "parent_id", pageComment.getParentId());
|
||||
List<WikiPageComment> authList = wikiPageCommentService.list(wrapper);
|
||||
@@ -71,19 +73,39 @@ public class WikiPageCommentController {
|
||||
return DocResponseJson.ok(commentList);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ResponseJson<Object> delete(Long id) {
|
||||
WikiPageComment pageCommentSel = wikiPageCommentService.getById(id);
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
if (!Objects.equals(pageCommentSel.getCreateUserId(), currentUser.getUserId())) {
|
||||
WikiPage wikiPageSel = wikiPageService.getById(pageCommentSel.getPageId());
|
||||
if (!Objects.equals(currentUser.getUserId(), wikiPageSel.getCreateUserId())) {
|
||||
return DocResponseJson.warn("只有评论人或页面创建人才有权限删除此评论!");
|
||||
}
|
||||
}
|
||||
WikiPageComment pageComment = new WikiPageComment();
|
||||
pageComment.setId(id);
|
||||
pageComment.setDelFlag(1);
|
||||
wikiPageCommentService.updateById(pageComment);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResponseJson<Object> update(WikiPageComment pageComment) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
Long id = pageComment.getId();
|
||||
Long pageId;
|
||||
if (id != null && id > 0) {
|
||||
WikiPageComment pageCommentSel = wikiPageCommentService.getById(id);
|
||||
if (!Objects.equals(pageCommentSel.getCreateUserId(), currentUser.getUserId())) {
|
||||
return DocResponseJson.warn("只能修改自己的评论!");
|
||||
}
|
||||
pageId = pageCommentSel.getPageId();
|
||||
} else if (pageComment.getPageId() != null) {
|
||||
pageId = pageComment.getPageId();
|
||||
} else {
|
||||
return DocResponseJson.warn("需指定所属页面!");
|
||||
}
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
WikiPage wikiPageSel = wikiPageService.getById(pageId);
|
||||
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId());
|
||||
// 私人空间
|
||||
@@ -98,6 +120,7 @@ public class WikiPageCommentController {
|
||||
// }
|
||||
// }
|
||||
if (id != null && id > 0) {
|
||||
pageComment.setDelFlag(0);
|
||||
wikiPageCommentService.updateById(pageComment);
|
||||
} else {
|
||||
pageComment.setCreateTime(new Date());
|
||||
|
||||
@@ -132,6 +132,7 @@ public class WikiPageController {
|
||||
vo.setPageContent(pageContent);
|
||||
vo.setFileList(pageFiles);
|
||||
vo.setSelfZan((pageZan != null) ? 1 : 0);
|
||||
vo.setSelfUserId(currentUser.getUserId());
|
||||
// 高并发下会有覆盖问题,但不重要~
|
||||
Integer viewNum = Optional.ofNullable(wikiPageSel.getViewNum()).orElse(0);
|
||||
WikiPage wikiPageUp = new WikiPage();
|
||||
|
||||
@@ -11,6 +11,7 @@ public class WikiPageContentVo {
|
||||
private WikiPageContent pageContent;
|
||||
private List<WikiPageFile> fileList;
|
||||
private Integer selfZan;
|
||||
private Long selfUserId;
|
||||
|
||||
public WikiPage getWikiPage() {
|
||||
return wikiPage;
|
||||
@@ -43,4 +44,12 @@ public class WikiPageContentVo {
|
||||
public void setSelfZan(Integer selfZan) {
|
||||
this.selfZan = selfZan;
|
||||
}
|
||||
|
||||
public Long getSelfUserId() {
|
||||
return selfUserId;
|
||||
}
|
||||
|
||||
public void setSelfUserId(Long selfUserId) {
|
||||
this.selfUserId = selfUserId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ public class SpaceType {
|
||||
public static final Integer personalSpace = 2;
|
||||
public static final Integer privateSpace = 3;
|
||||
|
||||
public static boolean isPublic(Integer type){
|
||||
public static boolean isPublic(Integer type) {
|
||||
return Objects.equals(type, publicSpace);
|
||||
}
|
||||
|
||||
@@ -15,19 +15,19 @@ public class SpaceType {
|
||||
return Objects.equals(type, personalSpace);
|
||||
}
|
||||
|
||||
public static boolean isOthersPersonal(Integer type, Long loginUserId, Long spaceUserId){
|
||||
public static boolean isOthersPersonal(Integer type, Long loginUserId, Long spaceUserId) {
|
||||
return Objects.equals(type, personalSpace) && !Objects.equals(loginUserId, spaceUserId);
|
||||
}
|
||||
|
||||
public static boolean isPrivate(Integer type){
|
||||
public static boolean isPrivate(Integer type) {
|
||||
return Objects.equals(type, privateSpace);
|
||||
}
|
||||
|
||||
public static boolean isSelfPrivate(Integer type, Long loginUserId, Long spaceUserId){
|
||||
public static boolean isSelfPrivate(Integer type, Long loginUserId, Long spaceUserId) {
|
||||
return Objects.equals(type, privateSpace) && Objects.equals(loginUserId, spaceUserId);
|
||||
}
|
||||
|
||||
public static boolean isOthersPrivate(Integer type, Long loginUserId, Long spaceUserId){
|
||||
public static boolean isOthersPrivate(Integer type, Long loginUserId, Long spaceUserId) {
|
||||
return Objects.equals(type, privateSpace) && !Objects.equals(loginUserId, spaceUserId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user