发布于2021-05-30 19:52 阅读(456) 评论(0) 点赞(17) 收藏(3)
主要功能:用户、角色、权限、菜单、内部邮件群发、给管理员发送邮件、酒类管理、红酒信息管理、通知公告管理、修改密码等
- /**
- * .
- *
- *
- *
- *
- */
-
- package io.renren.modules.sys.controller;
-
- import io.renren.common.annotation.SysLog;
- import io.renren.common.exception.RRException;
- import io.renren.common.utils.Constant;
- import io.renren.common.utils.R;
- import io.renren.modules.sys.entity.SysMenuEntity;
- import io.renren.modules.sys.service.SysMenuService;
- import org.apache.commons.lang.StringUtils;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
-
- import java.util.List;
-
- /**
- * 系统菜单
- *
- * @author Mark s.com
- */
- @RestController
- @RequestMapping("/sys/menu")
- public class SysMenuController extends AbstractController {
- @Autowired
- private SysMenuService sysMenuService;
-
- /**
- * 导航菜单
- */
- @RequestMapping("/nav")
- public R nav(){
- List<SysMenuEntity> menuList = sysMenuService.getUserMenuList(getUserId());
- return R.ok().put("menuList", menuList);
- }
-
- /**
- * 所有菜单列表
- */
- @RequestMapping("/list")
- @RequiresPermissions("sys:menu:list")
- public List<SysMenuEntity> list(){
- List<SysMenuEntity> menuList = sysMenuService.list();
- for(SysMenuEntity sysMenuEntity : menuList){
- SysMenuEntity parentMenuEntity = sysMenuService.getById(sysMenuEntity.getParentId());
- if(parentMenuEntity != null){
- sysMenuEntity.setParentName(parentMenuEntity.getName());
- }
- }
-
- return menuList;
- }
-
- /**
- * 选择菜单(添加、修改菜单)
- */
- @RequestMapping("/select")
- @RequiresPermissions("sys:menu:select")
- public R select(){
- //查询列表数据
- List<SysMenuEntity> menuList = sysMenuService.queryNotButtonList();
-
- //添加顶级菜单
- SysMenuEntity root = new SysMenuEntity();
- root.setMenuId(0L);
- root.setName("一级菜单");
- root.setParentId(-1L);
- root.setOpen(true);
- menuList.add(root);
-
- return R.ok().put("menuList", menuList);
- }
-
- /**
- * 菜单信息
- */
- @RequestMapping("/info/{menuId}")
- @RequiresPermissions("sys:menu:info")
- public R info(@PathVariable("menuId") Long menuId){
- SysMenuEntity menu = sysMenuService.getById(menuId);
- return R.ok().put("menu", menu);
- }
-
- /**
- * 保存
- */
- @SysLog("保存菜单")
- @RequestMapping("/save")
- @RequiresPermissions("sys:menu:save")
- public R save(@RequestBody SysMenuEntity menu){
- //数据校验
- verifyForm(menu);
-
- sysMenuService.save(menu);
-
- return R.ok();
- }
-
- /**
- * 修改
- */
- @SysLog("修改菜单")
- @RequestMapping("/update")
- @RequiresPermissions("sys:menu:update")
- public R update(@RequestBody SysMenuEntity menu){
- //数据校验
- verifyForm(menu);
-
- sysMenuService.updateById(menu);
-
- return R.ok();
- }
-
- /**
- * 删除
- */
- @SysLog("删除菜单")
- @RequestMapping("/delete")
- @RequiresPermissions("sys:menu:delete")
- public R delete(long menuId){
- if(menuId <= 31){
- return R.error("系统菜单,不能删除");
- }
-
- //判断是否有子菜单或按钮
- List<SysMenuEntity> menuList = sysMenuService.queryListParentId(menuId);
- if(menuList.size() > 0){
- return R.error("请先删除子菜单或按钮");
- }
-
- sysMenuService.delete(menuId);
-
- return R.ok();
- }
-
- /**
- * 验证参数是否正确
- */
- private void verifyForm(SysMenuEntity menu){
- if(StringUtils.isBlank(menu.getName())){
- throw new RRException("菜单名称不能为空");
- }
-
- if(menu.getParentId() == null){
- throw new RRException("上级菜单不能为空");
- }
-
- //菜单
- if(menu.getType() == Constant.MenuType.MENU.getValue()){
- if(StringUtils.isBlank(menu.getUrl())){
- throw new RRException("菜单URL不能为空");
- }
- }
-
- //上级菜单类型
- int parentType = Constant.MenuType.CATALOG.getValue();
- if(menu.getParentId() != 0){
- SysMenuEntity parentMenu = sysMenuService.getById(menu.getParentId());
- parentType = parentMenu.getType();
- }
-
- //目录、菜单
- if(menu.getType() == Constant.MenuType.CATALOG.getValue() ||
- menu.getType() == Constant.MenuType.MENU.getValue()){
- if(parentType != Constant.MenuType.CATALOG.getValue()){
- throw new RRException("上级菜单只能为目录类型");
- }
- return ;
- }
-
- //按钮
- if(menu.getType() == Constant.MenuType.BUTTON.getValue()){
- if(parentType != Constant.MenuType.MENU.getValue()){
- throw new RRException("上级菜单只能为菜单类型");
- }
- return ;
- }
- }
- }
作者:龙膜授权
链接:http://www.phpheidong.com/blog/article/86756/07b1447c23e2acabf1ed/
来源:php黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 php黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-4
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!