增加配置

This commit is contained in:
GYJ 2025-03-06 15:34:07 +08:00
parent d5941e5ed0
commit 98e1b9a345
4 changed files with 39 additions and 27 deletions

View File

@ -4,12 +4,14 @@ import cn.hutool.core.thread.ThreadUtil;
import com.google.gson.Gson;
import com.sqx.common.utils.HttpContextUtils;
import com.sqx.common.utils.IPUtils;
import com.sqx.modules.common.service.CommonInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
@ -27,6 +29,9 @@ import javax.servlet.http.HttpServletRequest;
//@Profile({"dev"})
public class AppApiMethodAspect {
@Autowired
private CommonInfoService commonInfoService;
@Pointcut("!execution(public * (com.sqx.modules.sys.controller.SysLoginController).*(..)) " +
"&& execution(public * (com.sqx.modules.*.controller..*).*(..)))")
public void pkg() {
@ -50,31 +55,35 @@ public class AppApiMethodAspect {
// 执行被拦截的方法
Object result = pjp.proceed();
long end = System.currentTimeMillis();
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
String method = request.getMethod();
String requestUrl = request.getRequestURL().toString();
String requestIp = IPUtils.getIpAddr(request);
long useTime = end - start;
ThreadUtil.execAsync(() -> {
//请求的参数
String value = commonInfoService.findOne(933).getValue();
if ("1".equals(value)) {
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
String method = request.getMethod();
String requestUrl = request.getRequestURL().toString();
String requestIp = IPUtils.getIpAddr(request);
long useTime = end - start;
ThreadUtil.execAsync(() -> {
//请求的参数
// String resultJson = new Gson().toJson(result);
String resultJson = "1";
try {
if (StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)) {
log.info("\n>>>>>> {} {}" +
"\n>>>>>> IP: {} " +
"\n>>>>>> execute time:{}ms " +
"\n>>>>>> Request: {}" +
"\n>>>>>> Response: {}",
method, requestUrl, requestIp, useTime,
params,
resultJson
);
String resultJson = "1";
try {
if (StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)) {
log.info("\n>>>>>> {} {}" +
"\n>>>>>> IP: {} " +
"\n>>>>>> execute time:{}ms " +
"\n>>>>>> Request: {}" +
"\n>>>>>> Response: {}",
method, requestUrl, requestIp, useTime,
params,
resultJson
);
}
} catch (Exception e) {
log.error("Request 为空" + e.getMessage());
}
} catch (Exception e) {
log.error("Request 为空" + e.getMessage());
}
});
});
}
return result;
}
}

View File

@ -265,7 +265,10 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
log.info("操作过于频繁请稍后再试userId:{}", userId);
return Result.error("操作过于频繁,请稍后再试!");
}
redisService.setUserCanCreateOrder(userId);
long seconds = Long.parseLong(commonInfoService.findOne(934).getValue());
redisService.setUserCanCreateOrder(userId, seconds);
UserEntity userEntity = userService.getById(userId);
if (userEntity == null) {
throw new SqxException("用户不存在");

View File

@ -39,7 +39,7 @@ public interface RedisService {
* 设置用户上次创建订单时间
* @param userId 用户id
*/
void setUserCanCreateOrder(Long userId);
void setUserCanCreateOrder(Long userId, Long seconds);
/**
* 判断用户是否可以创建订单 30s 内只能创建一次订单

View File

@ -363,9 +363,9 @@ public class RedisServiceImpl implements RedisService {
}
@Override
public void setUserCanCreateOrder(Long userId) {
public void setUserCanCreateOrder(Long userId, Long seconds) {
String key = "user:canCreateOrder:" + userId;
redisTemplate.opsForValue().set(key, "1", 30, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(key, "1", seconds, TimeUnit.SECONDS);
}
@Override