package com.mrkj.yql.web;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.mrkj.ygl.entity.role.Sys_permissionTree;
import com.mrkj.ygl.entity.role.Sys_role;
import com.mrkj.ygl.entity.role.Sys_roleTree;
import com.mrkj.ygl.service.role.Sys_permissionService;
import com.mrkj.ygl.service.role.Sys_permissionTreeService;
import com.mrkj.ygl.service.role.Sys_roleService;
import com.mrkj.ygl.service.role.Sys_role_permissionService;

@Controller
@RequestMapping("role")
public class Sys_roleController {

	@Resource
	Sys_roleService roleService;
	
	@Resource
	Sys_role_permissionService sysRolPerService;
	
	@Resource
	Sys_permissionService perService;
	
	@Resource
	Sys_permissionTreeService perTreeService;
	
	@RequestMapping("getTree")
	@ResponseBody
//	@RequiresRoles(value = { "admin" },logical=Logical.OR)

public class Sys_roleController {
		response.setHeader("Content-type", "text/html;charset=UTF-8");
		
		List<Sys_roleTree> listRole = roleService.selectTreeAll();
		
		return listRole;
	}
	
	@RequestMapping("getTreeCheck")
	@ResponseBody
//	@RequiresRoles(value = { "admin" },logical=Logical.OR)
	public List<Sys_permissionTree> getTreeCheck(HttpServletRequest request,HttpServletResponse response,String roleName) {
		response.setHeader("Content-type", "text/html;charset=UTF-8");
		
		List<Sys_permissionTree> listPer = null;
		
		listPer = perTreeService.selectAll();
		
		return perTreeService.checked(listPer, roleName);
	}
	
	@RequestMapping("mainView")
//	@RequiresRoles(value = { "admin" },logical=Logical.OR)
	public ModelAndView getMainView (){
		ModelAndView mav = new ModelAndView();
		
		mav.setViewName("sys/role");
		
		return mav;
	}
	
	@RequestMapping("editView")
//	@RequiresRoles(value = { "admin" },logical=Logical.OR)
	public ModelAndView getEdit(HttpServletRequest request,HttpServletResponse response,Sys_role role) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("sys/role_per");
		mav.addObject("entity", role);
		/*List<Sys_role_permission> checked = sysRolPerService.selectByRoleName(role.getRoleName());
		if (checked!=null){
			mav.addObject("checked", checked);
		}*/
		return mav;
	}
	
		
		
		
		
		