Blame view

src/main/java/com/huaheng/pc/system/menu/controller/MenuController.java 6.02 KB
tangying authored
1
2
3
4
package com.huaheng.pc.system.menu.controller;

import java.util.List;
import java.util.Map;
mahuandong authored
5
6

import com.huaheng.common.utils.security.ShiroUtils;
7
8
9
10
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
tangying authored
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
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.system.menu.domain.Menu;
import com.huaheng.pc.system.menu.service.IMenuService;
import com.huaheng.pc.system.role.domain.Role;

/**
 * 菜单信息
 * 
 * @author huaheng
 */
@Controller
@RequestMapping("/system/menu")
36
37
@Api(tags = "菜单")
public class MenuController extends BaseController {
tangying authored
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

    private String prefix = "system/menu";

    @Autowired
    private IMenuService menuService;

    @RequiresPermissions("system:menu:view")
    @GetMapping()
    public String menu()
    {
        return prefix + "/menu";
    }

    @RequiresPermissions("system:menu:list")
    @Log(title = "系统管理-菜单管理", operating = "出库菜单列表", action = BusinessType.GRANT)
    @GetMapping("/list")
    @ResponseBody
55
56
    @ApiOperation(value="菜单查询", notes="菜单查询", httpMethod = "POST")
    public List<Menu> list(@ApiParam(name = "menu") Menu menu)
tangying authored
57
58
59
60
61
62
63
64
65
66
67
68
    {
        List<Menu> menuList = menuService.selectMenuList(menu);
        return menuList;
    }

    /**
     * 删除菜单
     */
    @Log(title = "系统管理-菜单管理", operating = "删除菜单", action = BusinessType.DELETE)
    @RequiresPermissions("system:menu:remove")
    @PostMapping("/remove/{id}")
    @ResponseBody
69
70
    @ApiOperation(value="菜单删除", notes="菜单删除", httpMethod = "POST")
    public AjaxResult remove(@PathVariable("id") @ApiParam(name = "id") Integer id)
tangying authored
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
    {
        if (menuService.selectCountMenuByParentId(id) > 0)
        {
            return error("存在子菜单,不允许删除");
        }
        if (menuService.selectCountRoleMenuByMenuId(id) > 0)
        {
            return error("菜单已分配,不允许删除");
        }
        return toAjax(menuService.deleteMenuById(id));
    }

    /**
     * 新增
     */
    @GetMapping("/add/{parentId}")
    public String add(@PathVariable("parentId") Integer parentId, ModelMap mmap)
    {
        Menu menu = null;
        if (0L != parentId)
        {
            menu = menuService.selectMenuById(parentId);
        }
        else
        {
            menu = new Menu();
            menu.setId(0);
            menu.setMenuName("主目录");
        }
        mmap.put("menu", menu);
        return prefix + "/add";
    }

    /**
     * 新增保存菜单
     */
    @Log(title = "系统管理-菜单管理", operating = "新增菜单", action = BusinessType.INSERT)
    @RequiresPermissions("system:menu:add")
    @PostMapping("/add")
    @ResponseBody
111
112
    @ApiOperation(value="菜单新增", notes="菜单新增", httpMethod = "POST")
    public AjaxResult addSave(@ApiParam(name = "menu")Menu menu)
tangying authored
113
    {
114
115
116
117
118
119
120
121
        int parentId = menu.getParentId();
        if (parentId != 0)
        {
           Menu parentMenu = menuService.selectMenuById(parentId);
           if(parentMenu != null) {
               menu.setParentName(parentMenu.getMenuName());
           }
        }
tangying authored
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
        return toAjax(menuService.insertMenu(menu));
    }

    /**
     * 修改菜单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        mmap.put("menu", menuService.selectMenuById(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存菜单
     */
    @Log(title = "系统管理-菜单管理", operating = "修改菜单", action = BusinessType.UPDATE)
    @RequiresPermissions("system:menu:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Menu menu)
    {
        return toAjax(menuService.updateMenu(menu));
    }

    /**
     * 选择菜单图标
     */
    @GetMapping("/icon")
    public String icon()
    {
        return prefix + "/icon";
    }

    /**
157
     * 校验菜单名称  需要判断是否有重复,应该是在新增的时候
tangying authored
158
159
160
     */
    @PostMapping("/checkMenuNameUnique")
    @ResponseBody
mahuandong authored
161
    public Integer checkMenuNameUnique(Menu menu)
tangying authored
162
    {
mahuandong authored
163
        Integer uniqueFlag = 0;
tangying authored
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
        if (StringUtils.isNotNull(menu))
        {
            uniqueFlag = menuService.checkMenuNameUnique(menu);
        }
        return uniqueFlag;
    }

    /**
     * 加载角色菜单列表树
     */
    @GetMapping("/roleMenuTreeData")
    @ResponseBody
    public List<Map<String, Object>> roleMenuTreeData(Role role)
    {
        List<Map<String, Object>> tree = menuService.roleMenuTreeData(role);
        return tree;
    }

    /**
     * 加载所有菜单列表树
     */
    @GetMapping("/menuTreeData")
    @ResponseBody
    public List<Map<String, Object>> menuTreeData(Role role)
    {
        List<Map<String, Object>> tree = menuService.menuTreeData();
        return tree;
    }

    /**
     * 选择菜单树
     */
    @GetMapping("/selectMenuTree/{id}")
    public String selectMenuTree(@PathVariable("id") Integer id, ModelMap mmap)
    {
        mmap.put("menu", menuService.selectMenuById(id));
        return prefix + "/tree";
    }
mahuandong authored
202
203
204
205
206
207

    @GetMapping("/getMenuByUserId")
    @ResponseBody
    public List<Menu> list(){
        return menuService.selectPCMenusByUserId(ShiroUtils.getUserId());
    }
tangying authored
208
}