inleft
2022-03-02 42b7d05dfdf60ee67c876084a3240ff48a3bf3a5
commit | author | age
9bcb19 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.service.impl;
26
27 import cn.hutool.core.bean.BeanUtil;
28 import cn.hutool.core.util.ObjectUtil;
29 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
30 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
f1b087 31 import org.springframework.stereotype.Service;
I 32 import org.springframework.transaction.annotation.Transactional;
9bcb19 33 import vip.xiaonuo.core.exception.ServiceException;
I 34 import vip.xiaonuo.core.factory.PageFactory;
35 import vip.xiaonuo.core.pojo.page.PageResult;
36 import vip.xiaonuo.core.util.PoiUtil;
a9c4c9 37 import vip.xiaonuo.modular.blogStatistics.vo.BlogArchiveDetailVo;
9bcb19 38 import vip.xiaonuo.modular.blogarticle.entity.BlogArticle;
I 39 import vip.xiaonuo.modular.blogarticle.enums.BlogArticleExceptionEnum;
40 import vip.xiaonuo.modular.blogarticle.mapper.BlogArticleMapper;
41 import vip.xiaonuo.modular.blogarticle.param.BlogArticleParam;
42 import vip.xiaonuo.modular.blogarticle.service.BlogArticleService;
f1b087 43
9bcb19 44 import java.util.List;
0613f2 45 import java.util.Map;
9bcb19 46
I 47 /**
f1b087 48  * blog文章service接口实现类
9bcb19 49  *
I 50  * @author inleft
f1b087 51  * @date 2022-02-09 18:20:46
9bcb19 52  */
I 53 @Service
54 public class BlogArticleServiceImpl extends ServiceImpl<BlogArticleMapper, BlogArticle> implements BlogArticleService {
55
56     @Override
57     public PageResult<BlogArticle> page(BlogArticleParam blogArticleParam) {
58         QueryWrapper<BlogArticle> queryWrapper = new QueryWrapper<>();
59         if (ObjectUtil.isNotNull(blogArticleParam)) {
60
61             // 根据文章标题 查询
62             if (ObjectUtil.isNotEmpty(blogArticleParam.getTitle())) {
f1b087 63                 queryWrapper.lambda().like(BlogArticle::getTitle, blogArticleParam.getTitle());
9bcb19 64             }
f1b087 65             // 根据文件类型 查询
9bcb19 66             if (ObjectUtil.isNotEmpty(blogArticleParam.getArticleFileType())) {
I 67                 queryWrapper.lambda().eq(BlogArticle::getArticleFileType, blogArticleParam.getArticleFileType());
68             }
f1b087 69             // 根据文章分类 查询
9bcb19 70             if (ObjectUtil.isNotEmpty(blogArticleParam.getArticleTypeId())) {
I 71                 queryWrapper.lambda().eq(BlogArticle::getArticleTypeId, blogArticleParam.getArticleTypeId());
72             }
73             // 根据文章引言 查询
74             if (ObjectUtil.isNotEmpty(blogArticleParam.getIntroduce())) {
f1b087 75                 queryWrapper.lambda().like(BlogArticle::getIntroduce, blogArticleParam.getIntroduce());
9bcb19 76             }
I 77             // 根据发布时间 查询
78             if (ObjectUtil.isNotEmpty(blogArticleParam.getPublishDate())) {
f1b087 79                 queryWrapper.lambda().ge(BlogArticle::getPublishDate, blogArticleParam.getPublishDate());
9bcb19 80             }
f1b087 81             // 根据是否置顶 查询
9bcb19 82             if (ObjectUtil.isNotEmpty(blogArticleParam.getIsTop())) {
I 83                 queryWrapper.lambda().eq(BlogArticle::getIsTop, blogArticleParam.getIsTop());
84             }
f1b087 85             // 根据公开状态 查询
9bcb19 86             if (ObjectUtil.isNotEmpty(blogArticleParam.getAuthStatus())) {
I 87                 queryWrapper.lambda().eq(BlogArticle::getAuthStatus, blogArticleParam.getAuthStatus());
88             }
f1b087 89             // 根据编辑状态 查询
9bcb19 90             if (ObjectUtil.isNotEmpty(blogArticleParam.getEditorStatus())) {
I 91                 queryWrapper.lambda().eq(BlogArticle::getEditorStatus, blogArticleParam.getEditorStatus());
92             }
93             // 根据创建时间 查询
94             if (ObjectUtil.isNotEmpty(blogArticleParam.getCreateDate())) {
f1b087 95                 queryWrapper.lambda().ge(BlogArticle::getCreateDate, blogArticleParam.getCreateDate());
9bcb19 96             }
I 97         }
98         return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
99     }
100
101     @Override
102     public List<BlogArticle> list(BlogArticleParam blogArticleParam) {
103         return this.list();
104     }
105
106     @Override
107     public void add(BlogArticleParam blogArticleParam) {
108         BlogArticle blogArticle = new BlogArticle();
109         BeanUtil.copyProperties(blogArticleParam, blogArticle);
110         this.save(blogArticle);
111     }
112
113     @Transactional(rollbackFor = Exception.class)
114     @Override
115     public void delete(List<BlogArticleParam> blogArticleParamList) {
116         blogArticleParamList.forEach(blogArticleParam -> {
117             this.removeById(blogArticleParam.getId());
118         });
119     }
120
121     @Transactional(rollbackFor = Exception.class)
122     @Override
123     public void edit(BlogArticleParam blogArticleParam) {
124         BlogArticle blogArticle = this.queryBlogArticle(blogArticleParam);
125         BeanUtil.copyProperties(blogArticleParam, blogArticle);
126         this.updateById(blogArticle);
127     }
128
129     @Override
130     public BlogArticle detail(BlogArticleParam blogArticleParam) {
131         return this.queryBlogArticle(blogArticleParam);
132     }
133
134     /**
f1b087 135      * 获取blog文章
9bcb19 136      *
I 137      * @author inleft
f1b087 138      * @date 2022-02-09 18:20:46
9bcb19 139      */
I 140     private BlogArticle queryBlogArticle(BlogArticleParam blogArticleParam) {
141         BlogArticle blogArticle = this.getById(blogArticleParam.getId());
142         if (ObjectUtil.isNull(blogArticle)) {
143             throw new ServiceException(BlogArticleExceptionEnum.NOT_EXIST);
144         }
145         return blogArticle;
146     }
147
148     @Override
149     public void export(BlogArticleParam blogArticleParam) {
150         List<BlogArticle> list = this.list(blogArticleParam);
151         PoiUtil.exportExcelWithStream("SnowyBlogArticle.xls", BlogArticle.class, list);
152     }
153
0613f2 154
I 155     @Override
a9c4c9 156     public List searchList(Map<String, Object> param) {
I 157         return this.baseMapper.searchList(param);
0613f2 158     }
I 159
160     @Override
a9c4c9 161     public long searchListCount(Map<String, Object> param) {
I 162         return this.baseMapper.searchListCount(param);
163     }
164
165     @Override
166     public List<BlogArchiveDetailVo> searchMonthCount(Integer separateYear) {
167         return this.baseMapper.searchMonthCount(separateYear);
168
0613f2 169     }
9bcb19 170 }