Browse Source

菜单提交增加重名重号校验

test
smallchill 4 years ago
parent
commit
ed47fc8ed4
  1. 18
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java

18
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java

@ -16,6 +16,7 @@
*/ */
package org.springblade.system.service.impl; 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.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -62,6 +63,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
private final IRoleScopeService roleScopeService; private final IRoleScopeService roleScopeService;
private final ITopMenuSettingService topMenuSettingService; private final ITopMenuSettingService topMenuSettingService;
private final static String PARENT_ID = "parentId"; private final static String PARENT_ID = "parentId";
private final static Integer MENU_CATEGORY = 1;
@Override @Override
public List<MenuVO> lazyList(Long parentId, Map<String, Object> param) { public List<MenuVO> lazyList(Long parentId, Map<String, Object> param) {
@ -183,6 +185,22 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
@Override @Override
public boolean submit(Menu menu) { public boolean submit(Menu menu) {
LambdaQueryWrapper<Menu> 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) { if (menu.getParentId() == null && menu.getId() == null) {
menu.setParentId(BladeConstant.TOP_PARENT_ID); menu.setParentId(BladeConstant.TOP_PARENT_ID);
} }

Loading…
Cancel
Save