commit | author | age
|
0613f2
|
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.blogarticle.controller; |
|
26 |
|
bd3bc1
|
27 |
import cn.hutool.core.bean.BeanUtil; |
31e475
|
28 |
import cn.hutool.core.date.DateUtil; |
0613f2
|
29 |
import cn.hutool.core.util.PageUtil; |
I |
30 |
import cn.hutool.core.util.StrUtil; |
bd3bc1
|
31 |
import cn.hutool.crypto.SecureUtil; |
0613f2
|
32 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
552004
|
33 |
import org.springframework.validation.annotation.Validated; |
I |
34 |
import org.springframework.web.bind.annotation.*; |
0613f2
|
35 |
import vip.xiaonuo.core.annotion.BusinessLog; |
bd3bc1
|
36 |
import vip.xiaonuo.core.consts.MyConstant; |
cfde48
|
37 |
import vip.xiaonuo.core.context.constant.ConstantContextHolder; |
0613f2
|
38 |
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum; |
bd3bc1
|
39 |
import vip.xiaonuo.core.exception.BlogException; |
I |
40 |
import vip.xiaonuo.core.exception.enums.BlogExceptionEnum; |
0613f2
|
41 |
import vip.xiaonuo.core.pojo.response.ResponseData; |
I |
42 |
import vip.xiaonuo.core.pojo.response.SuccessResponseData; |
bd3bc1
|
43 |
import vip.xiaonuo.modular.blogarticle.entity.BlogArticle; |
552004
|
44 |
import vip.xiaonuo.modular.blogarticle.param.BlogArticleAddDto; |
0613f2
|
45 |
import vip.xiaonuo.modular.blogarticle.param.BlogArticleQueryDto; |
I |
46 |
import vip.xiaonuo.modular.blogarticle.param.BlogArticleVo; |
|
47 |
import vip.xiaonuo.modular.blogarticle.service.BlogArticleService; |
552004
|
48 |
import vip.xiaonuo.modular.blogarticletype.entity.BlogArticleType; |
I |
49 |
import vip.xiaonuo.modular.blogarticletype.service.BlogArticleTypeService; |
cfde48
|
50 |
import vip.xiaonuo.sys.modular.file.entity.SysFileInfo; |
I |
51 |
import vip.xiaonuo.sys.modular.file.service.SysFileInfoService; |
0613f2
|
52 |
|
I |
53 |
import javax.annotation.Resource; |
552004
|
54 |
import java.util.Date; |
0613f2
|
55 |
import java.util.HashMap; |
I |
56 |
import java.util.List; |
|
57 |
import java.util.Map; |
|
58 |
import java.util.stream.Collectors; |
|
59 |
|
|
60 |
/** |
|
61 |
* blog文章控制器 (提供给外部blog系统查询) |
|
62 |
* |
|
63 |
* @author inleft |
|
64 |
* @date 2022-02-09 18:20:22 |
|
65 |
*/ |
|
66 |
@RestController |
|
67 |
@RequestMapping("/outside") |
|
68 |
public class BlogArticleOutsideController { |
|
69 |
|
|
70 |
@Resource |
|
71 |
private BlogArticleService blogArticleService; |
|
72 |
|
cfde48
|
73 |
|
I |
74 |
@Resource |
552004
|
75 |
private BlogArticleTypeService blogArticleTypeService; |
I |
76 |
|
|
77 |
@Resource |
cfde48
|
78 |
private SysFileInfoService fileInfoService; |
552004
|
79 |
|
I |
80 |
@PostMapping("/blogArticle/add") |
|
81 |
@BusinessLog(title = "外部blog系统_blog文章_增加", opType = LogAnnotionOpTypeEnum.ADD) |
|
82 |
public ResponseData add(@RequestBody @Validated(BlogArticleAddDto.add.class) BlogArticleAddDto addDto) { |
31e475
|
83 |
if (!SecureUtil.md5(addDto.getSecret()).equals("b49e4cc48616cfb8d5ed3e5b983165c8")) { |
552004
|
84 |
throw new BlogException("口令错误.."); |
I |
85 |
} |
|
86 |
|
|
87 |
if (MyConstant.Yes.equals(addDto.getIsTop()) && addDto.getTopValue() == null) { |
|
88 |
throw new BlogException("选择了置顶需要指定置顶值.."); |
|
89 |
} |
|
90 |
|
|
91 |
if (addDto.getIsLock().equals(MyConstant.Yes)) { |
|
92 |
if (addDto.getAuthStatus().equals(MyConstant.AuthStatus.authCode) && StrUtil.isEmpty(addDto.getAuthPassword())) { |
|
93 |
throw new BlogException("选择了密码授权,密码不能为空"); |
|
94 |
} |
|
95 |
} else { |
|
96 |
addDto.setAuthPassword(null); |
|
97 |
} |
|
98 |
|
|
99 |
if (MyConstant.Yes.equals(addDto.getIsOnline())) { |
|
100 |
if (addDto.getArticleFileId() == null || fileInfoService.getById(addDto.getArticleFileId()) == null) { |
|
101 |
throw new BlogException("已选择在线模式..文件id非法"); |
|
102 |
} |
|
103 |
} else { |
|
104 |
if (StrUtil.isEmpty(addDto.getContent())) { |
|
105 |
throw new BlogException("已选择在线模式..文件内容非法"); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
if (addDto.getCoverFileId() != null && fileInfoService.getById(addDto.getCoverFileId()) == null) { |
|
110 |
throw new BlogException("封面文件id非法"); |
|
111 |
} |
|
112 |
|
|
113 |
if (blogArticleTypeService.lambdaQuery() |
|
114 |
.eq(BlogArticleType::getIsEnable, MyConstant.Yes) |
|
115 |
.eq(BlogArticleType::getId, addDto.getArticleTypeId()) |
|
116 |
.one() == null) { |
|
117 |
throw new BlogException("分类id非法"); |
|
118 |
} |
|
119 |
|
|
120 |
if (addDto.getPublishDate() == null) { |
|
121 |
addDto.setPublishDate(new Date()); |
|
122 |
} |
|
123 |
|
|
124 |
BlogArticle article = new BlogArticle(); |
|
125 |
BeanUtil.copyProperties(addDto, article); |
31e475
|
126 |
article.setSeparateYear(DateUtil.year(article.getPublishDate())); |
cb2e50
|
127 |
article.setSeparateMonth(DateUtil.month(article.getPublishDate())+1); |
31e475
|
128 |
article.setSeparateDay(DateUtil.dayOfMonth(article.getPublishDate())); |
I |
129 |
|
|
130 |
article.setIsEnable(MyConstant.Yes); |
|
131 |
blogArticleService.save(article); |
552004
|
132 |
return new SuccessResponseData(); |
I |
133 |
} |
cfde48
|
134 |
|
0613f2
|
135 |
/** |
I |
136 |
* 查询blog文章 |
|
137 |
* |
|
138 |
* @author inleft |
|
139 |
* @date 2022-02-09 18:20:22 |
|
140 |
*/ |
|
141 |
@GetMapping("/blogArticle/queryBlogArticleList") |
|
142 |
@BusinessLog(title = "外部blog系统_blog文章_查询", opType = LogAnnotionOpTypeEnum.QUERY) |
|
143 |
public ResponseData queryBlogArticleList(BlogArticleQueryDto queryDto) { |
|
144 |
|
|
145 |
|
|
146 |
Map<String, Object> param = new HashMap<>(16); |
|
147 |
param.put("pageNo", PageUtil.getStart(queryDto.getPageNo() - 1, queryDto.getPageSize())); |
|
148 |
param.put("pageSize", queryDto.getPageSize()); |
a9c4c9
|
149 |
param.put("typeId", queryDto.getTypeId()); |
0613f2
|
150 |
|
cfde48
|
151 |
String blogSourcePrefix = ConstantContextHolder.getBlogSourcePrefix(); |
a9c4c9
|
152 |
List<BlogArticleVo> resList = blogArticleService.searchList(param).stream().map(e -> { |
504927
|
153 |
if (StrUtil.isNotEmpty(e.getCoverFileURL())) { |
I |
154 |
if (!e.getCoverFileURL().startsWith("http")) { |
|
155 |
//补上访问参数 |
cfde48
|
156 |
e.setCoverFileURL(blogSourcePrefix + e.getCoverFileURL()); |
504927
|
157 |
} |
0613f2
|
158 |
} |
I |
159 |
return e; |
|
160 |
}).collect(Collectors.toList()); |
|
161 |
|
a9c4c9
|
162 |
long count = blogArticleService.searchListCount(param); |
0613f2
|
163 |
|
I |
164 |
Page<BlogArticleVo> queryPage = new Page<>(queryDto.getPageNo(), queryDto.getPageSize()); |
|
165 |
queryPage.setRecords(resList); |
|
166 |
queryPage.setTotal(count); |
|
167 |
|
|
168 |
return new SuccessResponseData(queryPage); |
|
169 |
} |
|
170 |
|
bd3bc1
|
171 |
@GetMapping("/blogArticle/queryBlogArticleDetail") |
I |
172 |
@BusinessLog(title = "外部blog系统_blog文章详情_查询", opType = LogAnnotionOpTypeEnum.QUERY) |
|
173 |
public ResponseData queryBlogArticleDetail(BlogArticleQueryDto queryDto) { |
|
174 |
BlogArticle find = blogArticleService.lambdaQuery() |
|
175 |
.eq(BlogArticle::getIsEnable, MyConstant.Yes) |
|
176 |
.eq(BlogArticle::getEditorStatus, MyConstant.Yes) |
|
177 |
.eq(BlogArticle::getId, queryDto.getId()) |
|
178 |
.one(); |
|
179 |
|
|
180 |
if (find == null) { |
|
181 |
throw new BlogException(BlogExceptionEnum.article_not_found); |
|
182 |
} |
|
183 |
|
|
184 |
//加密文章 |
|
185 |
if (find.getAuthStatus().equals(MyConstant.AuthStatus.authCode)) { |
|
186 |
//授权码缺失 |
|
187 |
if (StrUtil.isEmpty(queryDto.getAuthWord())) { |
|
188 |
throw new BlogException(BlogExceptionEnum.article_auth_error); |
|
189 |
} |
|
190 |
//授权码比对 |
|
191 |
if (!SecureUtil.md5(find.getAuthPassword()).equals(queryDto.getAuthWord())) { |
|
192 |
throw new BlogException(BlogExceptionEnum.article_auth_pass_error); |
|
193 |
} |
cfde48
|
194 |
} else if (find.getAuthStatus().equals(MyConstant.AuthStatus.privateCode)) { |
bd3bc1
|
195 |
throw new BlogException(BlogExceptionEnum.article_auth_private_error); |
I |
196 |
} |
|
197 |
|
|
198 |
BlogArticleVo vo = new BlogArticleVo(); |
|
199 |
|
|
200 |
BeanUtil.copyProperties(find, vo); |
|
201 |
|
31e475
|
202 |
|
e99de8
|
203 |
String tempURL = this.getBlogSourceURL(find.getArticleFileId()); |
cfde48
|
204 |
|
e99de8
|
205 |
if (StrUtil.isEmpty(tempURL)) |
I |
206 |
throw new BlogException(BlogExceptionEnum.article_file_lose); |
|
207 |
|
|
208 |
vo.setArticleFileURL(tempURL); |
bd3bc1
|
209 |
|
I |
210 |
return new SuccessResponseData(vo); |
|
211 |
} |
|
212 |
|
cfde48
|
213 |
private String getBlogSourceURL(Long fileId) { |
I |
214 |
SysFileInfo sysFileInfo = fileInfoService.getById(fileId); |
|
215 |
if (sysFileInfo == null) { |
|
216 |
return null; |
|
217 |
} else { |
|
218 |
String blogSourcePrefix = ConstantContextHolder.getBlogSourcePrefix(); |
e99de8
|
219 |
return blogSourcePrefix + sysFileInfo.getFileBucket() + "/" + sysFileInfo.getFileObjectName(); |
cfde48
|
220 |
} |
I |
221 |
} |
0613f2
|
222 |
|
I |
223 |
} |