| | |
| | | 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.executor.Executor; |
| | | import org.apache.ibatis.mapping.MappedStatement; |
| | |
| | | return invocation.proceed(); |
| | | } |
| | | |
| | | if (SqlCommandType.INSERT == sqlCommandType) { |
| | | if (parameter instanceof DefaultSqlSession.StrictMap) { |
| | | Map map = (Map) parameter; |
| | | List list = (List) map.get("list"); |
| | | for (Object o : list) { |
| | | injectForInsert(o); |
| | | } |
| | | } else { |
| | | injectForInsert(parameter); |
| | | } |
| | | } |
| | | |
| | | if (SqlCommandType.UPDATE == sqlCommandType) { |
| | | if (parameter instanceof DefaultSqlSession.StrictMap) { |
| | | Map map = (Map) parameter; |
| | | List list = (List) map.get("list"); |
| | | for (Object o : list) { |
| | | injectForUpdate(o); |
| | | } |
| | | } else { |
| | | injectForUpdate(parameter); |
| | | } |
| | | } |
| | | |
| | | return invocation.proceed(); |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | public void injectForInsert(Object o) { |
| | | MemberEntity member = LoginUserUtils.getUser(); |
| | | if (o instanceof BaseEntity) { |
| | | BaseEntity baseEntity = (BaseEntity) o; |
| | | 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.getUser(); |
| | | if (o instanceof BaseEntity) { |
| | | BaseEntity baseEntity = (BaseEntity) o; |
| | | 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()); |
| | | } |
| | | } |
| | | } |