inleft
2022-03-02 42b7d05dfdf60ee67c876084a3240ff48a3bf3a5
commit | author | age
4d51af 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.blogfriendshiplink.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 org.springframework.stereotype.Service;
32 import org.springframework.transaction.annotation.Transactional;
33 import vip.xiaonuo.core.exception.ServiceException;
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.blogfriendshiplink.entity.BlogFriendshipLink;
38 import vip.xiaonuo.modular.blogfriendshiplink.enums.BlogFriendshipLinkExceptionEnum;
39 import vip.xiaonuo.modular.blogfriendshiplink.mapper.BlogFriendshipLinkMapper;
40 import vip.xiaonuo.modular.blogfriendshiplink.param.BlogFriendshipLinkParam;
41 import vip.xiaonuo.modular.blogfriendshiplink.service.BlogFriendshipLinkService;
42
43 import java.util.List;
44
45 /**
46  * 友情链接service接口实现类
47  *
48  * @author inleft
49  * @date 2022-02-17 15:05:44
50  */
51 @Service
52 public class BlogFriendshipLinkServiceImpl extends ServiceImpl<BlogFriendshipLinkMapper, BlogFriendshipLink> implements BlogFriendshipLinkService {
53
54     @Override
55     public PageResult<BlogFriendshipLink> page(BlogFriendshipLinkParam blogFriendshipLinkParam) {
56         QueryWrapper<BlogFriendshipLink> queryWrapper = new QueryWrapper<>();
57         if (ObjectUtil.isNotNull(blogFriendshipLinkParam)) {
58
59             // 根据名称 查询
60             if (ObjectUtil.isNotEmpty(blogFriendshipLinkParam.getName())) {
61                 queryWrapper.lambda().like(BlogFriendshipLink::getName, blogFriendshipLinkParam.getName());
62             }
63             // 根据链接类型 查询
64             if (ObjectUtil.isNotEmpty(blogFriendshipLinkParam.getLinkType())) {
65                 queryWrapper.lambda().eq(BlogFriendshipLink::getLinkType, blogFriendshipLinkParam.getLinkType());
66             }
67             // 根据权重 查询
68             if (ObjectUtil.isNotEmpty(blogFriendshipLinkParam.getTopValue())) {
69                 queryWrapper.lambda().eq(BlogFriendshipLink::getTopValue, blogFriendshipLinkParam.getTopValue());
70             }
71             // 根据是否启用 查询
72             if (ObjectUtil.isNotEmpty(blogFriendshipLinkParam.getIsEnable())) {
73                 queryWrapper.lambda().eq(BlogFriendshipLink::getIsEnable, blogFriendshipLinkParam.getIsEnable());
74             }
75             // 根据是否新窗口打开 查询
76             if (ObjectUtil.isNotEmpty(blogFriendshipLinkParam.getIsNewWindowOpen())) {
77                 queryWrapper.lambda().eq(BlogFriendshipLink::getIsNewWindowOpen, blogFriendshipLinkParam.getIsNewWindowOpen());
78             }
79             // 根据创建时间 查询
80             if (ObjectUtil.isNotEmpty(blogFriendshipLinkParam.getCreateDate())) {
81                 queryWrapper.lambda().eq(BlogFriendshipLink::getCreateDate, blogFriendshipLinkParam.getCreateDate());
82             }
83         }
84         return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
85     }
86
87     @Override
88     public List<BlogFriendshipLink> list(BlogFriendshipLinkParam blogFriendshipLinkParam) {
89         return this.list();
90     }
91
92     @Override
93     public void add(BlogFriendshipLinkParam blogFriendshipLinkParam) {
94         BlogFriendshipLink blogFriendshipLink = new BlogFriendshipLink();
95         BeanUtil.copyProperties(blogFriendshipLinkParam, blogFriendshipLink);
96         this.save(blogFriendshipLink);
97     }
98
99     @Transactional(rollbackFor = Exception.class)
100     @Override
101     public void delete(List<BlogFriendshipLinkParam> blogFriendshipLinkParamList) {
102         blogFriendshipLinkParamList.forEach(blogFriendshipLinkParam -> {
103             this.removeById(blogFriendshipLinkParam.getId());
104         });
105     }
106
107     @Transactional(rollbackFor = Exception.class)
108     @Override
109     public void edit(BlogFriendshipLinkParam blogFriendshipLinkParam) {
110         BlogFriendshipLink blogFriendshipLink = this.queryBlogFriendshipLink(blogFriendshipLinkParam);
111         BeanUtil.copyProperties(blogFriendshipLinkParam, blogFriendshipLink);
112         this.updateById(blogFriendshipLink);
113     }
114
115     @Override
116     public BlogFriendshipLink detail(BlogFriendshipLinkParam blogFriendshipLinkParam) {
117         return this.queryBlogFriendshipLink(blogFriendshipLinkParam);
118     }
119
120     /**
121      * 获取友情链接
122      *
123      * @author inleft
124      * @date 2022-02-17 15:05:44
125      */
126     private BlogFriendshipLink queryBlogFriendshipLink(BlogFriendshipLinkParam blogFriendshipLinkParam) {
127         BlogFriendshipLink blogFriendshipLink = this.getById(blogFriendshipLinkParam.getId());
128         if (ObjectUtil.isNull(blogFriendshipLink)) {
129             throw new ServiceException(BlogFriendshipLinkExceptionEnum.NOT_EXIST);
130         }
131         return blogFriendshipLink;
132     }
133
134     @Override
135     public void export(BlogFriendshipLinkParam blogFriendshipLinkParam) {
136         List<BlogFriendshipLink> list = this.list(blogFriendshipLinkParam);
137         PoiUtil.exportExcelWithStream("SnowyBlogFriendshipLink.xls", BlogFriendshipLink.class, list);
138     }
139
140 }