mirror of
https://github.com/jeequan/jeepay
synced 2024-11-17 23:08:03 +08:00
日志输出优化、商户操作用户增加日志
This commit is contained in:
parent
0268fb97e0
commit
893297f6e5
@ -20,6 +20,7 @@ import com.jeequan.jeepay.core.aop.MethodLog;
|
||||
import com.jeequan.jeepay.core.beans.RequestKitBean;
|
||||
import com.jeequan.jeepay.core.constants.CS;
|
||||
import com.jeequan.jeepay.core.entity.SysLog;
|
||||
import com.jeequan.jeepay.core.exception.BizException;
|
||||
import com.jeequan.jeepay.core.model.security.JeeUserDetails;
|
||||
import com.jeequan.jeepay.service.impl.SysLogService;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
@ -83,17 +84,13 @@ public class MethodLogAop {
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
|
||||
final SysLog sysLog = new SysLog();
|
||||
// 基础日志信息
|
||||
setBaseLogInfo(point, sysLog);
|
||||
//处理切面任务 发生异常将向外抛出 不记录日志
|
||||
Object result = point.proceed();
|
||||
|
||||
try {
|
||||
sysLog.setUserId(JeeUserDetails.getCurrentUserDetails().getSysUser().getSysUserId());
|
||||
sysLog.setUserName(JeeUserDetails.getCurrentUserDetails().getSysUser().getRealname());
|
||||
sysLog.setSystem(JeeUserDetails.getCurrentUserDetails().getSysUser().getSystem());
|
||||
// 基础日志信息
|
||||
setBaseLogInfo(point, sysLog, JeeUserDetails.getCurrentUserDetails());
|
||||
sysLog.setOptResInfo(JSONObject.toJSON(result).toString());
|
||||
|
||||
scheduledThreadPool.execute(() -> sysLogService.save(sysLog));
|
||||
} catch (Exception e) {
|
||||
logger.error("methodLogError", e);
|
||||
@ -111,8 +108,8 @@ public class MethodLogAop {
|
||||
public void doException(JoinPoint joinPoint, Throwable e) throws Exception{
|
||||
final SysLog sysLog = new SysLog();
|
||||
// 基础日志信息
|
||||
setBaseLogInfo(joinPoint, sysLog);
|
||||
sysLog.setOptResInfo("请求异常");
|
||||
setBaseLogInfo(joinPoint, sysLog, JeeUserDetails.getCurrentUserDetails());
|
||||
sysLog.setOptResInfo(e instanceof BizException ? e.getMessage() : "请求异常");
|
||||
scheduledThreadPool.execute(() -> sysLogService.save(sysLog));
|
||||
}
|
||||
|
||||
@ -139,7 +136,7 @@ public class MethodLogAop {
|
||||
* @date: 2021/6/7 14:12
|
||||
* @describe: 日志基本信息 公共方法
|
||||
*/
|
||||
private void setBaseLogInfo(JoinPoint joinPoint, SysLog sysLog) throws Exception {
|
||||
private void setBaseLogInfo(JoinPoint joinPoint, SysLog sysLog, JeeUserDetails userDetails) throws Exception {
|
||||
// 使用point.getArgs()可获取request,仅限于spring MVC参数包含request,改为通过contextHolder获取。
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
|
||||
@ -159,6 +156,12 @@ public class MethodLogAop {
|
||||
sysLog.setUserIp(requestKitBean.getClientIp());
|
||||
sysLog.setCreatedAt(new Date());
|
||||
sysLog.setSystem(CS.SYS_TYPE.MGR);
|
||||
|
||||
if (userDetails != null) {
|
||||
sysLog.setUserId(JeeUserDetails.getCurrentUserDetails().getSysUser().getSysUserId());
|
||||
sysLog.setUserName(JeeUserDetails.getCurrentUserDetails().getSysUser().getRealname());
|
||||
sysLog.setSystem(JeeUserDetails.getCurrentUserDetails().getSysUser().getSystem());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import com.jeequan.jeepay.core.aop.MethodLog;
|
||||
import com.jeequan.jeepay.core.beans.RequestKitBean;
|
||||
import com.jeequan.jeepay.core.constants.CS;
|
||||
import com.jeequan.jeepay.core.entity.SysLog;
|
||||
import com.jeequan.jeepay.core.exception.BizException;
|
||||
import com.jeequan.jeepay.core.model.security.JeeUserDetails;
|
||||
import com.jeequan.jeepay.service.impl.SysLogService;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
@ -82,18 +83,14 @@ public class MethodLogAop{
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
|
||||
final SysLog sysLog = new SysLog();
|
||||
// 基础日志信息
|
||||
setBaseLogInfo(point, sysLog);
|
||||
|
||||
//处理切面任务 发生异常将向外抛出 不记录日志
|
||||
Object result = point.proceed();
|
||||
|
||||
try {
|
||||
sysLog.setUserId(JeeUserDetails.getCurrentUserDetails().getSysUser().getSysUserId());
|
||||
sysLog.setUserName(JeeUserDetails.getCurrentUserDetails().getSysUser().getRealname());
|
||||
sysLog.setSystem(JeeUserDetails.getCurrentUserDetails().getSysUser().getSystem());
|
||||
// 基础日志信息
|
||||
setBaseLogInfo(point, sysLog, JeeUserDetails.getCurrentUserDetails());
|
||||
sysLog.setOptResInfo(JSONObject.toJSON(result).toString());
|
||||
|
||||
scheduledThreadPool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -116,8 +113,8 @@ public class MethodLogAop{
|
||||
public void doException(JoinPoint joinPoint, Throwable e) throws Exception{
|
||||
final SysLog sysLog = new SysLog();
|
||||
// 基础日志信息
|
||||
setBaseLogInfo(joinPoint, sysLog);
|
||||
sysLog.setOptResInfo("请求异常");
|
||||
setBaseLogInfo(joinPoint, sysLog, JeeUserDetails.getCurrentUserDetails());
|
||||
sysLog.setOptResInfo(e instanceof BizException ? e.getMessage() : "请求异常");
|
||||
scheduledThreadPool.execute(() -> sysLogService.save(sysLog));
|
||||
}
|
||||
|
||||
@ -144,7 +141,7 @@ public class MethodLogAop{
|
||||
* @date: 2021/6/7 14:12
|
||||
* @describe: 日志基本信息 公共方法
|
||||
*/
|
||||
private void setBaseLogInfo(JoinPoint joinPoint, SysLog sysLog) throws Exception {
|
||||
private void setBaseLogInfo(JoinPoint joinPoint, SysLog sysLog, JeeUserDetails userDetails) throws Exception {
|
||||
// 使用point.getArgs()可获取request,仅限于spring MVC参数包含request,改为通过contextHolder获取。
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
|
||||
@ -164,6 +161,12 @@ public class MethodLogAop{
|
||||
sysLog.setUserIp(requestKitBean.getClientIp());
|
||||
sysLog.setCreatedAt(new Date());
|
||||
sysLog.setSystem(CS.SYS_TYPE.MCH);
|
||||
|
||||
if (userDetails != null) {
|
||||
sysLog.setUserId(JeeUserDetails.getCurrentUserDetails().getSysUser().getSysUserId());
|
||||
sysLog.setUserName(JeeUserDetails.getCurrentUserDetails().getSysUser().getRealname());
|
||||
sysLog.setSystem(JeeUserDetails.getCurrentUserDetails().getSysUser().getSystem());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ package com.jeequan.jeepay.mch.ctrl.sysuser;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.jeequan.jeepay.core.aop.MethodLog;
|
||||
import com.jeequan.jeepay.core.constants.ApiCodeEnum;
|
||||
import com.jeequan.jeepay.core.constants.CS;
|
||||
import com.jeequan.jeepay.core.entity.SysUser;
|
||||
@ -94,6 +95,7 @@ public class SysUserController extends CommonCtrl {
|
||||
/** add */
|
||||
@PreAuthorize("hasAuthority( 'ENT_UR_USER_ADD' )")
|
||||
@RequestMapping(value="", method = RequestMethod.POST)
|
||||
@MethodLog(remark = "添加管理员")
|
||||
public ApiRes add() {
|
||||
SysUser sysUser = getObject(SysUser.class);
|
||||
sysUser.setBelongInfoId(getCurrentUser().getSysUser().getBelongInfoId());
|
||||
@ -130,6 +132,7 @@ public class SysUserController extends CommonCtrl {
|
||||
/** update */
|
||||
@PreAuthorize("hasAuthority( 'ENT_UR_USER_EDIT' )")
|
||||
@RequestMapping(value="/{recordId}", method = RequestMethod.PUT)
|
||||
@MethodLog(remark = "修改操作员信息")
|
||||
public ApiRes update(@PathVariable("recordId") Long recordId) {
|
||||
SysUser sysUser = getObject(SysUser.class);
|
||||
sysUser.setSysUserId(recordId);
|
||||
|
Loading…
Reference in New Issue
Block a user