inleft
2022-02-21 a9c4c99791e4d43971afd863946a2b0c4db44708
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;
0613f2 28 import cn.hutool.core.util.PageUtil;
I 29 import cn.hutool.core.util.StrUtil;
bd3bc1 30 import cn.hutool.crypto.SecureUtil;
0613f2 31 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
I 32 import org.springframework.web.bind.annotation.GetMapping;
33 import org.springframework.web.bind.annotation.RequestMapping;
34 import org.springframework.web.bind.annotation.RestController;
35 import vip.xiaonuo.core.annotion.BusinessLog;
bd3bc1 36 import vip.xiaonuo.core.consts.MyConstant;
0613f2 37 import vip.xiaonuo.core.context.constant.ConstantContextHolder;
I 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;
0613f2 44 import vip.xiaonuo.modular.blogarticle.param.BlogArticleQueryDto;
I 45 import vip.xiaonuo.modular.blogarticle.param.BlogArticleVo;
46 import vip.xiaonuo.modular.blogarticle.service.BlogArticleService;
47
48 import javax.annotation.Resource;
49 import java.util.HashMap;
50 import java.util.List;
51 import java.util.Map;
52 import java.util.stream.Collectors;
53
54 /**
55  * blog文章控制器 (提供给外部blog系统查询)
56  *
57  * @author inleft
58  * @date 2022-02-09 18:20:22
59  */
60 @RestController
61 @RequestMapping("/outside")
62 public class BlogArticleOutsideController {
63
64     @Resource
65     private BlogArticleService blogArticleService;
66
67     /**
68      * 查询blog文章
69      *
70      * @author inleft
71      * @date 2022-02-09 18:20:22
72      */
73     @GetMapping("/blogArticle/queryBlogArticleList")
74     @BusinessLog(title = "外部blog系统_blog文章_查询", opType = LogAnnotionOpTypeEnum.QUERY)
75     public ResponseData queryBlogArticleList(BlogArticleQueryDto queryDto) {
76
77
78         Map<String, Object> param = new HashMap<>(16);
79         param.put("pageNo", PageUtil.getStart(queryDto.getPageNo() - 1, queryDto.getPageSize()));
80         param.put("pageSize", queryDto.getPageSize());
a9c4c9 81         param.put("typeId", queryDto.getTypeId());
0613f2 82         String fileUploadPathForLinux = ConstantContextHolder.getDefaultFileUploadPathForLinux();
I 83
a9c4c9 84         List<BlogArticleVo> resList = blogArticleService.searchList(param).stream().map(e -> {
0613f2 85             if (StrUtil.isNotEmpty(e.getArticleFileURL())) {
I 86                 e.setArticleFileURL(fileUploadPathForLinux + e.getArticleFileURL());
87             }
88             return e;
89         }).collect(Collectors.toList());
90
a9c4c9 91         long count = blogArticleService.searchListCount(param);
0613f2 92
I 93         Page<BlogArticleVo> queryPage = new Page<>(queryDto.getPageNo(), queryDto.getPageSize());
94         queryPage.setRecords(resList);
95         queryPage.setTotal(count);
96
97         return new SuccessResponseData(queryPage);
98     }
99
bd3bc1 100     @GetMapping("/blogArticle/queryBlogArticleDetail")
I 101     @BusinessLog(title = "外部blog系统_blog文章详情_查询", opType = LogAnnotionOpTypeEnum.QUERY)
102     public ResponseData queryBlogArticleDetail(BlogArticleQueryDto queryDto) {
103         BlogArticle find = blogArticleService.lambdaQuery()
104                 .eq(BlogArticle::getIsEnable, MyConstant.Yes)
105                 .eq(BlogArticle::getEditorStatus, MyConstant.Yes)
106                 .eq(BlogArticle::getId, queryDto.getId())
107                 .one();
108
109         if (find == null) {
110             throw new BlogException(BlogExceptionEnum.article_not_found);
111         }
112
113         //加密文章
114         if (find.getAuthStatus().equals(MyConstant.AuthStatus.authCode)) {
115             //授权码缺失
116             if (StrUtil.isEmpty(queryDto.getAuthWord())) {
117                 throw new BlogException(BlogExceptionEnum.article_auth_error);
118             }
119             //授权码比对
120             if (!SecureUtil.md5(find.getAuthPassword()).equals(queryDto.getAuthWord())) {
121                 throw new BlogException(BlogExceptionEnum.article_auth_pass_error);
122             }
123         }else if(find.getAuthStatus().equals(MyConstant.AuthStatus.privateCode)){
124             throw new BlogException(BlogExceptionEnum.article_auth_private_error);
125         }
126
127         BlogArticleVo vo = new BlogArticleVo();
128
129         BeanUtil.copyProperties(find, vo);
130
131         if (queryDto.getId() % 2 == 0) {
132             vo.setArticleFileURL("http://t.inleft.com/share/book/blog/es_index.md");
133         } else {
134             vo.setArticleFileURL("http://t.inleft.com/share/book/blog/es-search.md");
135         }
136
137         return new SuccessResponseData(vo);
138     }
139
0613f2 140
I 141 }