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