@Aspect
@Component
@Slf4j
public class AopLog {
@Autowired
private EmployeeActionLogService employeeActionLogService
;
@Autowired
EmployeeActionLogDAO employeeActionLogDAO
;
private List
<SensitivityOperation> sensitivityOperations
= null
;
@Pointcut("execution(public * com.i2shopping.i2work.operation.action.*.*Action.*(..))")
public void log() {
}
@Before("log()")
public void beforeLog(JoinPoint point
) throws Throwable
{
String name
= point
.getSignature().getDeclaringTypeName() + '.' + point
.getSignature().getName();
if (sensitivityOperations
== null
) {
sensitivityOperations
= employeeActionLogService
.getIntercepts();
}
SensitivityOperation operation
= sensitivityOperations
.stream().filter(sensitivityOperation
-> StringUtils
.equalsIgnoreCase(sensitivityOperation
.getOperation(), name
)).findFirst().orElse(new SensitivityOperation());
Boolean intercept
= operation
.getIntercept();
if (null
== intercept
|| !intercept
) {
return;
}
EmployeeActionLog employeeActionLog
= new EmployeeActionLog();
ServletRequestAttributes attributes
= (ServletRequestAttributes
) RequestContextHolder
.getRequestAttributes();
HttpServletRequest request
= Objects
.requireNonNull(attributes
).getRequest();
Date date
= new Date();
String nowTime
= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date
);
Timestamp start
= Timestamp
.valueOf(nowTime
);
employeeActionLog
.setOperationUrl(request
.getRequestURI());
employeeActionLog
.setTypeName(name
);
employeeActionLog
.setEmployeeId(onlineObject
.getEmployeeId());
employeeActionLog
.setEmployeeName(onlineObject
.getUserName());
employeeActionLog
.setOperationDate(start
);
employeeActionLog
.setOperation(operation
.getValue());
employeeActionLogService
.addNewAction(employeeActionLog
);
}
}