inleft
2022-02-15 d734432a8bbbf863dc3de305f56e831c56ac767a
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;
37 import vip.xiaonuo.modular.blogarticle.entity.BlogArticle;
38 import vip.xiaonuo.modular.blogarticle.enums.BlogArticleExceptionEnum;
39 import vip.xiaonuo.modular.blogarticle.mapper.BlogArticleMapper;
40 import vip.xiaonuo.modular.blogarticle.param.BlogArticleParam;
41 import vip.xiaonuo.modular.blogarticle.service.BlogArticleService;
f1b087 42
9bcb19 43 import java.util.List;
I 44
45 /**
f1b087 46  * blog文章service接口实现类
9bcb19 47  *
I 48  * @author inleft
f1b087 49  * @date 2022-02-09 18:20:46
9bcb19 50  */
I 51 @Service
52 public class BlogArticleServiceImpl extends ServiceImpl<BlogArticleMapper, BlogArticle> implements BlogArticleService {
53
54     @Override
55     public PageResult<BlogArticle> page(BlogArticleParam blogArticleParam) {
56         QueryWrapper<BlogArticle> queryWrapper = new QueryWrapper<>();
57         if (ObjectUtil.isNotNull(blogArticleParam)) {
58
59             // 根据文章标题 查询
60             if (ObjectUtil.isNotEmpty(blogArticleParam.getTitle())) {
f1b087 61                 queryWrapper.lambda().like(BlogArticle::getTitle, blogArticleParam.getTitle());
9bcb19 62             }
f1b087 63             // 根据文件类型 查询
9bcb19 64             if (ObjectUtil.isNotEmpty(blogArticleParam.getArticleFileType())) {
I 65                 queryWrapper.lambda().eq(BlogArticle::getArticleFileType, blogArticleParam.getArticleFileType());
66             }
f1b087 67             // 根据文章分类 查询
9bcb19 68             if (ObjectUtil.isNotEmpty(blogArticleParam.getArticleTypeId())) {
I 69                 queryWrapper.lambda().eq(BlogArticle::getArticleTypeId, blogArticleParam.getArticleTypeId());
70             }
71             // 根据文章引言 查询
72             if (ObjectUtil.isNotEmpty(blogArticleParam.getIntroduce())) {
f1b087 73                 queryWrapper.lambda().like(BlogArticle::getIntroduce, blogArticleParam.getIntroduce());
9bcb19 74             }
I 75             // 根据发布时间 查询
76             if (ObjectUtil.isNotEmpty(blogArticleParam.getPublishDate())) {
f1b087 77                 queryWrapper.lambda().ge(BlogArticle::getPublishDate, blogArticleParam.getPublishDate());
9bcb19 78             }
f1b087 79             // 根据是否置顶 查询
9bcb19 80             if (ObjectUtil.isNotEmpty(blogArticleParam.getIsTop())) {
I 81                 queryWrapper.lambda().eq(BlogArticle::getIsTop, blogArticleParam.getIsTop());
82             }
f1b087 83             // 根据公开状态 查询
9bcb19 84             if (ObjectUtil.isNotEmpty(blogArticleParam.getAuthStatus())) {
I 85                 queryWrapper.lambda().eq(BlogArticle::getAuthStatus, blogArticleParam.getAuthStatus());
86             }
f1b087 87             // 根据编辑状态 查询
9bcb19 88             if (ObjectUtil.isNotEmpty(blogArticleParam.getEditorStatus())) {
I 89                 queryWrapper.lambda().eq(BlogArticle::getEditorStatus, blogArticleParam.getEditorStatus());
90             }
91             // 根据创建时间 查询
92             if (ObjectUtil.isNotEmpty(blogArticleParam.getCreateDate())) {
f1b087 93                 queryWrapper.lambda().ge(BlogArticle::getCreateDate, blogArticleParam.getCreateDate());
9bcb19 94             }
I 95         }
96         return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
97     }
98
99     @Override
100     public List<BlogArticle> list(BlogArticleParam blogArticleParam) {
101         return this.list();
102     }
103
104     @Override
105     public void add(BlogArticleParam blogArticleParam) {
106         BlogArticle blogArticle = new BlogArticle();
107         BeanUtil.copyProperties(blogArticleParam, blogArticle);
108         this.save(blogArticle);
109     }
110
111     @Transactional(rollbackFor = Exception.class)
112     @Override
113     public void delete(List<BlogArticleParam> blogArticleParamList) {
114         blogArticleParamList.forEach(blogArticleParam -> {
115             this.removeById(blogArticleParam.getId());
116         });
117     }
118
119     @Transactional(rollbackFor = Exception.class)
120     @Override
121     public void edit(BlogArticleParam blogArticleParam) {
122         BlogArticle blogArticle = this.queryBlogArticle(blogArticleParam);
123         BeanUtil.copyProperties(blogArticleParam, blogArticle);
124         this.updateById(blogArticle);
125     }
126
127     @Override
128     public BlogArticle detail(BlogArticleParam blogArticleParam) {
129         return this.queryBlogArticle(blogArticleParam);
130     }
131
132     /**
f1b087 133      * 获取blog文章
9bcb19 134      *
I 135      * @author inleft
f1b087 136      * @date 2022-02-09 18:20:46
9bcb19 137      */
I 138     private BlogArticle queryBlogArticle(BlogArticleParam blogArticleParam) {
139         BlogArticle blogArticle = this.getById(blogArticleParam.getId());
140         if (ObjectUtil.isNull(blogArticle)) {
141             throw new ServiceException(BlogArticleExceptionEnum.NOT_EXIST);
142         }
143         return blogArticle;
144     }
145
146     @Override
147     public void export(BlogArticleParam blogArticleParam) {
148         List<BlogArticle> list = this.list(blogArticleParam);
149         PoiUtil.exportExcelWithStream("SnowyBlogArticle.xls", BlogArticle.class, list);
150     }
151
152 }