yangys
2024-03-27 44c06e730b392ca2160a843cf54e221156a2b1a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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);
    }
}