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