|
@@ -7,8 +7,10 @@ package org.eco.vip.orm.listener;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.http.HttpStatus;
|
|
|
import com.mybatisflex.annotation.InsertListener;
|
|
|
import org.eco.vip.orm.domain.BaseEntity;
|
|
|
+import org.eco.vip.orm.exception.BusinessException;
|
|
|
import org.eco.vip.orm.pojo.LoginUserStorage;
|
|
|
import org.eco.vip.orm.utils.ObjUtils;
|
|
|
import org.eco.vip.security.utils.LoginHelper;
|
|
@@ -25,22 +27,26 @@ public class EntityInsertListener implements InsertListener {
|
|
|
|
|
|
@Override
|
|
|
public void onInsert(Object entity) {
|
|
|
- if (ObjectUtil.isNotNull(entity) && (entity instanceof BaseEntity baseEntity)) {
|
|
|
- LoginUserStorage loginUserStorage = LoginHelper.getLoginUser();
|
|
|
- String loginUserId = null;
|
|
|
- if (ObjUtils.isNotNull(loginUserStorage)) {
|
|
|
- loginUserId = loginUserStorage.getUserId();
|
|
|
+ try {
|
|
|
+ if (ObjectUtil.isNotNull(entity) && (entity instanceof BaseEntity baseEntity)) {
|
|
|
+ LoginUserStorage loginUserStorage = LoginHelper.getLoginUser();
|
|
|
+ String loginUserId = null;
|
|
|
+ if (ObjUtils.isNotNull(loginUserStorage)) {
|
|
|
+ loginUserId = loginUserStorage.getUserId();
|
|
|
+ }
|
|
|
+ Date createTime = ObjectUtil.isNotNull(baseEntity.getCreateTime())
|
|
|
+ ? baseEntity.getCreateTime() : new Date();
|
|
|
+ if (ObjectUtil.isNull(baseEntity.getCreateBy())) {
|
|
|
+ baseEntity.setCreateBy(loginUserId);
|
|
|
+ }
|
|
|
+ baseEntity.setCreateTime(createTime);
|
|
|
+ if (ObjectUtil.isNull(baseEntity.getUpdateBy())) {
|
|
|
+ baseEntity.setUpdateBy(loginUserId);
|
|
|
+ }
|
|
|
+ baseEntity.setUpdateTime(createTime);
|
|
|
}
|
|
|
- Date createTime = ObjectUtil.isNotNull(baseEntity.getCreateTime())
|
|
|
- ? baseEntity.getCreateTime() : new Date();
|
|
|
- if (ObjectUtil.isNull(baseEntity.getCreateBy())) {
|
|
|
- baseEntity.setCreateBy(loginUserId);
|
|
|
- }
|
|
|
- baseEntity.setCreateTime(createTime);
|
|
|
- if (ObjectUtil.isNull(baseEntity.getUpdateBy())) {
|
|
|
- baseEntity.setUpdateBy(loginUserId);
|
|
|
- }
|
|
|
- baseEntity.setUpdateTime(createTime);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BusinessException(HttpStatus.HTTP_UNAUTHORIZED, "全局插入数据监听器注入异常 => {}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|