package com.lsw.controller.admin.system.menu; import com.jfinal.aop.Before; import com.jfinal.kit.StrKit; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.ehcache.CacheKit; import com.lsw.base.BaseController; import com.lsw.commons.utils.Constant; import com.lsw.model.Menu; import org.apache.shiro.authz.annotation.RequiresPermissions; import java.util.List; /** * @author 李书文 * @description 菜单管理 * @time 2017-5-30 */ public class MenuController extends BaseController { static final MenuService menuService = new MenuService(); /** * 管理页面 */ @RequiresPermissions("menu:list") public void list() { render("list.html"); } /** * 菜单json数据 */ public void jsonList() { Page pgaeList = menuService.menuList(getPage(), getRows(), getPara("name"), getPara("pid"), getPara("id"), getPara("sidx", "viewSort"), getSord()); renderJson(getPage(pgaeList)); } /** * 选择图标 */ public void icon() { render("icon.html"); } /** * 选择上级菜单 */ public void select() { render("select.html"); } /** * 视图页面 */ public void view() { String op = getPara("op"); //上级菜单 List menu_list = menuService.superiorMenuList(); if (op.equals("edit")) { Menu menu = menuService.selectById(getParaToInt("id")); setAttr("menu", menu); } setAttr("menu_list", menu_list); setAttr("op", op); render("form.html"); } /** * 添加菜单 */ @RequiresPermissions("menu:add") @Before(MenuValidator.class) public void add() { Menu menu = getModel(Menu.class, "", true); menu.setOpen("true"); if (menu.getPId() == 0) { menu.setPId(0); } menu.save(); renderSuccess(); } /** * 编辑菜单 */ @RequiresPermissions("menu:edit") @Before(MenuValidator.class) public void edit() { getModel(Menu.class, "", true).update(); CacheKit.removeAll(Constant.menuRoleCache); renderSuccess(); } /** * 删除菜单 */ @RequiresPermissions("menu:delete") public void delete() { String ids = getPara("ids"); int row = Db.update("delete from sys_menu where id in(" + ids + ")"); if (row > 0) { //删除相应的资源权限 Db.update("delete from sys_menu_role where menuId in(" + ids + ")"); //删除相应的子菜单 boolean child = menuService.hasChild(ids); if (child) { Db.update("delete from sys_menu where pId in(" + ids + ")"); } //更新授权资源缓存 CacheKit.removeAll(Constant.menuRoleCache); renderSuccess(); } else { renderError("删除失败"); } } /** * 树型菜单json数据 */ public void getTreeJson() { List menu_list = menuService.getMenuList(); renderJson(menu_list); } /** * 树型菜单json数据 */ public void getTreeJson2() { List menu_list = menuService.getMenuList2(); renderJson(menu_list); } }