Search in sources :

Example 6 with MenuItem

use of com.ibeiliao.deployment.admin.utils.resource.MenuItem in project Corgi by kevinYin.

the class MenuController method updateMenu.

/**
 * 重新生成系统菜单
 *
 * @return
 */
@ResponseBody
@RequestMapping("updateMenu.do")
public RestResult<Object> updateMenu(HttpServletRequest request) {
    int appId = getAppId(request);
    logger.info("将更新菜单, appId=" + appId);
    RestResult<Object> result = null;
    if (appId > 0) {
        String[] scanPath = getScanPath(appId);
        try {
            MenuItem root = SearchResource.scanMenuTree(scanPath);
            menuService.updateMenu(appId, root);
            logger.info("更新菜单成功,菜单: " + JsonUtil.toJSONString(root));
            result = new RestResult<>(ApiCode.SUCCESS, "成功");
        } catch (Exception e) {
            logger.error("重新生成系统菜单错误, appId=" + appId, e);
            result = new RestResult<>(ApiCode.FAILURE, e.getMessage());
        }
    } else {
        result = new RestResult<>(ApiCode.FAILURE, "appId为空");
    }
    return result;
}
Also used : RestResult(com.ibeiliao.deployment.admin.common.RestResult) MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with MenuItem

use of com.ibeiliao.deployment.admin.utils.resource.MenuItem in project Corgi by kevinYin.

the class MenuController method autoClearMenuResource.

/**
 * 自动清除多余菜单/资源数据
 *
 * @param request
 * @return
 */
@ResponseBody
@RequestMapping("autoClearMenuResource.do")
public RestResult<Object> autoClearMenuResource(HttpServletRequest request) {
    int appId = getAppId(request);
    logger.info("将自动清除冗余菜单/资源, appId=" + appId);
    RestResult<Object> result = null;
    if (appId > 0) {
        String[] scanPath = getScanPath(appId);
        MenuItem root = SearchResource.scanMenuTree(scanPath);
        menuService.clearRedundantMenu(appId, root);
        result = new RestResult<>(ApiCode.SUCCESS, "执行成功.");
    } else {
        result = new RestResult<>(ApiCode.FAILURE, "appId为空");
    }
    return result;
}
Also used : MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with MenuItem

use of com.ibeiliao.deployment.admin.utils.resource.MenuItem in project Corgi by kevinYin.

the class MenuController method getRedundantMenuResource.

/**
 * 获取多余菜单/资源数据
 *
 * @param request
 * @return
 */
@ResponseBody
@RequestMapping("getRedundantMenuResource.do")
public RestResult<Map<String, Object>> getRedundantMenuResource(HttpServletRequest request) {
    int appId = getAppId(request);
    logger.info("将获取冗余菜单/资源, appId=" + appId);
    RestResult<Map<String, Object>> result = null;
    if (appId > 0) {
        String[] scanPath = getScanPath(appId);
        MenuItem root = SearchResource.scanMenuTree(scanPath);
        Map<String, Object> object = menuService.getRedundantMenu(appId, root);
        result = new RestResult<>(ApiCode.SUCCESS, "执行成功.", object);
    } else {
        result = new RestResult<>(ApiCode.FAILURE, "appId为空");
    }
    return result;
}
Also used : MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem) Map(java.util.Map) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with MenuItem

use of com.ibeiliao.deployment.admin.utils.resource.MenuItem in project Corgi by kevinYin.

the class MenuServiceImpl method mapResources.

/**
 * 获取类路径下类所包含的资源列表
 *
 * @param appId
 * @param root
 * @return
 */
private Map<String, Boolean> mapResources(int appId, MenuItem root) {
    Map<String, Boolean> map = new HashMap<>();
    List<MenuItem> children = root.getChildren();
    if (children == null || children.isEmpty()) {
        String key = appId + "_" + root.getUrl();
        map.put(key, Boolean.TRUE);
        return map;
    } else {
        for (MenuItem item : children) {
            Map<String, Boolean> childrenMap = mapResources(appId, item);
            map.putAll(childrenMap);
        }
        return map;
    }
}
Also used : MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem)

Example 10 with MenuItem

use of com.ibeiliao.deployment.admin.utils.resource.MenuItem in project Corgi by kevinYin.

the class MenuServiceImpl method mapMenus.

/**
 * 获取类路径下类所包含的菜单列表
 *
 * @param appId
 * @param root
 * @return
 */
private Map<String, Boolean> mapMenus(int appId, MenuItem root) {
    Map<String, Boolean> map = new HashMap<>();
    List<MenuItem> children = root.getChildren();
    if (children != null && !children.isEmpty()) {
        String key = appId + "_" + root.getName();
        map.put(key, Boolean.TRUE);
        for (MenuItem item : children) {
            Map<String, Boolean> childrenMap = mapMenus(appId, item);
            map.putAll(childrenMap);
        }
    }
    return map;
}
Also used : MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem)

Aggregations

MenuItem (com.ibeiliao.deployment.admin.utils.resource.MenuItem)13 MenuPO (com.ibeiliao.deployment.admin.po.account.MenuPO)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 RestResult (com.ibeiliao.deployment.admin.common.RestResult)1 UrlResourcePO (com.ibeiliao.deployment.admin.po.account.UrlResourcePO)1 MenuResource (com.ibeiliao.deployment.admin.utils.resource.MenuResource)1 AppDefine (com.ibeiliao.deployment.admin.vo.account.AppDefine)1 Role (com.ibeiliao.deployment.admin.vo.account.Role)1 RoleMenuRelation (com.ibeiliao.deployment.admin.vo.account.RoleMenuRelation)1 RoleResRelation (com.ibeiliao.deployment.admin.vo.account.RoleResRelation)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1