增加部门

This commit is contained in:
戚辰先生 2024-12-01 22:33:14 +08:00
parent 750f446844
commit 32f50ae7e4
15 changed files with 271 additions and 108 deletions

View File

@ -5,6 +5,7 @@ import com.qqchen.deploy.backend.framework.api.Response;
import com.qqchen.deploy.backend.framework.controller.BaseController; import com.qqchen.deploy.backend.framework.controller.BaseController;
import com.qqchen.deploy.backend.model.MenuDTO; import com.qqchen.deploy.backend.model.MenuDTO;
import com.qqchen.deploy.backend.model.query.MenuQuery; import com.qqchen.deploy.backend.model.query.MenuQuery;
import com.qqchen.deploy.backend.model.response.MenuPermissionTreeResponse;
import com.qqchen.deploy.backend.model.response.MenuResponse; import com.qqchen.deploy.backend.model.response.MenuResponse;
import com.qqchen.deploy.backend.service.IMenuService; import com.qqchen.deploy.backend.service.IMenuService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -42,6 +43,12 @@ public class MenuApiController extends BaseController<Menu, MenuDTO, Long, MenuQ
return Response.success(menuService.getMenuTree()); return Response.success(menuService.getMenuTree());
} }
@Operation(summary = "获取菜单树")
@GetMapping("/permission-tree")
public Response<List<MenuPermissionTreeResponse>> getPermissionTree() {
return Response.success(menuService.getPermissionTree());
}
@Override @Override
protected void exportData(HttpServletResponse response, List<MenuDTO> data) { protected void exportData(HttpServletResponse response, List<MenuDTO> data) {

View File

@ -0,0 +1,23 @@
package com.qqchen.deploy.backend.api;
import com.qqchen.deploy.backend.entity.Permission;
import com.qqchen.deploy.backend.framework.controller.BaseController;
import com.qqchen.deploy.backend.model.PermissionDTO;
import com.qqchen.deploy.backend.model.query.PermissionQuery;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Tag(name = "权限管理")
@RestController
@RequestMapping("/api/v1/permission")
public class PermissionApiController extends BaseController<Permission, PermissionDTO, Long, PermissionQuery> {
@Override
protected void exportData(HttpServletResponse response, List<PermissionDTO> data) {
// TODO: 实现导出功能
}
}

View File

@ -3,6 +3,7 @@ package com.qqchen.deploy.backend.converter;
import com.qqchen.deploy.backend.entity.Menu; import com.qqchen.deploy.backend.entity.Menu;
import com.qqchen.deploy.backend.framework.converter.BaseConverter; import com.qqchen.deploy.backend.framework.converter.BaseConverter;
import com.qqchen.deploy.backend.model.MenuDTO; import com.qqchen.deploy.backend.model.MenuDTO;
import com.qqchen.deploy.backend.model.response.MenuPermissionTreeResponse;
import com.qqchen.deploy.backend.model.response.MenuResponse; import com.qqchen.deploy.backend.model.response.MenuResponse;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
@ -22,4 +23,6 @@ public interface MenuConverter extends BaseConverter<Menu, MenuDTO> {
MenuResponse toResponse(MenuDTO dto); MenuResponse toResponse(MenuDTO dto);
List<MenuResponse> toResponseList(List<MenuDTO> dtoList); List<MenuResponse> toResponseList(List<MenuDTO> dtoList);
MenuPermissionTreeResponse toMenuPermissionResponse(Menu menu);
} }

View File

@ -3,8 +3,12 @@ package com.qqchen.deploy.backend.converter;
import com.qqchen.deploy.backend.entity.Permission; import com.qqchen.deploy.backend.entity.Permission;
import com.qqchen.deploy.backend.framework.converter.BaseConverter; import com.qqchen.deploy.backend.framework.converter.BaseConverter;
import com.qqchen.deploy.backend.model.PermissionDTO; import com.qqchen.deploy.backend.model.PermissionDTO;
import com.qqchen.deploy.backend.model.response.PermissionResponse;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import java.util.List;
@Mapper(config = BaseConverter.class) @Mapper(config = BaseConverter.class)
public interface PermissionConverter extends BaseConverter<Permission, PermissionDTO> { public interface PermissionConverter extends BaseConverter<Permission, PermissionDTO> {
List<PermissionResponse> toResponseList(List<Permission> list);
} }

View File

@ -3,6 +3,9 @@ package com.qqchen.deploy.backend.entity;
import com.qqchen.deploy.backend.framework.annotation.LogicDelete; import com.qqchen.deploy.backend.framework.annotation.LogicDelete;
import com.qqchen.deploy.backend.framework.domain.Entity; import com.qqchen.deploy.backend.framework.domain.Entity;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import lombok.Data; import lombok.Data;
@ -72,9 +75,10 @@ public class Menu extends Entity<Long> {
@ManyToMany(mappedBy = "menus") @ManyToMany(mappedBy = "menus")
private Set<Role> roles = new HashSet<>(); private Set<Role> roles = new HashSet<>();
/** @ManyToMany(fetch = FetchType.LAZY)
* 菜单关联的权限模板列表 @JoinTable(
*/ name = "sys_permission",
@ManyToMany(mappedBy = "menus") joinColumns = @JoinColumn(name = "menu_id")
private Set<PermissionTemplate> templates = new HashSet<>(); )
private Set<Permission> permissions = new HashSet<>();
} }

