From ed47fc8ed49cc28a4512b8f7eaa2cd093894e52f Mon Sep 17 00:00:00 2001 From: smallchill Date: Wed, 9 Sep 2020 18:12:28 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E8=8F=9C=E5=8D=95=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E5=90=8D=E9=87=8D=E5=8F=B7=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/impl/MenuServiceImpl.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java index 2a0d4015..26408009 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java @@ -16,6 +16,7 @@ */ package org.springblade.system.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; @@ -62,6 +63,7 @@ public class MenuServiceImpl extends ServiceImpl implements IM private final IRoleScopeService roleScopeService; private final ITopMenuSettingService topMenuSettingService; private final static String PARENT_ID = "parentId"; + private final static Integer MENU_CATEGORY = 1; @Override public List lazyList(Long parentId, Map param) { @@ -183,6 +185,22 @@ public class MenuServiceImpl extends ServiceImpl implements IM @Override public boolean submit(Menu menu) { + LambdaQueryWrapper menuQueryWrapper = Wrappers.lambdaQuery(); + if (menu.getId() == null) { + menuQueryWrapper.eq(Menu::getCode, menu.getCode()).or( + wrapper -> wrapper.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY) + ); + } else { + menuQueryWrapper.ne(Menu::getId, menu.getId()).and( + wrapper -> wrapper.eq(Menu::getCode, menu.getCode()).or( + o -> o.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY) + ) + ); + } + Integer cnt = baseMapper.selectCount(menuQueryWrapper); + if (cnt > 0) { + throw new ServiceException("菜单名或编号已存在!"); + } if (menu.getParentId() == null && menu.getId() == null) { menu.setParentId(BladeConstant.TOP_PARENT_ID); }