package com.yuanchu.mom.mybatis_config;
|
|
import cn.hutool.json.JSONUtil;
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
import com.yuanchu.mom.utils.Jwt;
|
import com.yuanchu.mom.utils.ServletUtils;
|
import org.apache.ibatis.reflection.MetaObject;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.time.LocalDateTime;
|
|
@Component
|
public class MyMetaObjectHandler implements MetaObjectHandler {
|
|
@Autowired
|
Jwt jwt;
|
|
@Override
|
public void insertFill(MetaObject metaObject) {
|
Integer userId = null;
|
try {
|
userId = Integer.parseInt(JSONUtil.parseObj(jwt.readJWT(ServletUtils.getRequest().getHeader("token")).get("data")).get("id") + "");
|
}catch (Exception ignored){}
|
this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐使用)
|
this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐使用)
|
this.strictInsertFill(metaObject, "createUser", Integer.class, userId);
|
this.strictInsertFill(metaObject, "updateUser", Integer.class, userId);
|
}
|
|
@Override
|
public void updateFill(MetaObject metaObject) {
|
Integer userId = null;
|
try {
|
userId = Integer.parseInt(JSONUtil.parseObj(jwt.readJWT(ServletUtils.getRequest().getHeader("token")).get("data")).get("id") + "");
|
}catch (Exception ignored){}
|
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐)
|
this.strictUpdateFill(metaObject, "updateUser", Integer.class, userId);
|
}
|
}
|