地质所 沉降监测网建设项目
zmk
2024-05-16 9d3b2a2265997d65e75f85f41e2c639f617ea35e
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.javaweb.applicationEvent;
 
import com.javaweb.common.utils.ServletUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
 
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
 
/**
 * 触发系统事件切面
 *
 * 利用apo触发系统事件相比在系统事件发生时触发系统事件降低了代码耦合度。避免代码入侵。
 */
@Aspect
@EnableAspectJAutoProxy(proxyTargetClass = false)
public class ApplicationEventAspect {
    private  Logger logger = LoggerFactory.getLogger(getClass());
 
    ApplicationEventManager applicationEventManager;
 
    public void setApplicationEventManager(ApplicationEventManager applicationEventManager) {
        this.applicationEventManager = applicationEventManager;
    }
 
    @Pointcut("execution(* com.javaweb.web.controller.system.SysLoginController.ajaxLogin(..))")
    public void afterLoginPointcut() {
    }
 
    @Pointcut("execution(* com.javaweb.quartz.controller.SysJobController.run(..))")
    public void onSchedulerExecutedByHandPointcut() {
    }
    /**
     * 用户登录后切点
     * @param point
     */
    @After("afterLoginPointcut()")
    public void afterLogin(JoinPoint point) {
        String className = point.getTarget().getClass().getName();
        String method = point.getSignature().getName();
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        Map paramMap= ServletUtils.getMap(request);
        applicationEventManager.trigger(ApplicationEventDefined.ON_AFTER_LOGIN,className+"."+method,paramMap);//触发系统定义事件
    }
 
    /**
     * 手工触发定时任务
     * @param point
     */
    @After("onSchedulerExecutedByHandPointcut()")
    public void onSchedulerExecutedByHand(JoinPoint point) {
        String className = point.getTarget().getClass().getName();
        String method = point.getSignature().getName();
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        Map paramMap= ServletUtils.getMap(request);
        applicationEventManager.trigger(ApplicationEventDefined.ON_SCHEDULER_EXECUTED_BY_HAND,className+"."+method,paramMap);
    }
 
}