DictionaryController.java
2.99 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
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vion.dto.DictionaryDTO;
import vion.dto.DictionaryTypeDTO;
import vion.model.Dictionary;
import vion.model.DictionaryType;
import vion.service.IDictionaryService;
import vion.service.IDictionaryTypeService;
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
public class DictionaryController {
private final IDictionaryService dictionaryService;
private final IDictionaryTypeService dictionaryTypeService;
private final Converter converter;
@GetMapping("/dictionarys")
@SaCheckPermission(value = "dict:list", orRole = "admin")
public Page<Dictionary> getDictionaryList(DictionaryDTO data) {
return dictionaryService.lambdaQuery(converter.convert(data, Dictionary.class))
.page(Page.of(data.getPageNum(), data.getPageSize()));
}
@GetMapping("/dictionary")
@SaCheckPermission(value = "dict:query", orRole = "admin")
public Object getDictionaryById(Long id) {
return dictionaryService.getById(id);
}
@PostMapping("/dictionary")
@SaCheckPermission(value = "dict:editAndSave", orRole = "admin")
public String saveOrUpdateDictionary(@RequestBody DictionaryDTO data) {
Dictionary dictionary = converter.convert(data, Dictionary.class);
return dictionaryService.saveOrUpdate(dictionary) ? "成功" : "失败";
}
@GetMapping("/dictionaryTypes")
@SaCheckPermission(value = "dict:type:list", orRole = "admin")
public Page<DictionaryType> getDictionaryTypeList(DictionaryTypeDTO data) {
return dictionaryTypeService.lambdaQuery(converter.convert(data, DictionaryType.class))
.page(Page.of(data.getPageNum(), data.getPageSize()));
}
@GetMapping("/dictionaryType")
@SaCheckPermission(value = "dict:type:query", orRole = "admin")
public Object getDictionaryTypeById(@RequestParam Integer id) {
return dictionaryTypeService.getById(id);
}
@PostMapping("/dictionaryType")
@SaCheckPermission(value = "dict:type:editAndSave", orRole = "admin")
public String saveOrUpdateDictionaryType(@RequestBody DictionaryTypeDTO data) {
DictionaryType dictionaryType = converter.convert(data, DictionaryType.class);
return dictionaryTypeService.saveOrUpdate(dictionaryType) ? "成功" : "失败";
}
/**
* 同步字典到 Redis
* 目前字典接口未使用,添加字典和字典项是直接在数据库中添加的,所以需要手动同步到 Redis
*
* @return java.lang.String
*/
@GetMapping("/dict/sync")
@SaCheckPermission(value = "dict:sync", orRole = "admin")
// todo 未加权限
public String syncDict() {
dictionaryService.syncDict();
return "同步成功";
}
}