MenuController.java
3.44 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
122
123
124
125
126
127
128
129
130
package com.bootdo.system.controller;
import com.bootdo.common.annotation.Log;
import com.bootdo.common.config.Constant;
import com.bootdo.common.controller.BaseController;
import com.bootdo.common.domain.Tree;
import com.bootdo.common.utils.R;
import com.bootdo.system.domain.MenuDO;
import com.bootdo.system.service.MenuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @author bootdo 1992lcg@163.com
*/
@RequestMapping("/sys/menu")
@Controller
public class MenuController extends BaseController {
String prefix = "system/menu";
@Autowired
MenuService menuService;
@RequiresPermissions("sys:menu:menu")
@GetMapping()
String menu(Model model) {
return prefix+"/menu";
}
@RequiresPermissions("sys:menu:menu")
@RequestMapping("/list")
@ResponseBody
List<MenuDO> list(@RequestParam Map<String, Object> params) {
List<MenuDO> menus = menuService.list(params);
return menus;
}
@Log("添加菜单")
@RequiresPermissions("sys:menu:add")
@GetMapping("/add/{pId}")
String add(Model model, @PathVariable("pId") Long pId) {
model.addAttribute("pId", pId);
if (pId == 0) {
model.addAttribute("pName", "根目录");
} else {
model.addAttribute("pName", menuService.get(pId).getName());
}
return prefix + "/add";
}
@Log("编辑菜单")
@RequiresPermissions("sys:menu:edit")
@GetMapping("/edit/{id}")
String edit(Model model, @PathVariable("id") Long id) {
MenuDO mdo = menuService.get(id);
Long pId = mdo.getParentId();
model.addAttribute("pId", pId);
if (pId == 0) {
model.addAttribute("pName", "根目录");
} else {
model.addAttribute("pName", menuService.get(pId).getName());
}
model.addAttribute("menu", mdo);
return prefix+"/edit";
}
@Log("保存菜单")
@RequiresPermissions("sys:menu:add")
@PostMapping("/save")
@ResponseBody
R save(MenuDO menu) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
if (menuService.save(menu) > 0) {
return R.ok();
} else {
return R.error(1, "保存失败");
}
}
@Log("更新菜单")
@RequiresPermissions("sys:menu:edit")
@PostMapping("/update")
@ResponseBody
R update(MenuDO menu) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
if (menuService.update(menu) > 0) {
return R.ok();
} else {
return R.error(1, "更新失败");
}
}
@Log("删除菜单")
@RequiresPermissions("sys:menu:remove")
@PostMapping("/remove")
@ResponseBody
R remove(Long id) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
if (menuService.remove(id) > 0) {
return R.ok();
} else {
return R.error(1, "删除失败");
}
}
@GetMapping("/tree")
@ResponseBody
Tree<MenuDO> tree() {
Tree<MenuDO> tree = menuService.getTree();
return tree;
}
@GetMapping("/tree/{roleId}")
@ResponseBody
Tree<MenuDO> tree(@PathVariable("roleId") Long roleId) {
Tree<MenuDO> tree = menuService.getTree(roleId);
return tree;
}
}