inleft
2022-02-15 91dc6cdda0548ff7f6e473a81933fa206d912cef
commit | author | age
91dc6c 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.blogarticletype.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.blogarticletype.entity.BlogArticleType;
40 import vip.xiaonuo.modular.blogarticletype.enums.BlogArticleTypeExceptionEnum;
41 import vip.xiaonuo.modular.blogarticletype.mapper.BlogArticleTypeMapper;
42 import vip.xiaonuo.modular.blogarticletype.param.BlogArticleTypeParam;
43 import vip.xiaonuo.modular.blogarticletype.service.BlogArticleTypeService;
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-02-15 15:17:15
54  */
55 @Service
56 public class BlogArticleTypeServiceImpl extends ServiceImpl<BlogArticleTypeMapper, BlogArticleType> implements BlogArticleTypeService {
57
58     @Override
59     public PageResult<BlogArticleType> page(BlogArticleTypeParam blogArticleTypeParam) {
60         QueryWrapper<BlogArticleType> queryWrapper = new QueryWrapper<>();
61         if (ObjectUtil.isNotNull(blogArticleTypeParam)) {
62
63             // 根据分类名称 查询
64             if (ObjectUtil.isNotEmpty(blogArticleTypeParam.getTypeName())) {
65                 queryWrapper.lambda().like(BlogArticleType::getTypeName, blogArticleTypeParam.getTypeName());
66             }
67             // 根据公开类型 查询
68             if (ObjectUtil.isNotEmpty(blogArticleTypeParam.getOpenType())) {
69                 queryWrapper.lambda().eq(BlogArticleType::getOpenType, blogArticleTypeParam.getOpenType());
70             }
71             // 根据是否启用 查询
72             if (ObjectUtil.isNotEmpty(blogArticleTypeParam.getIsEnable())) {
73                 queryWrapper.lambda().eq(BlogArticleType::getIsEnable, blogArticleTypeParam.getIsEnable());
74             }
75             // 根据创建时间 查询
76             if (ObjectUtil.isNotEmpty(blogArticleTypeParam.getCreateDate())) {
77                 queryWrapper.lambda().eq(BlogArticleType::getCreateDate, blogArticleTypeParam.getCreateDate());
78             }
79         }
80         return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
81     }
82
83     @Override
84     public List<BlogArticleType> list(BlogArticleTypeParam blogArticleTypeParam) {
85         return this.list();
86     }
87
88     @Override
89     public void add(BlogArticleTypeParam blogArticleTypeParam) {
90         BlogArticleType blogArticleType = new BlogArticleType();
91         BeanUtil.copyProperties(blogArticleTypeParam, blogArticleType);
92         this.save(blogArticleType);
93     }
94
95     @Transactional(rollbackFor = Exception.class)
96     @Override
97     public void delete(List<BlogArticleTypeParam> blogArticleTypeParamList) {
98         blogArticleTypeParamList.forEach(blogArticleTypeParam -> {
99             this.removeById(blogArticleTypeParam.getId());
100         });
101     }
102
103     @Transactional(rollbackFor = Exception.class)
104     @Override
105     public void edit(BlogArticleTypeParam blogArticleTypeParam) {
106         BlogArticleType blogArticleType = this.queryBlogArticleType(blogArticleTypeParam);
107         BeanUtil.copyProperties(blogArticleTypeParam, blogArticleType);
108         this.updateById(blogArticleType);
109     }
110
111     @Override
112     public BlogArticleType detail(BlogArticleTypeParam blogArticleTypeParam) {
113         return this.queryBlogArticleType(blogArticleTypeParam);
114     }
115
116     /**
117      * 获取blog文章分类
118      *
119      * @author inleft
120      * @date 2022-02-15 15:17:15
121      */
122     private BlogArticleType queryBlogArticleType(BlogArticleTypeParam blogArticleTypeParam) {
123         BlogArticleType blogArticleType = this.getById(blogArticleTypeParam.getId());
124         if (ObjectUtil.isNull(blogArticleType)) {
125             throw new ServiceException(BlogArticleTypeExceptionEnum.NOT_EXIST);
126         }
127         return blogArticleType;
128     }
129
130     @Override
131     public void export(BlogArticleTypeParam blogArticleTypeParam) {
132         List<BlogArticleType> list = this.list(blogArticleTypeParam);
133         PoiUtil.exportExcelWithStream("SnowyBlogArticleType.xls", BlogArticleType.class, list);
134     }
135
136 }