Search in sources :

Example 1 with OperationLogDto

use of com.paascloud.core.annotation.OperationLogDto in project paascloud-master by paascloud.

the class LogAspect method handleLog.

private void handleLog(final JoinPoint joinPoint, final Object result) {
    final Date startTime = this.threadLocal.get();
    final Date endTime = new Date(System.currentTimeMillis());
    HttpServletRequest request = RequestUtil.getRequest();
    final UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
    String requestURI = request.getRequestURI();
    try {
        LogAnnotation relog = giveController(joinPoint);
        LoginAuthDto loginUser = RequestUtil.getLoginUser();
        if (relog == null) {
            return;
        }
        // 获取客户端操作系统
        final String os = userAgent.getOperatingSystem().getName();
        // 获取客户端浏览器
        final String browser = userAgent.getBrowser().getName();
        final String ipAddress = RequestUtil.getRemoteAddr(request);
        OperationLogDto operationLogDto = new OperationLogDto();
        operationLogDto.setClassName(joinPoint.getTarget().getClass().getName());
        operationLogDto.setMethodName(joinPoint.getSignature().getName());
        operationLogDto.setExcuteTime(endTime.getTime() - startTime.getTime());
        operationLogDto.setStartTime(startTime);
        operationLogDto.setEndTime(endTime);
        operationLogDto.setIp(ipAddress);
        operationLogDto.setOs(os);
        operationLogDto.setBrowser(browser);
        operationLogDto.setRequestUrl(requestURI);
        operationLogDto.setGroupId(loginUser.getGroupId());
        operationLogDto.setGroupName(loginUser.getGroupName());
        operationLogDto.setCreatedTime(new Date());
        operationLogDto.setCreator(loginUser.getUserName());
        operationLogDto.setCreatorId(loginUser.getUserId());
        operationLogDto.setLastOperator(loginUser.getUserName());
        operationLogDto.setLastOperatorId(loginUser.getUserId());
        operationLogDto.setLogType(relog.logType().getType());
        operationLogDto.setLogName(relog.logType().getName());
        getControllerMethodDescription(relog, operationLogDto, result, joinPoint);
        threadLocal.remove();
        taskExecutor.execute(() -> this.restTemplate.postForObject("http://paascloud-provider-uac/auth/saveLog", operationLogDto, Integer.class));
    } catch (Exception ex) {
        log.error("获取注解类出现异常={}", ex.getMessage(), ex);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LogAnnotation(com.paascloud.core.annotation.LogAnnotation) UserAgent(eu.bitwalker.useragentutils.UserAgent) LoginAuthDto(com.paascloud.base.dto.LoginAuthDto) OperationLogDto(com.paascloud.core.annotation.OperationLogDto) Date(java.util.Date)

Aggregations

LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)1 LogAnnotation (com.paascloud.core.annotation.LogAnnotation)1 OperationLogDto (com.paascloud.core.annotation.OperationLogDto)1 UserAgent (eu.bitwalker.useragentutils.UserAgent)1 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1