菜单新增/修改重名校验增加归属类型条件筛选

This commit is contained in:
gaoqr
2025-09-03 16:07:11 +08:00
parent e940d0a7c6
commit 7b65752714
4 changed files with 10 additions and 9 deletions
@@ -76,7 +76,7 @@ public class MenuSaveVO {
private String description;
@Schema(description = "菜单归属类型 ,见 MenuSourceTypeValid 枚举",example = "1")
@NotNull
@NotNull(message = "菜单归属类型不能为空")
@MenuSourceTypeValid
private Integer sourceType;
@@ -11,8 +11,8 @@ import java.util.List;
@Mapper
public interface MenuMapper extends BaseMapperX<MenuDO> {
default MenuDO selectByParentIdAndName(Long parentId, String name) {
return selectOne(MenuDO::getParentId, parentId, MenuDO::getName, name);
default MenuDO selectByParentIdAndNameAndSourceType(Long parentId, String name, Integer sourceType) {
return selectOne(MenuDO::getParentId, parentId, MenuDO::getName, name, MenuDO::getSourceType, sourceType);
}
default Long selectCountByParentId(Long parentId) {
@@ -67,7 +67,7 @@ public class MenuServiceImpl implements MenuService {
// 校验父菜单存在
validateParentMenu(createReqVO.getParentId(), null);
// 校验菜单(自己)
validateMenu(createReqVO.getParentId(), createReqVO.getName(), null);
validateMenu(createReqVO.getParentId(), createReqVO.getName(), null, createReqVO.getSourceType());
// 校验管理端菜单增删改必须是晨丰组织下用户
validateManageSourceTypeOperatePermission(createReqVO.getSourceType());
@@ -96,7 +96,7 @@ public class MenuServiceImpl implements MenuService {
// 校验父菜单存在
validateParentMenu(updateReqVO.getParentId(), updateReqVO.getId());
// 校验菜单(自己)
validateMenu(updateReqVO.getParentId(), updateReqVO.getName(), updateReqVO.getId());
validateMenu(updateReqVO.getParentId(), updateReqVO.getName(), updateReqVO.getId(), updateReqVO.getSourceType());
// 校验管理端菜单增删改必须是晨丰组织下用户
validateManageSourceTypeOperatePermission(updateReqVO.getSourceType());
@@ -293,8 +293,8 @@ public class MenuServiceImpl implements MenuService {
* @param id 菜单编号
*/
@VisibleForTesting
void validateMenu(Long parentId, String name, Long id) {
MenuDO menu = menuMapper.selectByParentIdAndName(parentId, name);
void validateMenu(Long parentId, String name, Long id, Integer sourceType) {
MenuDO menu = menuMapper.selectByParentIdAndNameAndSourceType(parentId, name, sourceType);
if (menu == null) {
return;
}
@@ -6,6 +6,7 @@ import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuListReq
import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuSaveVO;
import com.cf.imes.module.system.dal.dataobject.permission.MenuDO;
import com.cf.imes.module.system.dal.mysql.permission.MenuMapper;
import com.cf.imes.module.system.enums.permission.MenuSourceTypeEnum;
import com.cf.imes.module.system.enums.permission.MenuTypeEnum;
import com.cf.imes.module.system.service.organ.OrganService;
import org.junit.jupiter.api.Test;
@@ -283,7 +284,7 @@ public class MenuServiceImplTest extends BaseDbUnitTest {
String otherSonMenuName = randomString();
// 调用,无需断言
menuService.validateMenu(parentId, otherSonMenuName, otherSonMenuId);
menuService.validateMenu(parentId, otherSonMenuName, otherSonMenuId, MenuSourceTypeEnum.PRODUCTION.getType());
}
@Test
@@ -296,7 +297,7 @@ public class MenuServiceImplTest extends BaseDbUnitTest {
String otherSonMenuName = sonMenu.getName(); //相同名称
// 调用,并断言异常
assertServiceException(() -> menuService.validateMenu(parentId, otherSonMenuName, otherSonMenuId),
assertServiceException(() -> menuService.validateMenu(parentId, otherSonMenuName, otherSonMenuId, MenuSourceTypeEnum.PRODUCTION.getType()),
MENU_NAME_DUPLICATE);
}