|
@@ -0,0 +1,52 @@
|
|
|
+
|
|
|
+
|
|
|
+package com.ruoyi.common.handler;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import org.apache.ibatis.reflection.MetaObject;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 公共字段,自动填充值
|
|
|
+ *
|
|
|
+ * @author ChenYang
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class FieldMetaObjectHandler implements MetaObjectHandler {
|
|
|
+
|
|
|
+ private final static String CREATE_DATE = "createDate";
|
|
|
+ private final static String CREATOR = "creator";
|
|
|
+ private final static String UPDATE_DATE = "updateDate";
|
|
|
+ private final static String UPDATER = "updater";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void insertFill(MetaObject metaObject) {
|
|
|
+ /*try {
|
|
|
+ if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) {
|
|
|
+ BaseExtEntity baseExtEntity = (BaseExtEntity) metaObject.getOriginalObject();
|
|
|
+ Date currentDate = ObjectUtil.isNotNull(baseExtEntity.getCreateDate())
|
|
|
+ ? baseExtEntity.getCreateDate() : new Date();
|
|
|
+ baseExtEntity.setCreateDate(currentDate).setUpdateDate(currentDate);
|
|
|
+ String operateUser = StringUtils.isNotBlank(baseExtEntity.getCreator())
|
|
|
+ ? baseExtEntity.getCreator() : SecurityUtils.getUsername();
|
|
|
+ baseExtEntity.setCreator(operateUser).setUpdater(operateUser);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED);
|
|
|
+ }*/
|
|
|
+ strictInsertFill(metaObject, CREATOR, String.class, SecurityUtils.getUsername());
|
|
|
+ strictInsertFill(metaObject, CREATE_DATE, Date.class, DateUtil.date());
|
|
|
+ strictInsertFill(metaObject, UPDATER, String.class, SecurityUtils.getUsername());
|
|
|
+ strictInsertFill(metaObject, UPDATE_DATE, Date.class, DateUtil.date());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateFill(MetaObject metaObject) {
|
|
|
+ strictInsertFill(metaObject, UPDATER, String.class, SecurityUtils.getUsername());
|
|
|
+ strictInsertFill(metaObject, UPDATE_DATE, Date.class, DateUtil.date());
|
|
|
+ }
|
|
|
+}
|