Commit 0b213877 by huluobin

美甲师登陆流程修改 线程变量保存登陆Seesion

parent 0208a765
......@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gogirl.infrastructure.interceptor.LogHandlerInterceptor;
import com.gogirl.infrastructure.interceptor.LoginHandlerInterceptor;
import com.gogirl.infrastructure.interceptor.SessionHandlerInterceptor;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -20,6 +21,7 @@ public class MvcInterceptorConfig extends WebMvcConfigurationSupport {
private final LoginHandlerInterceptor loginHandlerInterceptor;
private final LogHandlerInterceptor logHandlerInterceptor;
private final SessionHandlerInterceptor sessionHandlerInterceptor;
@Override
protected void addInterceptors(InterceptorRegistry registry) {
......@@ -28,7 +30,8 @@ public class MvcInterceptorConfig extends WebMvcConfigurationSupport {
/*addPathPatterns 用于添加拦截规则*/
/* **表示拦截所有请求*/
/*excludePathPatterns 用户排除拦截*/
registry.addInterceptor(loginHandlerInterceptor).addPathPatterns("/**")
registry.addInterceptor(loginHandlerInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**")
//登陆
.excludePathPatterns("/customer/xcx/login")
......@@ -67,6 +70,7 @@ public class MvcInterceptorConfig extends WebMvcConfigurationSupport {
;
registry.addInterceptor(logHandlerInterceptor);
registry.addInterceptor(sessionHandlerInterceptor);
super.addInterceptors(registry);
}
......
package com.gogirl.infrastructure.interceptor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gogirl.application.user.customer.CustomerService;
import com.gogirl.application.xcx.GogirlTokenService;
import com.gogirl.domain.store.store.StoreTechnician;
import com.gogirl.domain.user.Customer;
import com.gogirl.domain.xcx.GogirlToken;
import com.gogirl.infrastructure.mapper.store.StoreManageMapper;
import com.gogirl.infrastructure.mapper.store.StoreTechnicianMapper;
import com.gogirl.infrastructure.util.SessionUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
@AllArgsConstructor
@Slf4j
public class SessionHandlerInterceptor implements HandlerInterceptor {
private final GogirlTokenService gogirlTokenService;
private final CustomerService customerService;
private final StoreTechnicianMapper storeTechnicianMapper;
private final StoreManageMapper storeManageMapper;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String token = request.getHeader("token");
String sourceFrom = request.getHeader("sourceFrom");
if (sourceFrom == null) {
return true;
}
if (sourceFrom.equals("customer")) {
GogirlToken gogirlToken = gogirlTokenService.getOne(new LambdaQueryWrapper<GogirlToken>().eq(GogirlToken::getToken, token));
if (gogirlToken != null) {
Customer customer = customerService.getById(gogirlToken.getCustomerId());
SessionUtils.putCustomer(customer);
}
}
if (sourceFrom.equals("technician")) {
GogirlToken gogirlToken = gogirlTokenService.getByToken(token);
if (gogirlToken != null) {
StoreTechnician storeTechnician = storeTechnicianMapper.selectById(gogirlToken.getTechnicianId());
storeTechnician.setTechnicianId(storeTechnician.getId());
storeTechnician.setDepartmentId(gogirlToken.getDepartmentId());
SessionUtils.putStoreTechnician(storeTechnician);
}
}
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
SessionUtils.removeCustomer();
SessionUtils.removeStoreTechnician();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment