inleft
2022-02-20 bd3bc193d18718e0e8cb880cbadf0b9426732ef9
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());
81         String fileUploadPathForLinux = ConstantContextHolder.getDefaultFileUploadPathForLinux();
82
83         List<BlogArticleVo> resList = blogArticleService.searchMediaList(param).stream().map(e -> {
84             if (StrUtil.isNotEmpty(e.getArticleFileURL())) {
85                 e.setArticleFileURL(fileUploadPathForLinux + e.getArticleFileURL());
86             }
87             return e;
88         }).collect(Collectors.toList());
89
90         long count = blogArticleService.searchMediaListCount(param);
91
92         Page<BlogArticleVo> queryPage = new Page<>(queryDto.getPageNo(), queryDto.getPageSize());
93         queryPage.setRecords(resList);
94         queryPage.setTotal(count);
95
96         return new SuccessResponseData(queryPage);
97     }
98
bd3bc1 99     @GetMapping("/blogArticle/queryBlogArticleDetail")
I 100     @BusinessLog(title = "外部blog系统_blog文章详情_查询", opType = LogAnnotionOpTypeEnum.QUERY)
101     public ResponseData queryBlogArticleDetail(BlogArticleQueryDto queryDto) {
102         BlogArticle find = blogArticleService.lambdaQuery()
103                 .eq(BlogArticle::getIsEnable, MyConstant.Yes)
104                 .eq(BlogArticle::getEditorStatus, MyConstant.Yes)
105                 .eq(BlogArticle::getId, queryDto.getId())
106                 .one();
107
108         if (find == null) {
109             throw new BlogException(BlogExceptionEnum.article_not_found);
110         }
111
112         //加密文章
113         if (find.getAuthStatus().equals(MyConstant.AuthStatus.authCode)) {
114             //授权码缺失
115             if (StrUtil.isEmpty(queryDto.getAuthWord())) {
116                 throw new BlogException(BlogExceptionEnum.article_auth_error);
117             }
118             //授权码比对
119             if (!SecureUtil.md5(find.getAuthPassword()).equals(queryDto.getAuthWord())) {
120                 throw new BlogException(BlogExceptionEnum.article_auth_pass_error);
121             }
122         }else if(find.getAuthStatus().equals(MyConstant.AuthStatus.privateCode)){
123             throw new BlogException(BlogExceptionEnum.article_auth_private_error);
124         }
125
126         BlogArticleVo vo = new BlogArticleVo();
127
128         BeanUtil.copyProperties(find, vo);
129
130         if (queryDto.getId() % 2 == 0) {
131             vo.setArticleFileURL("http://t.inleft.com/share/book/blog/es_index.md");
132         } else {
133             vo.setArticleFileURL("http://t.inleft.com/share/book/blog/es-search.md");
134         }
135
136
137         return new SuccessResponseData(vo);
138     }
139
0613f2 140
I 141 }