package cn.com.qmth.stmms.analysis.home;

import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.qmth.stmms.biz.campus.model.Campus;
import cn.com.qmth.stmms.biz.campus.service.CampusService;
import cn.com.qmth.stmms.biz.user.model.User;
import cn.com.qmth.stmms.common.domain.WebUser;
import cn.com.qmth.stmms.common.enums.Role;
import cn.com.qmth.stmms.common.session.model.StmmsSession;
import cn.com.qmth.stmms.common.utils.RequestUtils;

@Controller("analysisHomeController")
@RequestMapping("/analysis/home")
public class HomeController {

    @Autowired
    private CampusService campusService;

    @RequestMapping
    public ModelAndView index(HttpServletRequest request) {
        StmmsSession session = RequestUtils.getSession(request);
        RequestUtils.setSession(request, session);
        User user = RequestUtils.getWebUser(request).getUser();
        Set<Role> roles = user.getRoles();
        if (roles.contains(Role.SCHOOL_ADMIN)) {
            return new ModelAndView("redirect:/analysis/home/sch");
        } else if (roles.contains(Role.MASTER)) {
            return new ModelAndView("redirect:/analysis/home/cam");
        } else if (roles.contains(Role.HEAD_TEACHER)) {
            return new ModelAndView("redirect:/analysis/home/hea");
        } else if (roles.contains(Role.SUBJECT_TEACHER)) {
            return new ModelAndView("redirect:/analysis/home/tea");
        } else {
            return new ModelAndView("redirect:/analysis/home/stu");
        }
    }

    @RequestMapping("/dep")
    public ModelAndView dephome(HttpServletRequest request) {
        return new ModelAndView("analysis/department/home");
    }

    @RequestMapping("/hea")
    public ModelAndView heahome(HttpServletRequest request) {
        return new ModelAndView("analysis/headerteacher/home");
    }

    @RequestMapping("/sch")
    public ModelAndView schhome(HttpServletRequest request) {
        return new ModelAndView("analysis/school/home");
    }

    @RequestMapping("/tea")
    public ModelAndView teahome(HttpServletRequest request) {
        return new ModelAndView("analysis/teacher/home");
    }

    @RequestMapping("/stu")
    public ModelAndView stuhome(HttpServletRequest request) {
        return new ModelAndView("student/home");
    }

}
