Search in sources :

Example 1 with SysLog

use of com.company.project.entity.SysLog in project springboot-manager by aitangbao.

the class SysLogController method pageInfo.

@PostMapping("/logs")
@ApiOperation(value = "分页查询系统操作日志接口")
@LogAnnotation(title = "系统操作日志管理", action = "分页查询系统操作日志")
@RequiresPermissions("sys:log:list")
public DataResult pageInfo(@RequestBody SysLog vo) {
    Page page = new Page(vo.getPage(), vo.getLimit());
    LambdaQueryWrapper<SysLog> queryWrapper = Wrappers.lambdaQuery();
    if (!StringUtils.isEmpty(vo.getUsername())) {
        queryWrapper.like(SysLog::getUsername, vo.getUsername());
    }
    if (!StringUtils.isEmpty(vo.getOperation())) {
        queryWrapper.like(SysLog::getOperation, vo.getOperation());
    }
    if (!StringUtils.isEmpty(vo.getStartTime())) {
        queryWrapper.gt(SysLog::getCreateTime, vo.getStartTime());
    }
    if (!StringUtils.isEmpty(vo.getEndTime())) {
        queryWrapper.lt(SysLog::getCreateTime, vo.getEndTime());
    }
    queryWrapper.orderByDesc(SysLog::getCreateTime);
    return DataResult.success(logService.page(page, queryWrapper));
}
Also used : SysLog(com.company.project.entity.SysLog) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) LogAnnotation(com.company.project.common.aop.annotation.LogAnnotation) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with SysLog

use of com.company.project.entity.SysLog in project springboot-manager by aitangbao.

the class SysLogAspect method saveSysLog.

/**
 * 把日志保存
 */
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    SysLog sysLog = new SysLog();
    LogAnnotation logAnnotation = method.getAnnotation(LogAnnotation.class);
    if (logAnnotation != null) {
        // 注解上的描述
        sysLog.setOperation(logAnnotation.title() + "-" + logAnnotation.action());
    }
    // 请求的方法名
    String className = joinPoint.getTarget().getClass().getName();
    String methodName = signature.getName();
    sysLog.setMethod(className + "." + methodName + "()");
    log.info("请求{}.{}耗时{}毫秒", className, methodName, time);
    try {
        // 请求的参数
        Object[] args = joinPoint.getArgs();
        String params = null;
        if (args.length != 0) {
            params = JSON.toJSONString(args);
        }
        sysLog.setParams(params);
    } catch (Exception e) {
        log.error("sysLog,exception:{}", e, e);
    }
    // 获取request
    HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
    // 设置IP地址
    sysLog.setIp(IPUtils.getIpAddr(request));
    log.info("Ip{},接口地址{},请求方式{},入参:{}", sysLog.getIp(), request.getRequestURL(), request.getMethod(), sysLog.getParams());
    // 用户名
    String userId = httpSessionService.getCurrentUserId();
    String username = httpSessionService.getCurrentUsername();
    sysLog.setUsername(username);
    sysLog.setUserId(userId);
    sysLog.setTime((int) time);
    log.info(sysLog.toString());
    sysLogMapper.insert(sysLog);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LogAnnotation(com.company.project.common.aop.annotation.LogAnnotation) MethodSignature(org.aspectj.lang.reflect.MethodSignature) SysLog(com.company.project.entity.SysLog) Method(java.lang.reflect.Method)

Aggregations

LogAnnotation (com.company.project.common.aop.annotation.LogAnnotation)2 SysLog (com.company.project.entity.SysLog)2 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Method (java.lang.reflect.Method)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1