| package com.doumee.api.web; | 
|   | 
| import com.doumee.core.Jwt.JwtTokenUtil; | 
| import com.doumee.core.constants.ResponseStatus; | 
| import com.doumee.core.exception.BusinessException; | 
| import com.doumee.dao.business.web.response.UserResponse; | 
| import com.doumee.service.business.MemberService; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.web.context.request.RequestContextHolder; | 
| import org.springframework.web.context.request.ServletRequestAttributes; | 
|   | 
| import javax.servlet.http.HttpServletRequest; | 
|   | 
| /** | 
|  * Controller基类 | 
|  * @author Eva.Caesar Liu | 
|  * @date 2022/03/15 09:54 | 
|  */ | 
| @Slf4j | 
| @Service | 
| public class ApiController { | 
|   | 
|     @Autowired | 
|     public MemberService memberService; | 
|   | 
|     /** | 
|      * 得到request对象 | 
|      * | 
|      * @return | 
|      */ | 
|     public HttpServletRequest getRequest() { | 
|         HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | 
|         return request; | 
|     } | 
|     /** | 
|      * 获取用户ID | 
|      * | 
|      * @return | 
|      */ | 
|     protected String getMemberId() { | 
|         Object obj = this.getRequest().getAttribute(JwtTokenUtil.UserId_Name); | 
|         return obj != null ? (String) obj : null; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获取登录用户对象信息 | 
|      * @return | 
|      */ | 
|     protected UserResponse getUserResponse(){ | 
|         Object obj = this.getRequest().getAttribute(JwtTokenUtil.UserId_Name); | 
|         if(obj != null){ | 
|             return memberService.getUserInfo((String) obj); | 
|         } | 
|         return null; | 
|     } | 
|   | 
| } |