public class BusinessEventLogger extends BaseServiceImpl implements ApplicationListener<BusinessEvent> {
private SessionRegistry sessionRegistry;
public void onApplicationEvent(BusinessEvent event) {
BusinessLogBean log = new BusinessLogBean();
log.setOperateAt(event.getIssueAt());
log.setOperation(StringUtils.defaultIfBlank(event.getDescription(), " "));
log.setResource(StringUtils.defaultIfBlank(event.getResource(), " "));
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (null == auth) return;
log.setOperator(auth.getName());
Object details = auth.getDetails();
if ((details instanceof WebAuthenticationDetails)) {
WebAuthenticationDetails webDetails = (WebAuthenticationDetails) details;
log.setIp(webDetails.getAgent().getIp());
log.setAgent(webDetails.getAgent().getOs() + " " + webDetails.getAgent().getBrowser());
log.setEntry(sessionRegistry.getResource(webDetails.getSessionId()));
}
if (null != event.getDetail()) {
log.setDetail(new BusinessLogDetailBean(log, event.getDetail()));
}
entityDao.saveOrUpdate(log);
}