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