Skip to content

Commit

Permalink
refactor($MyBatisPlus): add auto fill for deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnny Miller (锺俊) committed Jan 13, 2021
1 parent 2ea61f4 commit 31564ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public class PermissionPersistence implements Serializable {
/**
* Deleted flag
*/
@TableField(value = "deleted")
@TableLogic
@TableField(value = "deleted", fill = FieldFill.INSERT)
private Byte deleted;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.jmsoftware.maf.common.domain.DeleteField;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.time.LocalDateTime;
import java.util.Date;

/**
* <h1>MyBatisPlusConfiguration</h1>
Expand Down Expand Up @@ -67,12 +68,15 @@ public MybatisPlusInterceptor mybatisPlusInterceptor(PaginationInnerInterceptor
@Override
public void insertFill(MetaObject metaObject) {
log.info("Start to insert fill ....");
this.strictInsertFill(metaObject, "createdTime", LocalDateTime.class, LocalDateTime.now());
val now = new Date();
this.strictInsertFill(metaObject, "deleted", Byte.class, DeleteField.NOT_DELETED.getValue());
this.strictInsertFill(metaObject, "createdTime", Date.class, now);
this.strictInsertFill(metaObject, "modifiedTime", Date.class, now);
}

@Override
public void updateFill(MetaObject metaObject) {
log.info("Start to update fill ....");
this.strictUpdateFill(metaObject, "modifiedTime", LocalDateTime::now, LocalDateTime.class);
this.strictUpdateFill(metaObject, "modifiedTime", Date.class, new Date());
}
}

0 comments on commit 31564ca

Please sign in to comment.