/** * 设置拦截的路径和排除的路径 */ @Pointcut("@annotation(io.lenovo.clogistics.bms.common.util.TaskName)") public void pointCut() { } //通过环绕通知获取程序信息,用的是自定义注解命名每个定时器的名称,因为@Scheduled 不可以有返回值 @Around("pointCut()&&@annotation(taskName)") public void AroundAdvice1(ProceedingJoinPoint joinPoint, TaskName taskName) { CfTaskLogWriteVO cfTaskLog = new CfTaskLogWriteVO(); cfTaskLog.setBeginTime(new Date()); cfTaskLog.setName(taskName.name()); try { joinPoint.proceed(); cfTaskLog.setStatus(0); cfTaskLog.setRemark("程序正常"); cfTaskLog.setEndTime(new Date()); cfTaskLogService.insertCfTaskLog(cfTaskLog); } catch (Throwable e) { cfTaskLog.setStatus(1); cfTaskLog.setErr(e.getMessage()); cfTaskLog.setEndTime(new Date()); cfTaskLog.setRemark("程序运行异常"); cfTaskLogService.insertCfTaskLog(cfTaskLog); } }
//自定义注解
@Target({ ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface TaskName{ String name() default ""; }