MaterialServiceImpl.java
7.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.bs.reception.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bs.common.utils.SecurityUtils;
import com.bs.reception.entity.materials.Material;
import com.bs.reception.mapper.MaterialMapper;
import com.bs.reception.model.materials.HomepageMaterialVO;
import com.bs.reception.service.IMaterialService;
import com.bs.reception.model.materials.MaterialPageQuery;
import com.bs.reception.model.materials.MaterialPageVO;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> implements IMaterialService {
@Override
/** 查询首页展示素材(含业务类型与文件夹信息) */
public List<HomepageMaterialVO> listHomepageMaterials() {
return this.baseMapper.selectHomepageMaterials();
}
@Override
public Page<MaterialPageVO> pageMaterials(MaterialPageQuery query) {
Integer pageNum = query.getPageNum() == null || query.getPageNum() < 1 ? 1 : query.getPageNum();
Integer pageSize = query.getPageSize() == null || query.getPageSize() < 1 ? 10 : query.getPageSize();
Page<MaterialPageVO> page = new Page<>(pageNum, pageSize);
java.util.List<MaterialPageVO> rows = this.baseMapper.selectMaterialPage(page, query);
page.setRecords(rows);
return page;
}
@Override
public List<Material> getMaterialList(Material body) {
LambdaQueryWrapper<Material> qw = new LambdaQueryWrapper<>();
qw.eq(body.getTypeCode() != null, Material::getTypeCode, body.getTypeCode())
.eq(body.getFolderCode() != null, Material::getFolderCode, body.getFolderCode())
.like(body.getMaterialName() != null && !body.getMaterialName().isBlank(), Material::getMaterialName, body.getMaterialName())
.eq(body.getShowOnHomepage() != null, Material::getShowOnHomepage, body.getShowOnHomepage())
.eq(body.getStatus() != null, Material::getStatus, body.getStatus())
.eq(Material::getDelFlag, 0)
.orderByAsc(Material::getSortOrder);
return this.list(qw);
}
@Override
public Material createMaterial(Material body) {
if (body.getMaterialName() == null || body.getMaterialName().isBlank()) {
throw new RuntimeException("素材名称不能为空");
}
if (body.getTypeCode() == null || body.getTypeCode().isBlank()) {
throw new RuntimeException("业务类型编码不能为空");
}
if (body.getFolderCode() == null || body.getFolderCode().isBlank()) {
throw new RuntimeException("文件夹编码不能为空");
}
if (body.getMaterialUrl() == null || body.getMaterialUrl().isBlank()) {
throw new RuntimeException("素材URL不能为空");
}
if (body.getShowOnHomepage() == null) {
throw new RuntimeException("是否首页展示不能为空");
}
body.setId(null);
body.setMaterialCode("MC" + System.currentTimeMillis());
// 校验素材名称是否已存在(同业务类型、同文件夹下)
LambdaQueryWrapper<Material> qw = new LambdaQueryWrapper<>();
qw.eq(Material::getTypeCode, body.getTypeCode())
.eq(Material::getFolderCode, body.getFolderCode())
.eq(Material::getMaterialName, body.getMaterialName())
.eq(Material::getDelFlag, 0);
List<Material> list = this.list(qw);
if (list != null && !list.isEmpty()) {
throw new RuntimeException("素材名称已存在");
}
body.setCreateBy(SecurityUtils.getUserName());
body.setCreateById(SecurityUtils.getUserId());
body.setCreateTime(new java.util.Date());
this.save(body);
return body;
}
@Override
public boolean updateMaterial(Material body) {
if (body.getId() == null) {
throw new RuntimeException("ID不能为空");
}
if (body.getMaterialName() == null || body.getMaterialName().isBlank()) {
throw new RuntimeException("素材名称不能为空");
}
if (body.getTypeCode() == null || body.getTypeCode().isBlank()) {
throw new RuntimeException("业务类型编码不能为空");
}
if (body.getFolderCode() == null || body.getFolderCode().isBlank()) {
throw new RuntimeException("文件夹编码不能为空");
}
if (body.getMaterialUrl() == null || body.getMaterialUrl().isBlank()) {
throw new RuntimeException("素材URL不能为空");
}
if (body.getShowOnHomepage() == null) {
throw new RuntimeException("是否首页展示不能为空");
}
body.setMaterialCode(null);
// 校验素材名称是否已存在(同业务类型、同文件夹下)
LambdaQueryWrapper<Material> qw = new LambdaQueryWrapper<>();
qw.eq(Material::getTypeCode, body.getTypeCode())
.eq(Material::getFolderCode, body.getFolderCode())
.eq(Material::getMaterialName, body.getMaterialName())
.ne(Material::getId, body.getId())
.eq(Material::getDelFlag, 0);
List<Material> list = this.list(qw);
if (list != null && !list.isEmpty()) {
throw new RuntimeException("素材名称已存在");
}
body.setUpdateBy(SecurityUtils.getUserName());
body.setUpdateById(SecurityUtils.getUserId());
body.setUpdateTime(new java.util.Date());
return this.updateById(body);
}
@Override
public boolean setMaterialSort(Material body) {
if (body.getId() == null) {
throw new RuntimeException("ID不能为空");
}
if (body.getSortOrder() == null) {
throw new RuntimeException("排序不能为空");
}
return this.update(new LambdaUpdateWrapper<Material>()
.eq(Material::getId, body.getId())
.set(Material::getUpdateBy, SecurityUtils.getUserName())
.set(Material::getUpdateById, SecurityUtils.getUserId())
.set(Material::getUpdateTime, new java.util.Date())
.set(Material::getSortOrder, body.getSortOrder()));
}
@Override
public boolean setMaterialHomepage(Material body) {
if (body.getId() == null) {
throw new RuntimeException("ID不能为空");
}
if (body.getShowOnHomepage() == null) {
throw new RuntimeException("是否首页展示不能为空");
}
return this.update(new LambdaUpdateWrapper<Material>()
.eq(Material::getId, body.getId())
.set(Material::getUpdateBy, SecurityUtils.getUserName())
.set(Material::getUpdateById, SecurityUtils.getUserId())
.set(Material::getUpdateTime, new java.util.Date())
.set(Material::getShowOnHomepage, body.getShowOnHomepage()));
}
@Override
public boolean deleteMaterial(Material body) {
if (body.getId() == null) {
throw new RuntimeException("ID不能为空");
}
return this.update(new LambdaUpdateWrapper<Material>()
.eq(Material::getId, body.getId())
.set(Material::getUpdateTime, new java.util.Date())
.set(Material::getUpdateBy, SecurityUtils.getUserName())
.set(Material::getUpdateById, SecurityUtils.getUserId())
.set(Material::getDelFlag, 1));
}
@Override
public Material getMaterialDetail(Material body) {
if (body.getId() == null) {
throw new RuntimeException("ID不能为空");
}
return this.getById(body.getId());
}
}