DictionaryController.java
3.9 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
package vion.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.enums.ResultEnum;
import vion.model.Dictionary;
import vion.model.DictionaryType;
import vion.model.Store;
import vion.service.IDictionarySerrvice;
import vion.service.IDictionaryTypeSerrvice;
import vion.utils.ResultUtil;
import java.util.Comparator;
import java.util.List;
@RestController
@RequestMapping(Global.BASE_URL)
@Slf4j
public class DictionaryController {
@Autowired
private IDictionarySerrvice dictionarySerrvice;
@Autowired
private IDictionaryTypeSerrvice dictionaryTypeSerrvice;
@GetMapping("/dictionarys")
@ResponseBody
public Object getDictionaryList(@RequestParam(name = "pageNum")Integer pageNum,
@RequestParam(name = "pageSize")Integer pageSize,
@RequestParam(name = "type",required=false)String type){
//pageNum当前页,pageSize每页条数
Page page= PageHelper.startPage(pageNum,pageSize);
QueryWrapper<Dictionary> wrapper=new QueryWrapper<>();
if(type!=null)
wrapper.eq("type",type);
List<Dictionary> dictionaryList=dictionarySerrvice.list(wrapper);
dictionaryList.sort(Comparator.comparing(Dictionary::getId));
PageInfo pageInfo=new PageInfo<>(page);
pageInfo.setList(dictionaryList);
if (dictionaryList != null) {
return ResultUtil.success(pageInfo);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@GetMapping("/dictionary")
@ResponseBody
public Object getDictionaryByID(@RequestParam(name = "id")Integer id){
Dictionary dictionary=dictionarySerrvice.getById(id);
if (dictionary != null) {
return ResultUtil.success(dictionary);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@PostMapping("/dictionarys")
@ResponseBody
public Object saveOrUpdateDictionary(@RequestBody Dictionary data) {
try {
dictionarySerrvice.saveOrUpdate(data);
return ResultUtil.success();
}catch (Exception e) {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@GetMapping("/dictionaryTypes")
@ResponseBody
public Object getDictionaryTypeList(@RequestParam(name = "pageNum")Integer pageNum,
@RequestParam(name = "pageSize")Integer pageSize){
//pageNum当前页,pageSize每页条数
PageHelper.startPage(pageNum,pageSize);
List<DictionaryType> dictionaryTypeList=dictionaryTypeSerrvice.list();
PageInfo pageInfo=new PageInfo(dictionaryTypeList,10);
if (dictionaryTypeList != null) {
return ResultUtil.success(pageInfo);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@GetMapping("/dictionaryType")
@ResponseBody
public Object getDictionaryTypeByID(@RequestParam(name = "id")Integer id){
DictionaryType dictionaryType=dictionaryTypeSerrvice.getById(id);
if (dictionaryType != null) {
return ResultUtil.success(dictionaryType);
} else {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
@PostMapping("/dictionaryTypes")
@ResponseBody
public Object saveOrUpdateDictionaryType(@RequestBody DictionaryType data) {
try {
dictionaryTypeSerrvice.saveOrUpdate(data);
return ResultUtil.success();
}catch (Exception e) {
return ResultUtil.error(ResultEnum.SELECT_ERROR);
}
}
}