diff --git a/harmonylife_20240923_登录和获取用户信息完成.sql b/harmonylife_20240923_登录和获取用户信息完成.sql new file mode 100644 index 0000000..b5d3fa7 --- /dev/null +++ b/harmonylife_20240923_登录和获取用户信息完成.sql @@ -0,0 +1,198 @@ +/* + Navicat Premium Data Transfer + + Source Server : 本地连接 + Source Server Type : MySQL + Source Server Version : 50743 (5.7.43-log) + Source Host : localhost:3306 + Source Schema : harmonylife + + Target Server Type : MySQL + Target Server Version : 50743 (5.7.43-log) + File Encoding : 65001 + + Date: 23/09/2024 17:23:08 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for system_action +-- ---------------------------- +DROP TABLE IF EXISTS `system_action`; +CREATE TABLE `system_action` ( + `id` bigint(11) NOT NULL COMMENT '动作id', + `tag` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '动作标签 例如 add', + `describe` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '动作标题 例如 增加', + `default_check` tinyint(4) NULL DEFAULT NULL COMMENT '0 false 1 true', + `status` tinyint(4) NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '动作表' ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of system_action +-- ---------------------------- +INSERT INTO `system_action` VALUES (1, 'add', '新增', 0, 1); +INSERT INTO `system_action` VALUES (2, 'import', '导入', 0, 1); +INSERT INTO `system_action` VALUES (3, 'get', '详情', 0, 1); +INSERT INTO `system_action` VALUES (4, 'update', '更新', 0, 1); +INSERT INTO `system_action` VALUES (5, 'delete', '删除', 0, 1); +INSERT INTO `system_action` VALUES (6, 'export', '导出', 0, 1); + +-- ---------------------------- +-- Table structure for system_menu +-- ---------------------------- +DROP TABLE IF EXISTS `system_menu`; +CREATE TABLE `system_menu` ( + `id` bigint(11) NOT NULL COMMENT 'id', + `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '显示的中文名称', + `key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'key', + `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '路由名称', + `component` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '组件名称', + `redirect` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '重定向', + `icon` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '图标名称', + `status` tinyint(4) NULL DEFAULT NULL COMMENT '状态 0 未启用 -1 删除 1正常使用', + `parent` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '父级', + `order` int(11) NULL DEFAULT NULL COMMENT '排序,数字越小,越靠前', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of system_menu +-- ---------------------------- +INSERT INTO `system_menu` VALUES (1, '首页', NULL, 'index', 'BasicLayout', '/dashboard/workplace', '', 1, NULL, 1); +INSERT INTO `system_menu` VALUES (2, '仪表盘', 'dashboard', 'dashboard', 'RouteView', NULL, 'dashboard', 1, 'index', 1); +INSERT INTO `system_menu` VALUES (3, '分析页', 'analysis', NULL, NULL, NULL, NULL, NULL, NULL, 1); +INSERT INTO `system_menu` VALUES (4, '系统管理', 'system', 'system', 'PageView', NULL, 'setting', NULL, 'index', 1); +INSERT INTO `system_menu` VALUES (5, '用户管理', 'userList', 'userList', NULL, NULL, NULL, NULL, 'system', 1); +INSERT INTO `system_menu` VALUES (6, '菜单管理', 'menuList', 'menuList', NULL, NULL, NULL, NULL, 'system', 1); + +-- ---------------------------- +-- Table structure for system_permission +-- ---------------------------- +DROP TABLE IF EXISTS `system_permission`; +CREATE TABLE `system_permission` ( + `id` bigint(11) NOT NULL COMMENT '权限id', + `permission_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限id(文本型)', + `permission_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限名称(菜单名称)', + `status` tinyint(4) NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '权限表' ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of system_permission +-- ---------------------------- +INSERT INTO `system_permission` VALUES (1, 'dashboard', '数据中心', 1); +INSERT INTO `system_permission` VALUES (2, 'exception', '异常管理', 1); +INSERT INTO `system_permission` VALUES (3, 'result', '结果管理', 1); +INSERT INTO `system_permission` VALUES (4, 'profile', '个人信息管理', 1); +INSERT INTO `system_permission` VALUES (5, 'table', '表格管理', 1); +INSERT INTO `system_permission` VALUES (6, 'form', '表单管理', 1); +INSERT INTO `system_permission` VALUES (7, 'order', '订单管理', 1); +INSERT INTO `system_permission` VALUES (8, 'permission', '权限管理', 1); +INSERT INTO `system_permission` VALUES (9, 'role', '角色管理', 1); +INSERT INTO `system_permission` VALUES (10, 'user', '用户管理', 1); + +-- ---------------------------- +-- Table structure for system_permission_action +-- ---------------------------- +DROP TABLE IF EXISTS `system_permission_action`; +CREATE TABLE `system_permission_action` ( + `id` bigint(11) NOT NULL COMMENT 'id', + `action_tag` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '动作id 文本型', + `permission_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限id 文本型', + `status` tinyint(4) NULL DEFAULT NULL COMMENT '状态', + `uid` bigint(20) NULL DEFAULT NULL COMMENT '用户id Long', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of system_permission_action +-- ---------------------------- +INSERT INTO `system_permission_action` VALUES (1, 'add', 'role', 1, 1); +INSERT INTO `system_permission_action` VALUES (2, 'import', 'role', 1, 1); +INSERT INTO `system_permission_action` VALUES (3, 'get', 'role', 1, 1); +INSERT INTO `system_permission_action` VALUES (4, 'update', 'role', 1, 1); +INSERT INTO `system_permission_action` VALUES (5, 'delete', 'role', 1, 1); +INSERT INTO `system_permission_action` VALUES (6, 'export', 'role', 1, 1); +INSERT INTO `system_permission_action` VALUES (7, 'add', 'permission', 1, 1); +INSERT INTO `system_permission_action` VALUES (8, 'import', 'permission', 1, 1); +INSERT INTO `system_permission_action` VALUES (9, 'get', 'permission', 1, 1); +INSERT INTO `system_permission_action` VALUES (10, 'update', 'permission', 1, 1); +INSERT INTO `system_permission_action` VALUES (11, 'delete', 'permission', 1, 1); +INSERT INTO `system_permission_action` VALUES (12, 'export', 'permission', 1, 1); + +-- ---------------------------- +-- Table structure for system_role +-- ---------------------------- +DROP TABLE IF EXISTS `system_role`; +CREATE TABLE `system_role` ( + `id` bigint(11) NOT NULL COMMENT '角色id role_id', + `role_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '角色名称', + `role_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '角色id(文本型)', + `status` tinyint(4) NULL DEFAULT NULL, + `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '描述', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '角色表' ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of system_role +-- ---------------------------- +INSERT INTO `system_role` VALUES (1, '超级管理员', 'root', 1, '最高权限'); +INSERT INTO `system_role` VALUES (2, '管理员', 'admin', 1, '管理权限'); +INSERT INTO `system_role` VALUES (3, '机构', 'agent', 1, '使用权限'); + +-- ---------------------------- +-- Table structure for system_role_permission +-- ---------------------------- +DROP TABLE IF EXISTS `system_role_permission`; +CREATE TABLE `system_role_permission` ( + `id` bigint(11) NOT NULL, + `role_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '注意是文本型', + `permission_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '注意是文本型', + `status` tinyint(4) NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of system_role_permission +-- ---------------------------- +INSERT INTO `system_role_permission` VALUES (1, 'root', 'dashboard', 1); +INSERT INTO `system_role_permission` VALUES (2, 'root', 'exception', 1); +INSERT INTO `system_role_permission` VALUES (3, 'root', 'result', 1); +INSERT INTO `system_role_permission` VALUES (4, 'root', 'profile', 1); +INSERT INTO `system_role_permission` VALUES (5, 'root', 'table', 1); +INSERT INTO `system_role_permission` VALUES (6, 'root', 'form', 1); +INSERT INTO `system_role_permission` VALUES (7, 'root', 'order', 1); +INSERT INTO `system_role_permission` VALUES (8, 'root', 'permission', 1); +INSERT INTO `system_role_permission` VALUES (9, 'root', 'role', 1); +INSERT INTO `system_role_permission` VALUES (10, 'root', 'user', 1); + +-- ---------------------------- +-- Table structure for user_info +-- ---------------------------- +DROP TABLE IF EXISTS `user_info`; +CREATE TABLE `user_info` ( + `id` bigint(11) NOT NULL COMMENT '用户uid', + `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '昵称(用于显示,可以随意更改)', + `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户名(登录使用的账号)', + `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '密码', + `avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '头像图片地址', + `status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '状态', + `telephone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '手机号', + `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '邮箱', + `create_time` datetime NULL DEFAULT NULL COMMENT '注册时间', + `merchant_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '商户编号', + `deleted` tinyint(4) NULL DEFAULT NULL COMMENT '1 已删除 0未删除', + `role_id` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限id 文本类型', + `creator_id` int(11) NULL DEFAULT NULL COMMENT '创建者id 0 或者空为自己注册', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of user_info +-- ---------------------------- +INSERT INTO `user_info` VALUES (1, '萌狼蓝天', 'xrilang', 'VomAhgnr1XAkMKzicqYxdCFBx0ooiXBN66Xq9XCWGJTsJgH3uLJVAVGkoZi2n1Ml', 'https://q1.qlogo.cn/g?b=qq&nk=3447902411&s=640', '1', NULL, NULL, '2024-09-21 22:31:02', NULL, 0, 'root', NULL); + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/pom.xml b/pom.xml index 96de77e..3e515c3 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,12 @@ logback-classic 1.5.8 + + org.fusesource.jansi + jansi + 2.4.0 + + diff --git a/src/main/java/com/guaiguailang/harmony/controller/SystemController.java b/src/main/java/com/guaiguailang/harmony/controller/SystemController.java new file mode 100644 index 0000000..bc42d28 --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/controller/SystemController.java @@ -0,0 +1,35 @@ +package com.guaiguailang.harmony.controller; + +import cn.dev33.satoken.stp.StpUtil; +import com.guaiguailang.harmony.service.SystemService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Tag(name="系统相关接口") +@RequestMapping("/system") +public class SystemController { + @Autowired + private final SystemService systemService; + + public SystemController(SystemService systemService) { + this.systemService = systemService; + } + + @Operation( + summary = "菜单 加载", + description = "加载用户拥有的菜单", + tags = {"系统相关接口"} + ) + @GetMapping("/menu") + public ResponseEntity getMenu() { + return ResponseEntity.ok(systemService.getMenu()); + } + +} diff --git a/src/main/java/com/guaiguailang/harmony/domain/entity/SystemMenu.java b/src/main/java/com/guaiguailang/harmony/domain/entity/SystemMenu.java index 0ea3657..640f0d6 100644 --- a/src/main/java/com/guaiguailang/harmony/domain/entity/SystemMenu.java +++ b/src/main/java/com/guaiguailang/harmony/domain/entity/SystemMenu.java @@ -1,77 +1,18 @@ package com.guaiguailang.harmony.domain.entity; +import lombok.Data; +@Data public class SystemMenu { - private long id; + private Long id; + private String title; private String key; private String name; private String component; private String redirect; private String icon; - private long status; - - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - - public String getComponent() { - return component; - } - - public void setComponent(String component) { - this.component = component; - } - - - public String getRedirect() { - return redirect; - } - - public void setRedirect(String redirect) { - this.redirect = redirect; - } - - - public String getIcon() { - return icon; - } - - public void setIcon(String icon) { - this.icon = icon; - } - - - public long getStatus() { - return status; - } - - public void setStatus(long status) { - this.status = status; - } - + private int status; + private String parent; + private int order; } diff --git a/src/main/java/com/guaiguailang/harmony/domain/entity/SystemPermission.java b/src/main/java/com/guaiguailang/harmony/domain/entity/SystemPermission.java index 4499b1d..a2a8fb6 100644 --- a/src/main/java/com/guaiguailang/harmony/domain/entity/SystemPermission.java +++ b/src/main/java/com/guaiguailang/harmony/domain/entity/SystemPermission.java @@ -1,47 +1,12 @@ package com.guaiguailang.harmony.domain.entity; +import lombok.Data; +@Data public class SystemPermission { - private long id; + private Long id; private String permissionId; private String permissionName; - private long status; - - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - - public String getPermissionId() { - return permissionId; - } - - public void setPermissionId(String permissionId) { - this.permissionId = permissionId; - } - - - public String getPermissionName() { - return permissionName; - } - - public void setPermissionName(String permissionName) { - this.permissionName = permissionName; - } - - - public long getStatus() { - return status; - } - - public void setStatus(long status) { - this.status = status; - } - + private int status; } diff --git a/src/main/java/com/guaiguailang/harmony/domain/entity/SystemRolePermission.java b/src/main/java/com/guaiguailang/harmony/domain/entity/SystemRolePermission.java index 1b326a8..6a9e0d6 100644 --- a/src/main/java/com/guaiguailang/harmony/domain/entity/SystemRolePermission.java +++ b/src/main/java/com/guaiguailang/harmony/domain/entity/SystemRolePermission.java @@ -6,42 +6,6 @@ public class SystemRolePermission { private long id; private String roleId; private String permissionId; - private long status; - - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - - public String getRoleId() { - return roleId; - } - - public void setRoleId(String roleId) { - this.roleId = roleId; - } - - - public String getPermissionId() { - return permissionId; - } - - public void setPermissionId(String permissionId) { - this.permissionId = permissionId; - } - - - public long getStatus() { - return status; - } - - public void setStatus(long status) { - this.status = status; - } + private Long status; } diff --git a/src/main/java/com/guaiguailang/harmony/domain/vo/MenuVO.java b/src/main/java/com/guaiguailang/harmony/domain/vo/MenuVO.java new file mode 100644 index 0000000..70d5faf --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/domain/vo/MenuVO.java @@ -0,0 +1,21 @@ +package com.guaiguailang.harmony.domain.vo; + +import lombok.Data; + +import java.util.List; + +@Data +public class MenuVO { + private Long id; + private String title; + private String key; + private String name; + private String component; + private String redirect; + private String icon; + private int status; + private String parent; + private int order; + + private List children; +} diff --git a/src/main/java/com/guaiguailang/harmony/mapper/SystemMapper.java b/src/main/java/com/guaiguailang/harmony/mapper/SystemMapper.java new file mode 100644 index 0000000..f870a99 --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/mapper/SystemMapper.java @@ -0,0 +1,11 @@ +package com.guaiguailang.harmony.mapper; + +import com.guaiguailang.harmony.domain.entity.SystemMenu; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface SystemMapper { + List getAllMenus(); +} diff --git a/src/main/java/com/guaiguailang/harmony/service/SystemService.java b/src/main/java/com/guaiguailang/harmony/service/SystemService.java new file mode 100644 index 0000000..059191e --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/service/SystemService.java @@ -0,0 +1,7 @@ +package com.guaiguailang.harmony.service; + +import com.guaiguailang.harmony.domain.vo.ResponseResult; + +public interface SystemService { + ResponseResult getMenu(); +} diff --git a/src/main/java/com/guaiguailang/harmony/service/impl/SystemServiceImpl.java b/src/main/java/com/guaiguailang/harmony/service/impl/SystemServiceImpl.java new file mode 100644 index 0000000..d2d5b70 --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/service/impl/SystemServiceImpl.java @@ -0,0 +1,66 @@ +package com.guaiguailang.harmony.service.impl; + +import com.guaiguailang.harmony.domain.entity.SystemMenu; +import com.guaiguailang.harmony.domain.vo.MenuVO; +import com.guaiguailang.harmony.domain.vo.ResponseResult; +import com.guaiguailang.harmony.mapper.SystemMapper; +import com.guaiguailang.harmony.service.SystemService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class SystemServiceImpl implements SystemService { + + private final SystemMapper systemMapper; + + public SystemServiceImpl(SystemMapper systemMapper) { + this.systemMapper = systemMapper; + } + + public ResponseResult getMenu() { + // 获取所有激活的状态菜单 + List menus = systemMapper.getAllMenus(); + Map menuMap = new HashMap<>(); + List rootMenus = new ArrayList<>(); + // 第一步:将SystemMenu转换为MenuVO并存储在map中 + for (SystemMenu menu : menus) { + MenuVO menuVO = new MenuVO(); + menuVO.setId(menu.getId()); + menuVO.setTitle(menu.getTitle()); + menuVO.setKey(menu.getKey()); + menuVO.setName(menu.getName()); + menuVO.setComponent(menu.getComponent()); + menuVO.setRedirect(menu.getRedirect()); + menuVO.setIcon(menu.getIcon()); + menuVO.setStatus(menu.getStatus()); + menuVO.setOrder(menu.getOrder()); + menuVO.setParent(menu.getParent()); + menuMap.put(menu.getName(), menuVO); + } + // 第二步:构建树形结构 + for (MenuVO menuVO : menuMap.values()) { + String parentId = menuVO.getParent(); + if (parentId == null) { + // 没有父菜单,即为根菜单 + rootMenus.add(menuVO); + } else { + // 查找父菜单并添加到其子菜单列表中 + MenuVO parentMenuVO = menuMap.get(parentId); + if (parentMenuVO != null) { + if (parentMenuVO.getChildren() == null) { + parentMenuVO.setChildren(new ArrayList<>()); + } + parentMenuVO.getChildren().add(menuVO); + } + } + } + return ResponseResult.success(rootMenus); + } + +} diff --git a/src/main/resources/mapper/SystemMapper.xml b/src/main/resources/mapper/SystemMapper.xml new file mode 100644 index 0000000..ecc1d37 --- /dev/null +++ b/src/main/resources/mapper/SystemMapper.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file