| | |
| | | package com.java110.console.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.exception.NoAuthorityException; |
| | | import com.java110.common.exception.SMOException; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.console.smo.IConsoleServiceSMO; |
| | | import com.java110.core.base.controller.BaseController; |
| | | import com.java110.entity.service.PageData; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.Model; |
| | |
| | | @Controller |
| | | public class ConsoleController extends BaseController { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(ConsoleController.class); |
| | | |
| | | |
| | | @Autowired |
| | | private IConsoleServiceSMO consoleServiceSMOImpl; |
| | | |
| | |
| | | PageData pd = this.getPageData(request); |
| | | // 判断用户是否登录 |
| | | checkLogin(pd); |
| | | model.addAttribute("templateName","控制中心首页"); |
| | | //2.0 查询菜单信息 |
| | | List<Map> menuItems = consoleServiceSMOImpl.getMenuItemsByManageId(pd.getUserId()); |
| | | List<Map> removeMenuItems = new ArrayList<Map>(); |
| | | for(Map menuItem : menuItems){ |
| | | if(!"-1".equals(menuItem.get("parentId")) && !"1".equals(menuItem.get("level"))){ |
| | | Map parentMenuItem = this.getMenuItemFromList(menuItems,menuItem.get("parentId").toString()); |
| | | if(parentMenuItem == null){ |
| | | continue; |
| | | } |
| | | if(parentMenuItem.containsKey("subMenus")){ |
| | | List<Map> subMenus = (List<Map>) parentMenuItem.get("subMenus"); |
| | | subMenus.add(menuItem); |
| | | }else{ |
| | | List<Map> subMenus = new ArrayList<Map>(); |
| | | subMenus.add(menuItem); |
| | | parentMenuItem.put("subMenus",subMenus); |
| | | } |
| | | |
| | | removeMenuItems.add(menuItem); |
| | | } |
| | | } |
| | | |
| | | removeMap(menuItems,removeMenuItems); |
| | | model.addAttribute("menus",menuItems); |
| | | getMenus(model,pd,consoleServiceSMOImpl.getMenuItemsByManageId(pd.getUserId())); |
| | | //3.0 查询各个系统调用量 |
| | | }catch (NoAuthorityException e){ |
| | | //跳转到登录页面 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询数据 |
| | | * @param model |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @RequestMapping(path = "/console/list") |
| | | public String listData(Model model, HttpServletRequest request){ |
| | | String template = ""; |
| | | try { |
| | | |
| | | private Map getMenuItemFromList(List<Map> menuItems,String parentId){ |
| | | for(Map menuItem : menuItems){ |
| | | if(menuItem.get("mId").toString().equals(parentId)){ |
| | | return menuItem; |
| | | } |
| | | //1.0 获取对象 |
| | | PageData pd = this.getPageData(request); |
| | | |
| | | Assert.hasLength(pd.getParam().getString("templateCode"),"请求参数templateCode 不能为空!"); |
| | | // 判断用户是否登录 |
| | | checkLogin(pd); |
| | | //2.0 查询模板信息 |
| | | checkTemplate(pd,model); |
| | | //3.0 查询菜单信息 |
| | | getMenus(model,pd,consoleServiceSMOImpl.getMenuItemsByManageId(pd.getUserId())); |
| | | //3.0 查询各个系统调用量 |
| | | |
| | | template = pd.getData().getJSONObject("template").containsKey("htmlName") |
| | | && !StringUtil.isNullOrNone( pd.getData().getJSONObject("template").getString("htmlName")) ? |
| | | pd.getData().getJSONObject("template").getString("htmlName"): |
| | | "list_template"; |
| | | |
| | | }catch (NoAuthorityException e){ |
| | | //跳转到登录页面 |
| | | template = "redirect:/login"; |
| | | }catch (IllegalArgumentException e){ |
| | | template = "redirect:/system/error"; |
| | | }catch (SMOException e){ |
| | | template = "redirect:/system/error"; |
| | | }catch (Exception e){ |
| | | logger.error("系统异常:",e); |
| | | template = "redirect:/system/error"; |
| | | }finally { |
| | | return template; |
| | | } |
| | | return null; |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除map |
| | | * @param menuItems |
| | | * @param removeMenuItems |
| | | * 模板校验并将模板写入到 model 对象中 前台页面展示用 |
| | | * @param pd |
| | | * @param model |
| | | */ |
| | | private void removeMap(List<Map> menuItems,List<Map> removeMenuItems){ |
| | | if(removeMenuItems == null || removeMenuItems.size() == 0){ |
| | | return; |
| | | private void checkTemplate(PageData pd,Model model) throws IllegalArgumentException{ |
| | | try { |
| | | consoleServiceSMOImpl.getTemplate(pd); |
| | | JSONObject template = pd.getData().getJSONObject("template"); |
| | | model.addAttribute("templateCode",template.getString("templateCode")); |
| | | model.addAttribute("templateName",template.getString("templateName")); |
| | | }catch (Exception e){ |
| | | logger.error("查询异常",e); |
| | | throw new IllegalArgumentException("配置错误,没有当前模板【"+pd.getParam().getString("templateCode")+"】"); |
| | | } |
| | | |
| | | for(Map removeMenuItem : removeMenuItems){ |
| | | menuItems.remove(removeMenuItem); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public IConsoleServiceSMO getConsoleServiceSMOImpl() { |
| | | return consoleServiceSMOImpl; |
| | | } |