commit | author | age
|
88f419
|
1 |
/* |
I |
2 |
Copyright [2020] [https://www.xiaonuo.vip] |
|
3 |
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
you may not use this file except in compliance with the License. |
|
6 |
You may obtain a copy of the License at |
|
7 |
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
|
|
10 |
Unless required by applicable law or agreed to in writing, software |
|
11 |
distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
See the License for the specific language governing permissions and |
|
14 |
limitations under the License. |
|
15 |
|
|
16 |
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: |
|
17 |
|
|
18 |
1.请不要删除和修改根目录下的LICENSE文件。 |
|
19 |
2.请不要删除和修改Snowy源码头部的版权声明。 |
|
20 |
3.请保留源码和相关描述文件的项目出处,作者声明等。 |
|
21 |
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
22 |
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
23 |
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip |
|
24 |
*/ |
|
25 |
package vip.xiaonuo.modular.blogarticlecomment.controller; |
|
26 |
|
|
27 |
import cn.hutool.core.bean.BeanUtil; |
e343e5
|
28 |
import cn.hutool.core.collection.CollUtil; |
88f419
|
29 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
I |
30 |
import org.springframework.validation.annotation.Validated; |
|
31 |
import org.springframework.web.bind.annotation.*; |
|
32 |
import vip.xiaonuo.core.annotion.BusinessLog; |
|
33 |
import vip.xiaonuo.core.consts.MyConstant; |
|
34 |
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum; |
|
35 |
import vip.xiaonuo.core.exception.BlogException; |
|
36 |
import vip.xiaonuo.core.pojo.response.ResponseData; |
|
37 |
import vip.xiaonuo.core.pojo.response.SuccessResponseData; |
42b7d0
|
38 |
import vip.xiaonuo.modular.blogarticle.entity.BlogArticle; |
88f419
|
39 |
import vip.xiaonuo.modular.blogarticle.service.BlogArticleService; |
I |
40 |
import vip.xiaonuo.modular.blogarticlecomment.entity.BlogArticleComment; |
|
41 |
import vip.xiaonuo.modular.blogarticlecomment.entity.BlogCommentVo; |
|
42 |
import vip.xiaonuo.modular.blogarticlecomment.param.BlogArticleCommentAddDto; |
|
43 |
import vip.xiaonuo.modular.blogarticlecomment.param.BlogCommentQueryDto; |
|
44 |
import vip.xiaonuo.modular.blogarticlecomment.service.BlogArticleCommentService; |
|
45 |
|
|
46 |
import javax.annotation.Resource; |
|
47 |
import java.util.List; |
|
48 |
import java.util.stream.Collectors; |
|
49 |
|
|
50 |
/** |
|
51 |
* blog 留言/评论 控制器 (提供给外部blog系统查询) |
|
52 |
* |
|
53 |
* @author inleft |
|
54 |
* @date 2022-02-09 18:20:22 |
|
55 |
*/ |
|
56 |
@RestController |
|
57 |
@RequestMapping("/outside") |
|
58 |
public class BlogArticleCommentOutsideController { |
|
59 |
|
|
60 |
@Resource |
|
61 |
private BlogArticleService blogArticleService; |
|
62 |
|
|
63 |
|
|
64 |
@Resource |
|
65 |
private BlogArticleCommentService blogArticleCommentService; |
|
66 |
|
|
67 |
|
|
68 |
@PostMapping("/blogComment/add") |
|
69 |
@BusinessLog(title = "外部blog系统_blog留言/评论_增加", opType = LogAnnotionOpTypeEnum.ADD) |
|
70 |
public ResponseData add(@RequestBody @Validated(BlogArticleCommentAddDto.add.class) BlogArticleCommentAddDto addDto) { |
|
71 |
if (addDto.getCommentType().equals(MyConstant.CommentType.type_2)) { |
|
72 |
if (addDto.getArticleId() == null) { |
|
73 |
throw new BlogException("评论类型为日志评论,日志id不能为空"); |
|
74 |
} |
42b7d0
|
75 |
BlogArticle checkArticle = blogArticleService.getById(addDto.getId()); |
I |
76 |
if (checkArticle == null) { |
88f419
|
77 |
throw new BlogException("查询不到相关日志"); |
42b7d0
|
78 |
} |
I |
79 |
|
|
80 |
if (checkArticle.getIsAllowedComment().equals(MyConstant.No)) { |
|
81 |
throw new BlogException("该日志评论已经关闭.."); |
88f419
|
82 |
} |
I |
83 |
} |
|
84 |
BlogArticleComment insert = new BlogArticleComment(); |
|
85 |
BeanUtil.copyProperties(addDto, insert); |
42b7d0
|
86 |
insert.setIsCheck(MyConstant.Yes); |
88f419
|
87 |
insert.setIsEnable(MyConstant.Yes); |
I |
88 |
insert.setIsReceiveCallback(addDto.getIsReceiveMail()); |
|
89 |
|
|
90 |
blogArticleCommentService.save(insert); |
|
91 |
|
|
92 |
return new SuccessResponseData(); |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
@GetMapping("/blogComment/queryBlogCommentList") |
|
97 |
@BusinessLog(title = "外部blog系统_blog留言/评论_查询", opType = LogAnnotionOpTypeEnum.QUERY) |
|
98 |
public ResponseData queryBlogCommentList(BlogCommentQueryDto queryDto) { |
|
99 |
if (queryDto.getArticleId() != null && blogArticleService.getById(queryDto.getArticleId()) == null) { |
|
100 |
throw new BlogException("查询不到相关日志"); |
|
101 |
} |
|
102 |
|
|
103 |
Page queryPage = new Page<>(queryDto.getPageNo(), queryDto.getPageSize()); |
|
104 |
|
|
105 |
|
|
106 |
List<BlogArticleComment> commentList = blogArticleCommentService.lambdaQuery() |
|
107 |
.eq(queryDto.getArticleId() != null, BlogArticleComment::getArticleId, queryDto.getArticleId()) |
|
108 |
.eq(BlogArticleComment::getCommentType, queryDto.getArticleId() == null ? MyConstant.CommentType.type_1 : MyConstant.CommentType.type_2) |
e343e5
|
109 |
.eq(BlogArticleComment::getIsCheck, MyConstant.Yes) |
88f419
|
110 |
.eq(BlogArticleComment::getIsEnable, MyConstant.Yes) |
e343e5
|
111 |
.eq(BlogArticleComment::getParentId, 0) |
88f419
|
112 |
.orderByDesc(BlogArticleComment::getCreateDate) |
I |
113 |
.page(queryPage).getRecords(); |
|
114 |
|
42b7d0
|
115 |
int limitCount = 3; |
88f419
|
116 |
List<BlogCommentVo> res = commentList.stream().map(e -> { |
I |
117 |
BlogCommentVo vo = new BlogCommentVo(); |
|
118 |
BeanUtil.copyProperties(e, vo); |
e343e5
|
119 |
vo.setIsHasNext(MyConstant.No); |
I |
120 |
List<BlogCommentVo> replyList = blogArticleCommentService.getReplyListById(e.getId(), limitCount); |
|
121 |
vo.setReplyList(replyList); |
88f419
|
122 |
|
e343e5
|
123 |
if (e.getAuthStatus().equals(MyConstant.AuthStatus.privateCode)) { |
42b7d0
|
124 |
vo.setCommentContent(MyConstant.privateComment); |
e343e5
|
125 |
} |
I |
126 |
|
|
127 |
if (CollUtil.isNotEmpty(replyList) |
|
128 |
&& blogArticleCommentService.lambdaQuery() |
|
129 |
.eq(BlogArticleComment::getParentId, e.getId()) |
|
130 |
.eq(BlogArticleComment::getIsCheck, MyConstant.Yes) |
|
131 |
.eq(BlogArticleComment::getIsEnable, MyConstant.Yes) |
|
132 |
.count() > limitCount) { |
|
133 |
vo.setIsHasNext(MyConstant.Yes); |
|
134 |
} |
88f419
|
135 |
return vo; |
I |
136 |
} |
|
137 |
).collect(Collectors.toList()); |
|
138 |
|
|
139 |
queryPage.setRecords(res); |
|
140 |
return new SuccessResponseData(queryPage); |
|
141 |
} |
e343e5
|
142 |
|
I |
143 |
@GetMapping("/blogComment/queryBlogCommentSubList") |
|
144 |
@BusinessLog(title = "外部blog系统_blog留言/评论子列表_查询", opType = LogAnnotionOpTypeEnum.QUERY) |
|
145 |
public ResponseData queryBlogCommentSubList(BlogCommentQueryDto queryDto) { |
|
146 |
if (queryDto.getArticleId() != null && blogArticleCommentService.getById(queryDto.getCommentId()) == null) { |
|
147 |
throw new BlogException("查询不到相关评论"); |
|
148 |
} |
|
149 |
|
|
150 |
|
|
151 |
List<BlogCommentVo> replyList = blogArticleCommentService.getReplyListById(queryDto.getCommentId(), null); |
|
152 |
for (BlogCommentVo vo : replyList) { |
|
153 |
vo.setIsHasNext(MyConstant.No); |
|
154 |
if (vo.getAuthStatus().equals(MyConstant.AuthStatus.privateCode)) { |
42b7d0
|
155 |
vo.setCommentContent(MyConstant.privateComment); |
e343e5
|
156 |
} |
I |
157 |
} |
|
158 |
|
|
159 |
return new SuccessResponseData(replyList); |
|
160 |
} |
88f419
|
161 |
} |