|
@@ -10,13 +10,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.google.common.collect.Lists; |
|
|
import com.google.common.collect.Lists; |
|
|
import com.ningdatech.basic.exception.BaseUncheckedException; |
|
|
import com.ningdatech.basic.exception.BaseUncheckedException; |
|
|
|
|
|
import com.ningdatech.basic.exception.BizException; |
|
|
import com.ningdatech.basic.util.ValidatorUtil; |
|
|
import com.ningdatech.basic.util.ValidatorUtil; |
|
|
import com.ningdatech.pmapi.common.constant.DefValConst; |
|
|
import com.ningdatech.pmapi.common.constant.DefValConst; |
|
|
import com.ningdatech.pmapi.sys.model.entity.Menu; |
|
|
|
|
|
import com.ningdatech.pmapi.sys.model.enumeration.MenuTypeEnum; |
|
|
|
|
|
|
|
|
import com.ningdatech.pmapi.sys.mapper.MenuMapper; |
|
|
import com.ningdatech.pmapi.sys.model.dto.MenuSaveDTO; |
|
|
import com.ningdatech.pmapi.sys.model.dto.MenuSaveDTO; |
|
|
import com.ningdatech.pmapi.sys.model.dto.MenuUpdateDTO; |
|
|
import com.ningdatech.pmapi.sys.model.dto.MenuUpdateDTO; |
|
|
import com.ningdatech.pmapi.sys.mapper.MenuMapper; |
|
|
|
|
|
|
|
|
import com.ningdatech.pmapi.sys.model.entity.Menu; |
|
|
|
|
|
import com.ningdatech.pmapi.sys.model.enumeration.MenuTypeEnum; |
|
|
import com.ningdatech.pmapi.sys.service.IMenuService; |
|
|
import com.ningdatech.pmapi.sys.service.IMenuService; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
@@ -90,6 +91,8 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM |
|
|
throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【地址栏路径】:{}重复", data.getPath()); |
|
|
throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【地址栏路径】:{}重复", data.getPath()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
checkButtonUnique(data.getPid(), data.getPath(), data.getId()); |
|
|
} |
|
|
} |
|
|
Menu old = getById(data); |
|
|
Menu old = getById(data); |
|
|
if (Objects.isNull(old)) { |
|
|
if (Objects.isNull(old)) { |
|
@@ -113,16 +116,21 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM |
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public boolean save(MenuSaveDTO data, Long userId) { |
|
|
public boolean save(MenuSaveDTO data, Long userId) { |
|
|
if (StrUtil.isBlank(data.getPath())) { |
|
|
|
|
|
throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【地址栏路径】不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if (StrUtil.isBlank(data.getComponent())) { |
|
|
|
|
|
throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【页面路径】不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!ValidatorUtil.isUrl(data.getPath())) { |
|
|
|
|
|
if (checkPath(null, data.getPath())) { |
|
|
|
|
|
throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【地址栏路径】:{}重复", data.getPath()); |
|
|
|
|
|
|
|
|
data.setPid(Convert.toLong(data.getPid(), DEF_PARENT_ID)); |
|
|
|
|
|
if (data.getMenuType().equals(MenuTypeEnum.MENU)) { |
|
|
|
|
|
if (StrUtil.isBlank(data.getPath())) { |
|
|
|
|
|
throw BizException.wrap("【地址栏路径】不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if (StrUtil.isBlank(data.getComponent())) { |
|
|
|
|
|
throw BizException.wrap("【页面路径】不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!ValidatorUtil.isUrl(data.getPath())) { |
|
|
|
|
|
if (checkPath(null, data.getPath())) { |
|
|
|
|
|
throw BizException.wrap("【地址栏路径】:{}重复", data.getPath()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
checkButtonUnique(data.getPid(), data.getPath(), null); |
|
|
} |
|
|
} |
|
|
data.setPid(Convert.toLong(data.getPid(), DEF_PARENT_ID)); |
|
|
data.setPid(Convert.toLong(data.getPid(), DEF_PARENT_ID)); |
|
|
Menu menu = BeanUtil.toBean(data, Menu.class); |
|
|
Menu menu = BeanUtil.toBean(data, Menu.class); |
|
@@ -132,6 +140,15 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM |
|
|
return Boolean.TRUE; |
|
|
return Boolean.TRUE; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void checkButtonUnique(Long pid, String path, Long menuId) { |
|
|
|
|
|
LambdaQueryWrapper<Menu> query = Wrappers.lambdaQuery(Menu.class) |
|
|
|
|
|
.eq(Menu::getPid, pid).eq(Menu::getPath, path) |
|
|
|
|
|
.ne(menuId != null, Menu::getId, menuId); |
|
|
|
|
|
if (count(query) > 1) { |
|
|
|
|
|
throw BizException.wrap("【按钮路径】:{}重复", path); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public List<Menu> findChildrenByParentId(Long pid) { |
|
|
public List<Menu> findChildrenByParentId(Long pid) { |
|
|
if (Objects.isNull(pid)) { |
|
|
if (Objects.isNull(pid)) { |
|
|
throw new BaseUncheckedException(HttpStatus.HTTP_OK, "pid 不能为空"); |
|
|
throw new BaseUncheckedException(HttpStatus.HTTP_OK, "pid 不能为空"); |
|
|