inleft
2022-02-09 9bcb19959eeb9da9bde2561e7278f6d0a55eb151
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 cn.hutool.core.util.StrUtil;
30 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
31 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
32 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
33 import vip.xiaonuo.core.consts.CommonConstant;
34 import vip.xiaonuo.core.enums.CommonStatusEnum;
35 import vip.xiaonuo.core.exception.ServiceException;
36 import vip.xiaonuo.core.factory.PageFactory;
37 import vip.xiaonuo.core.pojo.page.PageResult;
38 import vip.xiaonuo.core.util.PoiUtil;
39 import vip.xiaonuo.modular.blogarticle.entity.BlogArticle;
40 import vip.xiaonuo.modular.blogarticle.enums.BlogArticleExceptionEnum;
41 import vip.xiaonuo.modular.blogarticle.mapper.BlogArticleMapper;
42 import vip.xiaonuo.modular.blogarticle.param.BlogArticleParam;
43 import vip.xiaonuo.modular.blogarticle.service.BlogArticleService;
44 import org.springframework.stereotype.Service;
45 import org.springframework.transaction.annotation.Transactional;
46 import javax.annotation.Resource;
47 import java.util.List;
48
49 /**
50  * blog文章主体service接口实现类
51  *
52  * @author inleft
53  * @date 2022-01-22 16:53:06
54  */
55 @Service
56 public class BlogArticleServiceImpl extends ServiceImpl<BlogArticleMapper, BlogArticle> implements BlogArticleService {
57
58     @Override
59     public PageResult<BlogArticle> page(BlogArticleParam blogArticleParam) {
60         QueryWrapper<BlogArticle> queryWrapper = new QueryWrapper<>();
61         if (ObjectUtil.isNotNull(blogArticleParam)) {
62
63             // 根据文章标题 查询
64             if (ObjectUtil.isNotEmpty(blogArticleParam.getTitle())) {
65                 queryWrapper.lambda().eq(BlogArticle::getTitle, blogArticleParam.getTitle());
66             }
67             // 根据文章文件id 查询
68             if (ObjectUtil.isNotEmpty(blogArticleParam.getArticleFileId())) {
69                 queryWrapper.lambda().eq(BlogArticle::getArticleFileId, blogArticleParam.getArticleFileId());
70             }
71             // 根据文件类型 1:markdown 2:html 查询
72             if (ObjectUtil.isNotEmpty(blogArticleParam.getArticleFileType())) {
73                 queryWrapper.lambda().eq(BlogArticle::getArticleFileType, blogArticleParam.getArticleFileType());
74             }
75             // 根据文章分类id 0:没有分类 查询
76             if (ObjectUtil.isNotEmpty(blogArticleParam.getArticleTypeId())) {
77                 queryWrapper.lambda().eq(BlogArticle::getArticleTypeId, blogArticleParam.getArticleTypeId());
78             }
79             // 根据文章引言 查询
80             if (ObjectUtil.isNotEmpty(blogArticleParam.getIntroduce())) {
81                 queryWrapper.lambda().eq(BlogArticle::getIntroduce, blogArticleParam.getIntroduce());
82             }
83             // 根据封面文件地址(id) 查询
84             if (ObjectUtil.isNotEmpty(blogArticleParam.getCoverFileId())) {
85                 queryWrapper.lambda().eq(BlogArticle::getCoverFileId, blogArticleParam.getCoverFileId());
86             }
87             // 根据上次编辑时间 查询
88             if (ObjectUtil.isNotEmpty(blogArticleParam.getLastEditorDate())) {
89                 queryWrapper.lambda().eq(BlogArticle::getLastEditorDate, blogArticleParam.getLastEditorDate());
90             }
91             // 根据发布时间 查询
92             if (ObjectUtil.isNotEmpty(blogArticleParam.getPublishDate())) {
93                 queryWrapper.lambda().eq(BlogArticle::getPublishDate, blogArticleParam.getPublishDate());
94             }
95             // 根据是否置顶 0:否 1:是 查询
96             if (ObjectUtil.isNotEmpty(blogArticleParam.getIsTop())) {
97                 queryWrapper.lambda().eq(BlogArticle::getIsTop, blogArticleParam.getIsTop());
98             }
99             // 根据置顶值(越小越靠前) 查询
100             if (ObjectUtil.isNotEmpty(blogArticleParam.getTopValue())) {
101                 queryWrapper.lambda().eq(BlogArticle::getTopValue, blogArticleParam.getTopValue());
102             }
103             // 根据公开状态 1:公开 2:私密 3:密码授权 查询
104             if (ObjectUtil.isNotEmpty(blogArticleParam.getAuthStatus())) {
105                 queryWrapper.lambda().eq(BlogArticle::getAuthStatus, blogArticleParam.getAuthStatus());
106             }
107             // 根据授权密码(在密码授权状态时) 查询
108             if (ObjectUtil.isNotEmpty(blogArticleParam.getAuthPassword())) {
109                 queryWrapper.lambda().eq(BlogArticle::getAuthPassword, blogArticleParam.getAuthPassword());
110             }
111             // 根据编辑状态 0:草稿 1:发布 查询
112             if (ObjectUtil.isNotEmpty(blogArticleParam.getEditorStatus())) {
113                 queryWrapper.lambda().eq(BlogArticle::getEditorStatus, blogArticleParam.getEditorStatus());
114             }
115             // 根据归档年份(以初次发布时间为准) 查询
116             if (ObjectUtil.isNotEmpty(blogArticleParam.getSeparateYear())) {
117                 queryWrapper.lambda().eq(BlogArticle::getSeparateYear, blogArticleParam.getSeparateYear());
118             }
119             // 根据归档月份 查询
120             if (ObjectUtil.isNotEmpty(blogArticleParam.getSeparateMonth())) {
121                 queryWrapper.lambda().eq(BlogArticle::getSeparateMonth, blogArticleParam.getSeparateMonth());
122             }
123             // 根据归档日 查询
124             if (ObjectUtil.isNotEmpty(blogArticleParam.getSeparateDay())) {
125                 queryWrapper.lambda().eq(BlogArticle::getSeparateDay, blogArticleParam.getSeparateDay());
126             }
127             // 根据是否启用 0:否 1:是 查询
128             if (ObjectUtil.isNotEmpty(blogArticleParam.getIsEnable())) {
129                 queryWrapper.lambda().eq(BlogArticle::getIsEnable, blogArticleParam.getIsEnable());
130             }
131             // 根据更新时间 查询
132             if (ObjectUtil.isNotEmpty(blogArticleParam.getUpdateDate())) {
133                 queryWrapper.lambda().eq(BlogArticle::getUpdateDate, blogArticleParam.getUpdateDate());
134             }
135             // 根据创建时间 查询
136             if (ObjectUtil.isNotEmpty(blogArticleParam.getCreateDate())) {
137                 queryWrapper.lambda().eq(BlogArticle::getCreateDate, blogArticleParam.getCreateDate());
138             }
139         }
140         return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
141     }
142
143     @Override
144     public List<BlogArticle> list(BlogArticleParam blogArticleParam) {
145         return this.list();
146     }
147
148     @Override
149     public void add(BlogArticleParam blogArticleParam) {
150         BlogArticle blogArticle = new BlogArticle();
151         BeanUtil.copyProperties(blogArticleParam, blogArticle);
152         this.save(blogArticle);
153     }
154
155     @Transactional(rollbackFor = Exception.class)
156     @Override
157     public void delete(List<BlogArticleParam> blogArticleParamList) {
158         blogArticleParamList.forEach(blogArticleParam -> {
159             this.removeById(blogArticleParam.getId());
160         });
161     }
162
163     @Transactional(rollbackFor = Exception.class)
164     @Override
165     public void edit(BlogArticleParam blogArticleParam) {
166         BlogArticle blogArticle = this.queryBlogArticle(blogArticleParam);
167         BeanUtil.copyProperties(blogArticleParam, blogArticle);
168         this.updateById(blogArticle);
169     }
170
171     @Override
172     public BlogArticle detail(BlogArticleParam blogArticleParam) {
173         return this.queryBlogArticle(blogArticleParam);
174     }
175
176     /**
177      * 获取blog文章主体
178      *
179      * @author inleft
180      * @date 2022-01-22 16:53:06
181      */
182     private BlogArticle queryBlogArticle(BlogArticleParam blogArticleParam) {
183         BlogArticle blogArticle = this.getById(blogArticleParam.getId());
184         if (ObjectUtil.isNull(blogArticle)) {
185             throw new ServiceException(BlogArticleExceptionEnum.NOT_EXIST);
186         }
187         return blogArticle;
188     }
189
190     @Override
191     public void export(BlogArticleParam blogArticleParam) {
192         List<BlogArticle> list = this.list(blogArticleParam);
193         PoiUtil.exportExcelWithStream("SnowyBlogArticle.xls", BlogArticle.class, list);
194     }
195
196 }