diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BaseFieldConst.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BaseFieldConst.java new file mode 100644 index 0000000..9b10e39 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BaseFieldConst.java @@ -0,0 +1,18 @@ +package com.ningdatech.pmapi.common.constant; + +/** + *
+ * 创建人修改人基础字段 + *
+ * + * @author WendyYang + * @since 17:17 2023/01/29 + */ +public interface BaseFieldConst { + + String CREATE_BY = "createBy"; + String UPDATE_BY = "updateBy"; + String CREATE_ON = "createOn"; + String UPDATE_ON = "updateOn"; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/handler/BaseFieldFillHandler.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/handler/BaseFieldFillHandler.java new file mode 100644 index 0000000..2a8f4fe --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/handler/BaseFieldFillHandler.java @@ -0,0 +1,48 @@ +package com.ningdatech.pmapi.common.handler; + +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.reflection.MetaObject; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +import static com.ningdatech.pmapi.common.constant.BaseFieldConst.*; + +/** + *+ * 字段自动填充处理 + *
+ * + * @author WendyYang + * @since 17:20 2022/11/24 + */ +@Slf4j +@Component +public class BaseFieldFillHandler implements MetaObjectHandler { + + private Long getUserId() { + if (LoginUserUtil.isLogin()) { + return LoginUserUtil.getUserId(); + } + return 0L; + } + + @Override + public void insertFill(MetaObject metaObject) { + long userId = getUserId(); + LocalDateTime now = LocalDateTime.now(); + this.fillStrategy(metaObject, CREATE_BY, userId); + this.fillStrategy(metaObject, CREATE_ON, now); + this.fillStrategy(metaObject, UPDATE_BY, userId); + this.fillStrategy(metaObject, UPDATE_ON, now); + } + + @Override + public void updateFill(MetaObject metaObject) { + this.fillStrategy(metaObject, UPDATE_BY, getUserId()); + this.fillStrategy(metaObject, UPDATE_ON, LocalDateTime.now()); + } + +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java index 5018ab1..0cdc8fc 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java @@ -16,6 +16,7 @@ import com.ningdatech.pmapi.sys.entity.vo.MenuRoleVO; import com.ningdatech.pmapi.sys.entity.vo.MenuVO; import com.ningdatech.pmapi.sys.manage.MenuManage; import com.ningdatech.pmapi.sys.service.IMenuService; +import com.ningdatech.pmapi.user.util.LoginUserUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -70,8 +71,7 @@ public class MenuController { @GetMapping("/myMenu") public List