Quellcode durchsuchen

增加按钮菜单

master
WendyYang vor 1 Jahr
Ursprung
Commit
d1ef721b78
3 geänderte Dateien mit 43 neuen und 13 gelöschten Zeilen
  1. +10
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuSaveDTO.java
  2. +4
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/Menu.java
  3. +29
    -12
      pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java

+ 10
- 1
pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuSaveDTO.java Datei anzeigen

@@ -1,11 +1,14 @@
package com.ningdatech.pmapi.sys.model.dto;

import com.ningdatech.pmapi.sys.model.enumeration.MenuTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
@@ -38,13 +41,14 @@ public class MenuSaveDTO implements Serializable {
* 标题
*/
@ApiModelProperty(value = "标题")
@NotEmpty(message = "请输入菜单标题")
@NotEmpty(message = "标题不能为空")
private String title;

/**
* 页面路径
*/
@ApiModelProperty(value = "页面路径")
@NotBlank(message = "页面路径不能为空")
private String path;

/**
@@ -88,4 +92,9 @@ public class MenuSaveDTO implements Serializable {
*/
@ApiModelProperty(value = "跳转")
private String redirect;

@ApiModelProperty("菜单类型")
@NotNull(message = "菜单类型不能为空")
private MenuTypeEnum menuType;

}

+ 4
- 0
pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/Menu.java Datei anzeigen

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ningdatech.pmapi.common.model.entity.MenuTreeEntity;
import com.ningdatech.pmapi.sys.model.enumeration.DataScopeEnum;
import com.ningdatech.pmapi.sys.model.enumeration.MenuTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
@@ -67,6 +68,9 @@ public class Menu extends MenuTreeEntity<Menu, Long> {
@ApiModelProperty("数据权限选项")
private String dataScopeOption;

@ApiModelProperty("菜单类型")
private MenuTypeEnum menuType;

@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateBy;



+ 29
- 12
pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java Datei anzeigen

@@ -10,13 +10,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.ningdatech.basic.exception.BaseUncheckedException;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.util.ValidatorUtil;
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.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 lombok.RequiredArgsConstructor;
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());
}
}
} else {
checkButtonUnique(data.getPid(), data.getPath(), data.getId());
}
Menu old = getById(data);
if (Objects.isNull(old)) {
@@ -113,16 +116,21 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
@Override
@Transactional(rollbackFor = Exception.class)
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));
Menu menu = BeanUtil.toBean(data, Menu.class);
@@ -132,6 +140,15 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
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) {
if (Objects.isNull(pid)) {
throw new BaseUncheckedException(HttpStatus.HTTP_OK, "pid 不能为空");


Laden…
Abbrechen
Speichern