diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/exception/enums/SysMenuButtonExceptionEnum.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/exception/enums/SysMenuButtonExceptionEnum.java index 5b47f372e..ff4fda5d1 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/exception/enums/SysMenuButtonExceptionEnum.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/exception/enums/SysMenuButtonExceptionEnum.java @@ -11,17 +11,11 @@ import cn.stylefeng.roses.kernel.system.constants.SystemConstants; * @date 2021/1/9 11:32 */ public enum SysMenuButtonExceptionEnum implements AbstractExceptionEnum { - /** - * 按钮code重复 - */ - BUTTON_CODE_REPEAT(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "90", "按钮code重复,请检查buttonCode参数"), /** * 菜单按钮不存在 */ - MENU_BUTTON_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "91", "菜单按钮不存在"), - - ; + MENU_BUTTON_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "91", "菜单按钮不存在"); private final String errorCode; diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/exception/enums/SysMenuExceptionEnum.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/exception/enums/SysMenuExceptionEnum.java index 1418362a4..44f991956 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/exception/enums/SysMenuExceptionEnum.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/exception/enums/SysMenuExceptionEnum.java @@ -20,52 +20,7 @@ public enum SysMenuExceptionEnum implements AbstractExceptionEnum { /** * 菜单不存在 */ - MENU_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "81", "菜单不存在"), - - /** - * 菜单编码重复 - */ - MENU_CODE_REPEAT(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "82", "菜单编码重复,请检查code参数"), - - /** - * 菜单名称重复 - */ - MENU_NAME_REPEAT(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "83", "菜单名称重复,请检查name参数"), - - /** - * 路由地址为空 - */ - MENU_ROUTER_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "84", "路由地址为空,请检查router参数"), - - /** - * 组件地址为空 - */ - MENU_COMPONENT_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "85", "组件地址为空,请检查component参数"), - - /** - * 打开方式为空 - */ - MENU_OPEN_TYPE_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "86", "打开方式为空,请检查openType参数"), - - /** - * 权限标识格式为空 - */ - MENU_PERMISSION_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "87", "权限标识为空,请检查permission参数"), - - /** - * 权限标识格式错误 - */ - MENU_PERMISSION_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "88", "权限标识格式错误,请检查permission参数"), - - /** - * 权限不存在 - */ - MENU_PERMISSION_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "89", "权限不存在,请检查permission参数"), - - /** - * 父级菜单不能为当前节点,请从新选择父级菜单 - */ - PID_CANT_EQ_ID(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "811", "父级菜单不能为当前节点,请从新选择父级菜单"); + MENU_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "81", "菜单不存在"); private final String errorCode; diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/pojo/menu/SysMenuButtonRequest.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/pojo/menu/SysMenuButtonRequest.java index 19967b3f4..dec2c6cb3 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/pojo/menu/SysMenuButtonRequest.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/pojo/menu/SysMenuButtonRequest.java @@ -1,6 +1,7 @@ package cn.stylefeng.roses.kernel.system.pojo.menu; import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest; +import cn.stylefeng.roses.kernel.validator.validators.unique.TableUniqueValue; import lombok.Data; import lombok.EqualsAndHashCode; @@ -47,6 +48,13 @@ public class SysMenuButtonRequest extends BaseRequest { * 按钮的编码 */ @NotBlank(message = "按钮编码不能为空,请检查buttonCode参数", groups = {add.class, edit.class}) + @TableUniqueValue( + message = "按钮编码存在重复", + groups = {add.class, edit.class}, + tableName = "sys_menu_button", + columnName = "button_code", + idFieldName = "button_id", + excludeLogicDeleteItems = true) private String buttonCode; /** diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/pojo/menu/SysMenuButtonResponse.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/pojo/menu/SysMenuButtonResponse.java deleted file mode 100644 index 8a544333c..000000000 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/pojo/menu/SysMenuButtonResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.stylefeng.roses.kernel.system.pojo.menu; - -import lombok.Data; - -import java.io.Serializable; - -/** - * 系统菜单按钮响应实体 - * - * @author luojie - * @date 2021/1/9 11:19 - */ -@Data -public class SysMenuButtonResponse implements Serializable { - - private static final long serialVersionUID = 6909784065876106042L; - - /** - * 主键 - */ - private Long buttonId; - - /** - * 菜单id,按钮需要挂在菜单下 - */ - private Long menuId; - - /** - * 按钮的名称 - */ - private String buttonName; - - /** - * 按钮的编码 - */ - private String buttonCode; - -} diff --git a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/controller/SysMenuButtonController.java b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/controller/SysMenuButtonController.java index 2c51d2727..2a7c17976 100644 --- a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/controller/SysMenuButtonController.java +++ b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/controller/SysMenuButtonController.java @@ -1,6 +1,7 @@ package cn.stylefeng.roses.kernel.menu.modular.controller; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; +import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenuButton; import cn.stylefeng.roses.kernel.menu.modular.service.SysMenuButtonService; import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource; import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource; @@ -8,7 +9,6 @@ import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource; import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData; import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData; import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuButtonRequest; -import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuButtonResponse; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -50,7 +50,7 @@ public class SysMenuButtonController { */ @GetResource(name = "获取菜单按钮详情", path = "/sysMenuButton/detail") public ResponseData detail(@Validated(SysMenuButtonRequest.detail.class) SysMenuButtonRequest sysMenuButtonRequest) { - SysMenuButtonResponse detail = sysMenuButtonService.detail(sysMenuButtonRequest); + SysMenuButton detail = sysMenuButtonService.detail(sysMenuButtonRequest); return new SuccessResponseData(detail); } @@ -102,7 +102,7 @@ public class SysMenuButtonController { */ @GetResource(name = "获取菜单按钮列表", path = "/sysMenuButton/pageList") public ResponseData pageList(@Validated(SysMenuButtonRequest.list.class) SysMenuButtonRequest sysMenuButtonRequest) { - PageResult pageResult = sysMenuButtonService.pageList(sysMenuButtonRequest); + PageResult pageResult = sysMenuButtonService.pageList(sysMenuButtonRequest); return new SuccessResponseData(pageResult); } diff --git a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/SysMenuButtonService.java b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/SysMenuButtonService.java index a48f07631..370dfb00e 100644 --- a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/SysMenuButtonService.java +++ b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/SysMenuButtonService.java @@ -3,7 +3,6 @@ package cn.stylefeng.roses.kernel.menu.modular.service; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenuButton; import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuButtonRequest; -import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuButtonResponse; import com.baomidou.mybatisplus.extension.service.IService; /** @@ -31,7 +30,7 @@ public interface SysMenuButtonService extends IService { * @author luojie * @date 2021/1/9 11:53 */ - SysMenuButtonResponse detail(SysMenuButtonRequest sysMenuButtonRequest); + SysMenuButton detail(SysMenuButtonRequest sysMenuButtonRequest); /** * 编辑系统菜单按钮 @@ -68,7 +67,7 @@ public interface SysMenuButtonService extends IService { * @author luojie * @date 2021/1/9 12:53 */ - PageResult pageList(SysMenuButtonRequest sysMenuButtonRequest); + PageResult pageList(SysMenuButtonRequest sysMenuButtonRequest); /** * 根据菜单id删除该菜单下的所有按钮 @@ -78,4 +77,5 @@ public interface SysMenuButtonService extends IService { * @date 2021/1/9 14:45 */ void deleteMenuButtonByMenuId(Long menuId); + } diff --git a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/impl/SysMenuButtonServiceImpl.java b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/impl/SysMenuButtonServiceImpl.java index 07b585225..05386f474 100644 --- a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/impl/SysMenuButtonServiceImpl.java +++ b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/impl/SysMenuButtonServiceImpl.java @@ -7,17 +7,14 @@ import cn.hutool.core.util.StrUtil; import cn.stylefeng.roses.kernel.db.api.factory.PageFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; -import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenu; import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenuButton; import cn.stylefeng.roses.kernel.menu.modular.mapper.SysMenuButtonMapper; import cn.stylefeng.roses.kernel.menu.modular.service.SysMenuButtonService; import cn.stylefeng.roses.kernel.menu.modular.service.SysMenuService; import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum; -import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException; +import cn.stylefeng.roses.kernel.system.exception.SystemModularException; import cn.stylefeng.roses.kernel.system.exception.enums.SysMenuButtonExceptionEnum; -import cn.stylefeng.roses.kernel.system.exception.enums.SysMenuExceptionEnum; import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuButtonRequest; -import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuButtonResponse; import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuRequest; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -26,9 +23,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.List; import java.util.Set; -import java.util.stream.Collectors; /** * 系统菜单按钮service接口实现类 @@ -46,80 +41,57 @@ public class SysMenuButtonServiceImpl extends ServiceImpl lqw = new LambdaQueryWrapper<>(); - lqw.eq(SysMenuButton::getButtonId, sysMenuButtonRequest.getButtonId()); - lqw.eq(SysMenuButton::getDelFlag, YesOrNotEnum.N.getCode()); - lqw.last("LIMIT 1"); - - SysMenuButton sysMenuButton = this.getOne(lqw); - - if (ObjectUtil.isEmpty(sysMenuButton)) { - throw new ServiceException(SysMenuButtonExceptionEnum.MENU_BUTTON_NOT_EXIST); - } - - SysMenuButtonResponse response = new SysMenuButtonResponse(); - BeanUtil.copyProperties(sysMenuButton, response); - return response; + public SysMenuButton detail(SysMenuButtonRequest sysMenuButtonRequest) { + return this.queryButton(sysMenuButtonRequest); } @Override @Transactional(rollbackFor = Exception.class) public void edit(SysMenuButtonRequest sysMenuButtonRequest) { - Long menuId = sysMenuButtonRequest.getMenuId(); - // 查询按钮是否存在 - this.detail(sysMenuButtonRequest); + // 查询按钮所属菜单是否存在 + findMenuExist(sysMenuButtonRequest.getMenuId()); - // 根据传过来的菜单id查询是否存在 - findMenuExist(menuId); + SysMenuButton button = this.queryButton(sysMenuButtonRequest); + BeanUtil.copyProperties(sysMenuButtonRequest, button); - SysMenuButton sysMenuButton = new SysMenuButton(); - BeanUtil.copyProperties(sysMenuButtonRequest, sysMenuButton); // 不更新删除状态 - sysMenuButton.setDelFlag(null); - // 不更新所属菜单id - sysMenuButton.setMenuId(null); - // 不更新菜单code - sysMenuButton.setButtonCode(null); + button.setDelFlag(null); - this.updateById(sysMenuButton); + // 不更新所属菜单id + button.setMenuId(null); + + // 不更新菜单code + button.setButtonCode(null); + + this.updateById(button); } @Override @Transactional(rollbackFor = Exception.class) public void delete(SysMenuButtonRequest sysMenuButtonRequest) { - // 查询按钮是否存在 - this.detail(sysMenuButtonRequest); - // 查询条件 - LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); - lqw.eq(SysMenuButton::getButtonId, sysMenuButtonRequest.getButtonId()); - lqw.eq(SysMenuButton::getDelFlag, YesOrNotEnum.N.getCode()); + // 查询按钮 + SysMenuButton button = this.queryButton(sysMenuButtonRequest); // 设置为删除状态 - SysMenuButton entity = new SysMenuButton(); - entity.setDelFlag(YesOrNotEnum.Y.getCode()); + button.setDelFlag(YesOrNotEnum.Y.getCode()); - this.update(entity, lqw); + this.updateById(button); } @Override @@ -128,29 +100,20 @@ public class SysMenuButtonServiceImpl extends ServiceImpl buttonIds = sysMenuButtonRequest.getButtonIds(); if (ArrayUtil.isNotEmpty(buttonIds)) { // 查询条件 - LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); - lqw.in(SysMenuButton::getButtonId, buttonIds); - lqw.eq(SysMenuButton::getDelFlag, YesOrNotEnum.N.getCode()); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.in(SysMenuButton::getButtonId, buttonIds); + lambdaQueryWrapper.eq(SysMenuButton::getDelFlag, YesOrNotEnum.N.getCode()); // 设置为删除状态 SysMenuButton entity = new SysMenuButton(); entity.setDelFlag(YesOrNotEnum.Y.getCode()); - this.update(entity, lqw); + this.update(entity, lambdaQueryWrapper); } - } - /** - * 分页获取菜单按钮列表 - * - * @param sysMenuButtonRequest 菜单id - * @return 菜单按钮列表 - * @author luojie - * @date 2021/1/9 12:53 - */ @Override - public PageResult pageList(SysMenuButtonRequest sysMenuButtonRequest) { + public PageResult pageList(SysMenuButtonRequest sysMenuButtonRequest) { String buttonName = sysMenuButtonRequest.getButtonName(); // 构造查询条件 根据菜单id查询菜单按钮列表 @@ -162,27 +125,9 @@ public class SysMenuButtonServiceImpl extends ServiceImpl page = this.page(PageFactory.defaultPage(), wrapper); - // 实体转换 - List sysButtonList = page.getRecords(); - List sysButtonResponseList = sysButtonList.stream().map(b -> { - SysMenuButtonResponse sysButtonResponse = new SysMenuButtonResponse(); - BeanUtil.copyProperties(b, sysButtonResponse); - return sysButtonResponse; - }).collect(Collectors.toList()); - - PageResult pageResult = new PageResult<>(); - BeanUtil.copyProperties(PageResultFactory.createPageResult(page), pageResult); - pageResult.setRows(sysButtonResponseList); - return pageResult; + return PageResultFactory.createPageResult(page); } - /** - * 根据菜单id删除该菜单下的所有按钮 - * - * @param menuId 菜单id - * @author luojie - * @date 2021/1/9 14:45 - */ @Override @Transactional(rollbackFor = Exception.class) public void deleteMenuButtonByMenuId(Long menuId) { @@ -204,42 +149,30 @@ public class SysMenuButtonServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); - wrapper.select(SysMenuButton::getButtonId); - wrapper.eq(SysMenuButton::getButtonCode, sysMenuButtonRequest.getButtonCode()); - wrapper.eq(SysMenuButton::getDelFlag, YesOrNotEnum.N.getCode()); - if (ObjectUtil.isNotEmpty(sysMenuButtonRequest.getButtonId())) { - wrapper.ne(SysMenuButton::getButtonId, sysMenuButtonRequest.getButtonId()); - } - wrapper.last("LIMIT 1"); - SysMenuButton button = getOne(wrapper); - if (ObjectUtil.isNotEmpty(button)) { - throw new ServiceException(SysMenuButtonExceptionEnum.BUTTON_CODE_REPEAT); + private SysMenuButton queryButton(SysMenuButtonRequest sysMenuButtonRequest) { + SysMenuButton button = this.getById(sysMenuButtonRequest.getButtonId()); + if (ObjectUtil.isNull(button) || YesOrNotEnum.Y.getCode().equals(button.getDelFlag())) { + throw new SystemModularException(SysMenuButtonExceptionEnum.MENU_BUTTON_NOT_EXIST); } + return button; } + } diff --git a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/impl/SysMenuServiceImpl.java b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/impl/SysMenuServiceImpl.java index 3405e0bdf..feda03fbc 100644 --- a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/impl/SysMenuServiceImpl.java +++ b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/menu/modular/service/impl/SysMenuServiceImpl.java @@ -346,7 +346,7 @@ public class SysMenuServiceImpl extends ServiceImpl impl */ private SysMenu querySysMenu(SysMenuRequest sysMenuRequest) { SysMenu sysMenu = this.getById(sysMenuRequest.getMenuId()); - if (ObjectUtil.isNull(sysMenu)) { + if (ObjectUtil.isNull(sysMenu) || YesOrNotEnum.Y.getCode().equals(sysMenu.getDelFlag())) { throw new ServiceException(SysMenuExceptionEnum.MENU_NOT_EXIST); } return sysMenu;