package com.cm.common.plugin.oauth.controller.routes;

import com.cm.common.component.SecurityComponent;
import com.cm.common.config.properties.OauthProperties;
import com.cm.common.config.properties.SystemProperties;
import com.cm.common.exception.SearchException;
import com.cm.common.pojo.bos.UserInfoBO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ClassName: RouteController
 * @Description: 路由
 * @Author: WangGeng
 * @Date: 2019-06-24 22:16
 * @Version: 1.0
 **/
@Controller
public class RouteController {

    @Autowired
    private SecurityComponent securityComponent;
    @Autowired
    private OauthProperties oauthProperties;
    @Autowired
    private SystemProperties systemProperties;

    /**
     * 首页
     *
     * @return
     */
    @GetMapping("index")
    public ModelAndView goIndex() throws SearchException {
        ModelAndView mv = new ModelAndView("index");
        UserInfoBO userInfoBO = securityComponent.getCurrentUser();
        mv.addObject("userUsername", userInfoBO.getUserUsername());
        // 门户URL不存在，跳转统一用户
        if (StringUtils.isBlank(systemProperties.getPortalUrl())) {
            mv.addObject("oauthServer", oauthProperties.getOauthServer());
        } else {
            mv.addObject("oauthServer", systemProperties.getPortalUrl());
        }
        mv.addObject("url", systemProperties.getUrl());
        mv.addObject("ws", systemProperties.getWs());
        mv.addObject("title", systemProperties.getTitle());
        return mv;
    }

}
