From 648c10dbb4224f7f7a9f5ab01b6957ddd3816658 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Mon, 18 May 2020 09:51:38 +0800 Subject: [PATCH] modify mybatis interceptor --- src/main/java/com/xcong/excoin/configurations/interceptor/MybatisInterceptor.java | 19 ++++++++++++++----- 1 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/xcong/excoin/configurations/interceptor/MybatisInterceptor.java b/src/main/java/com/xcong/excoin/configurations/interceptor/MybatisInterceptor.java index 144a8c0..b60a5a3 100644 --- a/src/main/java/com/xcong/excoin/configurations/interceptor/MybatisInterceptor.java +++ b/src/main/java/com/xcong/excoin/configurations/interceptor/MybatisInterceptor.java @@ -1,6 +1,7 @@ package com.xcong.excoin.configurations.interceptor; import com.xcong.excoin.common.LoginUserUtils; +import com.xcong.excoin.common.contants.AppContants; import com.xcong.excoin.common.system.base.BaseEntity; import com.xcong.excoin.modules.member.entity.MemberEntity; import lombok.extern.slf4j.Slf4j; @@ -11,7 +12,6 @@ import org.apache.ibatis.session.defaults.DefaultSqlSession; import org.springframework.stereotype.Component; -import java.lang.reflect.Field; import java.util.*; /** @@ -22,7 +22,7 @@ **/ @Slf4j @Component -@Intercepts({ @Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})}) +@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})}) public class MybatisInterceptor implements Interceptor { @Override public Object intercept(Invocation invocation) throws Throwable { @@ -78,8 +78,13 @@ MemberEntity member = LoginUserUtils.getAppLoginUser(); if (o instanceof BaseEntity) { BaseEntity baseEntity = (BaseEntity) o; - baseEntity.setCreateBy(member.getUsername()); - baseEntity.setUpdateBy(member.getUsername()); + if (member != null) { + baseEntity.setCreateBy(member.getUsername()); + baseEntity.setUpdateBy(member.getUsername()); + } else { + baseEntity.setCreateBy(AppContants.SYSTEM_USER); + baseEntity.setUpdateBy(AppContants.SYSTEM_USER); + } baseEntity.setCreateTime(new Date()); baseEntity.setUpdateTime(new Date()); } @@ -89,7 +94,11 @@ MemberEntity member = LoginUserUtils.getAppLoginUser(); if (o instanceof BaseEntity) { BaseEntity baseEntity = (BaseEntity) o; - baseEntity.setUpdateBy(member.getUsername()); + if (member != null) { + baseEntity.setUpdateBy(member.getUsername()); + } else { + baseEntity.setUpdateBy(AppContants.SYSTEM_USER); + } baseEntity.setUpdateTime(new Date()); } } -- Gitblit v1.9.1