package cn.pluss.platform.controller.auth;

import cn.pluss.platform.entity.MenuInfo;
import cn.pluss.platform.shiro.UserService;
import cn.pluss.platform.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@Controller
@RequestMapping("auth")
public class AuthController {

    @Autowired
    private UserService userService;

    @Autowired
    private HttpServletRequest request;

    @RequestMapping(value = "/getPermissionMenusOnceAll", method = RequestMethod.POST)
    @ResponseBody
    public List<MenuInfo> getPermissionMenusOnceAll() {
        String token = request.getHeader("token");
        Object loginName = JwtUtils.get("loginName", token);
        List<MenuInfo> menus = userService.getPermissionNames(loginName.toString());
        return menus;
    }

    @RequestMapping(value = "/menuId", method = RequestMethod.POST)
    @ResponseBody
    public Integer menuId(){
        String link="/notification/index";
        int notificationMenuId = userService.getNotificationMenuId(link);
        return notificationMenuId;
    }

}