View File

@ -37,6 +37,15 @@ public class Permission extends Entity<Long> {
@Column(length = 200) @Column(length = 200)
private String description; private String description;
@ManyToMany(mappedBy = "permissions") @ManyToMany(fetch = FetchType.LAZY)
private Set<Role> roles = new HashSet<>(); @JoinTable(
name = "sys_template_menu",
joinColumns = @JoinColumn(name = "template_id"),
inverseJoinColumns = @JoinColumn(name = "menu_id")
)
private Set<Menu> menus = new HashSet<>();
// @ManyToMany(mappedBy = "permissions")
// private Set<Role> roles = new HashSet<>();
} }

View File

@ -54,5 +54,5 @@ public class Role extends Entity<Long> {
joinColumns = @JoinColumn(name = "role_id"), joinColumns = @JoinColumn(name = "role_id"),
inverseJoinColumns = @JoinColumn(name = "permission_id") inverseJoinColumns = @JoinColumn(name = "permission_id")
) )
private Set<Permission> permissions; private Set<Permission> permissions = new HashSet<>();
} }

View File

@ -14,8 +14,6 @@ public class PermissionDTO extends BaseDTO {
private String type; private String type;
private Boolean enabled;
private Integer sort; private Integer sort;
private String menuName; // 关联的菜单名称 private String menuName; // 关联的菜单名称

View File

@ -0,0 +1,20 @@
package com.qqchen.deploy.backend.model.query;
import com.qqchen.deploy.backend.framework.query.BaseQuery;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = true)
public class PermissionQuery extends BaseQuery {
private String code;
private String name;
private String type;
private Boolean enabled;
private Long menuId;
}

View File

@ -0,0 +1,16 @@
package com.qqchen.deploy.backend.model.response;
import com.qqchen.deploy.backend.model.PermissionDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
public class MenuPermissionTreeResponse extends MenuResponse {
/**
* 菜单下的权限列表
*/
private List<PermissionResponse> permissions;
}

View File

@ -0,0 +1,21 @@
package com.qqchen.deploy.backend.model.response;
import com.qqchen.deploy.backend.framework.dto.BaseResponse;
import lombok.Data;
@Data
public class PermissionResponse extends BaseResponse {
private Long menuId;
private String menuName;
private String code;
private String name;
private String type;
private Integer sort;
}

View File

@ -3,6 +3,7 @@ package com.qqchen.deploy.backend.service;
import com.qqchen.deploy.backend.framework.service.IBaseService; import com.qqchen.deploy.backend.framework.service.IBaseService;
import com.qqchen.deploy.backend.entity.Menu; import com.qqchen.deploy.backend.entity.Menu;
import com.qqchen.deploy.backend.model.MenuDTO; import com.qqchen.deploy.backend.model.MenuDTO;
import com.qqchen.deploy.backend.model.response.MenuPermissionTreeResponse;
import com.qqchen.deploy.backend.model.response.MenuResponse; import com.qqchen.deploy.backend.model.response.MenuResponse;
import java.util.List; import java.util.List;
@ -25,4 +26,7 @@ public interface IMenuService extends IBaseService<Menu, MenuDTO, Long> {
* 获取菜单树 * 获取菜单树
*/ */
List<MenuDTO> getTree(); List<MenuDTO> getTree();
List<MenuPermissionTreeResponse> getPermissionTree();
} }

View File

