谢茂盛
authored
|
1
2
|
package com.canrd.webmagic.service.impl;
|
|
3
4
|
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
|
谢茂盛
authored
|
5
6
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
7
|
import com.canrd.webmagic.common.constant.ServerResult;
|
谢茂盛
authored
|
8
|
import com.canrd.webmagic.domain.dto.ArticleDO;
|
|
9
10
|
import com.canrd.webmagic.domain.vo.NatureArticleQueryVO;
import com.canrd.webmagic.domain.vo.NatureArticleVO;
|
谢茂盛
authored
|
11
12
|
import com.canrd.webmagic.mapper.ArticleMapper;
import com.canrd.webmagic.service.ArticleService;
|
谢茂盛
authored
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
/**
* nature-文章信息(NatureArticle)表服务实现类
*
* @author makejava
* @since 2024-04-07 18:39:49
*/
@Slf4j
@Service
|
谢茂盛
authored
|
27
|
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, ArticleDO> implements ArticleService {
|
谢茂盛
authored
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
/**
* 通过ID查询单条数据
* <p>
* natureArticleQueryVO 主键
*
* @return 实例对象
*/
@Override
public ServerResult queryById(NatureArticleQueryVO natureArticleQueryVO) {
if (Objects.isNull(natureArticleQueryVO.getId())) {
return ServerResult.fail("id 不能为空");
}
|
谢茂盛
authored
|
42
43
|
ArticleDO articleDo = getById(natureArticleQueryVO.getId());
if (Objects.isNull(articleDo)) {
|
谢茂盛
authored
|
44
45
|
return ServerResult.success(null);
}
|
谢茂盛
authored
|
46
|
return ServerResult.success(BeanUtil.copyProperties(articleDo, NatureArticleVO.class));
|
谢茂盛
authored
|
47
48
49
50
51
52
53
54
55
56
|
}
/**
* 分页查询
*
* @param natureArticleQueryVO 筛选条件
* @return 查询结果
*/
@Override
public ServerResult list(NatureArticleQueryVO natureArticleQueryVO) {
|
|
57
|
return ServerResult.success(ServerResult.success());
|
谢茂盛
authored
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
}
/**
* 新增数据
*
* @param natureArticleVO 实例对象
* @return 实例对象
*/
@Override
public ServerResult add(NatureArticleVO natureArticleVO) {
//todo 校验
if (Objects.nonNull(natureArticleVO.getId())) {
natureArticleVO.setId(null);
}
|
谢茂盛
authored
|
72
|
ArticleDO articleDo = BeanUtil.copyProperties(natureArticleVO, ArticleDO.class);
|
谢茂盛
authored
|
73
|
|
谢茂盛
authored
|
74
|
save(articleDo);
|
谢茂盛
authored
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
return ServerResult.success();
}
/**
* 修改数据
*
* @param natureArticleVO 实例对象
* @return 实例对象
*/
@Override
public ServerResult edit(NatureArticleVO natureArticleVO) {
//todo 校验
if (Objects.isNull(natureArticleVO.getId())) {
return ServerResult.fail("id 不能为空");
}
|
谢茂盛
authored
|
91
|
ArticleDO articleDo = BeanUtil.copyProperties(natureArticleVO, ArticleDO.class);
|
谢茂盛
authored
|
92
|
|
谢茂盛
authored
|
93
|
updateById(articleDo);
|
谢茂盛
authored
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
return ServerResult.success();
}
/**
* 通过主键删除数据
*
* @param natureArticleQueryVO 筛选条件
* @return 是否成功
*/
@Override
public ServerResult deleteById(NatureArticleQueryVO natureArticleQueryVO) {
List<Long> ids = natureArticleQueryVO.getIds();
if (CollUtil.isEmpty(ids)) {
return ServerResult.fail("ids 参数不能为空");
}
|
谢茂盛
authored
|
110
|
List<ArticleDO> natureArticleList = listByIds(ids);
|
谢茂盛
authored
|
111
112
113
114
|
if (CollUtil.isEmpty(natureArticleList)) {
return ServerResult.success();
}
//todo 校验是否可以逻辑删除
|
谢茂盛
authored
|
115
116
|
LambdaUpdateWrapper<ArticleDO> updateWrapper = new LambdaUpdateWrapper<ArticleDO>()
.in(ArticleDO::getId, ids);
|
谢茂盛
authored
|
117
118
119
120
|
update(updateWrapper);
return ServerResult.success();
}
}
|