CaptionSetController.java
2.46 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
package com.viontech.storage.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.viontech.storage.entity.Message;
import com.viontech.storage.model.CaptionSet;
import com.viontech.storage.model.PicConfig;
import com.viontech.storage.service.CaptionSetService;
import com.viontech.storage.service.PicConfigService;
import com.viontech.storage.vo.CaptionSetVo;
import org.h2.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@RestController
@RequestMapping("/captionSets")
public class CaptionSetController {
@Resource
private CaptionSetService captionSetService;
@Resource
private PicConfigService picConfigService;
@GetMapping("/{id}")
public Message<CaptionSet> getById(@PathVariable("id") Long id) {
CaptionSet byId = captionSetService.getById(id);
return Message.success(byId);
}
@GetMapping
public Message<List<CaptionSet>> listAll(CaptionSetVo captionSetVo) {
LambdaQueryChainWrapper<CaptionSet> query = captionSetService.lambdaQuery();
if (!StringUtils.isNullOrEmpty(captionSetVo.getNameLike())) {
query.like(CaptionSet::getName, captionSetVo.getNameLike());
}
List<CaptionSet> list = captionSetService.list(query.getWrapper());
return Message.success(list);
}
@PostMapping
public Message<CaptionSet> add(@RequestBody CaptionSet captionSet) {
boolean save = captionSetService.save(captionSet);
if (save) {
return Message.success(captionSet);
} else {
return Message.error();
}
}
@PutMapping("/{id}")
public Message<CaptionSet> updateById(@PathVariable Long id, @RequestBody CaptionSet captionSet) {
captionSet.setId(id);
boolean b = captionSetService.updateById(captionSet);
return Message.success(captionSet);
}
@DeleteMapping("/{id}")
public Message<CaptionSet> deleteById(@PathVariable Long id) {
List<PicConfig> list = picConfigService.list(picConfigService.lambdaQuery().eq(PicConfig::getCaptionSetId, id).getWrapper());
if (CollectionUtil.isNotEmpty(list)) {
return Message.error("字幕配置使用中");
}
boolean b = captionSetService.removeById(id);
return Message.success();
}
}