|
|
@@ -1,64 +1,66 @@
|
|
|
-package shop.alien.store.config;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.ibatis.reflection.MetaObject;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.context.request.RequestContextHolder;
|
|
|
-import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
-import shop.alien.util.common.JwtUtil;
|
|
|
-
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
-/**
|
|
|
- * Mybatis日期填充
|
|
|
- *
|
|
|
- * @author ssk
|
|
|
- * @version 1.0
|
|
|
- * @date 2024/12/6 10:19
|
|
|
- */
|
|
|
-@Component
|
|
|
-@Slf4j
|
|
|
-public class MyBatisFieldHandler implements MetaObjectHandler {
|
|
|
-
|
|
|
- /**
|
|
|
- * insert操作时填充方法
|
|
|
- *
|
|
|
- * @param metaObject 元对象
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void insertFill(MetaObject metaObject) {
|
|
|
- log.info("=================================insertFill=========================================");
|
|
|
- System.out.println(metaObject.getOriginalObject());
|
|
|
- //字段为实体类名, 不是表字段名
|
|
|
- this.setFieldValByName("createdTime", new Date(), metaObject);
|
|
|
- this.setFieldValByName("updatedTime", new Date(), metaObject);
|
|
|
- if (JwtUtil.hasToken()) {
|
|
|
- this.setFieldValByName("createdUserId", Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId"), metaObject);
|
|
|
- this.setFieldValByName("updatedUserId", Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId"), metaObject);
|
|
|
- } else {
|
|
|
- this.setFieldValByName("createdUserId", 0, metaObject);
|
|
|
- this.setFieldValByName("updatedUserId", 0, metaObject);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * update操作时填充方法
|
|
|
- *
|
|
|
- * @param metaObject 元对象
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void updateFill(MetaObject metaObject) {
|
|
|
- log.info("=================================updateFill=========================================");
|
|
|
- //字段为实体类名, 不是表字段名
|
|
|
- this.setFieldValByName("updatedTime", new Date(), metaObject);
|
|
|
- if (JwtUtil.hasToken()) {
|
|
|
- this.setFieldValByName("updatedUserId", Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId"), metaObject);
|
|
|
- } else {
|
|
|
- this.setFieldValByName("updatedUserId", 0, metaObject);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+package shop.alien.store.config;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.ibatis.reflection.MetaObject;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
+import shop.alien.util.common.JwtUtil;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Mybatis日期填充
|
|
|
+ *
|
|
|
+ * @author ssk
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2024/12/6 10:19
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class MyBatisFieldHandler implements MetaObjectHandler {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * insert操作时填充方法
|
|
|
+ *
|
|
|
+ * @param metaObject 元对象
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void insertFill(MetaObject metaObject) {
|
|
|
+ log.info("=================================insertFill=========================================");
|
|
|
+ System.out.println(metaObject.getOriginalObject());
|
|
|
+ //字段为实体类名, 不是表字段名
|
|
|
+ this.setFieldValByName("createdTime", new Date(), metaObject);
|
|
|
+ this.setFieldValByName("updatedTime", new Date(), metaObject);
|
|
|
+ // 设置pid默认值为0
|
|
|
+ this.setFieldValByName("pid", 0L, metaObject);
|
|
|
+ if (JwtUtil.hasToken()) {
|
|
|
+ this.setFieldValByName("createdUserId", Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId"), metaObject);
|
|
|
+ this.setFieldValByName("updatedUserId", Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId"), metaObject);
|
|
|
+ } else {
|
|
|
+ this.setFieldValByName("createdUserId", 0, metaObject);
|
|
|
+ this.setFieldValByName("updatedUserId", 0, metaObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * update操作时填充方法
|
|
|
+ *
|
|
|
+ * @param metaObject 元对象
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateFill(MetaObject metaObject) {
|
|
|
+ log.info("=================================updateFill=========================================");
|
|
|
+ //字段为实体类名, 不是表字段名
|
|
|
+ this.setFieldValByName("updatedTime", new Date(), metaObject);
|
|
|
+ if (JwtUtil.hasToken()) {
|
|
|
+ this.setFieldValByName("updatedUserId", Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId"), metaObject);
|
|
|
+ } else {
|
|
|
+ this.setFieldValByName("updatedUserId", 0, metaObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|