请求日志打印
This commit is contained in:
@@ -1,17 +0,0 @@
|
|||||||
package cn.ysk.cashier.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.data.redis.connection.Message;
|
|
||||||
import org.springframework.data.redis.connection.MessageListener;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class RedisKeyExpirationListener implements MessageListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(Message message, byte[] pattern) {
|
|
||||||
String expiredKey = new String(message.getBody());
|
|
||||||
System.out.println("过期的Key为: " + expiredKey);
|
|
||||||
// 在这里添加处理键过期事件的逻辑
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -22,9 +22,14 @@ import org.springframework.context.ApplicationContext;
|
|||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jie
|
* @author Jie
|
||||||
@@ -153,4 +158,11 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
|
|||||||
return new ArrayList<>(Arrays.asList(applicationContext
|
return new ArrayList<>(Arrays.asList(applicationContext
|
||||||
.getBeanNamesForAnnotation(Service.class)));
|
.getBeanNamesForAnnotation(Service.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpringMvc下获取request
|
||||||
|
*/
|
||||||
|
public static HttpServletRequest getRequest() {
|
||||||
|
return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
package cn.ysk.cashier.config;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.utils.SpringContextHolder;
|
||||||
|
import cn.ysk.cashier.utils.StringUtils;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.Signature;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 方法调用统一切面处理
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class AppApiMethodAspect {
|
||||||
|
|
||||||
|
// @Pointcut("execution(public * cn.ysk.cashier.controller.*.*(..))")
|
||||||
|
@Pointcut("execution(public * (" +
|
||||||
|
"cn.ysk.cashier.controller.* " +
|
||||||
|
"|| cn.ysk.cashier.controller.*.* " +
|
||||||
|
"|| cn.ysk.cashier.mnt.rest.* " +
|
||||||
|
"|| cn.ysk.cashier.system.rest.* " +
|
||||||
|
"|| cn.ysk.cashier.config.security.rest.*" +
|
||||||
|
").*(..))")
|
||||||
|
public void pkg() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Around("pkg()")
|
||||||
|
// @SuppressWarnings("unchecked")
|
||||||
|
public Object around(ProceedingJoinPoint pjp) throws Throwable {
|
||||||
|
Object[] args = pjp.getArgs();
|
||||||
|
HttpServletRequest req = SpringContextHolder.getRequest();
|
||||||
|
Signature sign = pjp.getSignature();
|
||||||
|
MethodSignature ms = (MethodSignature) sign;
|
||||||
|
Object result;
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 设置忽略空值
|
||||||
|
try {
|
||||||
|
// 执行被拦截的方法
|
||||||
|
result = pjp.proceed();
|
||||||
|
ResponseEntity<?> responseEntity = (ResponseEntity<?>) result;
|
||||||
|
Object responseBody = responseEntity.getBody();
|
||||||
|
log.info("\n>>>>>>{} {}\n>>>>>>{}\n>>>>>>Request: {}\n>>>>>>Response: {}"
|
||||||
|
, req.getMethod(), req.getRequestURL(), req.getRemoteAddr(),
|
||||||
|
mapper.writeValueAsString(args),
|
||||||
|
mapper.writeValueAsString(responseBody)
|
||||||
|
);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
result = getReturnObject(ms.getReturnType(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
log.warn("{}", e);
|
||||||
|
log.error("\n>>>>>>{} {}\n>>>>>> {}\n>>>>>>Request: {}\n>>>>>>Exception: {}"
|
||||||
|
, req.getMethod(),
|
||||||
|
req.getRequestURL(),
|
||||||
|
req.getRemoteAddr(),
|
||||||
|
mapper.writeValueAsString(args),
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 反射封装方法的返回值
|
||||||
|
*
|
||||||
|
* @param clz 方法返回值的字节码对象
|
||||||
|
* @param _enum 错误信息
|
||||||
|
* @param <T> 返回值类型
|
||||||
|
* @return 返回原方法的返回对象
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("SameParameterValue") // 忽略枚举只传入了一个值的异常
|
||||||
|
private <T> T getReturnObject(Class<T> clz, HttpStatus _enum) {
|
||||||
|
if (clz.getName().equals("void")) { //没有返回值时
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
T t = null;
|
||||||
|
try {
|
||||||
|
t = clz.newInstance();
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
log.warn("{}", e);
|
||||||
|
}
|
||||||
|
//设置错误码
|
||||||
|
setFiledValue("code", _enum.value(), t);
|
||||||
|
//设置错误信息
|
||||||
|
setFiledValue("message", _enum.getReasonPhrase(), t);
|
||||||
|
return t;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用setXX方法设置属性
|
||||||
|
*
|
||||||
|
* @param fileName 方法名
|
||||||
|
* @param value 方法值
|
||||||
|
* @param obj 返回对象
|
||||||
|
*/
|
||||||
|
private void setFiledValue(String fileName, Object value, Object obj) {
|
||||||
|
//该方式找不到对应字段不会报错
|
||||||
|
if (StringUtils.isBlank(fileName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//转成SetXXX方法名
|
||||||
|
char[] chars = fileName.toCharArray();
|
||||||
|
chars[0] = (char) (chars[0] - 32); //首字母转大写
|
||||||
|
//拼接成方法名
|
||||||
|
String methodName = "set" + String.copyValueOf(chars);
|
||||||
|
Class<?> clz = obj.getClass();
|
||||||
|
Method[] declaredMethods = clz.getMethods();
|
||||||
|
for (Method method : declaredMethods) {
|
||||||
|
boolean equals = method.getName().equals(methodName);
|
||||||
|
if (equals) {
|
||||||
|
try {
|
||||||
|
method.invoke(obj, value);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
log.warn("{}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
package cn.ysk.cashier.dto.order;
|
package cn.ysk.cashier.dto.order;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import java.math.BigDecimal;
|
import java.util.List;
|
||||||
|
|
||||||
import cn.ysk.cashier.annotation.Query;
|
import cn.ysk.cashier.annotation.Query;
|
||||||
|
|
||||||
@@ -36,14 +36,6 @@ public class TbOrderInfoQueryCriteria{
|
|||||||
@Query
|
@Query
|
||||||
private String orderNo;
|
private String orderNo;
|
||||||
|
|
||||||
/** 精确 */
|
|
||||||
@Query
|
|
||||||
private BigDecimal productAmount;
|
|
||||||
|
|
||||||
/** 精确 */
|
|
||||||
@Query
|
|
||||||
private BigDecimal payAmount;
|
|
||||||
|
|
||||||
/** 精确 */
|
/** 精确 */
|
||||||
@Query
|
@Query
|
||||||
private String sendType;
|
private String sendType;
|
||||||
@@ -55,24 +47,7 @@ public class TbOrderInfoQueryCriteria{
|
|||||||
/** 精确 */
|
/** 精确 */
|
||||||
@Query
|
@Query
|
||||||
private String shopId;
|
private String shopId;
|
||||||
|
/** BETWEEN */
|
||||||
/** 精确 */
|
@Query(type = Query.Type.BETWEEN)
|
||||||
@Query
|
private List<Long> createdAt;
|
||||||
private String memberId;
|
|
||||||
|
|
||||||
/** 精确 */
|
|
||||||
@Query
|
|
||||||
private String userId;
|
|
||||||
|
|
||||||
/** 精确 */
|
|
||||||
@Query
|
|
||||||
private Long paidTime;
|
|
||||||
|
|
||||||
/** 精确 */
|
|
||||||
@Query
|
|
||||||
private Long createdAt;
|
|
||||||
|
|
||||||
/** 精确 */
|
|
||||||
@Query
|
|
||||||
private Integer isAccepted;
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user