|
|
|
@ -3,14 +3,16 @@ package com.logpm.factorydata.suofeiya.interceptor;
|
|
|
|
|
import cn.hutool.http.HttpRequest; |
|
|
|
|
import cn.hutool.http.HttpResponse; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.logpm.factorydata.suofeiya.wrapper.CustomHttpServletRequestWrapper; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.log4j.Log4j2; |
|
|
|
|
import org.springblade.common.cache.CacheNames; |
|
|
|
|
import org.springblade.common.component.MockLoginService; |
|
|
|
|
import org.springblade.common.constant.LauncherConstant; |
|
|
|
|
import org.springblade.common.exception.CustomerException; |
|
|
|
|
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper; |
|
|
|
|
import org.springblade.core.redis.cache.BladeRedis; |
|
|
|
|
import org.springblade.core.redis.lock.LockType; |
|
|
|
|
import org.springblade.core.redis.lock.RedisLockClient; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.ThreadLocalUtil; |
|
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
@ -26,6 +28,7 @@ import java.io.PrintWriter;
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
@Log4j2 |
|
|
|
|
@AllArgsConstructor |
|
|
|
@ -33,18 +36,26 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt
|
|
|
|
|
|
|
|
|
|
private final BladeRedis bladeRedis; |
|
|
|
|
private final Environment environment; |
|
|
|
|
private final RedisLockClient redisLockClient; |
|
|
|
|
private final MockLoginService mockLoginService; |
|
|
|
|
@Override |
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request); |
|
|
|
|
org.springblade.common.wrapper.CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request); |
|
|
|
|
String account ="shujutongbu"; |
|
|
|
|
JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); |
|
|
|
|
if(Objects.isNull(data)){ |
|
|
|
|
data = mockLoginService.mockToken("627683",account); |
|
|
|
|
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L); |
|
|
|
|
boolean flag = redisLockClient.tryLock("local_server_user", LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS); |
|
|
|
|
if(flag){ |
|
|
|
|
data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); |
|
|
|
|
if(Objects.isNull(data)){ |
|
|
|
|
data = mockLoginService.mockToken("627683",account); |
|
|
|
|
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,25919900L); |
|
|
|
|
redisLockClient.unLock("local_server_user", LockType.FAIR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 修改或添加header
|
|
|
|
|