Revert "将 DefaultParamHandler 从 config 包移动到 core/handle 包下 将 DefaultParamHandler 改名为 DefaultDBFieldHandler"

This reverts commit ce7947b1
This commit is contained in:
niudehua 2021-03-09 00:57:44 +08:00
parent 8612bde309
commit 311b6522d6
1 changed files with 4 additions and 15 deletions

View File

@ -1,31 +1,24 @@
package cn.iocoder.dashboard.framework.mybatis.core.handle; package cn.iocoder.dashboard.framework.mybatis.config;
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.dashboard.framework.security.core.LoginUser; import cn.iocoder.dashboard.framework.security.core.LoginUser;
import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject; import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
/** /**
* 通用参数填充实现类 * 通用参数填充实现类
* <p> *
* 如果没有显式的对通用参数进行赋值这里会对通用参数进行填充赋值 * 如果没有显式的对通用参数进行赋值这里会对通用参数进行填充赋值
* *
* @author hexiaowu * @author hexiaowu
*/ */
@Component @Component
@Slf4j public class DefaultParamHandler implements MetaObjectHandler {
public class DefaultDBFieldHandler implements MetaObjectHandler {
@Resource
SysUserService userService;
@Override @Override
public void insertFill(MetaObject metaObject) { public void insertFill(MetaObject metaObject) {
@ -55,11 +48,9 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
@Override @Override
public void updateFill(MetaObject metaObject) { public void updateFill(MetaObject metaObject) {
log.error("进来更新");
Object modifyTime = getFieldValByName("updateTime", metaObject); Object modifyTime = getFieldValByName("updateTime", metaObject);
Object modifier = getFieldValByName("updater", metaObject); Object modifier = getFieldValByName("updater", metaObject);
// 获取登录用户信息 // 获取登录用户信息
// TODO 获取不到 username
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
// 更新时间为空则以当前时间为更新时间 // 更新时间为空则以当前时间为更新时间
@ -68,9 +59,7 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
} }
// 当前登录用户不为空更新人为空则当前登录用户为更新人 // 当前登录用户不为空更新人为空则当前登录用户为更新人
if (Objects.nonNull(loginUser) && Objects.isNull(modifier)) { if (Objects.nonNull(loginUser) && Objects.isNull(modifier)) {
Long id = loginUser.getId(); setFieldValByName("updater", loginUser.getId(), metaObject);
SysUserDO user = userService.getUser(id);
setFieldValByName("updater", user.getUsername(), metaObject);
} }
} }
} }