Search in sources :

Example 1 with LogDTO

use of org.jeecg.common.api.dto.LogDTO in project jeecg-boot by jeecgboot.

the class BaseCommonServiceImpl method addLog.

@Override
public void addLog(String logContent, Integer logType, Integer operatetype, LoginUser user) {
    LogDTO sysLog = new LogDTO();
    sysLog.setId(String.valueOf(IdWorker.getId()));
    // 注解上的描述,操作日志内容
    sysLog.setLogContent(logContent);
    sysLog.setLogType(logType);
    sysLog.setOperateType(operatetype);
    try {
        // 获取request
        HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
        // 设置IP地址
        sysLog.setIp(IPUtils.getIpAddr(request));
    } catch (Exception e) {
        sysLog.setIp("127.0.0.1");
    }
    // 获取登录用户信息
    if (user == null) {
        try {
            user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        } catch (Exception e) {
        // e.printStackTrace();
        }
    }
    if (user != null) {
        sysLog.setUserid(user.getUsername());
        sysLog.setUsername(user.getRealname());
    }
    sysLog.setCreateTime(new Date());
    // 保存日志(异常捕获处理,防止数据太大存储失败,导致业务失败)JT-238
    try {
        baseCommonMapper.saveLog(sysLog);
    } catch (Exception e) {
        log.warn(" LogContent length : " + sysLog.getLogContent().length());
        log.warn(e.getMessage());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LogDTO(org.jeecg.common.api.dto.LogDTO)

Example 2 with LogDTO

use of org.jeecg.common.api.dto.LogDTO in project kms by mahonelau.

the class AutoLogAspect method saveSysLog.

private void saveSysLog(ProceedingJoinPoint joinPoint, long time, Object obj) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    LogDTO dto = new LogDTO();
    AutoLog syslog = method.getAnnotation(AutoLog.class);
    if (syslog != null) {
        // update-begin-author:taoyan date:
        String content = syslog.value();
        if (syslog.module() == ModuleType.ONLINE) {
            content = getOnlineLogContent(obj, content);
        }
        // 注解上的描述,操作日志内容
        dto.setLogType(syslog.logType());
        dto.setLogContent(content);
    }
    // 请求的方法名
    String className = joinPoint.getTarget().getClass().getName();
    String methodName = signature.getName();
    dto.setMethod(className + "." + methodName + "()");
    // 设置操作类型
    if (dto.getLogType() == CommonConstant.LOG_TYPE_2) {
        dto.setOperateType(getOperateType(methodName, syslog.operateType()));
    }
    // 获取request
    HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
    // 请求的参数
    dto.setRequestParam(getReqestParams(request, joinPoint));
    // 设置IP地址
    dto.setIp(IPUtils.getIpAddr(request));
    // 获取登录用户信息
    LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    if (sysUser != null) {
        dto.setUserid(sysUser.getUsername());
        dto.setUsername(sysUser.getRealname());
    }
    // 耗时
    dto.setCostTime(time);
    dto.setCreateTime(new Date());
    // 保存系统日志
    baseCommonService.addLog(dto);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MethodSignature(org.aspectj.lang.reflect.MethodSignature) LogDTO(org.jeecg.common.api.dto.LogDTO) AutoLog(org.jeecg.common.aspect.annotation.AutoLog) Method(java.lang.reflect.Method) LoginUser(org.jeecg.common.system.vo.LoginUser) Date(java.util.Date)

Example 3 with LogDTO

use of org.jeecg.common.api.dto.LogDTO in project kykms by mahonelau.

the class BaseCommonServiceImpl method addLog.

@Override
public void addLog(String logContent, Integer logType, Integer operatetype, LoginUser user) {
    LogDTO sysLog = new LogDTO();
    sysLog.setId(String.valueOf(IdWorker.getId()));
    // 注解上的描述,操作日志内容
    sysLog.setLogContent(logContent);
    sysLog.setLogType(logType);
    sysLog.setOperateType(operatetype);
    try {
        // 获取request
        HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
        // 设置IP地址
        sysLog.setIp(IPUtils.getIpAddr(request));
    } catch (Exception e) {
        sysLog.setIp("127.0.0.1");
    }
    // 获取登录用户信息
    if (user == null) {
        try {
            user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        } catch (Exception e) {
        // e.printStackTrace();
        }
    }
    if (user != null) {
        sysLog.setUserid(user.getUsername());
        sysLog.setUsername(user.getRealname());
    }
    sysLog.setCreateTime(new Date());
    // 保存日志(异常捕获处理,防止数据太大存储失败,导致业务失败)JT-238
    try {
        baseCommonMapper.saveLog(sysLog);
    } catch (Exception e) {
        log.warn(" LogContent length : " + sysLog.getLogContent().length());
        log.warn(e.getMessage());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LogDTO(org.jeecg.common.api.dto.LogDTO)

Example 4 with LogDTO

use of org.jeecg.common.api.dto.LogDTO in project kykms by mahonelau.

the class AutoLogAspect method saveSysLog.

private void saveSysLog(ProceedingJoinPoint joinPoint, long time, Object obj) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    LogDTO dto = new LogDTO();
    AutoLog syslog = method.getAnnotation(AutoLog.class);
    if (syslog != null) {
        // update-begin-author:taoyan date:
        String content = syslog.value();
        if (syslog.module() == ModuleType.ONLINE) {
            content = getOnlineLogContent(obj, content);
        }
        // 注解上的描述,操作日志内容
        dto.setLogType(syslog.logType());
        dto.setLogContent(content);
    }
    // 请求的方法名
    String className = joinPoint.getTarget().getClass().getName();
    String methodName = signature.getName();
    dto.setMethod(className + "." + methodName + "()");
    // 设置操作类型
    if (dto.getLogType() == CommonConstant.LOG_TYPE_2) {
        dto.setOperateType(getOperateType(methodName, syslog.operateType()));
    }
    // 获取request
    HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
    // 请求的参数
    dto.setRequestParam(getReqestParams(request, joinPoint));
    // 设置IP地址
    dto.setIp(IPUtils.getIpAddr(request));
    // 获取登录用户信息
    LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    if (sysUser != null) {
        dto.setUserid(sysUser.getUsername());
        dto.setUsername(sysUser.getRealname());
    }
    // 耗时
    dto.setCostTime(time);
    dto.setCreateTime(new Date());
    // 保存系统日志
    baseCommonService.addLog(dto);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MethodSignature(org.aspectj.lang.reflect.MethodSignature) LogDTO(org.jeecg.common.api.dto.LogDTO) AutoLog(org.jeecg.common.aspect.annotation.AutoLog) Method(java.lang.reflect.Method) LoginUser(org.jeecg.common.system.vo.LoginUser) Date(java.util.Date)

Example 5 with LogDTO

use of org.jeecg.common.api.dto.LogDTO in project kms by mahonelau.

the class BaseCommonServiceImpl method addLog.

@Override
public void addLog(String logContent, Integer logType, Integer operatetype, LoginUser user) {
    LogDTO sysLog = new LogDTO();
    sysLog.setId(String.valueOf(IdWorker.getId()));
    // 注解上的描述,操作日志内容
    sysLog.setLogContent(logContent);
    sysLog.setLogType(logType);
    sysLog.setOperateType(operatetype);
    try {
        // 获取request
        HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
        // 设置IP地址
        sysLog.setIp(IPUtils.getIpAddr(request));
    } catch (Exception e) {
        sysLog.setIp("127.0.0.1");
    }
    // 获取登录用户信息
    if (user == null) {
        try {
            user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        } catch (Exception e) {
        // e.printStackTrace();
        }
    }
    if (user != null) {
        sysLog.setUserid(user.getUsername());
        sysLog.setUsername(user.getRealname());
    }
    sysLog.setCreateTime(new Date());
    // 保存日志(异常捕获处理,防止数据太大存储失败,导致业务失败)JT-238
    try {
        baseCommonMapper.saveLog(sysLog);
    } catch (Exception e) {
        log.warn(" LogContent length : " + sysLog.getLogContent().length());
        log.warn(e.getMessage());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LogDTO(org.jeecg.common.api.dto.LogDTO)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)6 LogDTO (org.jeecg.common.api.dto.LogDTO)6 Method (java.lang.reflect.Method)3 Date (java.util.Date)3 MethodSignature (org.aspectj.lang.reflect.MethodSignature)3 AutoLog (org.jeecg.common.aspect.annotation.AutoLog)3 LoginUser (org.jeecg.common.system.vo.LoginUser)3