Search in sources :

Example 1 with LogOperateDo

use of com.albedo.java.modules.sys.domain.LogOperateDo in project albedo by somowhere.

the class SysLogUtils method getSysLogOperate.

public LogOperateDo getSysLogOperate() {
    HttpServletRequest request = RequestHolder.getHttpServletRequest();
    LogOperateDo logOperateDo = new LogOperateDo();
    logOperateDo.setCreatedBy(getUserId());
    logOperateDo.setCreatedDate(LocalDateTime.now());
    logOperateDo.setUsername(getUsername());
    logOperateDo.setIpAddress(WebUtil.getIp(request));
    logOperateDo.setIpLocation(AddressUtil.getRegion(logOperateDo.getIpAddress()));
    logOperateDo.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT));
    UserAgent userAgent = UserAgentUtil.parse(logOperateDo.getUserAgent());
    logOperateDo.setBrowser(userAgent.getBrowser().getName());
    logOperateDo.setOs(userAgent.getOs().getName());
    logOperateDo.setRequestUri(URLUtil.getPath(request.getRequestURI()));
    return logOperateDo;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LogOperateDo(com.albedo.java.modules.sys.domain.LogOperateDo) UserAgent(cn.hutool.http.useragent.UserAgent)

Example 2 with LogOperateDo

use of com.albedo.java.modules.sys.domain.LogOperateDo in project albedo by somowhere.

the class LogOperateResource method download.

@LogOperate(value = "操作日志导出")
@GetMapping(value = "/download")
@PreAuthorize("@pms.hasPermission('sys_logOperate_export')")
public void download(LogOperateQueryCriteria logOperateQueryCriteria, HttpServletResponse response) {
    QueryWrapper wrapper = QueryWrapperUtil.getWrapper(logOperateQueryCriteria);
    ExcelUtil<LogOperateDo> util = new ExcelUtil(LogOperateDo.class);
    util.exportExcel(logOperateService.list(wrapper), "操作日志", response);
}
Also used : ExcelUtil(com.albedo.java.common.util.ExcelUtil) LogOperateDo(com.albedo.java.modules.sys.domain.LogOperateDo) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LogOperate(com.albedo.java.common.log.annotation.LogOperate) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with LogOperateDo

use of com.albedo.java.modules.sys.domain.LogOperateDo in project albedo by somowhere.

the class SysLogAspect method around.

@Around("@annotation(logOperate)")
@SneakyThrows
public Object around(ProceedingJoinPoint point, com.albedo.java.common.log.annotation.LogOperate logOperate) {
    MethodSignature signature = (MethodSignature) point.getSignature();
    String strClassName = point.getTarget().getClass().getName();
    String strMethodName = point.getSignature().getName();
    SysLogAspect.log.debug("[Class]:{},[Method]:{}", strClassName, strMethodName);
    // 方法路径
    String methodName = point.getTarget().getClass().getName() + StrPool.DOT + signature.getName() + "()";
    StringBuilder params = new StringBuilder("{");
    // 参数值
    Object[] argValues = point.getArgs();
    // 参数名称
    String[] argNames = ((MethodSignature) point.getSignature()).getParameterNames();
    if (argValues != null) {
        for (int i = 0; i < argValues.length; i++) {
            params.append(" ").append(argNames[i]).append(": ").append(argValues[i]);
        }
    }
    LogOperateDo logOperateDoVo = SysLogUtils.getSysLogOperate();
    logOperateDoVo.setTitle(logOperate.value());
    logOperateDoVo.setMethod(methodName);
    logOperateDoVo.setParams(params + " }");
    logOperateDoVo.setOperatorType(logOperate.operatorType().name());
    setDescription(point, logOperate, logOperateDoVo);
    Long startTime = System.currentTimeMillis();
    Object obj;
    try {
        obj = point.proceed();
        logOperateDoVo.setLogType(LogType.INFO.name());
    } catch (Exception e) {
        logOperateDoVo.setDescription(e.getMessage());
        if (e instanceof BizException) {
            logOperateDoVo.setLogType(LogType.WARN.name());
        } else {
            logOperateDoVo.setException(ExceptionUtil.stacktraceToString(e));
            logOperateDoVo.setLogType(LogType.ERROR.name());
        }
        throw e;
    } finally {
        saveLog(System.currentTimeMillis() - startTime, logOperateDoVo, logOperate);
    }
    return obj;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) LogOperateDo(com.albedo.java.modules.sys.domain.LogOperateDo) BizException(com.albedo.java.common.core.exception.BizException) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) BizException(com.albedo.java.common.core.exception.BizException) Around(org.aspectj.lang.annotation.Around) SneakyThrows(lombok.SneakyThrows)

Example 4 with LogOperateDo

use of com.albedo.java.modules.sys.domain.LogOperateDo in project albedo by somowhere.

the class SysLogOperateListener method saveSysLog.

@Async
@Order
@EventListener(SysLogOperateEvent.class)
public void saveSysLog(SysLogOperateEvent event) {
    LogOperateDo logOperateDo = (LogOperateDo) event.getSource();
    logOperateService.saveOrUpdate(logOperateDo);
}
Also used : LogOperateDo(com.albedo.java.modules.sys.domain.LogOperateDo) Order(org.springframework.core.annotation.Order) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Aggregations

LogOperateDo (com.albedo.java.modules.sys.domain.LogOperateDo)4 UserAgent (cn.hutool.http.useragent.UserAgent)1 BizException (com.albedo.java.common.core.exception.BizException)1 LogOperate (com.albedo.java.common.log.annotation.LogOperate)1 ExcelUtil (com.albedo.java.common.util.ExcelUtil)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SneakyThrows (lombok.SneakyThrows)1 JoinPoint (org.aspectj.lang.JoinPoint)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 Around (org.aspectj.lang.annotation.Around)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1 EventListener (org.springframework.context.event.EventListener)1 Order (org.springframework.core.annotation.Order)1 Async (org.springframework.scheduling.annotation.Async)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1