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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
package cn.wisenergy.chnmuseum.party.web.controller;
import cn.wisenergy.chnmuseum.party.common.dfs.FastDFSUtils;
import cn.wisenergy.chnmuseum.party.common.enums.*;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Update;
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;
import cn.wisenergy.chnmuseum.party.model.*;
import cn.wisenergy.chnmuseum.party.service.*;
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* <pre>
* 展板 前端控制器
* </pre>
*
* @author Danny Lee
* @since 2021-03-19
*/
@Slf4j
@RestController
@RequestMapping("/exhibitionBoard")
@Api(tags = {"展板操作接口"})
public class ExhibitionBoardController extends BaseController {
@Resource
private ExhibitionBoardService exhibitionBoardService;
@Resource
private ExhibitionBoardCatService exhibitionBoardCatService;
@Resource
private CopyrightOwnerService copyrightOwnerService;
@Resource
private VideoContentService videoContentService;
@Resource
private AuditService auditService;
@Resource
private AssetService assetService;
@PostMapping("/save")
@RequiresAuthentication //@RequiresPermissions("exhibition:board:save")
@ApiOperation(value = "添加展板", notes = "添加展板")
public Map<String, Object> saveExhibitionBoard(@Validated(value = {Add.class}) ExhibitionBoard exhibitionBoard) {
TUser user = getcurUser();
final List<String> audioIdList = exhibitionBoard.getAudioIdList();
if (audioIdList == null || audioIdList.isEmpty()) {
return getFailResult("400", "导览音频文件必须上传");
}
final List<String> datumIdList = exhibitionBoard.getDatumIdList();
if (datumIdList == null || datumIdList.isEmpty()) {
return getFailResult("400", "参考资料文件必须上传");
}
exhibitionBoard.setAuditStatus(AuditStatusEnum.TBC.name());
exhibitionBoard.setPublished(false);
exhibitionBoard.setDeleted(false);
// 保存业务节点信息
boolean result = exhibitionBoardService.save(exhibitionBoard);
// 返回操作结果
if (result) {
for (String audioId : audioIdList) {
final Asset asset = this.assetService.getById(audioId);
asset.setFileType(FileTypeEnum.AUDIO.name());
asset.setFileCat(FileCatEnum.EXHIBITION_BOARD_AUDIO.name());
asset.setRefItemId(exhibitionBoard.getId());
this.assetService.updateById(asset);
}
for (String datumId : datumIdList) {
final Asset asset = this.assetService.getById(datumId);
asset.setFileCat(FileCatEnum.EXHIBITION_BOARD_DATUM.name());
asset.setRefItemId(exhibitionBoard.getId());
this.assetService.updateById(asset);
}
final Audit audit = Audit.builder()
.content(exhibitionBoard.getName())
.refItemId(exhibitionBoard.getId())
.userId(user.getId())
.type(AuditTypeEnum.EXHIBITION_BOARD.name())
.operation(AuditOperationEnum.ADD.name())
.status(AuditStatusEnum.TBC.name())
.deleted(false)
.level(AuditStatusEnum.TBC.name())
.build();
this.auditService.save(audit);
return getSuccessResult();
} else {
// 保存失败
return getFailResult();
}
}
@PutMapping("/update")
@RequiresAuthentication //@RequiresPermissions("exhibition:board:update")
@ApiOperation(value = "修改展板信息", notes = "修改展板信息")
public Map<String, Object> updateExhibitionBoard(@Validated(value = {Update.class}) ExhibitionBoard exhibitionBoard) {
TUser user = getcurUser();
final VideoContent videoContent = this.videoContentService.getById(exhibitionBoard.getVideoContentId());
exhibitionBoard.setVideoContentName(videoContent.getName());
exhibitionBoard.setAuditStatus(AuditStatusEnum.TBC.name());
exhibitionBoard.setPublished(false);
boolean flag = exhibitionBoardService.updateById(exhibitionBoard);
if (flag) {
final List<String> audioIdList = exhibitionBoard.getAudioIdList();
if (audioIdList != null && !audioIdList.isEmpty()) {
final LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_AUDIO.name());
final List<Asset> assetList = this.assetService.list(assetQueryWrapper);
final Map<String, String> collect = assetList.stream().collect(Collectors.toMap(Asset::getId, Asset::getFileUrl));
for (String audioId : audioIdList) {
final Asset asset = this.assetService.getById(audioId);
asset.setFileType(FileTypeEnum.AUDIO.name());
asset.setFileCat(FileCatEnum.EXHIBITION_BOARD_AUDIO.name());
asset.setRefItemId(exhibitionBoard.getId());
this.assetService.updateById(asset);
collect.remove(audioId);
}
collect.forEach((k, v) -> {
final boolean deleted = this.assetService.removeById(k);
if (deleted) {
FastDFSUtils.deleteFile(v);
}
});
}
final List<String> datumIdList = exhibitionBoard.getDatumIdList();
if (datumIdList != null && !datumIdList.isEmpty()) {
final LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_DATUM.name());
final List<Asset> assetList = this.assetService.list(assetQueryWrapper);
final Map<String, String> collect = assetList.stream().collect(Collectors.toMap(Asset::getId, Asset::getFileUrl));
for (String datumId : datumIdList) {
final Asset asset = this.assetService.getById(datumId);
asset.setFileCat(FileCatEnum.EXHIBITION_BOARD_DATUM.name());
asset.setRefItemId(exhibitionBoard.getId());
this.assetService.updateById(asset);
collect.remove(datumId);
}
collect.forEach((k, v) -> {
final boolean deleted = this.assetService.removeById(k);
if (deleted) {
FastDFSUtils.deleteFile(v);
}
});
}
final Audit audit = Audit.builder()
.content(exhibitionBoard.getName())
.refItemId(exhibitionBoard.getId())
.userId(user.getId())
.type(AuditTypeEnum.EXHIBITION_BOARD.name())
.operation(AuditOperationEnum.EDIT.name())
.status(AuditStatusEnum.TBC.name())
.deleted(false)
.level(AuditStatusEnum.TBC.name())
.build();
this.auditService.save(audit);
return getSuccessResult();
}
return getFailResult();
}
@DeleteMapping("/delete/{id}")
@RequiresAuthentication //@RequiresPermissions("exhibition:board:delete")
@ApiOperation(value = "根据ID删除展板", notes = "根据ID删除展板")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "id", value = "标识ID", paramType = "path", dataType = "String")
})
public Map<String, Object> deleteExhibitionBoard(@PathVariable("id") String id) {
TUser user = getcurUser();
final Audit audit = Audit.builder()
.content(this.exhibitionBoardService.getById(id).getName())
.userId(user.getId())
.refItemId(id)
.type(AuditTypeEnum.EXHIBITION_BOARD.name())
.operation(AuditOperationEnum.REMOVE.name())
.status(AuditStatusEnum.TBC.name())
.deleted(false)
.level(AuditStatusEnum.TBC.name())
.build();
final boolean result = this.auditService.save(audit);
if (result) {
return getSuccessResult();
}
return getFailResult();
}
@PostMapping("/getList")
@RequiresAuthentication //@RequiresPermissions("exhibition:board:list")
@ApiOperation(value = "获取展板全部列表(无分页)", notes = "获取展板全部列表(无分页)")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "auditStatus", value = "审核状态", paramType = "query", dataType = "String")
})
public Map<String, Object> getExhibitionBoardList(
@RequestParam(value = "exhibitionBoardCatIdList[]", required = false) List<String> exhibitionBoardCatIdList,
@RequestParam(value = "boardCopyrightOwnerIdList[]", required = false) List<String> boardCopyrightOwnerIdList,
@RequestParam(value = "auditStatus", defaultValue = "APPROVED_FINAL", required = false) AuditStatusEnum auditStatus) {
final LambdaQueryWrapper<ExhibitionBoard> lambdaQueryWrapper = Wrappers.<ExhibitionBoard>lambdaQuery().eq(ExhibitionBoard::getAuditStatus, auditStatus.name()).eq(ExhibitionBoard::getPublished, true);
lambdaQueryWrapper.eq(ExhibitionBoard::getPublished, true);
lambdaQueryWrapper.eq(ExhibitionBoard::getDeleted, false);
if (exhibitionBoardCatIdList != null && !exhibitionBoardCatIdList.isEmpty()) {
lambdaQueryWrapper.in(ExhibitionBoard::getExhibitionBoardCatId, exhibitionBoardCatIdList);
}
if (boardCopyrightOwnerIdList != null && !boardCopyrightOwnerIdList.isEmpty()) {
lambdaQueryWrapper.in(ExhibitionBoard::getBoardCopyrightOwnerId, boardCopyrightOwnerIdList);
}
lambdaQueryWrapper.eq(ExhibitionBoard::getPublished,true);
lambdaQueryWrapper.orderByDesc(ExhibitionBoard::getCreateTime);
List<ExhibitionBoard> exhibitionBoardList = exhibitionBoardService.list(lambdaQueryWrapper);
for (ExhibitionBoard exhibitionBoard : exhibitionBoardList) {
if (exhibitionBoard.getBoardCopyrightOwnerId() != null) {
String name = this.copyrightOwnerService.getById(exhibitionBoard.getBoardCopyrightOwnerId()).getName();
exhibitionBoard.setBoardCopyrightOwnerName(name);
}
if (exhibitionBoard.getVideoContentCopyrightOwnerId() != null) {
String name = this.copyrightOwnerService.getById(exhibitionBoard.getVideoContentCopyrightOwnerId()).getName();
exhibitionBoard.setVideoContentCopyrightOwnerName(name);
}
if (exhibitionBoard.getExhibitionBoardCatId() != null) {
String name = this.exhibitionBoardCatService.getById(exhibitionBoard.getExhibitionBoardCatId()).getName();
exhibitionBoard.setExhibitionBoardCatName(name);
}
}
return getResult(exhibitionBoardList);
}
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "nameOrCode", value = "名称或编码", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "copyrightOwner", value = "版权方", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "startDate", value = "创建时间-开始", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endDate", value = "创建时间-结束", paramType = "query", dataType = "String")
})
@PostMapping("/getPageList")
@RequiresAuthentication //@RequiresPermissions("exhibition:board:page")
@ApiOperation(value = "获取展板分页列表", notes = "获取展板分页列表")
public Map<String, Object> getExhibitionBoardPageList(GenericPageParam genericPageParam) {
LambdaQueryWrapper<ExhibitionBoard> queryWrapper = new LambdaQueryWrapper<>();
// 对名称或编码模糊查询
if (StringUtils.isNotBlank(genericPageParam.getNameOrCode())) {
queryWrapper.like(ExhibitionBoard::getName, genericPageParam.getNameOrCode());
}
// 对版权方模糊查询
if (StringUtils.isNotBlank(genericPageParam.getBoardCopyrightOwnerId())) {
queryWrapper.eq(ExhibitionBoard::getBoardCopyrightOwnerId, genericPageParam.getBoardCopyrightOwnerId());
}
// 对版权方模糊查询
if (StringUtils.isNotBlank(genericPageParam.getExhibitionBoardCatId())) {
queryWrapper.eq(ExhibitionBoard::getExhibitionBoardCatId, genericPageParam.getExhibitionBoardCatId());
}
// 根据创建时间区间检索
if (genericPageParam.getStartDate() != null && genericPageParam.getEndDate() != null) {
queryWrapper.ge(ExhibitionBoard::getCreateTime, genericPageParam.getStartDate().atTime(0, 0, 0))
.le(ExhibitionBoard::getCreateTime, genericPageParam.getEndDate().atTime(23, 59, 59));
}
// 设置排序规则
queryWrapper.orderByDesc(ExhibitionBoard::getCreateTime);
// 设置查询内容
queryWrapper.select(
ExhibitionBoard::getId,
ExhibitionBoard::getName,
ExhibitionBoard::getRemarks,
ExhibitionBoard::getQrcodeUrl,
ExhibitionBoard::getAuditStatus,
ExhibitionBoard::getPublished,
ExhibitionBoard::getDeleted,
ExhibitionBoard::getVideoContentCopyrightOwnerId,
ExhibitionBoard::getExhibitionBoardCatId,
ExhibitionBoard::getBoardCopyrightOwnerId,
ExhibitionBoard::getVideoContentId,
ExhibitionBoard::getCreateTime,
ExhibitionBoard::getUpdateTime);
Page<ExhibitionBoard> page = this.exhibitionBoardService.page(getPage(), queryWrapper);
for (ExhibitionBoard exhibitionBoard : page.getRecords()) {
if (exhibitionBoard.getBoardCopyrightOwnerId() != null) {
String name = this.copyrightOwnerService.getById(exhibitionBoard.getBoardCopyrightOwnerId()).getName();
exhibitionBoard.setBoardCopyrightOwnerName(name);
}
if (exhibitionBoard.getVideoContentCopyrightOwnerId() != null) {
String name = this.copyrightOwnerService.getById(exhibitionBoard.getVideoContentCopyrightOwnerId()).getName();
exhibitionBoard.setVideoContentCopyrightOwnerName(name);
}
if (exhibitionBoard.getExhibitionBoardCatId() != null) {
String name = this.exhibitionBoardCatService.getById(exhibitionBoard.getExhibitionBoardCatId()).getName();
exhibitionBoard.setExhibitionBoardCatName(name);
}
if (exhibitionBoard.getVideoContentId() != null) {
final VideoContent videoContent = this.videoContentService.getById(exhibitionBoard.getVideoContentId());
if (videoContent == null) {
exhibitionBoard.setVideoContentName("该视频内容已被删除");
} else {
exhibitionBoard.setVideoContentName(videoContent.getName());
}
}
}
return getResult(page);
}
@ApiOperation(value = "获取展板详情", notes = "获取展板详情")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path")
})
@GetMapping("/get/{id}")
@RequiresAuthentication //@RequiresPermissions("exhibition:board:get:id")
public Map<String, Object> getById(@PathVariable("id") String id) {
ExhibitionBoard exhibitionBoard = exhibitionBoardService.getById(id);
String exhibitionBoardCatId = exhibitionBoard.getExhibitionBoardCatId();
if (exhibitionBoardCatId != null) {
exhibitionBoard.setExhibitionBoardCatName(this.exhibitionBoardCatService.getById(exhibitionBoardCatId).getName());
}
String boardCopyrightOwnerId = exhibitionBoard.getBoardCopyrightOwnerId();
if (boardCopyrightOwnerId != null) {
exhibitionBoard.setBoardCopyrightOwnerName(this.copyrightOwnerService.getById(boardCopyrightOwnerId).getName());
}
if (exhibitionBoard.getVideoContentCopyrightOwnerId() != null) {
String name = this.copyrightOwnerService.getById(exhibitionBoard.getVideoContentCopyrightOwnerId()).getName();
exhibitionBoard.setVideoContentCopyrightOwnerName(name);
}
LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_AUDIO.name());
final List<Asset> audioList = this.assetService.list(assetQueryWrapper);
exhibitionBoard.setAudioList(audioList);
exhibitionBoard.setAudioIdList(audioList.stream().map(Asset::getId).collect(Collectors.toList()));
assetQueryWrapper.clear();
assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_DATUM.name());
final List<Asset> datumList = this.assetService.list(assetQueryWrapper);
exhibitionBoard.setDatumList(datumList);
exhibitionBoard.setDatumIdList(datumList.stream().map(Asset::getId).collect(Collectors.toList()));
final LambdaQueryWrapper<Audit> auditQueryWrapper = Wrappers.<Audit>lambdaQuery().eq(Audit::getRefItemId, id);
auditQueryWrapper.select(Audit::getContent);
auditQueryWrapper.select(Audit::getType);
auditQueryWrapper.select(Audit::getOperation);
auditQueryWrapper.select(Audit::getStatus);
auditQueryWrapper.select(Audit::getFirstTime);
auditQueryWrapper.select(Audit::getFirstRemarks);
auditQueryWrapper.select(Audit::getSecondTime);
auditQueryWrapper.select(Audit::getSecondTime);
auditQueryWrapper.select(Audit::getLevel);
final List<Audit> auditList = this.auditService.list(auditQueryWrapper);
exhibitionBoard.setAuditHistoryList(auditList);
final String videoContentId = exhibitionBoard.getVideoContentId();
if (videoContentId != null) {
final VideoContent videoContent = this.videoContentService.getById(videoContentId);
exhibitionBoard.setVideoContentName(videoContent.getName());
assetQueryWrapper.clear();
assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, videoContentId);
assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.VIDEO_CONTENT.name());
final List<Asset> videoList = this.assetService.list(assetQueryWrapper);
exhibitionBoard.setVideoList(videoList);
}
return getResult(exhibitionBoard);
}
@ApiOperation(value = "上架/下架展板内容", notes = "上架/下架展板内容")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path"),
@ApiImplicitParam(name = "isPublish", value = "是否上架", dataType = "boolean", paramType = "query", allowableValues = "True, False")
})
@PutMapping("/publish/{id}")
@RequiresAuthentication //@RequiresPermissions("exhibition:board:publish")
public Map<String, Object> enableExhibitionBoard(@PathVariable("id") String id, @RequestParam("isPublish") Boolean isPublish) {
TUser user = getcurUser();
final Audit audit = Audit.builder()
.userId(user.getId())
.content(this.exhibitionBoardService.getById(id).getName())
.refItemId(id)
.type(AuditTypeEnum.EXHIBITION_BOARD.name())
.operation(isPublish ? AuditOperationEnum.UPPER.name() : AuditOperationEnum.LOWER.name())
.status(AuditStatusEnum.TBC.name())
.deleted(false)
.level(AuditStatusEnum.TBC.name())
.build();
this.auditService.save(audit);
return getSuccessResult();
}
}