package lemon.web;

import javax.servlet.http.HttpSession;

import lemon.web.base.MMTAction;
import lemon.web.system.bean.Menu;
import lemon.web.system.bean.User;
import lemon.web.system.mapper.RoleMenuMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
/**
 * Manage index page, for redirect
 * 
 * @author lemon
 * @version 1.0
 * 
 */
@Controller
public class ManageIndexAction extends MMTAction {
	@Autowired
	private RoleMenuMapper roleMenuMapper;
	
	/**
	 * show manager home page
	 * @param first
	 * @param second
	 * @param session
	 * @return
	 */
	@RequestMapping("{first}/{second}")
	public String index(@PathVariable String first,
			@PathVariable String second, HttpSession session) {
		if(null == second || "".equals(second))
			sendNotFoundError();
		User user = (User) session.getAttribute(TOKEN);
		Menu activeMenu = roleMenuMapper.getMenuByRoleAndUrl(user.getRole_id(),
				first + "/" + second);
		if(null == activeMenu)
			sendNotFoundError();
		//跳转到视图
		String view = "redirect:../" + activeMenu.getMenuurl() + "/"
				+ DEFAULT_VIEW;
		return view;
	}
	
	/**
	 * show manage home page
	 * @param menu_L2 二级菜单
	 * @param session
	 * @return
	 */
	@RequestMapping("{menu_L2}")
	public String index(@PathVariable String menu_L2, HttpSession session) {
		User user = (User) session.getAttribute(TOKEN);
		//获取二级目录
		Menu secondMenu = roleMenuMapper.getMenuByRoleAndUrl(user.getRole_id(), menu_L2);
		if(null == secondMenu)
			sendNotFoundError();
		//获取三级目录
		Menu activeMenu = roleMenuMapper.getDefaultChild(secondMenu.getMenu_id(), user.getRole_id());
		if(null == activeMenu)
			sendNotFoundError();
		//跳转到视图
		String view = "redirect:../" + activeMenu.getMenuurl() + "/"
				+ DEFAULT_VIEW;
		return view;
	}

}

@@ -91,16 +91,46 @@
 ction;%0D%0A
+import lemon.web.global.MMT;%0D%0A
 import l
@@ -1253,38 +1253,53 @@
 iew = %22redirect:
-../
 %22 +
+ getManageRoot() +
  activeMenu.getM
@@ -1302,36 +1302,36 @@
 getMenuurl()
- + %22/%22
 %0D%0A%09%09%09%09
++ %22/%22 
 + DEFAULT_VI
@@ -1961,14 +1961,29 @@
 ect:
-../
 %22 +
+ getManageRoot() +
  act
@@ -2006,21 +2006,21 @@
 rl()
- + %22/%22
 %0D%0A%09%09%09%09+
+ %22/%22 +
  DEF
@@ -2050,14 +2050,124 @@
 ew;%0D%0A%09%7D%0D
+%0A%09%0D%0A%09/**%0D%0A%09 * %E8%8E%B7%E5%8F%96Manage%E6%A0%B9%E8%B7%AF%E5%BE%84%0D%0A%09 * @return%0D%0A%09 */%0D%0A%09private String getManageRoot()%7B%0D%0A%09%09return MMT.FILTER_ROOT;%0D%0A%09%7D%0D
 %0A%0D%0A%7D%0D%0A

修复redirect BUG。