| | |
| | | |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * @Author: zhangxy |
| | | * @Date: 2020-08-05 14:40 |
| | | */ |
| | | @Component |
| | | public class MyMetaObjectHandler implements MetaObjectHandler { |
| | | |
| | | @Override |
| | | public void insertFill(MetaObject metaObject) { |
| | | Long userId = SecurityUtils.getLoginUser().getUserId(); |
| | | this.strictInsertFill(metaObject, "createBy", Long.class, userId); |
| | | this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now()); |
| | | public void insertFill(MetaObject meta) { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | Long uid = SecurityUtils.getLoginUser().getUserId(); |
| | | if (uid != null) { |
| | | strictInsertFill(meta, "createBy", String.class, uid.toString()); |
| | | strictInsertFill(meta, "updateBy", String.class, uid.toString()); |
| | | } |
| | | strictInsertFill(meta, "createTime", LocalDateTime.class, now); |
| | | strictInsertFill(meta, "updateTime", LocalDateTime.class, now); |
| | | } |
| | | |
| | | @Override |
| | | public void updateFill(MetaObject metaObject) { |
| | | Long userId = SecurityUtils.getLoginUser().getUserId(); |
| | | this.strictInsertFill(metaObject, "updateBy", Long.class, userId); |
| | | this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); |
| | | public void updateFill(MetaObject meta) { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | Long uid = SecurityUtils.getLoginUser().getUserId(); |
| | | if (uid != null) { |
| | | strictUpdateFill(meta, "updateBy", String.class, uid.toString()); |
| | | } |
| | | // 强制覆盖 updateTime |
| | | setFieldValByName("updateTime", now, meta); |
| | | } |
| | | } |
| | | |
| | | } |