Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -66,9 +66,9 @@ public class MenuController {
|
||||
}
|
||||
|
||||
@Operation(summary = "删除菜单权限", description = "删除菜单权限")
|
||||
@DeleteMapping("/delete/fun/{menuBindFunId}")
|
||||
public XResult<Void> deleteFun(@PathVariable Long menuBindFunId) {
|
||||
return menuService.deleteFun(menuBindFunId);
|
||||
@DeleteMapping("/delete/fun/{menuId}")
|
||||
public XResult<Void> deleteFun(@PathVariable Long menuId) {
|
||||
return menuService.deleteFun(menuId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.cczsa.xinghe.codegen.entity;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.enums.ClientTypeEnum;
|
||||
import com.cczsa.xinghe.codegen.entity.enums.MenuTypeEnum;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import com.mybatisflex.core.keygen.KeyGenerators;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -54,6 +53,16 @@ public class MenuEntity extends BaseEntity implements Serializable {
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 操作ID/来自操作表
|
||||
*/
|
||||
private Long funId;
|
||||
|
||||
/**
|
||||
* 0菜单1按钮
|
||||
*/
|
||||
private MenuTypeEnum menuType;
|
||||
|
||||
/**
|
||||
* 路由路径
|
||||
*/
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
package com.cczsa.xinghe.codegen.entity;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.enums.ClientTypeEnum;
|
||||
import com.cczsa.xinghe.codegen.entity.enums.UsableConfigEnum;
|
||||
import com.cczsa.xinghe.codegen.handler.PostgreSQLJsonTypeHandler;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import org.postgresql.util.PGobject;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色权限表 实体类。
|
||||
@@ -69,4 +68,9 @@ public class RoleFunEntity extends BaseEntity implements Serializable {
|
||||
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||
private List<String> excludeField;
|
||||
|
||||
/**
|
||||
* 客户端类型:0 PC端,1 小程序端,2 H5端
|
||||
*/
|
||||
private ClientTypeEnum clientType;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.cczsa.xinghe.codegen.entity.enums;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.mybatisflex.annotation.EnumValue;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 菜单类型
|
||||
*
|
||||
* @author My
|
||||
*/
|
||||
@Schema(description = "菜单类型",
|
||||
example = "0",
|
||||
allowableValues = {"0: 菜单", "1: 按钮"})
|
||||
@Getter
|
||||
public enum MenuTypeEnum {
|
||||
// 0: 菜单 1: 按钮
|
||||
MENU_ID(0, "菜单"),
|
||||
BUTTON_ID(1, "按钮");
|
||||
|
||||
private final int code;
|
||||
private final String desc;
|
||||
|
||||
MenuTypeEnum(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
@EnumValue
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.cczsa.xinghe.codegen.entity.req.menu;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.enums.ClientTypeEnum;
|
||||
import com.cczsa.xinghe.codegen.entity.enums.MenuTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
@@ -50,4 +51,8 @@ public class MenuAddReq implements Serializable {
|
||||
@Schema(description = "排序")
|
||||
private Integer sortOrder;
|
||||
|
||||
@NotNull(message = "菜单类型不能为空")
|
||||
@Schema(description = "0菜单1按钮")
|
||||
private MenuTypeEnum menuType;
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import lombok.Setter;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单绑定权限 请求参数
|
||||
@@ -29,6 +28,6 @@ public class MenuBindFunReq implements Serializable {
|
||||
|
||||
@NotNull(message = "功能ID不能为空")
|
||||
@Schema(description = "功能ID")
|
||||
private List<Long> funIdList;
|
||||
private Long funId;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.cczsa.xinghe.codegen.entity.req.menu;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.enums.ClientTypeEnum;
|
||||
import com.cczsa.xinghe.codegen.entity.enums.MenuTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
@@ -52,4 +53,8 @@ public class MenuEditReq implements Serializable {
|
||||
@Schema(description = "排序")
|
||||
private Integer sortOrder;
|
||||
|
||||
@NotNull(message = "菜单类型不能为空")
|
||||
@Schema(description = "0菜单1按钮")
|
||||
private MenuTypeEnum menuType;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.cczsa.xinghe.codegen.entity.req.role;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.enums.ClientTypeEnum;
|
||||
import com.cczsa.xinghe.codegen.entity.enums.UsableConfigEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -42,4 +43,8 @@ public class RoleBindFunReq implements Serializable {
|
||||
@Schema(description = "排除的字段 根据 fieldConfig 进行设置")
|
||||
private List<String> excludeField;
|
||||
|
||||
@NotNull(message = "客户端类型不能为空")
|
||||
@Schema(description = "客户端类型:0 PC端,1 小程序端,2 H5端")
|
||||
private ClientTypeEnum clientType;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.cczsa.xinghe.codegen.entity.res.menu;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 菜单功能列表 响应参数
|
||||
*
|
||||
* @author xia
|
||||
* @version 0.0.1
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "菜单功能列表-响应")
|
||||
public class MenuFunListQueryRes implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "菜单绑定功能ID")
|
||||
private Long menuBindFunId;
|
||||
|
||||
@Schema(description = "功能ID")
|
||||
private Long funId;
|
||||
|
||||
@Schema(description = "功能名称")
|
||||
private String funName;
|
||||
|
||||
@Schema(description = "存在个数")
|
||||
private Integer existNum;
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.cczsa.xinghe.codegen.entity.res.menu;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.enums.ClientTypeEnum;
|
||||
import com.cczsa.xinghe.codegen.entity.enums.MenuTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -50,8 +51,17 @@ public class MenuQueryRes implements Serializable {
|
||||
@Schema(description = "排序")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Schema(description = "菜单功能列表")
|
||||
private List<MenuFunListQueryRes> funList;
|
||||
@Schema(description = "0菜单1按钮")
|
||||
private MenuTypeEnum menuType;
|
||||
|
||||
@Schema(description = "功能ID")
|
||||
private Long funId;
|
||||
|
||||
@Schema(description = "功能名称")
|
||||
private String funName;
|
||||
|
||||
@Schema(description = "功能存在个数")
|
||||
private Integer existNum;
|
||||
|
||||
@Schema(description = "子菜单")
|
||||
private List<MenuQueryRes> children;
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.cczsa.xinghe.codegen.entity.res.role;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.enums.UsableConfigEnum;
|
||||
import com.cczsa.xinghe.codegen.handler.PostgreSQLJsonTypeHandler;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单功能列表 响应参数
|
||||
*
|
||||
* @author xia
|
||||
* @version 0.0.1
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "菜单功能列表-响应")
|
||||
public class MenuFunListRes implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "权限id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "操作名称")
|
||||
private String funName;
|
||||
|
||||
@Schema(description = "可配置数据类型")
|
||||
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||
private List<UsableConfigEnum> usableConfig;
|
||||
|
||||
@Schema(description = "可配置字段")
|
||||
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||
private List<String> fieldConfig;
|
||||
|
||||
@Schema(description = "排序")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Schema(description = "说明")
|
||||
private String describe;
|
||||
|
||||
@Schema(description = "是否已选择")
|
||||
private Boolean isSelect = false;
|
||||
|
||||
@Schema(description = "角色权限绑定的id")
|
||||
private Long funBindId;
|
||||
|
||||
@Schema(description = "数据权限")
|
||||
private UsableConfigEnum dataScope;
|
||||
|
||||
@Schema(description = "指定的数据权限范围")
|
||||
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||
private List<Long> assignDataScope;
|
||||
|
||||
@Schema(description = "排除的字段")
|
||||
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||
private List<String> excludeField;
|
||||
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.cczsa.xinghe.codegen.entity.res.role;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.enums.ClientTypeEnum;
|
||||
import com.cczsa.xinghe.codegen.entity.enums.UsableConfigEnum;
|
||||
import com.cczsa.xinghe.codegen.handler.PostgreSQLJsonTypeHandler;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -50,8 +53,42 @@ public class RoleQueryFunRes implements Serializable {
|
||||
@Schema(description = "排序")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Schema(description = "菜单功能列表")
|
||||
private List<MenuFunListRes> menuFunList;
|
||||
@Schema(description = "权限id")
|
||||
private Long funId;
|
||||
|
||||
@Schema(description = "操作名称")
|
||||
private String funName;
|
||||
|
||||
@Schema(description = "可配置数据类型")
|
||||
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||
private List<UsableConfigEnum> usableConfig;
|
||||
|
||||
@Schema(description = "可配置字段")
|
||||
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||
private List<String> fieldConfig;
|
||||
|
||||
@Schema(description = "说明")
|
||||
private String describe;
|
||||
|
||||
@Schema(description = "是否已选择")
|
||||
private Boolean isSelect = false;
|
||||
|
||||
@Schema(description = "角色权限绑定的id")
|
||||
private Long funBindId;
|
||||
|
||||
@Schema(description = "数据权限")
|
||||
private UsableConfigEnum dataScope;
|
||||
|
||||
@Schema(description = "指定的数据权限范围")
|
||||
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||
private List<Long> assignDataScope;
|
||||
|
||||
@Schema(description = "排除的字段")
|
||||
@Column(typeHandler = PostgreSQLJsonTypeHandler.class)
|
||||
private List<String> excludeField;
|
||||
|
||||
@Schema(description = "功能客户端类型:0 PC端,1 小程序端,2 H5端")
|
||||
private ClientTypeEnum funClientType;
|
||||
|
||||
@Schema(description = "子菜单")
|
||||
private List<RoleQueryFunRes> children;
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.cczsa.xinghe.codegen.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.cczsa.xinghe.codegen.entity.MenuBindFunEntity;
|
||||
|
||||
/**
|
||||
* 菜单绑定权限 映射层。
|
||||
*
|
||||
* @author My
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Mapper
|
||||
public interface MenuBindFunMapper extends BaseMapper<MenuBindFunEntity> {
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.cczsa.xinghe.codegen.mapper.def;
|
||||
|
||||
import com.mybatisflex.core.query.QueryColumn;
|
||||
import com.mybatisflex.core.table.TableDef;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 菜单绑定权限 表定义层。
|
||||
*
|
||||
* @author My
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public class MenuBindFunDef extends TableDef {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 菜单绑定权限
|
||||
*/
|
||||
public static final MenuBindFunDef MENU_BIND_FUN_ENTITY = new MenuBindFunDef();
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
public final QueryColumn ID = new QueryColumn(this, "id");
|
||||
|
||||
/**
|
||||
* 功能ID
|
||||
*/
|
||||
public final QueryColumn FUN_ID = new QueryColumn(this, "fun_id");
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
public final QueryColumn MENU_ID = new QueryColumn(this, "menu_id");
|
||||
|
||||
/**
|
||||
* 所有字段。
|
||||
*/
|
||||
public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");
|
||||
|
||||
/**
|
||||
* 默认字段,不包含逻辑删除或者 large 等字段。
|
||||
*/
|
||||
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, MENU_ID, FUN_ID};
|
||||
|
||||
public MenuBindFunDef() {
|
||||
super("", "cg_menu_bind_fun");
|
||||
}
|
||||
|
||||
private MenuBindFunDef(String schema, String name, String alisa) {
|
||||
super(schema, name, alisa);
|
||||
}
|
||||
|
||||
public MenuBindFunDef as(String alias) {
|
||||
String key = getNameWithSchema() + "." + alias;
|
||||
return getCache(key, k -> new MenuBindFunDef("", "cg_menu_bind_fun", alias));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,6 +36,11 @@ public class MenuDef extends TableDef {
|
||||
*/
|
||||
public final QueryColumn PATH = new QueryColumn(this, "path");
|
||||
|
||||
/**
|
||||
* 操作ID/来自操作表
|
||||
*/
|
||||
public final QueryColumn FUN_ID = new QueryColumn(this, "fun_id");
|
||||
|
||||
/**
|
||||
* 是否隐藏
|
||||
*/
|
||||
@@ -51,12 +56,19 @@ public class MenuDef extends TableDef {
|
||||
*/
|
||||
public final QueryColumn MENU_NAME = new QueryColumn(this, "menu_name");
|
||||
|
||||
/**
|
||||
* 0菜单1按钮
|
||||
*/
|
||||
public final QueryColumn MENU_TYPE = new QueryColumn(this, "menu_type");
|
||||
|
||||
/**
|
||||
* 父菜单ID
|
||||
*/
|
||||
public final QueryColumn PARENT_ID = new QueryColumn(this, "parent_id");
|
||||
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
public final QueryColumn SORT_ORDER = new QueryColumn(this, "sort_order");
|
||||
|
||||
/**
|
||||
@@ -72,7 +84,7 @@ public class MenuDef extends TableDef {
|
||||
/**
|
||||
* 默认字段,不包含逻辑删除或者 large 等字段。
|
||||
*/
|
||||
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, CLIENT_TYPE, MENU_NAME, PARENT_ID, PATH, ICON, IS_TENANT, IS_HIDE, SORT_ORDER};
|
||||
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, CLIENT_TYPE, MENU_NAME, PARENT_ID, FUN_ID, MENU_TYPE, PATH, ICON, IS_TENANT, IS_HIDE, SORT_ORDER};
|
||||
|
||||
public MenuDef() {
|
||||
super("", "cg_menu");
|
||||
|
||||
@@ -27,7 +27,7 @@ public class RoleFunDef extends TableDef {
|
||||
public final QueryColumn ID = new QueryColumn(this, "id");
|
||||
|
||||
/**
|
||||
* 权限ID
|
||||
* 操作ID
|
||||
*/
|
||||
public final QueryColumn FUN_ID = new QueryColumn(this, "fun_id");
|
||||
|
||||
@@ -41,6 +41,11 @@ public class RoleFunDef extends TableDef {
|
||||
*/
|
||||
public final QueryColumn DATA_SCOPE = new QueryColumn(this, "data_scope");
|
||||
|
||||
/**
|
||||
* 客户端类型:0 PC端,1 小程序端,2 H5端
|
||||
*/
|
||||
public final QueryColumn CLIENT_TYPE = new QueryColumn(this, "client_type");
|
||||
|
||||
/**
|
||||
* 排除的字段
|
||||
*/
|
||||
@@ -59,7 +64,7 @@ public class RoleFunDef extends TableDef {
|
||||
/**
|
||||
* 默认字段,不包含逻辑删除或者 large 等字段。
|
||||
*/
|
||||
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, ROLE_ID, FUN_ID, DATA_SCOPE, ASSIGN_DATA_SCOPE, EXCLUDE_FIELD};
|
||||
public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, ROLE_ID, FUN_ID, DATA_SCOPE, ASSIGN_DATA_SCOPE, EXCLUDE_FIELD, CLIENT_TYPE};
|
||||
|
||||
public RoleFunDef() {
|
||||
super("", "cg_role_fun");
|
||||
|
||||
@@ -45,6 +45,6 @@ public interface MenuService {
|
||||
/**
|
||||
* 删除菜单权限
|
||||
*/
|
||||
XResult<Void> deleteFun(Long menuBindFunId);
|
||||
XResult<Void> deleteFun(Long menuId);
|
||||
|
||||
}
|
||||
@@ -8,14 +8,11 @@ import com.cczsa.xinghe.codegen.entity.req.menu.MenuAddReq;
|
||||
import com.cczsa.xinghe.codegen.entity.req.menu.MenuBindFunReq;
|
||||
import com.cczsa.xinghe.codegen.entity.req.menu.MenuEditReq;
|
||||
import com.cczsa.xinghe.codegen.entity.req.menu.MenuQueryReq;
|
||||
import com.cczsa.xinghe.codegen.entity.res.menu.MenuFunListQueryRes;
|
||||
import com.cczsa.xinghe.codegen.entity.res.menu.MenuQueryRes;
|
||||
import com.cczsa.xinghe.codegen.mapper.FunItemMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.FunOperationMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.MenuBindFunMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.MenuMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.FunOperationDef;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.MenuBindFunDef;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.MenuDef;
|
||||
import com.cczsa.xinghe.codegen.service.MenuService;
|
||||
import com.cczsa.xinghe.codegen.util.XResult;
|
||||
@@ -42,7 +39,6 @@ import java.util.Map;
|
||||
public class MenuServiceImpl implements MenuService {
|
||||
|
||||
private final MenuMapper menuMapper;
|
||||
private final MenuBindFunMapper menuBindFunMapper;
|
||||
private final FunOperationMapper funOperationMapper;
|
||||
private final FunItemMapper funItemMapper;
|
||||
|
||||
@@ -53,65 +49,45 @@ public class MenuServiceImpl implements MenuService {
|
||||
@Override
|
||||
public XResult<List<MenuQueryRes>> query(MenuQueryReq req) {
|
||||
MenuDef menuDef = MenuDef.MENU_ENTITY;
|
||||
FunOperationDef funOperationDef = FunOperationDef.FUN_OPERATION_ENTITY;
|
||||
QueryWrapper query = new QueryWrapper();
|
||||
query.select(menuDef.ALL_COLUMNS)
|
||||
query.select(
|
||||
menuDef.ALL_COLUMNS,
|
||||
funOperationDef.ID.as("funId"),
|
||||
funOperationDef.FUN_NAME.as("funName")
|
||||
)
|
||||
.from(menuDef)
|
||||
.leftJoin(funOperationDef).on(menuDef.FUN_ID.eq(funOperationDef.ID))
|
||||
.eq(MenuEntity::getClientType, req.getClientType())
|
||||
.like(MenuEntity::getMenuName, req.getMenuName(), StrUtil.isNotBlank(req.getMenuName()))
|
||||
.eq(MenuEntity::getParentId, req.getParentId(), req.getParentId() != null)
|
||||
.orderBy(MenuEntity::getSortOrder, false);
|
||||
List<MenuQueryRes> menuEntities = menuMapper.selectListByQueryAs(query, MenuQueryRes.class);
|
||||
// 获取功能ID
|
||||
for (MenuQueryRes menuEntity : menuEntities) {
|
||||
FunOperationDef funOperationDef = FunOperationDef.FUN_OPERATION_ENTITY;
|
||||
MenuBindFunDef menuBindFunDef = MenuBindFunDef.MENU_BIND_FUN_ENTITY;
|
||||
QueryWrapper queryMenuBindFun = new QueryWrapper();
|
||||
queryMenuBindFun.select(
|
||||
menuBindFunDef.ID.as("menuBindFunId"),
|
||||
funOperationDef.ID.as("funId"),
|
||||
funOperationDef.FUN_NAME.as("funName")
|
||||
)
|
||||
.from(menuBindFunDef)
|
||||
.leftJoin(funOperationDef).on(menuBindFunDef.FUN_ID.eq(funOperationDef.ID))
|
||||
.eq(MenuBindFunEntity::getMenuId, menuEntity.getId());
|
||||
List<MenuFunListQueryRes> menuFunListQueryRes = menuBindFunMapper.selectListByQueryAs(queryMenuBindFun, MenuFunListQueryRes.class);
|
||||
menuEntity.setFunList(menuFunListQueryRes);
|
||||
}
|
||||
// 为功能列表填充存在个数信息
|
||||
fillExistNumForFunList(menuEntities);
|
||||
fillExistNumForMenuList(menuEntities);
|
||||
// 构建树形结构
|
||||
List<MenuQueryRes> treeList = buildMenuTree(menuEntities);
|
||||
return XResult.ok(treeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为功能列表填充存在个数信息
|
||||
* 为菜单列表填充功能存在个数信息
|
||||
*
|
||||
* @param menuEntities 菜单实体列表
|
||||
*/
|
||||
private void fillExistNumForFunList(List<MenuQueryRes> menuEntities) {
|
||||
private void fillExistNumForMenuList(List<MenuQueryRes> menuEntities) {
|
||||
// 统计每个功能ID在整个系统中的出现次数
|
||||
Map<Long, Integer> funIdCountMap = new HashMap<>();
|
||||
// 遍历所有菜单及其功能列表,统计功能ID出现次数
|
||||
// 遍历所有菜单,统计功能ID出现次数
|
||||
for (MenuQueryRes menu : menuEntities) {
|
||||
if (menu.getFunList() != null && !menu.getFunList().isEmpty()) {
|
||||
for (MenuFunListQueryRes fun : menu.getFunList()) {
|
||||
if (fun.getFunId() != null) {
|
||||
funIdCountMap.put(fun.getFunId(),
|
||||
funIdCountMap.getOrDefault(fun.getFunId(), 0) + 1);
|
||||
}
|
||||
}
|
||||
if (menu.getFunId() != null) {
|
||||
funIdCountMap.put(menu.getFunId(),
|
||||
funIdCountMap.getOrDefault(menu.getFunId(), 0) + 1);
|
||||
}
|
||||
}
|
||||
// 更新每个菜单中的功能列表的 existNum 字段
|
||||
// 更新每个菜单中的 existNum 字段
|
||||
for (MenuQueryRes menu : menuEntities) {
|
||||
if (menu.getFunList() != null && !menu.getFunList().isEmpty()) {
|
||||
for (MenuFunListQueryRes fun : menu.getFunList()) {
|
||||
if (fun.getFunId() != null) {
|
||||
// 设置该功能在整个系统中的存在个数
|
||||
fun.setExistNum(funIdCountMap.get(fun.getFunId()));
|
||||
}
|
||||
}
|
||||
if (menu.getFunId() != null && funIdCountMap.containsKey(menu.getFunId())) {
|
||||
menu.setExistNum(funIdCountMap.get(menu.getFunId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,10 +202,6 @@ public class MenuServiceImpl implements MenuService {
|
||||
QueryWrapper deleteMenu = new QueryWrapper();
|
||||
deleteMenu.eq(MenuEntity::getId, id);
|
||||
menuMapper.deleteByQuery(deleteMenu);
|
||||
// 删除菜单绑定的权限
|
||||
QueryWrapper deleteMenuBindFun = new QueryWrapper();
|
||||
deleteMenuBindFun.eq(MenuBindFunEntity::getMenuId, id);
|
||||
menuBindFunMapper.deleteByQuery(deleteMenuBindFun);
|
||||
return XResult.ok();
|
||||
}
|
||||
|
||||
@@ -246,50 +218,26 @@ public class MenuServiceImpl implements MenuService {
|
||||
if (menuEntity == null) {
|
||||
return XResult.failed("菜单不存在");
|
||||
}
|
||||
// 获取操作
|
||||
List<Long> funIdList = req.getFunIdList();
|
||||
// 删除旧绑定
|
||||
QueryWrapper deleteMenuBindFun = new QueryWrapper();
|
||||
deleteMenuBindFun.eq(MenuBindFunEntity::getMenuId, req.getMenuId());
|
||||
menuBindFunMapper.deleteByQuery(deleteMenuBindFun);
|
||||
for (Long funId : funIdList) {
|
||||
QueryWrapper queryFun = new QueryWrapper();
|
||||
queryFun.eq(FunOperationEntity::getId, funId);
|
||||
FunOperationEntity funOperationEntity = funOperationMapper.selectOneByQuery(queryFun);
|
||||
if (funOperationEntity == null) {
|
||||
return XResult.failed("权限不存在:" + funId);
|
||||
}
|
||||
// 获取功能
|
||||
QueryWrapper queryItem = new QueryWrapper();
|
||||
queryItem.eq(FunItemEntity::getId, funOperationEntity.getItemId());
|
||||
FunItemEntity funItemEntity = funItemMapper.selectOneByQuery(queryItem);
|
||||
if (funItemEntity == null) {
|
||||
return XResult.failed("功能不存在:" + funId);
|
||||
}
|
||||
Boolean menuIsTenant = menuEntity.getIsTenant();
|
||||
Boolean itemIsTenant = funItemEntity.getIsTenant();
|
||||
if (!menuIsTenant.equals(itemIsTenant)) {
|
||||
return XResult.failed("菜单和权限是否租户不一致:" + funId);
|
||||
}
|
||||
// 获取最大ID
|
||||
MenuBindFunDef menuBindFunDef = MenuBindFunDef.MENU_BIND_FUN_ENTITY;
|
||||
QueryWrapper queryId = new QueryWrapper();
|
||||
queryId.select(menuBindFunDef.ID)
|
||||
.from(menuBindFunDef)
|
||||
.orderBy(MenuBindFunEntity::getId, false);
|
||||
Long maxId = menuBindFunMapper.selectOneByQueryAs(queryId, Long.class);
|
||||
if (maxId == null) {
|
||||
maxId = 10000L;
|
||||
} else {
|
||||
maxId++;
|
||||
}
|
||||
// 新增绑定
|
||||
MenuBindFunEntity menuBindFunEntity = new MenuBindFunEntity();
|
||||
menuBindFunEntity.setId(maxId);
|
||||
menuBindFunEntity.setMenuId(req.getMenuId());
|
||||
menuBindFunEntity.setFunId(funId);
|
||||
menuBindFunMapper.insertSelective(menuBindFunEntity);
|
||||
QueryWrapper queryFun = new QueryWrapper();
|
||||
queryFun.eq(FunOperationEntity::getId, req.getFunId());
|
||||
FunOperationEntity funOperationEntity = funOperationMapper.selectOneByQuery(queryFun);
|
||||
if (funOperationEntity == null) {
|
||||
return XResult.failed("权限不存在:" + req.getFunId());
|
||||
}
|
||||
// 获取功能
|
||||
QueryWrapper queryItem = new QueryWrapper();
|
||||
queryItem.eq(FunItemEntity::getId, funOperationEntity.getItemId());
|
||||
FunItemEntity funItemEntity = funItemMapper.selectOneByQuery(queryItem);
|
||||
if (funItemEntity == null) {
|
||||
return XResult.failed("功能不存在:" + req.getFunId());
|
||||
}
|
||||
Boolean menuIsTenant = menuEntity.getIsTenant();
|
||||
Boolean itemIsTenant = funItemEntity.getIsTenant();
|
||||
if (!menuIsTenant.equals(itemIsTenant)) {
|
||||
return XResult.failed("菜单和权限是否租户不一致:" + req.getFunId());
|
||||
}
|
||||
menuEntity.setFunId(req.getFunId());
|
||||
menuMapper.update(menuEntity);
|
||||
return XResult.ok();
|
||||
}
|
||||
|
||||
@@ -297,10 +245,16 @@ public class MenuServiceImpl implements MenuService {
|
||||
* 删除菜单权限
|
||||
*/
|
||||
@Override
|
||||
public XResult<Void> deleteFun(Long menuBindFunId) {
|
||||
QueryWrapper deleteMenuBindFun = new QueryWrapper();
|
||||
deleteMenuBindFun.eq(MenuBindFunEntity::getId, menuBindFunId);
|
||||
menuBindFunMapper.deleteByQuery(deleteMenuBindFun);
|
||||
public XResult<Void> deleteFun(Long menuId) {
|
||||
// 获取菜单
|
||||
QueryWrapper queryMenu = new QueryWrapper();
|
||||
queryMenu.eq(MenuEntity::getId, menuId);
|
||||
MenuEntity menuEntity = menuMapper.selectOneByQuery(queryMenu);
|
||||
if (menuEntity == null) {
|
||||
return XResult.failed("菜单不存在");
|
||||
}
|
||||
menuEntity.setFunId(null);
|
||||
menuMapper.update(menuEntity, false);
|
||||
return XResult.ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.cczsa.xinghe.codegen.service.impl;
|
||||
|
||||
import com.cczsa.xinghe.codegen.entity.FunOperationEntity;
|
||||
import com.cczsa.xinghe.codegen.entity.MenuBindFunEntity;
|
||||
import com.cczsa.xinghe.codegen.entity.MenuEntity;
|
||||
import com.cczsa.xinghe.codegen.entity.RoleEntity;
|
||||
import com.cczsa.xinghe.codegen.entity.RoleFunEntity;
|
||||
@@ -11,16 +10,13 @@ import com.cczsa.xinghe.codegen.entity.req.role.RoleBindFunReq;
|
||||
import com.cczsa.xinghe.codegen.entity.req.role.RoleEditReq;
|
||||
import com.cczsa.xinghe.codegen.entity.req.role.RoleQueryFunReq;
|
||||
import com.cczsa.xinghe.codegen.entity.req.role.RoleQueryReq;
|
||||
import com.cczsa.xinghe.codegen.entity.res.role.MenuFunListRes;
|
||||
import com.cczsa.xinghe.codegen.entity.res.role.RoleQueryFunRes;
|
||||
import com.cczsa.xinghe.codegen.entity.res.role.RoleQueryRes;
|
||||
import com.cczsa.xinghe.codegen.mapper.FunOperationMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.MenuBindFunMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.MenuMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.RoleFunMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.RoleMapper;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.FunOperationDef;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.MenuBindFunDef;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.MenuDef;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.RoleDef;
|
||||
import com.cczsa.xinghe.codegen.mapper.def.RoleFunDef;
|
||||
@@ -52,7 +48,6 @@ public class RoleServiceImpl implements RoleService {
|
||||
private final RoleFunMapper roleFunMapper;
|
||||
private final FunOperationMapper funOperationMapper;
|
||||
private final MenuMapper menuMapper;
|
||||
private final MenuBindFunMapper menuBindFunMapper;
|
||||
|
||||
|
||||
/**
|
||||
@@ -179,6 +174,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
roleFunEntity.setFunId(req.getFunId());
|
||||
roleFunEntity.setDataScope(req.getDataScope());
|
||||
roleFunEntity.setExcludeField(req.getExcludeField());
|
||||
roleFunEntity.setClientType(req.getClientType());
|
||||
if (req.getExcludeField() == null || !req.getExcludeField().isEmpty()) {
|
||||
roleFunEntity.setExcludeField(new ArrayList<>());
|
||||
}
|
||||
@@ -223,9 +219,19 @@ public class RoleServiceImpl implements RoleService {
|
||||
public XResult<List<RoleQueryFunRes>> queryRoleFun(RoleQueryFunReq req) {
|
||||
// 获取菜单
|
||||
MenuDef menuDef = MenuDef.MENU_ENTITY;
|
||||
FunOperationDef funOperationDef = FunOperationDef.FUN_OPERATION_ENTITY;
|
||||
QueryWrapper queryMenu = new QueryWrapper();
|
||||
queryMenu.select(menuDef.ALL_COLUMNS)
|
||||
queryMenu.select
|
||||
(
|
||||
menuDef.ALL_COLUMNS,
|
||||
funOperationDef.ID.as("funId"),
|
||||
funOperationDef.FUN_NAME,
|
||||
funOperationDef.USABLE_CONFIG,
|
||||
funOperationDef.FIELD_CONFIG,
|
||||
funOperationDef.DESCRIBE
|
||||
)
|
||||
.from(menuDef)
|
||||
.leftJoin(funOperationDef).on(menuDef.FUN_ID.eq(funOperationDef.ID))
|
||||
.eq(MenuEntity::getClientType, req.getClientType());
|
||||
List<RoleQueryFunRes> roleQueryFunList = menuMapper.selectListByQueryAs(queryMenu, RoleQueryFunRes.class);
|
||||
// 获取角色功能权限
|
||||
@@ -237,42 +243,24 @@ public class RoleServiceImpl implements RoleService {
|
||||
List<RoleFunEntity> roleFunEntities = roleFunMapper.selectListByQuery(queryRoleFun);
|
||||
for (RoleQueryFunRes roleQueryFunRes : roleQueryFunList) {
|
||||
// 获取菜单功能
|
||||
FunOperationDef funOperationDef = FunOperationDef.FUN_OPERATION_ENTITY;
|
||||
MenuBindFunDef menuBindFunDef = MenuBindFunDef.MENU_BIND_FUN_ENTITY;
|
||||
QueryWrapper queryMenuBindFun = new QueryWrapper();
|
||||
queryMenuBindFun.select(
|
||||
funOperationDef.ID,
|
||||
funOperationDef.FUN_NAME,
|
||||
funOperationDef.USABLE_CONFIG,
|
||||
funOperationDef.FIELD_CONFIG,
|
||||
funOperationDef.SORT_ORDER,
|
||||
funOperationDef.DESCRIBE
|
||||
)
|
||||
.from(menuBindFunDef)
|
||||
.leftJoin(funOperationDef).on(funOperationDef.ID.eq(menuBindFunDef.FUN_ID))
|
||||
.eq(MenuBindFunEntity::getMenuId, roleQueryFunRes.getId());
|
||||
List<MenuFunListRes> menuFunList = menuBindFunMapper.selectListByQueryAs(queryMenuBindFun, MenuFunListRes.class);
|
||||
for (MenuFunListRes menuFunListRes : menuFunList) {
|
||||
// 在roleFunEntities中查找匹配的功能权限
|
||||
RoleFunEntity roleFunEntity = roleFunEntities.stream()
|
||||
.filter(entity -> entity.getFunId().equals(menuFunListRes.getId()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (roleFunEntity != null) {
|
||||
// 设置角色权限配置
|
||||
menuFunListRes.setDataScope(roleFunEntity.getDataScope());
|
||||
menuFunListRes.setExcludeField(roleFunEntity.getExcludeField());
|
||||
menuFunListRes.setAssignDataScope(roleFunEntity.getAssignDataScope());
|
||||
menuFunListRes.setIsSelect(true);
|
||||
menuFunListRes.setFunBindId(roleFunEntity.getId());
|
||||
} else {
|
||||
// 如果角色没有此功能的权限,设置默认值
|
||||
menuFunListRes.setDataScope(null);
|
||||
menuFunListRes.setExcludeField(new ArrayList<>());
|
||||
menuFunListRes.setAssignDataScope(new ArrayList<>());
|
||||
}
|
||||
RoleFunEntity roleFunEntity = roleFunEntities.stream()
|
||||
.filter(entity -> entity.getFunId().equals(roleQueryFunRes.getFunId()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (roleFunEntity != null) {
|
||||
// 设置角色权限配置
|
||||
roleQueryFunRes.setDataScope(roleFunEntity.getDataScope());
|
||||
roleQueryFunRes.setExcludeField(roleFunEntity.getExcludeField());
|
||||
roleQueryFunRes.setAssignDataScope(roleFunEntity.getAssignDataScope());
|
||||
roleQueryFunRes.setIsSelect(true);
|
||||
roleQueryFunRes.setFunBindId(roleFunEntity.getId());
|
||||
roleQueryFunRes.setFunClientType(roleFunEntity.getClientType());
|
||||
} else {
|
||||
// 如果角色没有此功能的权限,设置默认值
|
||||
roleQueryFunRes.setDataScope(null);
|
||||
roleQueryFunRes.setExcludeField(new ArrayList<>());
|
||||
roleQueryFunRes.setAssignDataScope(new ArrayList<>());
|
||||
}
|
||||
roleQueryFunRes.setMenuFunList(menuFunList);
|
||||
}
|
||||
// 构建树形结构
|
||||
List<RoleQueryFunRes> treeList = buildMenuTree(roleQueryFunList);
|
||||
|
||||
Reference in New Issue
Block a user