com.fhs.index.IndexAction Maven / Gradle / Ivy
The newest version!
package com.fhs.index;
import com.fhs.common.constant.Constant;
import com.fhs.common.utils.*;
import com.fhs.core.api.annotation.AutowareYLM;
import com.fhs.core.exception.BusinessException;
import com.fhs.core.log.LogDesc;
import com.fhs.core.result.HttpResult;
import com.fhs.redis.service.RedisCacheService;
import com.fhs.system.api.FeignlogAdminOperatorLogApiService;
import com.fhs.system.bean.LogAdminOperatorLogVo;
import com.fhs.ucenter.api.service.FeignSysUserApiService;
import com.fhs.ucenter.api.vo.SysUserVo;
import io.buji.pac4j.subject.Pac4jPrincipal;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
/**
* 首页请求action
*
* @Filename: IndexAction.java
* @Description:
* @Version: 1.0
* @Author: qixiaobo
* @Email: [email protected]
* @History:
* 陕西小伙伴网络科技有限公司
* Copyright (c) 2017 All Rights Reserved.
*
*/
@Controller
@AutowareYLM
public class IndexAction {
private static final Logger LOGGER = Logger.getLogger(IndexAction.class);
/** 后台用户feign服务 */
@AutowareYLM
private FeignSysUserApiService feignSysUserService;
@AutowareYLM
private FeignlogAdminOperatorLogApiService feignlogAdminOperatorLogApiService;
/**
* @desc redis service
*/
@Autowired
RedisCacheService redisCacheService;
@Value("${fhs.login.enable-cas}")
private boolean isEnableCas;
/**
* 初始化项目主页
* @return
*/
@RequestMapping("/")
public ModelAndView initIndex(HttpServletRequest request,HttpServletResponse response) throws IOException {
return index(request,response);
}
/**
* 判断用户是否登录及转发用户请求地址
* @param request
* @return
*/
@RequestMapping("/ms/index")
public ModelAndView index(HttpServletRequest request,HttpServletResponse response) throws IOException {
String serviceURL = null;
// session中的url不为空就取session中的
if(!CheckUtils.isNullOrEmpty(request.getSession().getAttribute("serviceURL")))
{
serviceURL = (String) request.getSession().getAttribute("serviceURL");
}
// 参数中的url不为空则取request的
else if(!CheckUtils.isNullOrEmpty(request.getParameter("serviceUrl")))
{
try {
serviceURL = URLDecoder.decode(request.getParameter("serviceUrl"),"UTF-8") ;
} catch (UnsupportedEncodingException e) {
LOGGER.error(this,e);
}
}
ModelAndView modelAndView = new ModelAndView();
// 如果有其他的进程已经放了用户,则直接302
if(request.getSession().getAttribute(Constant.SESSION_USER)!=null)
{
// 如果url为空则到子系统选择页面
if(serviceURL == null)
{
modelAndView.setViewName("page/ms/index/indexMenuLayui");
}else
{
modelAndView.setViewName("redirect:" + serviceURL);
}
return modelAndView;
}
// 获取登录名称
String userLoginName = null;
if(isEnableCas)
{
userLoginName = ((Pac4jPrincipal) SecurityUtils.getSubject().getPrincipal()).getProfile().getId();
}
else{
userLoginName = SecurityUtils.getSubject().getPrincipal().toString();
}
// 根据登录名称获取用户信息,并放入session
HttpResult result = feignSysUserService.getSysUserByName(userLoginName);
LOGGER.infoMsg("后端用户登录成功,用户信息:{}",result.getData());
if (result.getCode() == 200){
SysUserVo user = result.getData();
feignlogAdminOperatorLogApiService.addLogAdminOperatorLog(
LogAdminOperatorLogVo.builder().operatorId(user.getUserId()).url(request.getRequestURI())
.createTime(DateUtils.getCurrentDateStr(DateUtils.DATE_FULL_STR_SSS))
.networkIp(NetworkUtil.getIpAddress(request)).logType(LogDesc.OTHER).operatDesc("登录").reqParam("不可见").menuId(0).build());
if(user.getIsAdmin() == Constant.INT_TRUE)
{
request.getSession().setAttribute(Constant.SESSION_USER_DATA_PERMISSION, new HashMap<>());
request.getSession().setAttribute(Constant.SESSION_USER, user);
}
else
{
HttpResult
© 2015 - 2024 Weber Informatics LLC | Privacy Policy