| | |
| | | package com.ruoyi.framework.aspectj; |
| | | |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.dto.EquipmentLogDTO; |
| | | import com.ruoyi.common.core.domain.dto.OperLogDTO; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.service.EquipmentService; |
| | | import com.ruoyi.common.core.service.OperLogService; |
| | | import com.ruoyi.common.enums.BusinessStatus; |
| | | import com.ruoyi.common.enums.HttpMethod; |
| | | import com.ruoyi.common.enums.LogType; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | |
| | | |
| | | // *========数据库日志=========*// |
| | | OperLogDTO operLog = new OperLogDTO(); |
| | | // 联机日志 |
| | | EquipmentLogDTO equipmentLogDTO = new EquipmentLogDTO(); |
| | | |
| | | operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); |
| | | equipmentLogDTO.setStatus(BusinessStatus.SUCCESS.ordinal()); |
| | | |
| | | // 请求的地址 |
| | | String ip = ServletUtils.getClientIP(); |
| | | operLog.setOperIp(ip); |
| | | equipmentLogDTO.setIp(ip); |
| | | operLog.setOperUrl(ServletUtils.getRequest().getRequestURI()); |
| | | if (loginUser != null) { |
| | | operLog.setOperName(loginUser.getUsername()); |
| | | equipmentLogDTO.setUserName(loginUser.getUsername()); |
| | | } |
| | | |
| | | if (e != null) { |
| | | operLog.setStatus(BusinessStatus.FAIL.ordinal()); |
| | | operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); |
| | | |
| | | equipmentLogDTO.setStatus(BusinessStatus.FAIL.ordinal()); |
| | | equipmentLogDTO.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); |
| | | } |
| | | // 设置方法名称 |
| | | String className = joinPoint.getTarget().getClass().getName(); |
| | |
| | | operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); |
| | | // 处理设置注解上的参数 |
| | | getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); |
| | | if (LogType.SYS_LOG.ordinal() == controllerLog.type().ordinal()) { |
| | | // 保存数据库 |
| | | SpringUtils.getBean(OperLogService.class).recordOper(operLog); |
| | | } |
| | | if (LogType.EQUIPMENT_LOG.ordinal() == controllerLog.type().ordinal()) { |
| | | equipmentLogDTO.setOperation(controllerLog.operation().ordinal()); |
| | | // 保存数据库 |
| | | SpringUtils.getBean(EquipmentService.class).recordOper(equipmentLogDTO); |
| | | } |
| | | } catch (Exception exp) { |
| | | // 记录本地异常日志 |
| | | log.error("==前置通知异常=="); |