From e52017c7da742376ed2b7ae4f6b8377435c0b57f Mon Sep 17 00:00:00 2001 From: WendyYang Date: Mon, 30 Jan 2023 15:13:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=94=A8=E5=AD=97=E6=AE=B5=E5=A1=AB?= =?UTF-8?q?=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/common/constant/BaseFieldConst.java | 18 ++++++++ .../pmapi/common/handler/BaseFieldFillHandler.java | 48 ++++++++++++++++++++++ .../pmapi/sys/controller/MenuController.java | 7 ++-- .../pmapi/sys/controller/RoleController.java | 20 ++++----- .../ningdatech/pmapi/sys/manage/MenuManage.java | 2 +- .../pmapi/user/model/UserInfoDetails.java | 2 + 6 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BaseFieldConst.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/handler/BaseFieldFillHandler.java 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 currentUserMenu() { List list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); - // TODO:登录用户信息 - return menuManage.buildUserMenu(list, null); + return menuManage.buildUserMenu(list, LoginUserUtil.loginUserDetail()); } @ApiOperation(value = "查询菜单", notes = "查询菜单") @@ -85,8 +85,7 @@ public class MenuController { @PostMapping("/save") @WebLog("保存菜单") public MenuVO handlerSave(@Valid @RequestBody MenuSaveDTO data) { - // todo:创建人ID - menuService.save(data, 0L); + menuService.save(data, LoginUserUtil.getUserId()); return BeanUtil.toBean(data, MenuVO.class); } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/RoleController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/RoleController.java index 09fd7c5..435c002 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/RoleController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/RoleController.java @@ -1,7 +1,7 @@ package com.ningdatech.pmapi.sys.controller; import cn.hutool.core.bean.BeanUtil; -import com.ningdatech.basic.auth.AbstractLoginUserUtil; +import cn.hutool.core.lang.Assert; import com.ningdatech.basic.model.PageVo; import com.ningdatech.log.annotation.WebLog; import com.ningdatech.pmapi.sys.entity.Role; @@ -11,6 +11,7 @@ import com.ningdatech.pmapi.sys.entity.dto.RoleUpdateDTO; import com.ningdatech.pmapi.sys.entity.vo.RoleVO; import com.ningdatech.pmapi.sys.manage.RoleManage; import com.ningdatech.pmapi.sys.service.IRoleService; +import com.ningdatech.pmapi.user.util.LoginUserUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -20,7 +21,6 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; -import java.util.Objects; /** *

@@ -58,34 +58,32 @@ public class RoleController { @GetMapping("/details") public RoleVO getDetails(@Valid @RequestParam Long id) { Role role = roleService.getById(id); + Assert.notNull(role, "角色不存在"); RoleVO query = BeanUtil.toBean(role, RoleVO.class); - if (Objects.isNull(query)) { - return null; - } - //菜单 + // 菜单 roleManage.buildMenu(query); return query; } @ApiOperation(value = "保存新角色", notes = "保存新角色") @PostMapping("/save") - @WebLog + @WebLog("保存新角色") public RoleVO handlerSave(@Valid @RequestBody RoleSaveDTO data) { - roleService.saveRole(data, null); + roleService.saveRole(data, LoginUserUtil.getUserId()); return BeanUtil.toBean(data, RoleVO.class); } @ApiOperation(value = "编辑角色", notes = "编辑角色") @PostMapping("/modify") - @WebLog + @WebLog("编辑角色") public RoleVO handlerUpdate(@Valid @RequestBody RoleUpdateDTO data) { - roleService.updateRole(data, AbstractLoginUserUtil.getUserId()); + roleService.updateRole(data, LoginUserUtil.getUserId()); return BeanUtil.toBean(data, RoleVO.class); } @ApiOperation(value = "删除角色", notes = "删除角色") @PostMapping("/remove") - @WebLog + @WebLog("删除角色") public Boolean handlerDelete(@Valid @RequestBody List ids) { return roleService.removeByIdWithCache(ids); } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java index 3307485..2f9fb0c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java @@ -9,7 +9,7 @@ import com.ningdatech.pmapi.sys.entity.Menu; import com.ningdatech.pmapi.sys.entity.RoleMenu; import com.ningdatech.pmapi.sys.entity.vo.MenuRoleVO; import com.ningdatech.pmapi.sys.service.IRoleMenuService; -import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; +import com.ningdatech.pmapi.user.model.UserInfoDetails; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/UserInfoDetails.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/UserInfoDetails.java index de91775..c5834a5 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/UserInfoDetails.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/UserInfoDetails.java @@ -40,6 +40,8 @@ public class UserInfoDetails extends AbstractLoginUser implements UserDetails { private String regionName; + private List roleIdList; + /** * 获取用户权限 */