系统日志/业务日志
This commit is contained in:
parent
eadf29d27f
commit
ce8a3760e3
|
|
@ -15,10 +15,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -97,15 +94,11 @@ public class OperLogAspect {
|
|||
// 从获取RequestAttributes中获取HttpServletRequest的信息
|
||||
HttpServletRequest request = (HttpServletRequest) requestAttributes
|
||||
.resolveReference(RequestAttributes.REFERENCE_REQUEST);
|
||||
// HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
//获取注解
|
||||
Log aopLog = method.getAnnotation(Log.class);
|
||||
|
||||
|
||||
|
||||
SysLog sysLog = new SysLog();
|
||||
// 获取当前的用户
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
|
|
@ -119,54 +112,46 @@ public class OperLogAspect {
|
|||
sysLog.setOperUri(request.getRequestURI());
|
||||
//操作结果 成功/失败
|
||||
sysLog.setResult(BusinessStatus.SUCCESS.ordinal());
|
||||
sysLog.setTimes(time + "");
|
||||
// operLog.setOperUserAgent(CommonUtil.getUserAgent(request));
|
||||
sysLog.setTimes(time != null ? time + "" : null);
|
||||
// 请求的地址
|
||||
String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
|
||||
sysLog.setIp(ip);
|
||||
|
||||
// 返回参数
|
||||
// sysLog.setOperResponseParam(JSON.toJSONString(jsonResult));
|
||||
|
||||
// 设置方法名称
|
||||
String className = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
//设置请求方法名
|
||||
sysLog.setMethod(className + "." + methodName + "()");
|
||||
// 设置请求方式GET..
|
||||
// operLog.setRequestMethod(request.getMethod());
|
||||
// 处理设置注解上的参数
|
||||
getControllerMethodDescription(joinPoint, aopLog, sysLog);
|
||||
|
||||
//利用是否有异常定性记录失败信息
|
||||
if (e != null) {
|
||||
sysLog.setResult(BusinessStatus.FAIL.ordinal());//失败
|
||||
sysLog.setFailureReason(e.getClass().getName());
|
||||
//失败
|
||||
sysLog.setResult(BusinessStatus.FAIL.ordinal());
|
||||
System.err.println(e.getClass().getName());
|
||||
sysLog.setFailureReason(StringUtils.substring(e.getMessage(), 0, 2000));
|
||||
|
||||
// operLog.setErrorMsg(ThrowableUtil.getStackTrace(e));
|
||||
|
||||
log.error("耗时:{} 用户id:{} 用户名username: {} 请求ip:{} User-Agent:{} 方法路径:{} 方法参数:{}",
|
||||
sysLog.getTimes(),
|
||||
sysLog.getUserId(),
|
||||
sysLog.getOperaUserName(),
|
||||
sysLog.getIp(),
|
||||
// operLog.getOperUserAgent(),
|
||||
null,
|
||||
methodName,
|
||||
sysLog.getParams());
|
||||
log.error("==控制层方法通知异常==");
|
||||
log.error("异常信息:{}", e.getMessage());
|
||||
//e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
log.info(JSON.toJSONString(sysLog));
|
||||
// 保存数据库
|
||||
//可以借助异步持久化AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
|
||||
log.info("耗时:{} 用户id:{} 用户名username: {} 请求ip:{} User-Agent:{} 方法路径:{} 方法参数:{}",
|
||||
sysLog.getTimes(),
|
||||
sysLog.getUserId(),
|
||||
sysLog.getOperaUserName(),
|
||||
sysLog.getIp(),
|
||||
// sysLog.getOperUserAgent(),
|
||||
null,
|
||||
methodName,
|
||||
sysLog.getParams());
|
||||
asyncLogService.addSaveSysLog(sysLog);
|
||||
|
|
@ -192,7 +177,7 @@ public class OperLogAspect {
|
|||
sysLog.setOperType(log.grade().getInfo());
|
||||
sysLog.setOperateDetail(log.details());
|
||||
sysLog.setOperTime(DateTimeHelper.getNowTime());
|
||||
sysLog.setLogType(Objects.equals(log.type(),constantArr[0]) ? 1 : 0);
|
||||
sysLog.setLogType(Objects.equals(log.type(), constantArr[0]) ? 1 : 0);
|
||||
} else {
|
||||
//用于无注解的控制层方法 异常抛出 记录
|
||||
sysLog.setModel("未知模块");
|
||||
|
|
@ -265,18 +250,21 @@ public class OperLogAspect {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
//用于未定义log注解,抛出异常也需要记录耗时情况
|
||||
@Before("operExceptionLogPoinCut()")
|
||||
public void beforeMethod(JoinPoint joinPoint){
|
||||
/**
|
||||
* 用于未定义log注解,抛出异常也需要记录耗时情况
|
||||
* @param joinPoint
|
||||
* @description
|
||||
* @author cwchen
|
||||
* @date 2024/2/29 10:51
|
||||
*/
|
||||
@Before("operExceptionLogPointCut()")
|
||||
public void beforeMethod(JoinPoint joinPoint) {
|
||||
currentTime.set(System.currentTimeMillis());
|
||||
}
|
||||
@After("operExceptionLogPoinCut()")
|
||||
public void afterMethod(JoinPoint joinPoint){
|
||||
|
||||
@After("operExceptionLogPointCut()")
|
||||
public void afterMethod(JoinPoint joinPoint) {
|
||||
currentTime.remove();
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ public enum OperationType {
|
|||
UPDATE_SYS("修改系统数据"),
|
||||
DELETE_SYS("删除系统数据"),
|
||||
QUERY_SYS("查询系统数据"),
|
||||
RESET_USER_PWD("重置系统用户密码"),
|
||||
COPY_LOG("备份日志"),
|
||||
RETURN_LOG("恢复日志"),
|
||||
ERR_SYS("错误日志"),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.securitycontrol.system.base.controller;
|
||||
|
||||
import com.securitycontrol.common.core.exception.ServiceException;
|
||||
import com.securitycontrol.common.core.web.controller.BaseController;
|
||||
import com.securitycontrol.common.core.web.domain.AjaxResult;
|
||||
import com.securitycontrol.common.core.web.page.TableDataInfo;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.securitycontrol.system.base.controller;
|
|||
import com.securitycontrol.common.core.web.controller.BaseController;
|
||||
import com.securitycontrol.common.core.web.domain.AjaxResult;
|
||||
import com.securitycontrol.common.core.web.page.TableDataInfo;
|
||||
import com.securitycontrol.common.log.annotation.Log;
|
||||
import com.securitycontrol.common.log.enums.OperationType;
|
||||
import com.securitycontrol.entity.system.dto.UserDto;
|
||||
import com.securitycontrol.entity.system.vo.UserVo;
|
||||
import com.securitycontrol.system.base.service.IUserService;
|
||||
|
|
@ -35,12 +37,14 @@ public class UserController extends BaseController {
|
|||
|
||||
@ApiOperation(value = "新增用户")
|
||||
@PostMapping("addUser")
|
||||
@Log(title = "系统管理", menu = "系统管理->用户管理", grade = OperationType.ADD_SYS, details = "新增用户", type = "系统日志")
|
||||
public AjaxResult addUser(@RequestBody UserVo vo){
|
||||
return service.addOrUpdateUser(vo);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改用户")
|
||||
@PostMapping("editUser")
|
||||
@Log(title = "系统管理", menu = "系统管理->用户管理", grade = OperationType.UPDATE_SYS, details = "修改用户", type = "系统日志")
|
||||
public AjaxResult editUser(@RequestBody UserVo vo){
|
||||
return service.addOrUpdateUser(vo);
|
||||
}
|
||||
|
|
@ -53,12 +57,14 @@ public class UserController extends BaseController {
|
|||
|
||||
@ApiOperation(value = "删除用户")
|
||||
@PostMapping("delUser")
|
||||
@Log(title = "系统管理", menu = "系统管理->用户管理", grade = OperationType.DELETE_SYS, details = "删除用户", type = "系统日志")
|
||||
public AjaxResult delUser(UserDto dto){
|
||||
return service.delUser(dto);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "重置密码")
|
||||
@PostMapping("editPwd")
|
||||
@Log(title = "系统管理", menu = "系统管理->用户管理", grade = OperationType.RESET_USER_PWD, details = "重置密码", type = "系统日志")
|
||||
public AjaxResult editPwd(@RequestBody UserVo vo){
|
||||
return service.editPwd(vo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.securitycontrol.system.controller;
|
|||
|
||||
import com.securitycontrol.common.core.domain.Result;
|
||||
import com.securitycontrol.common.core.web.controller.BaseController;
|
||||
import com.securitycontrol.common.log.annotation.Log;
|
||||
import com.securitycontrol.common.log.enums.OperationType;
|
||||
import com.securitycontrol.entity.system.dto.DictDto;
|
||||
import com.securitycontrol.entity.system.vo.DictVo;
|
||||
import com.securitycontrol.system.service.DictService;
|
||||
|
|
@ -30,6 +32,7 @@ public class DictController extends BaseController {
|
|||
* @return
|
||||
*/
|
||||
@GetMapping("getDictList")
|
||||
@Log(title = "系统管理", menu = "系统管理->字典管理", grade = OperationType.QUERY_SYS, details = "查询字典", type = "系统日志")
|
||||
public Result<List<DictVo>> getDictList(@Valid DictDto dto) {
|
||||
return service.getDictList(dto);
|
||||
}
|
||||
|
|
@ -43,6 +46,7 @@ public class DictController extends BaseController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("addDict")
|
||||
@Log(title = "系统管理", menu = "系统管理->字典管理", grade = OperationType.ADD_SYS, details = "新增字典", type = "系统日志")
|
||||
public Result<String> addDict(@RequestBody @Valid DictVo dto) {
|
||||
return service.addDict(dto);
|
||||
}
|
||||
|
|
@ -54,6 +58,7 @@ public class DictController extends BaseController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("updateDict")
|
||||
@Log(title = "系统管理", menu = "系统管理->字典管理", grade = OperationType.UPDATE_SYS, details = "修改字典", type = "系统日志")
|
||||
public Result<String> updateDict(@RequestBody @Valid DictVo dto) {
|
||||
return service.updateDict(dto);
|
||||
}
|
||||
|
|
@ -65,6 +70,7 @@ public class DictController extends BaseController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("delDict")
|
||||
@Log(title = "系统管理", menu = "系统管理->字典管理", grade = OperationType.DELETE_SYS, details = "删除字典", type = "系统日志")
|
||||
public Result<String> delDict(@RequestBody DictDto dto) {
|
||||
return service.delDict(dto);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.securitycontrol.system.controller;
|
|||
import com.securitycontrol.common.core.domain.Result;
|
||||
import com.securitycontrol.common.core.web.controller.BaseController;
|
||||
import com.securitycontrol.common.core.web.page.TableDataInfo;
|
||||
import com.securitycontrol.common.log.annotation.Log;
|
||||
import com.securitycontrol.common.log.enums.OperationType;
|
||||
import com.securitycontrol.entity.system.dto.OrgDto;
|
||||
import com.securitycontrol.entity.system.vo.OrgVo;
|
||||
import com.securitycontrol.system.service.OrgService;
|
||||
|
|
@ -30,6 +32,7 @@ public class OrgController extends BaseController {
|
|||
* @return
|
||||
*/
|
||||
@GetMapping("getOrgList")
|
||||
@Log(title = "系统管理", menu = "系统管理->组织机构", grade = OperationType.QUERY_SYS, details = "查询组织机构", type = "系统日志")
|
||||
public Result<List<OrgVo>> getOrgList(@Valid OrgDto dto) {
|
||||
return service.getOrgList(dto);
|
||||
}
|
||||
|
|
@ -42,6 +45,7 @@ public class OrgController extends BaseController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("addOrg")
|
||||
@Log(title = "系统管理", menu = "系统管理->组织机构", grade = OperationType.ADD_SYS, details = "新增组织机构", type = "系统日志")
|
||||
public Result<String> addOrg(@RequestBody @Valid OrgVo dto) {
|
||||
return service.addOrg(dto);
|
||||
}
|
||||
|
|
@ -53,6 +57,7 @@ public class OrgController extends BaseController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("updateOrg")
|
||||
@Log(title = "系统管理", menu = "系统管理->组织机构", grade = OperationType.UPDATE_SYS, details = "修改组织机构", type = "系统日志")
|
||||
public Result<String> updateOrg(@RequestBody @Valid OrgVo dto) {
|
||||
return service.updateOrg(dto);
|
||||
}
|
||||
|
|
@ -64,6 +69,7 @@ public class OrgController extends BaseController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("delOrg")
|
||||
@Log(title = "系统管理", menu = "系统管理->组织机构", grade = OperationType.DELETE_SYS, details = "删除组织机构", type = "系统日志")
|
||||
public Result<String> delOrg(@RequestBody OrgDto dto) {
|
||||
return service.delOrg(dto);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue