mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-03 19:16:07 +00:00
@@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.dromara.common.core.factory.YmlPropertySourceFactory;
|
||||
import org.dromara.common.mybatis.handler.CreateAndUpdateMetaObjectHandler;
|
||||
import org.dromara.common.mybatis.handler.InjectionMetaObjectHandler;
|
||||
import org.dromara.common.mybatis.interceptor.PlusDataPermissionInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
@@ -71,7 +71,7 @@ public class MybatisPlusConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
public MetaObjectHandler metaObjectHandler() {
|
||||
return new CreateAndUpdateMetaObjectHandler();
|
||||
return new InjectionMetaObjectHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -18,7 +18,7 @@ import java.util.Date;
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
|
||||
public class InjectionMetaObjectHandler implements MetaObjectHandler {
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
@@ -30,14 +30,16 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
|
||||
baseEntity.setCreateTime(current);
|
||||
baseEntity.setUpdateTime(current);
|
||||
LoginUser loginUser = getLoginUser();
|
||||
Long userId = ObjectUtil.isNotNull(baseEntity.getCreateBy())
|
||||
? baseEntity.getCreateBy() : loginUser.getUserId();
|
||||
// 当前已登录 且 创建人为空 则填充
|
||||
baseEntity.setCreateBy(userId);
|
||||
// 当前已登录 且 更新人为空 则填充
|
||||
baseEntity.setUpdateBy(userId);
|
||||
baseEntity.setCreateDept(ObjectUtil.isNotNull(baseEntity.getCreateDept())
|
||||
? baseEntity.getCreateDept() : loginUser.getDeptId());
|
||||
if (ObjectUtil.isNotNull(loginUser)) {
|
||||
Long userId = ObjectUtil.isNotNull(baseEntity.getCreateBy())
|
||||
? baseEntity.getCreateBy() : loginUser.getUserId();
|
||||
// 当前已登录 且 创建人为空 则填充
|
||||
baseEntity.setCreateBy(userId);
|
||||
// 当前已登录 且 更新人为空 则填充
|
||||
baseEntity.setUpdateBy(userId);
|
||||
baseEntity.setCreateDept(ObjectUtil.isNotNull(baseEntity.getCreateDept())
|
||||
? baseEntity.getCreateDept() : loginUser.getDeptId());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
|
Reference in New Issue
Block a user