@ -1,19 +1,24 @@
package com.qqchen.deploy.backend.service.impl; package com.qqchen.deploy.backend.service.impl;
import com.qqchen.deploy.backend.converter.MenuConverter; import com.qqchen.deploy.backend.converter.MenuConverter;
import com.qqchen.deploy.backend.converter.PermissionConverter;
import com.qqchen.deploy.backend.entity.Menu; import com.qqchen.deploy.backend.entity.Menu;
import com.qqchen.deploy.backend.entity.Permission;
import com.qqchen.deploy.backend.framework.annotation.ServiceType; import com.qqchen.deploy.backend.framework.annotation.ServiceType;
import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl; import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl;
import com.qqchen.deploy.backend.model.MenuDTO; import com.qqchen.deploy.backend.model.MenuDTO;
import com.qqchen.deploy.backend.model.UserDTO; import com.qqchen.deploy.backend.model.UserDTO;
import com.qqchen.deploy.backend.model.response.MenuPermissionTreeResponse;
import com.qqchen.deploy.backend.model.response.MenuResponse; import com.qqchen.deploy.backend.model.response.MenuResponse;
import com.qqchen.deploy.backend.repository.IMenuRepository; import com.qqchen.deploy.backend.repository.IMenuRepository;
import com.qqchen.deploy.backend.repository.IPermissionRepository;
import com.qqchen.deploy.backend.service.IMenuService; import com.qqchen.deploy.backend.service.IMenuService;
import com.qqchen.deploy.backend.service.IUserService; import com.qqchen.deploy.backend.service.IUserService;
import com.qqchen.deploy.backend.service.IRoleService; import com.qqchen.deploy.backend.service.IRoleService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,9 +36,15 @@ public class MenuServiceImpl extends BaseServiceImpl<Menu, MenuDTO, Long> implem
@Resource @Resource
private IMenuRepository menuRepository; private IMenuRepository menuRepository;
@Resource
private IPermissionRepository permissionRepository;
@Resource @Resource
private MenuConverter menuConverter; private MenuConverter menuConverter;
@Resource
private PermissionConverter permissionConverter;
@Resource @Resource
private IUserService userService; private IUserService userService;
@ -73,6 +84,19 @@ public class MenuServiceImpl extends BaseServiceImpl<Menu, MenuDTO, Long> implem
return buildTree(menus); return buildTree(menus);
} }
@Override
public List<MenuPermissionTreeResponse> getPermissionTree() {
List<Menu> menus = menuRepository.findByDeletedFalseOrderBySort();
List<Permission> permissions = permissionRepository.findAllEnabledOrderByMenuAndSort();
List<MenuPermissionTreeResponse> tree = new ArrayList<>();
menus.forEach(menu -> {
MenuPermissionTreeResponse menuPermissionResponse = menuConverter.toMenuPermissionResponse(menu);
List<Permission> list = permissions.stream().filter(permission -> permission.getMenuId().equals(menu.getId())).toList();
menuPermissionResponse.setPermissions(permissionConverter.toResponseList(list));
});
return null;
}
private List<MenuDTO> buildTree(List<Menu> menus) { private List<MenuDTO> buildTree(List<Menu> menus) {
Map<Long, MenuDTO> dtoMap = new HashMap<>(); Map<Long, MenuDTO> dtoMap = new HashMap<>();
List<MenuDTO> roots = new ArrayList<>(); List<MenuDTO> roots = new ArrayList<>();

View File

@ -53,8 +53,8 @@ CREATE TABLE IF NOT EXISTS sys_user (
phone VARCHAR(255) NULL, phone VARCHAR(255) NULL,
username VARCHAR(255) NOT NULL, username VARCHAR(255) NOT NULL,
department_id BIGINT NULL, department_id BIGINT NULL,
CONSTRAINT UK_user_username UNIQUE (username), CONSTRAINT UK_user_username UNIQUE (username)
CONSTRAINT FK_user_department FOREIGN KEY (department_id) REFERENCES sys_department(id) -- CONSTRAINT FK_user_department FOREIGN KEY (department_id) REFERENCES sys_department(id)
); );
-- 创建系统参数表 -- 创建系统参数表
@ -114,7 +114,6 @@ CREATE TABLE sys_role (
type INT NOT NULL DEFAULT 2 COMMENT '角色类型1系统角色 2自定义角色', type INT NOT NULL DEFAULT 2 COMMENT '角色类型1系统角色 2自定义角色',
description VARCHAR(255) COMMENT '角色描述', description VARCHAR(255) COMMENT '角色描述',
sort INT NOT NULL DEFAULT 0 COMMENT '显示顺序', sort INT NOT NULL DEFAULT 0 COMMENT '显示顺序',
enabled BIT NOT NULL DEFAULT 1 COMMENT '是否启用',
CONSTRAINT UK_role_code UNIQUE (code) CONSTRAINT UK_role_code UNIQUE (code)
) COMMENT '角色表'; ) COMMENT '角色表';
@ -137,9 +136,9 @@ CREATE TABLE sys_role_tag (
CREATE TABLE sys_role_tag_relation ( CREATE TABLE sys_role_tag_relation (
role_id BIGINT NOT NULL COMMENT '角色ID', role_id BIGINT NOT NULL COMMENT '角色ID',
tag_id BIGINT NOT NULL COMMENT '标签ID', tag_id BIGINT NOT NULL COMMENT '标签ID',
PRIMARY KEY (role_id, tag_id), PRIMARY KEY (role_id, tag_id)
CONSTRAINT FK_role_tag_role FOREIGN KEY (role_id) REFERENCES sys_role (id), -- CONSTRAINT FK_role_tag_role FOREIGN KEY (role_id) REFERENCES sys_role (id),
CONSTRAINT FK_role_tag_tag FOREIGN KEY (tag_id) REFERENCES sys_role_tag (id) -- CONSTRAINT FK_role_tag_tag FOREIGN KEY (tag_id) REFERENCES sys_role_tag (id)
) COMMENT '角色标签关联表'; ) COMMENT '角色标签关联表';
-- 用户角色关联表 -- 用户角色关联表
@ -155,18 +154,18 @@ CREATE TABLE sys_user_role (
user_id BIGINT NOT NULL COMMENT '用户ID', user_id BIGINT NOT NULL COMMENT '用户ID',
role_id BIGINT NOT NULL COMMENT '角色ID', role_id BIGINT NOT NULL COMMENT '角色ID',
CONSTRAINT UK_user_role UNIQUE (user_id, role_id), CONSTRAINT UK_user_role UNIQUE (user_id, role_id)
CONSTRAINT FK_user_role_user FOREIGN KEY (user_id) REFERENCES sys_user (id), -- CONSTRAINT FK_user_role_user FOREIGN KEY (user_id) REFERENCES sys_user (id),
CONSTRAINT FK_user_role_role FOREIGN KEY (role_id) REFERENCES sys_role (id) -- CONSTRAINT FK_user_role_role FOREIGN KEY (role_id) REFERENCES sys_role (id)
) COMMENT '用户角色关联表'; ) COMMENT '用户角色关联表';
-- 角色菜单关联表 -- 角色菜单关联表
CREATE TABLE sys_role_menu ( CREATE TABLE sys_role_menu (
role_id BIGINT NOT NULL COMMENT '角色ID', role_id BIGINT NOT NULL COMMENT '角色ID',
menu_id BIGINT NOT NULL COMMENT '菜单ID', menu_id BIGINT NOT NULL COMMENT '菜单ID',
PRIMARY KEY (role_id, menu_id), PRIMARY KEY (role_id, menu_id)
CONSTRAINT FK_role_menu_role FOREIGN KEY (role_id) REFERENCES sys_role (id), -- CONSTRAINT FK_role_menu_role FOREIGN KEY (role_id) REFERENCES sys_role (id),
CONSTRAINT FK_role_menu_menu FOREIGN KEY (menu_id) REFERENCES sys_menu (id) -- CONSTRAINT FK_role_menu_menu FOREIGN KEY (menu_id) REFERENCES sys_menu (id)
) COMMENT '角色菜单关联表'; ) COMMENT '角色菜单关联表';
-- 权限模板表 -- 权限模板表
@ -192,9 +191,9 @@ CREATE TABLE sys_permission_template (
CREATE TABLE sys_template_menu ( CREATE TABLE sys_template_menu (
template_id BIGINT NOT NULL COMMENT '模板ID', template_id BIGINT NOT NULL COMMENT '模板ID',
menu_id BIGINT NOT NULL COMMENT '菜单ID', menu_id BIGINT NOT NULL COMMENT '菜单ID',
PRIMARY KEY (template_id, menu_id), PRIMARY KEY (template_id, menu_id)
CONSTRAINT FK_template_menu_template FOREIGN KEY (template_id) REFERENCES sys_permission_template (id), -- CONSTRAINT FK_template_menu_template FOREIGN KEY (template_id) REFERENCES sys_permission_template (id),
CONSTRAINT FK_template_menu_menu FOREIGN KEY (menu_id) REFERENCES sys_menu (id) -- CONSTRAINT FK_template_menu_menu FOREIGN KEY (menu_id) REFERENCES sys_menu (id)
) COMMENT '模板菜单关联表'; ) COMMENT '模板菜单关联表';
-- 创建权限表 -- 创建权限表
@ -211,7 +210,6 @@ CREATE TABLE sys_permission (
code VARCHAR(100) NOT NULL COMMENT '权限编码', code VARCHAR(100) NOT NULL COMMENT '权限编码',
name VARCHAR(100) NOT NULL COMMENT '权限名称', name VARCHAR(100) NOT NULL COMMENT '权限名称',
type VARCHAR(50) NOT NULL DEFAULT 'FUNCTION' COMMENT '权限类型MENU/FUNCTION/API', type VARCHAR(50) NOT NULL DEFAULT 'FUNCTION' COMMENT '权限类型MENU/FUNCTION/API',
enabled BIT NOT NULL DEFAULT TRUE COMMENT '是否启用',
sort INT NULL COMMENT '排序', sort INT NULL COMMENT '排序',
UNIQUE KEY UK_CODE (CODE), UNIQUE KEY UK_CODE (CODE),
@ -253,8 +251,8 @@ CREATE TABLE sys_external_system (
CREATE TABLE sys_role_permission ( CREATE TABLE sys_role_permission (
role_id BIGINT NOT NULL COMMENT '角色ID', role_id BIGINT NOT NULL COMMENT '角色ID',
permission_id BIGINT NOT NULL COMMENT '权限ID', permission_id BIGINT NOT NULL COMMENT '权限ID',
PRIMARY KEY (role_id, permission_id), PRIMARY KEY (role_id, permission_id)
CONSTRAINT FK_role_permission_role FOREIGN KEY (role_id) REFERENCES sys_role (id), -- CONSTRAINT FK_role_permission_role FOREIGN KEY (role_id) REFERENCES sys_role (id),
CONSTRAINT FK_role_permission_permission FOREIGN KEY (permission_id) REFERENCES sys_permission (id) -- CONSTRAINT FK_role_permission_permission FOREIGN KEY (permission_id) REFERENCES sys_permission (id)
) COMMENT '角色权限关联表'; ) COMMENT '角色权限关联表';

View File

@ -1,130 +1,162 @@
-- 初始化租户
INSERT INTO sys_tenant
(create_by, create_time, deleted, update_by, update_time, version,
address, code, contact_name, contact_phone, email, enabled, name)
VALUES ('system', '2024-01-01 00:00:00', 0, 'system', '2024-01-01 00:00:00', 0,
'北京市朝阳区望京SOHO T1 C座', 'default', '张三', '13900000001',
'admin@deploy-ease.com', 1, '默认租户');
-- 初始化系统参数 -- 初始化系统参数
INSERT INTO sys_param (id, code, name, value, type, description, enabled, create_by, create_time, version, deleted) INSERT INTO sys_param (id, code, name, value, type, description, enabled, create_by, create_time, version, deleted)
VALUES (1, 'USER_STATUS_ENUM', '用户状态枚举', '[{"code":"0","name":"禁用"},{"code":"1","name":"启用"}]', 'ENUM', '用户状态枚举值', true, 'system', '2024-01-01 00:00:00', 0, false); VALUES (1, 'USER_STATUS_ENUM', '用户状态枚举', '[{"code":"0","name":"禁用"},{"code":"1","name":"启用"}]', 'ENUM', '用户状态枚举值', TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE);
-- 初始化角色标签 -- 初始化角色标签
INSERT INTO sys_role_tag (id, name, color, create_by, create_time, deleted, version) INSERT INTO sys_role_tag (id, name, color, create_by, create_time, deleted, version)
VALUES (1, '研发', '#1890FF', 'system', '2024-01-01 00:00:00', false, 0), VALUES (1, '研发', '#1890FF', 'system', '2024-01-01 00:00:00', FALSE, 0),
(2, '运维', '#52C41A', 'system', '2024-01-01 00:00:00', false, 0), (2, '运维', '#52C41A', 'system', '2024-01-01 00:00:00', FALSE, 0),
(3, '安全', '#FF4D4F', 'system', '2024-01-01 00:00:00', false, 0), (3, '安全', '#FF4D4F', 'system', '2024-01-01 00:00:00', FALSE, 0),
(4, '临时', '#FAAD14', 'system', '2024-01-01 00:00:00', false, 0), (4, '临时', '#FAAD14', 'system', '2024-01-01 00:00:00', FALSE, 0),
(5, '外部', '#722ED1', 'system', '2024-01-01 00:00:00', false, 0); (5, '外部', '#722ED1', 'system', '2024-01-01 00:00:00', FALSE, 0);
-- 初始化菜单数据 -- 初始化菜单数据
INSERT INTO sys_menu (id, name, path, component, icon, type, parent_id, sort, hidden, enabled, create_by, create_time, version, deleted) INSERT INTO sys_menu (id, name, path, component, icon, type, parent_id, sort, hidden, enabled, create_by, create_time, version, deleted)
VALUES VALUES
-- 系统管理 -- 系统管理
(1, '系统管理', '/system', 'LAYOUT', 'setting', 1, null, 1, false, true, 'system', '2024-01-01 00:00:00', 0, false), (1, '系统管理', '/system', 'LAYOUT', 'setting', 1, NULL, 1, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 用户管理 -- 用户管理
(2, '用户管理', '/system/user', '/System/User/index', 'user', 2, 1, 10, false, true, 'system', '2024-01-01 00:00:00', 0, false), (2, '用户管理', '/system/user', '/System/User/index', 'user', 2, 1, 10, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 角色管理 -- 角色管理
(3, '角色管理', '/system/role', '/System/Role/index', 'peoples', 2, 1, 20, false, true, 'system', '2024-01-01 00:00:00', 0, false), (3, '角色管理', '/system/role', '/System/Role/index', 'peoples', 2, 1, 20, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 菜单管理 -- 菜单管理
(4, '菜单管理', '/system/menu', '/System/Menu/index', 'tree-table', 2, 1, 30, false, true, 'system', '2024-01-01 00:00:00', 0, false), (4, '菜单管理', '/system/menu', '/System/Menu/index', 'tree-table', 2, 1, 30, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 部门管理 -- 部门管理
(5, '部门管理', '/system/department', '/System/Department/index', 'tree', 2, 1, 40, false, true, 'system', '2024-01-01 00:00:00', 0, false), (5, '部门管理', '/system/department', '/System/Department/index', 'tree', 2, 1, 40, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 三方系统 -- 三方系统
(70, '三方系统', '/system/external', '/System/External/index', 'api', 2, 1, 70, false, true, 'system', '2024-01-01 00:00:00', 0, false); (70, '三方系统', '/system/external', '/System/External/index', 'api', 2, 1, 70, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE);
-- 初始化角色数据 -- 初始化角色数据
INSERT INTO sys_role (id, code, name, type, description, sort, enabled, create_by, create_time, version, deleted) INSERT INTO sys_role (id, code, name, type, description, sort, create_by, create_time, version, deleted)
VALUES (1, 'SUPER_ADMIN', '超级管理员', 1, '系统超级管理员', 1, true, 'system', '2024-01-01 00:00:00', 0, false), VALUES (1, 'SUPER_ADMIN', '超级管理员', 1, '系统超级管理员', 1, 'system', '2024-01-01 00:00:00', 0, FALSE),
(2, 'DEV_MANAGER', '开发主管', 2, '开发团队主管', 2, true, 'system', '2024-01-01 00:00:00', 0, false), (2, 'DEV_MANAGER', '开发主管', 2, '开发团队主管', 2, 'system', '2024-01-01 00:00:00', 0, FALSE),
(3, 'OPS_MANAGER', '运维主管', 2, '运维团队主管', 3, true, 'system', '2024-01-01 00:00:00', 0, false); (3, 'OPS_MANAGER', '运维主管', 2, '运维团队主管', 3, 'system', '2024-01-01 00:00:00', 0, FALSE);
-- 初始化部门数据 -- 初始化部门数据
INSERT INTO sys_department (id, code, name, description, enabled, sort, parent_id, create_by, create_time, version, deleted) INSERT INTO sys_department (id, code, name, description, enabled, sort, parent_id, create_by, create_time, version, deleted)
VALUES (1, 'TECH', '技术部', '技术研发部门', true, 1, null, 'system', '2024-01-01 00:00:00', 0, false), VALUES (1, 'TECH', '技术部', '技术研发部门', TRUE, 1, NULL, 'system', '2024-01-01 00:00:00', 0, FALSE),
(2, 'DEV', '研发组', '研发团队', true, 1, 1, 'system', '2024-01-01 00:00:00', 0, false), (2, 'DEV', '研发组', '研发团队', TRUE, 1, 1, 'system', '2024-01-01 00:00:00', 0, FALSE),
(3, 'OPS', '运维组', '运维团队', true, 2, 1, 'system', '2024-01-01 00:00:00', 0, false); (3, 'OPS', '运维组', '运维团队', TRUE, 2, 1, 'system', '2024-01-01 00:00:00', 0, FALSE);
-- 初始化用户数据 -- 初始化用户数据
INSERT INTO sys_user (id, username, password, nickname, email, phone, enabled, department_id, create_by, create_time, version, deleted) INSERT INTO sys_user (id, username, password, nickname, email, phone, enabled, department_id, create_by, create_time, version, deleted)
VALUES (1, 'admin', '$2a$10$VTbMVv3M.gVaMcLsELtBZuHxGrHyFqf3CYfSFQhcBn0A6pBTvThSy', '系统管理员', 'admin@example.com', '13800138000', true, null, 'system', '2024-01-01 00:00:00', 0, false), VALUES (1, 'admin', '$2a$10$VTbMVv3M.gVaMcLsELtBZuHxGrHyFqf3CYfSFQhcBn0A6pBTvThSy', '系统管理员', 'admin@example.com', '13800138000', TRUE, NULL, 'system', '2024-01-01 00:00:00', 0, FALSE),
(2, 'dev_manager', '$2a$10$VTbMVv3M.gVaMcLsELtBZuHxGrHyFqf3CYfSFQhcBn0A6pBTvThSy', '开发主管', 'dev@example.com', '13800138001', true, 2, 'system', '2024-01-01 00:00:00', 0, false), (2, 'dev_manager', '$2a$10$VTbMVv3M.gVaMcLsELtBZuHxGrHyFqf3CYfSFQhcBn0A6pBTvThSy', '开发主管', 'dev@example.com', '13800138001', TRUE, 2, 'system', '2024-01-01 00:00:00', 0, FALSE),
(3, 'ops_manager', '$2a$10$VTbMVv3M.gVaMcLsELtBZuHxGrHyFqf3CYfSFQhcBn0A6pBTvThSy', '运维主管', 'ops@example.com', '13800138002', true, 3, 'system', '2024-01-01 00:00:00', 0, false); (3, 'ops_manager', '$2a$10$VTbMVv3M.gVaMcLsELtBZuHxGrHyFqf3CYfSFQhcBn0A6pBTvThSy', '运维主管', 'ops@example.com', '13800138002', TRUE, 3, 'system', '2024-01-01 00:00:00', 0, FALSE);
-- 初始化用户角色关联数据 -- 初始化用户角色关联数据
INSERT INTO sys_user_role (user_id, role_id, create_by, create_time, version, deleted) INSERT INTO sys_user_role (user_id, role_id, create_by, create_time, version, deleted)
VALUES (1, 1, 'system', '2024-01-01 00:00:00', 0, false), -- 超级管理员 -> 超级管理员角色 VALUES (1, 1, 'system', '2024-01-01 00:00:00', 0, FALSE), -- 超级管理员 -> 超级管理员角色
(2, 2, 'system', '2024-01-01 00:00:00', 0, false), -- 开发主管 -> 开发主管角色 (2, 2, 'system', '2024-01-01 00:00:00', 0, FALSE), -- 开发主管 -> 开发主管角色
(3, 3, 'system', '2024-01-01 00:00:00', 0, false); -- 运维主管 -> 运维主管角色 (3, 3, 'system', '2024-01-01 00:00:00', 0, FALSE);
-- 运维主管 -> 运维主管角色
-- 初始化角色标签关联数据 -- 初始化角色标签关联数据
INSERT INTO sys_role_tag_relation (role_id, tag_id) INSERT INTO sys_role_tag_relation (role_id, tag_id)
VALUES (1, 3), -- 超级管理员 -> 安全标签 VALUES (1, 3), -- 超级管理员 -> 安全标签
(2, 1), -- 开发主管 -> 研发标签 (2, 1), -- 开发主管 -> 研发标签
(3, 2); -- 运维主管 -> 运维标签 (3, 2);
-- 运维主管 -> 运维标签
-- 初始化角色菜单关联数据 -- 初始化角色菜单关联数据
INSERT INTO sys_role_menu (role_id, menu_id) INSERT INTO sys_role_menu (role_id, menu_id)
VALUES VALUES
-- 超级管理员拥有所有菜单权限 -- 超级管理员拥有所有菜单权限
(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 70), (1, 1),
(1, 2),
(1, 3),
(1, 4),
(1, 5),
(1, 70),
-- 开发主管权限 -- 开发主管权限
(2, 70), (2, 70),
-- 运维主管权限 -- 运维主管权限
(3, 70); (3, 70);
-- 初始化权限数据 -- 初始化权限数据
INSERT INTO sys_permission (id, menu_id, code, name, type, enabled, sort, create_by, create_time, update_by, update_time, version, deleted) INSERT INTO sys_permission (id, menu_id, code, name, type, sort, create_by, create_time, update_by, update_time, version, deleted)
VALUES VALUES
-- 用户管理权限 -- 用户管理权限
(21, 2, 'system:user:add', '用户新增', 'FUNCTION', true, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (21, 2, 'system:user:add', '用户新增', 'FUNCTION', 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(22, 2, 'system:user:edit', '用户编辑', 'FUNCTION', true, 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (22, 2, 'system:user:edit', '用户编辑', 'FUNCTION', 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(23, 2, 'system:user:delete', '用户删除', 'FUNCTION', true, 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (23, 2, 'system:user:delete', '用户删除', 'FUNCTION', 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(24, 2, 'system:user:reset-password', '重置密码', 'FUNCTION', true, 4, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (24, 2, 'system:user:reset-password', '重置密码', 'FUNCTION', 4, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(25, 2, 'system:user:assign-roles', '分配角色', 'FUNCTION', true, 5, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (25, 2, 'system:user:assign-roles', '分配角色', 'FUNCTION', 5, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 角色管理权限 -- 角色管理权限
(31, 3, 'system:role:add', '角色新增', 'FUNCTION', true, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (31, 3, 'system:role:add', '角色新增', 'FUNCTION', 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(32, 3, 'system:role:edit', '角色编辑', 'FUNCTION', true, 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (32, 3, 'system:role:edit', '角色编辑', 'FUNCTION', 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(33, 3, 'system:role:delete', '角色删除', 'FUNCTION', true, 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (33, 3, 'system:role:delete', '角色删除', 'FUNCTION', 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(34, 3, 'system:role:assign-tags', '分配标签', 'FUNCTION', true, 4, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (34, 3, 'system:role:assign-tags', '分配标签', 'FUNCTION', 4, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(35, 3, 'system:role:assign-permissions', '分配权限', 'FUNCTION', true, 5, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (35, 3, 'system:role:assign-permissions', '分配权限', 'FUNCTION', 5, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(36, 3, 'system:role:permission-list', '权限列表', 'FUNCTION', true, 6, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (36, 3, 'system:role:permission-list', '权限列表', 'FUNCTION', 6, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 菜单管理权限 -- 菜单管理权限
(41, 4, 'system:menu:add', '菜单新增', 'FUNCTION', true, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (41, 4, 'system:menu:add', '菜单新增', 'FUNCTION', 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(42, 4, 'system:menu:edit', '菜单编辑', 'FUNCTION', true, 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (42, 4, 'system:menu:edit', '菜单编辑', 'FUNCTION', 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(43, 4, 'system:menu:delete', '菜单删除', 'FUNCTION', true, 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (43, 4, 'system:menu:delete', '菜单删除', 'FUNCTION', 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 部门管理权限 -- 部门管理权限
(51, 5, 'system:department:add', '部门新增', 'FUNCTION', true, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (51, 5, 'system:department:add', '部门新增', 'FUNCTION', 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(52, 5, 'system:department:edit', '部门编辑', 'FUNCTION', true, 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (52, 5, 'system:department:edit', '部门编辑', 'FUNCTION', 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(53, 5, 'system:department:delete', '部门删除', 'FUNCTION', true, 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (53, 5, 'system:department:delete', '部门删除', 'FUNCTION', 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 三方系统管理权限 -- 三方系统管理权限
(71, 70, 'system:external:list', '查看三方系统', 'FUNCTION', true, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (71, 70, 'system:external:list', '查看三方系统', 'FUNCTION', 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(72, 70, 'system:external:create', '新增三方系统', 'FUNCTION', true, 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (72, 70, 'system:external:create', '新增三方系统', 'FUNCTION', 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(73, 70, 'system:external:update', '编辑三方系统', 'FUNCTION', true, 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (73, 70, 'system:external:update', '编辑三方系统', 'FUNCTION', 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(74, 70, 'system:external:delete', '删除三方系统', 'FUNCTION', true, 4, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false), (74, 70, 'system:external:delete', '删除三方系统', 'FUNCTION', 4, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE),
(75, 70, 'system:external:sync', '同步三方系统', 'FUNCTION', true, 5, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, false); (75, 70, 'system:external:sync', '同步三方系统', 'FUNCTION', 5, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 0, FALSE);
-- 初始化角色权限关联数据 -- 初始化角色权限关联数据
INSERT INTO sys_role_permission (role_id, permission_id) INSERT INTO sys_role_permission (role_id, permission_id)
VALUES VALUES
-- 用户管理权限 -- 用户管理权限
(1, 21), (1, 22), (1, 23), (1, 24), (1, 25), (1, 21),
(1, 22),
(1, 23),
(1, 24),
(1, 25),
-- 角色管理权限(包含权限管理功能) -- 角色管理权限(包含权限管理功能)
(1, 31), (1, 32), (1, 33), (1, 34), (1, 35), (1, 36), (1, 31),
(1, 32),
(1, 33),
(1, 34),
(1, 35),
(1, 36),
-- 菜单管理权限 -- 菜单管理权限
(1, 41), (1, 42), (1, 43), (1, 41),
(1, 42),
(1, 43),
-- 部门管理权限 -- 部门管理权限
(1, 51), (1, 52), (1, 53), (1, 51),
(1, 52),
(1, 53),
-- 三方系统管理权限 -- 三方系统管理权限
(1, 71), (1, 72), (1, 73), (1, 74), (1, 75); (1, 71),
(1, 72),
(1, 73),
(1, 74),
(1, 75);
-- 初始化三方系统数据 -- 初始化三方系统数据
INSERT INTO sys_external_system (id, name, type, url, auth_type, username, password, enabled, sort, create_by, create_time, version, deleted, remark) INSERT INTO sys_external_system (id, name, type, url, auth_type, username, password, enabled, sort, create_by, create_time, version, deleted, remark)
VALUES VALUES
-- Jenkins示例 -- Jenkins示例
(1, 'Jenkins-开发环境', 'JENKINS', 'http://jenkins-dev.example.com', 'BASIC', 'admin', 'password123', true, 1, 'system', '2024-01-01 00:00:00', 0, false, 'Jenkins开发环境'), (1, 'Jenkins-开发环境', 'JENKINS', 'http://jenkins-dev.example.com', 'BASIC', 'admin', 'password123', TRUE, 1, 'system', '2024-01-01 00:00:00', 0, FALSE, 'Jenkins开发环境'),
(2, 'Jenkins-测试环境', 'JENKINS', 'http://jenkins-test.example.com', 'BASIC', 'admin', 'password123', true, 2, 'system', '2024-01-01 00:00:00', 0, false, 'Jenkins测试环境'), (2, 'Jenkins-测试环境', 'JENKINS', 'http://jenkins-test.example.com', 'BASIC', 'admin', 'password123', TRUE, 2, 'system', '2024-01-01 00:00:00', 0, FALSE, 'Jenkins测试环境'),
-- Git仓库示例 -- Git仓库示例
(3, 'GitLab-主库', 'GIT', 'http://gitlab.example.com', 'TOKEN', null, null, true, 3, 'system', '2024-01-01 00:00:00', 0, false, '公司GitLab主库'), (3, 'GitLab-主库', 'GIT', 'http://gitlab.example.com', 'TOKEN', NULL, NULL, TRUE, 3, 'system', '2024-01-01 00:00:00', 0, FALSE, '公司GitLab主库'),
(4, 'GitHub', 'GIT', 'https://github.com', 'OAUTH', null, null, true, 4, 'system', '2024-01-01 00:00:00', 0, false, 'GitHub仓库'), (4, 'GitHub', 'GIT', 'https://github.com', 'OAUTH', NULL, NULL, TRUE, 4, 'system', '2024-01-01 00:00:00', 0, FALSE, 'GitHub仓库'),
-- 禅道示例 -- 禅道示例
(5, '禅道-项目管理', 'ZENTAO', 'http://zentao.example.com', 'BASIC', 'admin', 'password123', true, 5, 'system', '2024-01-01 00:00:00', 0, false, '禅道项目管理系统'); (5, '禅道-项目管理', 'ZENTAO', 'http://zentao.example.com', 'BASIC', 'admin', 'password123', TRUE, 5, 'system', '2024-01-01 00:00:00', 0, FALSE, '禅道项目管理系统');