Merge branch 'test' into dev
This commit is contained in:
@@ -4,12 +4,14 @@ import cn.hutool.core.thread.ThreadUtil;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.sqx.common.utils.HttpContextUtils;
|
import com.sqx.common.utils.HttpContextUtils;
|
||||||
import com.sqx.common.utils.IPUtils;
|
import com.sqx.common.utils.IPUtils;
|
||||||
|
import com.sqx.modules.common.service.CommonInfoService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -27,6 +29,9 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
//@Profile({"dev"})
|
//@Profile({"dev"})
|
||||||
public class AppApiMethodAspect {
|
public class AppApiMethodAspect {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommonInfoService commonInfoService;
|
||||||
|
|
||||||
@Pointcut("!execution(public * (com.sqx.modules.sys.controller.SysLoginController).*(..)) " +
|
@Pointcut("!execution(public * (com.sqx.modules.sys.controller.SysLoginController).*(..)) " +
|
||||||
"&& execution(public * (com.sqx.modules.*.controller..*).*(..)))")
|
"&& execution(public * (com.sqx.modules.*.controller..*).*(..)))")
|
||||||
public void pkg() {
|
public void pkg() {
|
||||||
@@ -50,31 +55,35 @@ public class AppApiMethodAspect {
|
|||||||
// 执行被拦截的方法
|
// 执行被拦截的方法
|
||||||
Object result = pjp.proceed();
|
Object result = pjp.proceed();
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
String value = commonInfoService.findOne(933).getValue();
|
||||||
String method = request.getMethod();
|
if ("1".equals(value)) {
|
||||||
String requestUrl = request.getRequestURL().toString();
|
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
||||||
String requestIp = IPUtils.getIpAddr(request);
|
String method = request.getMethod();
|
||||||
long useTime = end - start;
|
String requestUrl = request.getRequestURL().toString();
|
||||||
ThreadUtil.execAsync(() -> {
|
String requestIp = IPUtils.getIpAddr(request);
|
||||||
//请求的参数
|
long useTime = end - start;
|
||||||
|
ThreadUtil.execAsync(() -> {
|
||||||
|
//请求的参数
|
||||||
// String resultJson = new Gson().toJson(result);
|
// String resultJson = new Gson().toJson(result);
|
||||||
String resultJson = "1";
|
String resultJson = "1";
|
||||||
try {
|
try {
|
||||||
if (StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)) {
|
if (StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)) {
|
||||||
log.info("\n>>>>>> {} {}" +
|
log.info("\n>>>>>> {} {}" +
|
||||||
"\n>>>>>> IP: {} " +
|
"\n>>>>>> IP: {} " +
|
||||||
"\n>>>>>> execute time:{}ms " +
|
"\n>>>>>> execute time:{}ms " +
|
||||||
"\n>>>>>> Request: {}" +
|
"\n>>>>>> Request: {}" +
|
||||||
"\n>>>>>> Response: {}",
|
"\n>>>>>> Response: {}",
|
||||||
method, requestUrl, requestIp, useTime,
|
method, requestUrl, requestIp, useTime,
|
||||||
params,
|
params,
|
||||||
resultJson
|
resultJson
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Request 为空" + e.getMessage());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
});
|
||||||
log.error("Request 为空" + e.getMessage());
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,7 +265,10 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
|||||||
log.info("操作过于频繁,请稍后再试!userId:{}", userId);
|
log.info("操作过于频繁,请稍后再试!userId:{}", userId);
|
||||||
return Result.error("操作过于频繁,请稍后再试!");
|
return Result.error("操作过于频繁,请稍后再试!");
|
||||||
}
|
}
|
||||||
redisService.setUserCanCreateOrder(userId);
|
|
||||||
|
long seconds = Long.parseLong(commonInfoService.findOne(934).getValue());
|
||||||
|
|
||||||
|
redisService.setUserCanCreateOrder(userId, seconds);
|
||||||
UserEntity userEntity = userService.getById(userId);
|
UserEntity userEntity = userService.getById(userId);
|
||||||
if (userEntity == null) {
|
if (userEntity == null) {
|
||||||
throw new SqxException("用户不存在");
|
throw new SqxException("用户不存在");
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public interface RedisService {
|
|||||||
* 设置用户上次创建订单时间
|
* 设置用户上次创建订单时间
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
*/
|
*/
|
||||||
void setUserCanCreateOrder(Long userId);
|
void setUserCanCreateOrder(Long userId, Long seconds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断用户是否可以创建订单 30s 内只能创建一次订单
|
* 判断用户是否可以创建订单 30s 内只能创建一次订单
|
||||||
|
|||||||
@@ -363,9 +363,9 @@ public class RedisServiceImpl implements RedisService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUserCanCreateOrder(Long userId) {
|
public void setUserCanCreateOrder(Long userId, Long seconds) {
|
||||||
String key = "user:canCreateOrder:" + userId;
|
String key = "user:canCreateOrder:" + userId;
|
||||||
redisTemplate.opsForValue().set(key, "1", 30, TimeUnit.SECONDS);
|
redisTemplate.opsForValue().set(key, "1", seconds, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class Tets {
|
|||||||
System.out.println("用户可以创建订单");
|
System.out.println("用户可以创建订单");
|
||||||
}
|
}
|
||||||
|
|
||||||
redisService.setUserCanCreateOrder(userId);
|
redisService.setUserCanCreateOrder(userId, 30L);
|
||||||
|
|
||||||
createOrder = redisService.getUserCanCreateOrder(userId);
|
createOrder = redisService.getUserCanCreateOrder(userId);
|
||||||
System.out.println(createOrder);
|
System.out.println(createOrder);
|
||||||
|
|||||||
Reference in New Issue
Block a user