package com.qianwen.core.excel.extend.aop;
|
|
import java.time.LocalDateTime;
|
import java.util.Objects;
|
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.reflect.MethodSignature;
|
import com.qianwen.core.excel.extend.annotation.ResponseExcel;
|
import com.qianwen.core.excel.extend.processor.NameProcessor;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.context.request.RequestAttributes;
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
@Aspect
|
/* loaded from: blade-starter-excel-9.3.0.0-SNAPSHOT.jar:org/springblade/core/excel/extend/aop/DynamicNameAspect.class */
|
public class DynamicNameAspect {
|
public static final String EXCEL_NAME_KEY = "__EXCEL_NAME_KEY__";
|
private final NameProcessor processor;
|
|
public DynamicNameAspect(final NameProcessor processor) {
|
this.processor = processor;
|
}
|
|
@Before("@annotation(excel)")
|
public void around(JoinPoint point, ResponseExcel excel) {
|
MethodSignature ms = (MethodSignature)point.getSignature();
|
String name = excel.name();
|
if (!StringUtils.hasText(name)) {
|
name = LocalDateTime.now().toString();
|
} else {
|
name = this.processor.doDetermineName(point.getArgs(), ms.getMethod(), excel.name());
|
}
|
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
|
((RequestAttributes) Objects.requireNonNull(requestAttributes)).setAttribute(EXCEL_NAME_KEY, name, 0);
|
}
|
}
|