inleft
2022-03-01 88f419df77ade235ea5e5e24be204842a24b7b33
commit | author | age
88f419 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.blogarticlecomment.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;
31 import vip.xiaonuo.core.exception.ServiceException;
32 import vip.xiaonuo.core.factory.PageFactory;
33 import vip.xiaonuo.core.pojo.page.PageResult;
34 import vip.xiaonuo.core.util.PoiUtil;
35 import vip.xiaonuo.modular.blogarticlecomment.entity.BlogArticleComment;
36 import vip.xiaonuo.modular.blogarticlecomment.enums.BlogArticleCommentExceptionEnum;
37 import vip.xiaonuo.modular.blogarticlecomment.mapper.BlogArticleCommentMapper;
38 import vip.xiaonuo.modular.blogarticlecomment.param.BlogArticleCommentParam;
39 import vip.xiaonuo.modular.blogarticlecomment.service.BlogArticleCommentService;
40 import org.springframework.stereotype.Service;
41 import org.springframework.transaction.annotation.Transactional;
42
43 import java.util.List;
44
45 /**
46  * 文章评论service接口实现类
47  *
48  * @author inleft
49  * @date 2022-03-01 14:00:53
50  */
51 @Service
52 public class BlogArticleCommentServiceImpl extends ServiceImpl<BlogArticleCommentMapper, BlogArticleComment> implements BlogArticleCommentService {
53
54     @Override
55     public PageResult<BlogArticleComment> page(BlogArticleCommentParam blogArticleCommentParam) {
56         QueryWrapper<BlogArticleComment> queryWrapper = new QueryWrapper<>();
57         if (ObjectUtil.isNotNull(blogArticleCommentParam)) {
58
59             // 根据留言类型 1:留言板 2:日志评论 查询
60             if (ObjectUtil.isNotEmpty(blogArticleCommentParam.getCommentType())) {
61                 queryWrapper.lambda().eq(BlogArticleComment::getCommentType, blogArticleCommentParam.getCommentType());
62             }
63             // 根据文章id主键 查询
64             if (ObjectUtil.isNotEmpty(blogArticleCommentParam.getArticleId())) {
65                 queryWrapper.lambda().eq(BlogArticleComment::getArticleId, blogArticleCommentParam.getArticleId());
66             }
67             // 根据访客id(随机字符) 查询
68             if (ObjectUtil.isNotEmpty(blogArticleCommentParam.getVisitorId())) {
69                 queryWrapper.lambda().eq(BlogArticleComment::getVisitorId, blogArticleCommentParam.getVisitorId());
70             }
71             // 根据访客名称 查询
72             if (ObjectUtil.isNotEmpty(blogArticleCommentParam.getVisitorNickName())) {
73                 queryWrapper.lambda().like(BlogArticleComment::getVisitorNickName, blogArticleCommentParam.getVisitorNickName());
74             }
75             // 根据访客邮箱 查询
76             if (ObjectUtil.isNotEmpty(blogArticleCommentParam.getVisitorEmail())) {
77                 queryWrapper.lambda().like(BlogArticleComment::getVisitorEmail, blogArticleCommentParam.getVisitorEmail());
78             }
79             // 根据访客主页 查询
80             if (ObjectUtil.isNotEmpty(blogArticleCommentParam.getVisitorHomePage())) {
81                 queryWrapper.lambda().like(BlogArticleComment::getVisitorHomePage, blogArticleCommentParam.getVisitorHomePage());
82             }
83             // 根据是否已审核 0:否 1:是 查询
84             if (ObjectUtil.isNotEmpty(blogArticleCommentParam.getIsCheck())) {
85                 queryWrapper.lambda().eq(BlogArticleComment::getIsCheck, blogArticleCommentParam.getIsCheck());
86             }
87             // 根据公开状态 1:公开 2:私密 3:密码授权 查询
88             if (ObjectUtil.isNotEmpty(blogArticleCommentParam.getAuthStatus())) {
89                 queryWrapper.lambda().eq(BlogArticleComment::getAuthStatus, blogArticleCommentParam.getAuthStatus());
90             }
91             // 根据是否启用 0:否 1是 查询
92             if (ObjectUtil.isNotEmpty(blogArticleCommentParam.getIsEnable())) {
93                 queryWrapper.lambda().eq(BlogArticleComment::getIsEnable, blogArticleCommentParam.getIsEnable());
94             }
95             // 根据创建时间 查询
96             if (ObjectUtil.isNotEmpty(blogArticleCommentParam.getCreateDate())) {
97                 queryWrapper.lambda().gt(BlogArticleComment::getCreateDate, blogArticleCommentParam.getCreateDate());
98             }
99         }
100         return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
101     }
102
103     @Override
104     public List<BlogArticleComment> list(BlogArticleCommentParam blogArticleCommentParam) {
105         return this.list();
106     }
107
108     @Override
109     public void add(BlogArticleCommentParam blogArticleCommentParam) {
110         BlogArticleComment blogArticleComment = new BlogArticleComment();
111         BeanUtil.copyProperties(blogArticleCommentParam, blogArticleComment);
112         this.save(blogArticleComment);
113     }
114
115     @Transactional(rollbackFor = Exception.class)
116     @Override
117     public void delete(List<BlogArticleCommentParam> blogArticleCommentParamList) {
118         blogArticleCommentParamList.forEach(blogArticleCommentParam -> {
119             this.removeById(blogArticleCommentParam.getId());
120         });
121     }
122
123     @Transactional(rollbackFor = Exception.class)
124     @Override
125     public void edit(BlogArticleCommentParam blogArticleCommentParam) {
126         BlogArticleComment blogArticleComment = this.queryBlogArticleComment(blogArticleCommentParam);
127         BeanUtil.copyProperties(blogArticleCommentParam, blogArticleComment);
128         this.updateById(blogArticleComment);
129     }
130
131     @Override
132     public BlogArticleComment detail(BlogArticleCommentParam blogArticleCommentParam) {
133         return this.queryBlogArticleComment(blogArticleCommentParam);
134     }
135
136     /**
137      * 获取文章评论
138      *
139      * @author inleft
140      * @date 2022-03-01 14:00:53
141      */
142     private BlogArticleComment queryBlogArticleComment(BlogArticleCommentParam blogArticleCommentParam) {
143         BlogArticleComment blogArticleComment = this.getById(blogArticleCommentParam.getId());
144         if (ObjectUtil.isNull(blogArticleComment)) {
145             throw new ServiceException(BlogArticleCommentExceptionEnum.NOT_EXIST);
146         }
147         return blogArticleComment;
148     }
149
150     @Override
151     public void export(BlogArticleCommentParam blogArticleCommentParam) {
152         List<BlogArticleComment> list = this.list(blogArticleCommentParam);
153         PoiUtil.exportExcelWithStream("SnowyBlogArticleComment.xls", BlogArticleComment.class, list);
154     }
155
156 }