|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.doumee.config.Jwt.JwtTokenUtil; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Member; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Users; | 
|---|
|  |  |  | import com.doumee.service.business.MemberService; | 
|---|
|  |  |  | import com.doumee.service.business.UsersService; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.poi.ss.formula.ptg.MemAreaPtg; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | public class ApiController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | UsersService usersService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | MemberService memberService; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 是否开发者 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Value("${debug_model}") | 
|---|
|  |  |  | private Boolean isDebug; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到request对象 | 
|---|
|  |  |  | 
|---|
|  |  |  | return request; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取用户ID | 
|---|
|  |  |  | * | 
|---|
|  |  |  | 
|---|
|  |  |  | Object obj = this.getRequest().getAttribute(JwtTokenUtil.UserId_Name); | 
|---|
|  |  |  | return obj != null ? (Long) obj : null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | protected Long getUserId() { | 
|---|
|  |  |  | if(isDebug){ | 
|---|
|  |  |  | return 2L; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Object obj = this.getRequest().getAttribute(JwtTokenUtil.UserId_Name); | 
|---|
|  |  |  | return obj != null ? (Long) obj : null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | protected Users getLoginUserInfo() { | 
|---|
|  |  |  | Long userId = getUserId(); | 
|---|
|  |  |  | if(userId== null){ | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Users user = usersService.findById(userId); | 
|---|
|  |  |  | return user; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | protected Member getLoginMemberInfo() { | 
|---|
|  |  |  | Long userId = getMemberId(); | 
|---|
|  |  |  | if(userId== null){ | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Member user = memberService.findById(userId); | 
|---|
|  |  |  | return user; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected Long getUserType() { | 
|---|
|  |  |  | Object obj = this.getRequest().getAttribute(JwtTokenUtil.UserType); | 
|---|
|  |  |  | return obj != null ? (Long) obj : null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|