Skip to content

Commit

Permalink
:refactor: mybatis填充功能中硬编码替换
Browse files Browse the repository at this point in the history
  • Loading branch information
carl committed Oct 23, 2024
1 parent 1f4934e commit 7dab4e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.FieldNameConstants;

import java.io.Serializable;
import java.time.LocalDateTime;
Expand All @@ -17,6 +18,7 @@
*/
@Getter
@Setter
@FieldNameConstants
public class BaseEntity implements Serializable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.pig4cloud.pig.common.core.constant.CommonConstants;
import com.pig4cloud.pig.common.mybatis.base.BaseEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
Expand All @@ -27,10 +28,10 @@ public void insertFill(MetaObject metaObject) {
log.debug("mybatis plus start insert fill ....");
LocalDateTime now = LocalDateTime.now();

fillValIfNullByName("createTime", now, metaObject, true);
fillValIfNullByName("updateTime", now, metaObject, true);
fillValIfNullByName("createBy", getUserName(), metaObject, true);
fillValIfNullByName("updateBy", getUserName(), metaObject, true);
fillValIfNullByName(BaseEntity.Fields.createTime, now, metaObject, true);
fillValIfNullByName(BaseEntity.Fields.updateTime, now, metaObject, true);
fillValIfNullByName(BaseEntity.Fields.createBy, getUserName(), metaObject, true);
fillValIfNullByName(BaseEntity.Fields.updateBy, getUserName(), metaObject, true);

// 删除标记自动填充
fillValIfNullByName("delFlag", CommonConstants.STATUS_NORMAL, metaObject, true);
Expand All @@ -39,8 +40,8 @@ public void insertFill(MetaObject metaObject) {
@Override
public void updateFill(MetaObject metaObject) {
log.debug("mybatis plus start update fill ....");
fillValIfNullByName("updateTime", LocalDateTime.now(), metaObject, true);
fillValIfNullByName("updateBy", getUserName(), metaObject, true);
fillValIfNullByName(BaseEntity.Fields.updateTime, LocalDateTime.now(), metaObject, true);
fillValIfNullByName(BaseEntity.Fields.updateBy, getUserName(), metaObject, true);
}

/**
Expand Down

0 comments on commit 7dab4e6

Please sign in to comment.