|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.apache.ibatis.session.defaults.DefaultSqlSession; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.lang.reflect.Field; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | **/ | 
|---|
|  |  |  | @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 { | 
|---|
|  |  |  | MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0]; | 
|---|
|  |  |  | String sqlId = mappedStatement.getId(); | 
|---|
|  |  |  | log.info("----sqlId----" + sqlId); | 
|---|
|  |  |  | SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType(); | 
|---|
|  |  |  | log.info("-------------->{}", sqlCommandType); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Object parameter = invocation.getArgs()[1]; | 
|---|
|  |  |  | if (parameter == null) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void injectForInsert(Object o) { | 
|---|
|  |  |  | MemberEntity member = LoginUserUtils.getAppLoginUser(); | 
|---|
|  |  |  | MemberEntity member = LoginUserUtils.getUser(); | 
|---|
|  |  |  | if (o instanceof BaseEntity) { | 
|---|
|  |  |  | BaseEntity baseEntity = (BaseEntity) o; | 
|---|
|  |  |  | baseEntity.setCreateBy(member.getUsername()); | 
|---|
|  |  |  | baseEntity.setUpdateBy(member.getUsername()); | 
|---|
|  |  |  | if (member != null) { | 
|---|
|  |  |  | String by = member.getPhone() != null ? member.getPhone() : member.getEmail(); | 
|---|
|  |  |  | baseEntity.setCreateBy(by); | 
|---|
|  |  |  | baseEntity.setUpdateBy(by); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | baseEntity.setCreateBy(AppContants.SYSTEM_USER); | 
|---|
|  |  |  | baseEntity.setUpdateBy(AppContants.SYSTEM_USER); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | baseEntity.setCreateTime(new Date()); | 
|---|
|  |  |  | baseEntity.setUpdateTime(new Date()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void injectForUpdate(Object o) { | 
|---|
|  |  |  | MemberEntity member = LoginUserUtils.getAppLoginUser(); | 
|---|
|  |  |  | MemberEntity member = LoginUserUtils.getUser(); | 
|---|
|  |  |  | if (o instanceof BaseEntity) { | 
|---|
|  |  |  | BaseEntity baseEntity = (BaseEntity) o; | 
|---|
|  |  |  | baseEntity.setUpdateBy(member.getUsername()); | 
|---|
|  |  |  | if (member != null) { | 
|---|
|  |  |  | String by = member.getPhone() != null ? member.getPhone() : member.getEmail(); | 
|---|
|  |  |  | baseEntity.setUpdateBy(by); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | baseEntity.setUpdateBy(AppContants.SYSTEM_USER); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | baseEntity.setUpdateTime(new Date()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|