展开全部
package com.tiamaes.gjds.dxp.aop;import java.util.Date;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Pointcut;import org.springframework.beans.factory.annotation.Autowired;import com.tiamaes.gjds.dxp.annotation.Task;import com.tiamaes.gjds.dxp.bean.TbScheduledExcuteLog;import com.tiamaes.gjds.dxp.repository.TbScheduledExcuteLogRepository;import com.tiamaes.gjds.dxp.task.DxpScheduled;/**
@Aspect
public class ScheduledStatisticsHandler {
@Autowired
private TbScheduledExcuteLogRepository tbScheduledExcuteLogRepository;
@Pointcut("@annotation(org.springframework.scheduling.annotation.Scheduled)")
public void proxyAspect() {
}
@Around("proxyAspect()")
public Object doInvoke(ProceedingJoinPoint joinPoint) throws Throwable{
Date date = new Date();
long start = System.currentTimeMillis();
Object result = joinPoint.proceed();
long end = System.currentTimeMillis();
Object target = joinPoint.getTarget();
TbScheduledExcuteLog log = new TbScheduledExcuteLog();
log.setClassName(joinPoint.getTarget().getClass().getName());
log.setConsum(end-start);
log.setExcuteDate(date);
log.setExcuteTime(date);
log.setIsError(false);
if (target instanceof DxpScheduled) {
DxpScheduled scheduled = (DxpScheduled) target;
Task task = scheduled.getClass().getAnnotation(Task.class);
log.setContentName(task.value());
log.setRemark(scheduled.getTaskExcuteInfo());
log.setGetRecCount(scheduled.getRemoteCount());
log.setSyncRecCount(scheduled.getSyncCount());
}
this.tbScheduledExcuteLogRepository.save(log);
return result;
}
}
这个并不难,主要是知道注入的位62616964757a686964616fe59b9ee7ad9431333363373665置