PicConfigController.java
3.5 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
package com.viontech.storage.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.viontech.storage.entity.Context;
import com.viontech.storage.entity.Message;
import com.viontech.storage.model.PicConfig;
import com.viontech.storage.model.StorageConfig;
import com.viontech.storage.service.PicConfigService;
import com.viontech.storage.service.StorageConfigService;
import com.viontech.storage.vo.PicConfigVo;
import com.viontech.storage.vo.StorageConfigVo;
import org.h2.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/9
*/
@RestController
@RequestMapping("/picConfigs")
public class PicConfigController {
@Resource
private PicConfigService picConfigService;
@Resource
private StorageConfigService storageConfigService;
@GetMapping("/{id}")
public Message<PicConfig> getById(@PathVariable("id") Long id) {
PicConfig byId = picConfigService.getById(id);
PicConfigVo copy = PicConfigVo.copy(byId);
return Message.success(copy);
}
@GetMapping
public Message<List<PicConfig>> listAll(PicConfigVo configVo) {
LambdaQueryChainWrapper<PicConfig> query = picConfigService.lambdaQuery();
if (!StringUtils.isNullOrEmpty(configVo.getNameLike())) {
query.like(PicConfig::getName, configVo.getNameLike());
}
if (configVo.getPictureQualityGte() != null) {
query.ge(PicConfig::getPictureQuality, configVo.getPictureQualityGte());
}
if (configVo.getPictureQualityLte() != null) {
query.le(PicConfig::getPictureQuality, configVo.getPictureQualityLte());
}
List<PicConfig> list = query.list();
List<PicConfig> collect = list.stream().map(PicConfigVo::copy).collect(Collectors.toList());
return Message.success(collect);
}
@PostMapping
public Message<PicConfig> add(@RequestBody PicConfigVo item) {
List<Context> contexts = item.getContexts();
if (CollectionUtil.isNotEmpty(contexts)) {
item.setContext(JSONUtil.toJsonStr(contexts));
}
boolean save = picConfigService.save(item);
return Message.success(item);
}
@PutMapping("/{id}")
public Message<PicConfig> updateById(@PathVariable Long id, @RequestBody PicConfigVo item) {
List<Context> contexts = item.getContexts();
if (contexts != null) {
item.setContext(JSONUtil.toJsonStr(contexts));
}
item.setId(id);
picConfigService.updateById(item);
return Message.success(item);
}
@DeleteMapping("/{id}")
public Message<PicConfig> deleteById(@PathVariable Long id) {
List<StorageConfig> list = storageConfigService.list();
List<StorageConfigVo> collect = list.stream().map(StorageConfigVo::copy).collect(Collectors.toList());
for (StorageConfigVo item : collect) {
List<Context> contexts = item.getContexts();
if (contexts != null) {
boolean used = contexts.stream().anyMatch(x -> x.getPicConfigId().equals(id));
if (used) {
return Message.error("图片合成规则正在使用中");
}
}
}
boolean b = picConfigService.removeById(id);
return Message.success();
}
}