|
|
@@ -0,0 +1,33 @@
|
|
|
+package com.ruoyi.common.handler;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
|
+import com.ruoyi.common.core.text.Convert;
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import org.apache.ibatis.reflection.MetaObject;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class AutoFillHandler implements MetaObjectHandler {
|
|
|
+ @Override
|
|
|
+ public void insertFill(MetaObject metaObject) {
|
|
|
+ String userId = Convert.toStr(SecurityUtils.getUserId());
|
|
|
+ if (metaObject.hasSetter("createBy")) {
|
|
|
+ metaObject.setValue("createBy", userId);
|
|
|
+ }
|
|
|
+ if (metaObject.hasSetter("createTime")) {
|
|
|
+ metaObject.setValue("createTime", DateUtils.getNowDate());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateFill(MetaObject metaObject) {
|
|
|
+ String userId = Convert.toStr(SecurityUtils.getUserId());
|
|
|
+ if (metaObject.hasSetter("updateBy")) {
|
|
|
+ metaObject.setValue("updateBy", userId);
|
|
|
+ }
|
|
|
+ if (metaObject.hasSetter("updateTime")) {
|
|
|
+ metaObject.setValue("updateTime", DateUtils.getNowDate());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|